msi: Support remote calls to MsiEnumComponentCosts.
[wine/multimedia.git] / dlls / msi / msi.c
blobd48d1d140b3de79a98c7e1d0dbf90a5c8254d22c
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 "msi.h"
32 #include "msidefs.h"
33 #include "msiquery.h"
34 #include "msipriv.h"
35 #include "msiserver.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 "wintrust.h"
43 #include "softpub.h"
45 #include "wine/debug.h"
46 #include "wine/unicode.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msi);
50 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
52 static UINT msi_locate_product(LPCWSTR szProduct, MSIINSTALLCONTEXT *context)
54 HKEY hkey = NULL;
56 *context = MSIINSTALLCONTEXT_NONE;
58 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
59 &hkey, FALSE) == ERROR_SUCCESS)
60 *context = MSIINSTALLCONTEXT_USERMANAGED;
61 else if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
62 &hkey, FALSE) == ERROR_SUCCESS)
63 *context = MSIINSTALLCONTEXT_MACHINE;
64 else if (MSIREG_OpenProductKey(szProduct, NULL,
65 MSIINSTALLCONTEXT_USERUNMANAGED,
66 &hkey, FALSE) == ERROR_SUCCESS)
67 *context = MSIINSTALLCONTEXT_USERUNMANAGED;
69 RegCloseKey(hkey);
71 if (*context == MSIINSTALLCONTEXT_NONE)
72 return ERROR_UNKNOWN_PRODUCT;
74 return ERROR_SUCCESS;
77 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
79 UINT r;
80 LPWSTR szwProd = NULL;
82 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
84 if( szProduct )
86 szwProd = strdupAtoW( szProduct );
87 if( !szwProd )
88 return ERROR_OUTOFMEMORY;
91 r = MsiOpenProductW( szwProd, phProduct );
93 msi_free( szwProd );
95 return r;
98 static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
100 UINT r;
101 HKEY props;
102 LPWSTR path;
103 MSIINSTALLCONTEXT context;
105 static const WCHAR managed[] = {
106 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
107 static const WCHAR local[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
109 TRACE("%s %p\n", debugstr_w(szProduct), package);
111 r = msi_locate_product(szProduct, &context);
112 if (r != ERROR_SUCCESS)
113 return r;
115 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &props, FALSE);
116 if (r != ERROR_SUCCESS)
117 return ERROR_UNKNOWN_PRODUCT;
119 if (context == MSIINSTALLCONTEXT_USERMANAGED)
120 path = msi_reg_get_val_str(props, managed);
121 else
122 path = msi_reg_get_val_str(props, local);
124 r = ERROR_UNKNOWN_PRODUCT;
126 if (!path || GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
127 goto done;
129 if (PathIsRelativeW(path))
131 r = ERROR_INSTALL_PACKAGE_OPEN_FAILED;
132 goto done;
135 r = MSI_OpenPackageW(path, package);
137 done:
138 RegCloseKey(props);
139 msi_free(path);
140 return r;
143 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
145 MSIPACKAGE *package = NULL;
146 WCHAR squished_pc[GUID_SIZE];
147 UINT r;
149 if (!szProduct || !squash_guid(szProduct, squished_pc))
150 return ERROR_INVALID_PARAMETER;
152 if (!phProduct)
153 return ERROR_INVALID_PARAMETER;
155 r = MSI_OpenProductW(szProduct, &package);
156 if (r != ERROR_SUCCESS)
157 return r;
159 *phProduct = alloc_msihandle(&package->hdr);
160 if (!*phProduct)
161 r = ERROR_NOT_ENOUGH_MEMORY;
163 msiobj_release(&package->hdr);
164 return r;
167 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
168 LPCSTR szTransforms, LANGID lgidLanguage)
170 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
171 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
172 return ERROR_CALL_NOT_IMPLEMENTED;
175 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
176 LPCWSTR szTransforms, LANGID lgidLanguage)
178 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
179 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
180 return ERROR_CALL_NOT_IMPLEMENTED;
183 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
184 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
186 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
187 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
188 lgidLanguage, dwPlatform, dwOptions);
189 return ERROR_CALL_NOT_IMPLEMENTED;
192 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
193 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
195 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
196 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
197 lgidLanguage, dwPlatform, dwOptions);
198 return ERROR_CALL_NOT_IMPLEMENTED;
201 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
203 LPWSTR szwPath = NULL, szwCommand = NULL;
204 UINT r = ERROR_OUTOFMEMORY;
206 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
208 if( szPackagePath )
210 szwPath = strdupAtoW( szPackagePath );
211 if( !szwPath )
212 goto end;
215 if( szCommandLine )
217 szwCommand = strdupAtoW( szCommandLine );
218 if( !szwCommand )
219 goto end;
222 r = MsiInstallProductW( szwPath, szwCommand );
224 end:
225 msi_free( szwPath );
226 msi_free( szwCommand );
228 return r;
231 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
233 MSIPACKAGE *package = NULL;
234 UINT r;
236 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
238 if (!szPackagePath)
239 return ERROR_INVALID_PARAMETER;
241 if (!*szPackagePath)
242 return ERROR_PATH_NOT_FOUND;
244 r = MSI_OpenPackageW( szPackagePath, &package );
245 if (r == ERROR_SUCCESS)
247 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
248 msiobj_release( &package->hdr );
251 return r;
254 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
256 LPWSTR wszProduct;
257 UINT rc;
259 TRACE("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
261 wszProduct = strdupAtoW(szProduct);
263 rc = MsiReinstallProductW(wszProduct, dwReinstallMode);
265 msi_free(wszProduct);
266 return rc;
269 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
271 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
273 return MsiReinstallFeatureW(szProduct, szAll, dwReinstallMode);
276 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
277 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
279 LPWSTR patch_package = NULL;
280 LPWSTR install_package = NULL;
281 LPWSTR command_line = NULL;
282 UINT r = ERROR_OUTOFMEMORY;
284 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
285 eInstallType, debugstr_a(szCommandLine));
287 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
288 goto done;
290 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
291 goto done;
293 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
294 goto done;
296 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
298 done:
299 msi_free(patch_package);
300 msi_free(install_package);
301 msi_free(command_line);
303 return r;
307 static UINT get_patch_product_codes( LPCWSTR szPatchPackage, WCHAR ***product_codes )
309 MSIHANDLE patch, info = 0;
310 UINT r, type;
311 DWORD size;
312 static WCHAR empty[] = {0};
313 WCHAR *codes = NULL;
315 r = MsiOpenDatabaseW( szPatchPackage, MSIDBOPEN_READONLY, &patch );
316 if (r != ERROR_SUCCESS)
317 return r;
319 r = MsiGetSummaryInformationW( patch, NULL, 0, &info );
320 if (r != ERROR_SUCCESS)
321 goto done;
323 size = 0;
324 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, empty, &size );
325 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
327 ERR("Failed to read product codes from patch\n");
328 r = ERROR_FUNCTION_FAILED;
329 goto done;
332 codes = msi_alloc( ++size * sizeof(WCHAR) );
333 if (!codes)
335 r = ERROR_OUTOFMEMORY;
336 goto done;
339 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, codes, &size );
340 if (r == ERROR_SUCCESS)
341 *product_codes = msi_split_string( codes, ';' );
343 done:
344 MsiCloseHandle( info );
345 MsiCloseHandle( patch );
346 msi_free( codes );
347 return r;
350 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
352 UINT r, i;
353 DWORD size;
354 LPCWSTR cmd_ptr = szCommandLine;
355 LPWSTR cmd, *codes = NULL;
356 BOOL succeeded = FALSE;
358 static const WCHAR fmt[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
359 static WCHAR empty[] = {0};
361 if (!szPatchPackage || !szPatchPackage[0])
362 return ERROR_INVALID_PARAMETER;
364 if (!szProductCode && (r = get_patch_product_codes( szPatchPackage, &codes )))
365 return r;
367 if (!szCommandLine)
368 cmd_ptr = empty;
370 size = strlenW(cmd_ptr) + strlenW(fmt) + strlenW(szPatchPackage) + 1;
371 cmd = msi_alloc(size * sizeof(WCHAR));
372 if (!cmd)
374 msi_free(codes);
375 return ERROR_OUTOFMEMORY;
377 sprintfW(cmd, fmt, cmd_ptr, szPatchPackage);
379 if (szProductCode)
380 r = MsiConfigureProductExW(szProductCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
381 else
383 for (i = 0; codes[i]; i++)
385 r = MsiConfigureProductExW(codes[i], INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
386 if (r == ERROR_SUCCESS)
388 TRACE("patch applied\n");
389 succeeded = TRUE;
393 if (succeeded)
394 r = ERROR_SUCCESS;
397 msi_free(cmd);
398 msi_free(codes);
399 return r;
402 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
403 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
405 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
406 eInstallType, debugstr_w(szCommandLine));
408 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
409 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
411 FIXME("Only reading target products from patch\n");
412 return ERROR_CALL_NOT_IMPLEMENTED;
415 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
418 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
419 LPCSTR szProductCode, LPCSTR szPropertiesList)
421 LPWSTR patch_packages = NULL;
422 LPWSTR product_code = NULL;
423 LPWSTR properties_list = NULL;
424 UINT r = ERROR_OUTOFMEMORY;
426 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
427 debugstr_a(szPropertiesList));
429 if (!szPatchPackages || !szPatchPackages[0])
430 return ERROR_INVALID_PARAMETER;
432 if (!(patch_packages = strdupAtoW(szPatchPackages)))
433 return ERROR_OUTOFMEMORY;
435 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
436 goto done;
438 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
439 goto done;
441 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
443 done:
444 msi_free(patch_packages);
445 msi_free(product_code);
446 msi_free(properties_list);
448 return r;
451 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
452 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
454 UINT r = ERROR_SUCCESS;
455 LPCWSTR beg, end;
457 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
458 debugstr_w(szPropertiesList));
460 if (!szPatchPackages || !szPatchPackages[0])
461 return ERROR_INVALID_PARAMETER;
463 beg = end = szPatchPackages;
464 while (*beg)
466 DWORD len;
467 LPWSTR patch;
469 while (*beg == ' ') beg++;
470 while (*end && *end != ';') end++;
472 len = end - beg;
473 while (len && beg[len - 1] == ' ') len--;
475 if (!len) return ERROR_INVALID_NAME;
477 patch = msi_alloc((len + 1) * sizeof(WCHAR));
478 if (!patch)
479 return ERROR_OUTOFMEMORY;
481 memcpy(patch, beg, len * sizeof(WCHAR));
482 patch[len] = '\0';
484 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
485 msi_free(patch);
487 if (r != ERROR_SUCCESS)
488 break;
490 beg = ++end;
492 return r;
495 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
496 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
498 UINT i, r;
499 WCHAR *package_path = NULL;
500 MSIPATCHSEQUENCEINFOW *psi;
502 TRACE("(%s, %d, %p)\n", debugstr_a(szProductPackagePath), cPatchInfo, pPatchInfo);
504 if (szProductPackagePath && !(package_path = strdupAtoW( szProductPackagePath )))
505 return ERROR_OUTOFMEMORY;
507 psi = msi_alloc( cPatchInfo * sizeof(*psi) );
508 if (!psi)
510 msi_free( package_path );
511 return ERROR_OUTOFMEMORY;
514 for (i = 0; i < cPatchInfo; i++)
516 psi[i].szPatchData = strdupAtoW( pPatchInfo[i].szPatchData );
517 psi[i].ePatchDataType = pPatchInfo[i].ePatchDataType;
520 r = MsiDetermineApplicablePatchesW( package_path, cPatchInfo, psi );
521 if (r == ERROR_SUCCESS)
523 for (i = 0; i < cPatchInfo; i++)
525 pPatchInfo[i].dwOrder = psi[i].dwOrder;
526 pPatchInfo[i].uStatus = psi[i].uStatus;
530 msi_free( package_path );
531 for (i = 0; i < cPatchInfo; i++)
532 msi_free( (WCHAR *)psi[i].szPatchData );
533 msi_free( psi );
534 return r;
537 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
539 MSISUMMARYINFO *si;
540 MSIDATABASE *patch_db;
541 UINT r = ERROR_SUCCESS;
543 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
544 if (r != ERROR_SUCCESS)
546 WARN("failed to open patch file %s\n", debugstr_w(patch));
547 return r;
550 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
551 if (!si)
553 msiobj_release( &patch_db->hdr );
554 return ERROR_FUNCTION_FAILED;
557 r = msi_check_patch_applicable( package, si );
558 if (r != ERROR_SUCCESS)
559 TRACE("patch not applicable\n");
561 msiobj_release( &patch_db->hdr );
562 msiobj_release( &si->hdr );
563 return r;
566 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
567 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
569 UINT i, r, ret = ERROR_FUNCTION_FAILED;
570 MSIPACKAGE *package;
572 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
574 r = MSI_OpenPackageW( szProductPackagePath, &package );
575 if (r != ERROR_SUCCESS)
577 ERR("failed to open package %u\n", r);
578 return r;
581 for (i = 0; i < cPatchInfo; i++)
583 switch (pPatchInfo[i].ePatchDataType)
585 case MSIPATCH_DATATYPE_PATCHFILE:
587 FIXME("patch ordering not supported\n");
588 r = MSI_ApplicablePatchW( package, pPatchInfo[i].szPatchData );
589 if (r != ERROR_SUCCESS)
591 pPatchInfo[i].dwOrder = ~0u;
592 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
594 else
596 pPatchInfo[i].dwOrder = i;
597 pPatchInfo[i].uStatus = ret = ERROR_SUCCESS;
599 break;
601 default:
603 FIXME("patch data type %u not supported\n", pPatchInfo[i].ePatchDataType);
604 pPatchInfo[i].dwOrder = ~0u;
605 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
606 break;
610 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo[i].szPatchData));
611 TRACE("ePatchDataType: %u\n", pPatchInfo[i].ePatchDataType);
612 TRACE(" dwOrder: %u\n", pPatchInfo[i].dwOrder);
613 TRACE(" uStatus: %u\n", pPatchInfo[i].uStatus);
615 return ret;
618 UINT WINAPI MsiDeterminePatchSequenceA(LPCSTR szProductCode, LPCSTR szUserSid,
619 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
621 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode),
622 debugstr_a(szUserSid), dwContext, cPatchInfo, pPatchInfo);
624 return ERROR_CALL_NOT_IMPLEMENTED;
627 UINT WINAPI MsiDeterminePatchSequenceW(LPCWSTR szProductCode, LPCWSTR szUserSid,
628 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
630 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode),
631 debugstr_w(szUserSid), dwContext, cPatchInfo, pPatchInfo);
633 return ERROR_CALL_NOT_IMPLEMENTED;
636 static UINT msi_open_package(LPCWSTR product, MSIINSTALLCONTEXT context,
637 MSIPACKAGE **package)
639 UINT r;
640 DWORD sz;
641 HKEY props;
642 LPWSTR localpack;
643 WCHAR sourcepath[MAX_PATH];
644 WCHAR filename[MAX_PATH];
646 r = MSIREG_OpenInstallProps(product, context, NULL, &props, FALSE);
647 if (r != ERROR_SUCCESS)
648 return ERROR_BAD_CONFIGURATION;
650 localpack = msi_reg_get_val_str(props, szLocalPackage);
651 if (localpack)
653 lstrcpyW(sourcepath, localpack);
654 msi_free(localpack);
657 if (!localpack || GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
659 sz = sizeof(sourcepath);
660 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
661 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
663 sz = sizeof(filename);
664 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
665 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
667 lstrcatW(sourcepath, filename);
670 if (GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
671 return ERROR_INSTALL_SOURCE_ABSENT;
673 return MSI_OpenPackageW(sourcepath, package);
676 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
677 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
679 MSIPACKAGE* package = NULL;
680 MSIINSTALLCONTEXT context;
681 UINT r;
682 DWORD sz;
683 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
684 LPWSTR commandline;
686 static const WCHAR szInstalled[] = {
687 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
688 static const WCHAR szInstallLevel[] = {
689 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
690 static const WCHAR szRemoveAll[] = {
691 ' ','R','E','M','O','V','E','=','A','L','L',0};
692 static const WCHAR szMachine[] = {
693 ' ','A','L','L','U','S','E','R','S','=','1',0};
695 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
696 debugstr_w(szCommandLine));
698 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
699 return ERROR_INVALID_PARAMETER;
701 if (eInstallState == INSTALLSTATE_ADVERTISED ||
702 eInstallState == INSTALLSTATE_SOURCE)
704 FIXME("State %d not implemented\n", eInstallState);
705 return ERROR_CALL_NOT_IMPLEMENTED;
708 r = msi_locate_product(szProduct, &context);
709 if (r != ERROR_SUCCESS)
710 return r;
712 r = msi_open_package(szProduct, context, &package);
713 if (r != ERROR_SUCCESS)
714 return r;
716 sz = lstrlenW(szInstalled) + 1;
718 if (szCommandLine)
719 sz += lstrlenW(szCommandLine);
721 if (eInstallState != INSTALLSTATE_DEFAULT)
722 sz += lstrlenW(szInstallLevel);
724 if (eInstallState == INSTALLSTATE_ABSENT)
725 sz += lstrlenW(szRemoveAll);
727 if (context == MSIINSTALLCONTEXT_MACHINE)
728 sz += lstrlenW(szMachine);
730 commandline = msi_alloc(sz * sizeof(WCHAR));
731 if (!commandline)
733 r = ERROR_OUTOFMEMORY;
734 goto end;
737 commandline[0] = 0;
738 if (szCommandLine)
739 lstrcpyW(commandline,szCommandLine);
741 if (eInstallState != INSTALLSTATE_DEFAULT)
742 lstrcatW(commandline, szInstallLevel);
744 if (eInstallState == INSTALLSTATE_ABSENT)
745 lstrcatW(commandline, szRemoveAll);
747 if (context == MSIINSTALLCONTEXT_MACHINE)
748 lstrcatW(commandline, szMachine);
750 sz = sizeof(sourcepath);
751 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
752 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
754 sz = sizeof(filename);
755 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
756 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
758 strcatW(sourcepath, filename);
760 r = MSI_InstallPackage( package, sourcepath, commandline );
762 msi_free(commandline);
764 end:
765 msiobj_release( &package->hdr );
767 return r;
770 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
771 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
773 LPWSTR szwProduct = NULL;
774 LPWSTR szwCommandLine = NULL;
775 UINT r = ERROR_OUTOFMEMORY;
777 if( szProduct )
779 szwProduct = strdupAtoW( szProduct );
780 if( !szwProduct )
781 goto end;
784 if( szCommandLine)
786 szwCommandLine = strdupAtoW( szCommandLine );
787 if( !szwCommandLine)
788 goto end;
791 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
792 szwCommandLine );
793 end:
794 msi_free( szwProduct );
795 msi_free( szwCommandLine);
797 return r;
800 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
801 INSTALLSTATE eInstallState)
803 LPWSTR szwProduct = NULL;
804 UINT r;
806 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
808 if( szProduct )
810 szwProduct = strdupAtoW( szProduct );
811 if( !szwProduct )
812 return ERROR_OUTOFMEMORY;
815 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
816 msi_free( szwProduct );
818 return r;
821 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
822 INSTALLSTATE eInstallState)
824 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
827 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
829 LPWSTR szwComponent = NULL;
830 UINT r;
831 WCHAR szwBuffer[GUID_SIZE];
833 TRACE("%s %p\n", debugstr_a(szComponent), szBuffer);
835 if( szComponent )
837 szwComponent = strdupAtoW( szComponent );
838 if( !szwComponent )
839 return ERROR_OUTOFMEMORY;
842 *szwBuffer = '\0';
843 r = MsiGetProductCodeW( szwComponent, szwBuffer );
845 if(*szwBuffer)
846 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
848 msi_free( szwComponent );
850 return r;
853 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
855 UINT rc, index;
856 HKEY compkey, prodkey;
857 WCHAR squished_comp[GUID_SIZE];
858 WCHAR squished_prod[GUID_SIZE];
859 DWORD sz = GUID_SIZE;
861 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
863 if (!szComponent || !*szComponent)
864 return ERROR_INVALID_PARAMETER;
866 if (!squash_guid(szComponent, squished_comp))
867 return ERROR_INVALID_PARAMETER;
869 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
870 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
872 return ERROR_UNKNOWN_COMPONENT;
875 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
876 if (rc != ERROR_SUCCESS)
878 RegCloseKey(compkey);
879 return ERROR_UNKNOWN_COMPONENT;
882 /* check simple case, only one product */
883 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
884 if (rc == ERROR_NO_MORE_ITEMS)
886 rc = ERROR_SUCCESS;
887 goto done;
890 index = 0;
891 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
892 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
894 index++;
895 sz = GUID_SIZE;
896 unsquash_guid(squished_prod, szBuffer);
898 if (MSIREG_OpenProductKey(szBuffer, NULL,
899 MSIINSTALLCONTEXT_USERMANAGED,
900 &prodkey, FALSE) == ERROR_SUCCESS ||
901 MSIREG_OpenProductKey(szBuffer, NULL,
902 MSIINSTALLCONTEXT_USERUNMANAGED,
903 &prodkey, FALSE) == ERROR_SUCCESS ||
904 MSIREG_OpenProductKey(szBuffer, NULL,
905 MSIINSTALLCONTEXT_MACHINE,
906 &prodkey, FALSE) == ERROR_SUCCESS)
908 RegCloseKey(prodkey);
909 rc = ERROR_SUCCESS;
910 goto done;
914 rc = ERROR_INSTALL_FAILURE;
916 done:
917 RegCloseKey(compkey);
918 unsquash_guid(squished_prod, szBuffer);
919 return rc;
922 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
924 DWORD dval;
925 LONG res;
926 WCHAR temp[20];
928 static const WCHAR format[] = {'%','d',0};
930 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
931 if (res != ERROR_SUCCESS)
932 return NULL;
934 if (*type == REG_SZ)
935 return msi_reg_get_val_str(hkey, name);
937 if (!msi_reg_get_val_dword(hkey, name, &dval))
938 return NULL;
940 sprintfW(temp, format, dval);
941 return strdupW(temp);
944 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
945 awstring *szValue, LPDWORD pcchValueBuf)
947 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
948 UINT r = ERROR_UNKNOWN_PROPERTY;
949 HKEY prodkey, userdata, source;
950 LPWSTR val = NULL;
951 WCHAR squished_pc[GUID_SIZE];
952 WCHAR packagecode[GUID_SIZE];
953 BOOL badconfig = FALSE;
954 LONG res;
955 DWORD type = REG_NONE;
957 static WCHAR empty[] = {0};
958 static const WCHAR sourcelist[] = {
959 'S','o','u','r','c','e','L','i','s','t',0};
960 static const WCHAR display_name[] = {
961 'D','i','s','p','l','a','y','N','a','m','e',0};
962 static const WCHAR display_version[] = {
963 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
964 static const WCHAR assignment[] = {
965 'A','s','s','i','g','n','m','e','n','t',0};
967 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
968 debugstr_w(szAttribute), szValue, pcchValueBuf);
970 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
971 return ERROR_INVALID_PARAMETER;
973 if (!squash_guid(szProduct, squished_pc))
974 return ERROR_INVALID_PARAMETER;
976 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
977 MSIINSTALLCONTEXT_USERMANAGED,
978 &prodkey, FALSE)) != ERROR_SUCCESS &&
979 (r = MSIREG_OpenProductKey(szProduct, NULL,
980 MSIINSTALLCONTEXT_USERUNMANAGED,
981 &prodkey, FALSE)) != ERROR_SUCCESS &&
982 (r = MSIREG_OpenProductKey(szProduct, NULL,
983 MSIINSTALLCONTEXT_MACHINE,
984 &prodkey, FALSE)) == ERROR_SUCCESS)
986 context = MSIINSTALLCONTEXT_MACHINE;
989 MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
991 if (!strcmpW( szAttribute, INSTALLPROPERTY_HELPLINKW ) ||
992 !strcmpW( szAttribute, INSTALLPROPERTY_HELPTELEPHONEW ) ||
993 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLDATEW ) ||
994 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
995 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
996 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLSOURCEW ) ||
997 !strcmpW( szAttribute, INSTALLPROPERTY_LOCALPACKAGEW ) ||
998 !strcmpW( szAttribute, INSTALLPROPERTY_PUBLISHERW ) ||
999 !strcmpW( szAttribute, INSTALLPROPERTY_URLINFOABOUTW ) ||
1000 !strcmpW( szAttribute, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1001 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMINORW ) ||
1002 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMAJORW ) ||
1003 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1004 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTIDW ) ||
1005 !strcmpW( szAttribute, INSTALLPROPERTY_REGCOMPANYW ) ||
1006 !strcmpW( szAttribute, INSTALLPROPERTY_REGOWNERW ))
1008 if (!prodkey)
1010 r = ERROR_UNKNOWN_PRODUCT;
1011 goto done;
1014 if (!userdata)
1015 return ERROR_UNKNOWN_PROPERTY;
1017 if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1018 szAttribute = display_name;
1019 else if (!strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ))
1020 szAttribute = display_version;
1022 val = msi_reg_get_value(userdata, szAttribute, &type);
1023 if (!val)
1024 val = empty;
1026 else if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTANCETYPEW ) ||
1027 !strcmpW( szAttribute, INSTALLPROPERTY_TRANSFORMSW ) ||
1028 !strcmpW( szAttribute, INSTALLPROPERTY_LANGUAGEW ) ||
1029 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1030 !strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ) ||
1031 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ) ||
1032 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONW ) ||
1033 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTICONW ) ||
1034 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ) ||
1035 !strcmpW( szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1037 if (!prodkey)
1039 r = ERROR_UNKNOWN_PRODUCT;
1040 goto done;
1043 if (!strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1044 szAttribute = assignment;
1046 if (!strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ))
1048 res = RegOpenKeyW(prodkey, sourcelist, &source);
1049 if (res != ERROR_SUCCESS)
1051 r = ERROR_UNKNOWN_PRODUCT;
1052 goto done;
1055 val = msi_reg_get_value(source, szAttribute, &type);
1056 if (!val)
1057 val = empty;
1059 RegCloseKey(source);
1061 else
1063 val = msi_reg_get_value(prodkey, szAttribute, &type);
1064 if (!val)
1065 val = empty;
1068 if (val != empty && type != REG_DWORD &&
1069 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ))
1071 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1072 badconfig = TRUE;
1073 else
1075 unsquash_guid(val, packagecode);
1076 msi_free(val);
1077 val = strdupW(packagecode);
1082 if (!val)
1084 r = ERROR_UNKNOWN_PROPERTY;
1085 goto done;
1088 if (pcchValueBuf)
1090 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1091 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1092 * can't rely on its value.
1094 if (szValue->str.a || szValue->str.w)
1096 DWORD size = *pcchValueBuf;
1097 if (strlenW(val) < size)
1098 r = msi_strcpy_to_awstring(val, szValue, &size);
1099 else
1101 r = ERROR_MORE_DATA;
1105 if (!badconfig)
1106 *pcchValueBuf = lstrlenW(val);
1109 if (badconfig)
1110 r = ERROR_BAD_CONFIGURATION;
1112 if (val != empty)
1113 msi_free(val);
1115 done:
1116 RegCloseKey(prodkey);
1117 RegCloseKey(userdata);
1118 return r;
1121 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1122 LPSTR szBuffer, LPDWORD pcchValueBuf)
1124 LPWSTR szwProduct, szwAttribute = NULL;
1125 UINT r = ERROR_OUTOFMEMORY;
1126 awstring buffer;
1128 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1129 szBuffer, pcchValueBuf);
1131 szwProduct = strdupAtoW( szProduct );
1132 if( szProduct && !szwProduct )
1133 goto end;
1135 szwAttribute = strdupAtoW( szAttribute );
1136 if( szAttribute && !szwAttribute )
1137 goto end;
1139 buffer.unicode = FALSE;
1140 buffer.str.a = szBuffer;
1142 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1143 &buffer, pcchValueBuf );
1145 end:
1146 msi_free( szwProduct );
1147 msi_free( szwAttribute );
1149 return r;
1152 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1153 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1155 awstring buffer;
1157 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1158 szBuffer, pcchValueBuf);
1160 buffer.unicode = TRUE;
1161 buffer.str.w = szBuffer;
1163 return MSI_GetProductInfo( szProduct, szAttribute,
1164 &buffer, pcchValueBuf );
1167 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1168 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1169 LPSTR szValue, LPDWORD pcchValue)
1171 LPWSTR product = NULL;
1172 LPWSTR usersid = NULL;
1173 LPWSTR property = NULL;
1174 LPWSTR value = NULL;
1175 DWORD len = 0;
1176 UINT r;
1178 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1179 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1180 szValue, pcchValue);
1182 if (szValue && !pcchValue)
1183 return ERROR_INVALID_PARAMETER;
1185 if (szProductCode) product = strdupAtoW(szProductCode);
1186 if (szUserSid) usersid = strdupAtoW(szUserSid);
1187 if (szProperty) property = strdupAtoW(szProperty);
1189 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1190 NULL, &len);
1191 if (r != ERROR_SUCCESS)
1192 goto done;
1194 value = msi_alloc(++len * sizeof(WCHAR));
1195 if (!value)
1197 r = ERROR_OUTOFMEMORY;
1198 goto done;
1201 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1202 value, &len);
1203 if (r != ERROR_SUCCESS)
1204 goto done;
1206 if (!pcchValue)
1207 goto done;
1209 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1210 if (*pcchValue >= len)
1211 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1212 else if (szValue)
1214 r = ERROR_MORE_DATA;
1215 if (*pcchValue > 0)
1216 *szValue = '\0';
1219 if (*pcchValue <= len || !szValue)
1220 len = len * sizeof(WCHAR) - 1;
1222 *pcchValue = len - 1;
1224 done:
1225 msi_free(product);
1226 msi_free(usersid);
1227 msi_free(property);
1228 msi_free(value);
1230 return r;
1233 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1235 UINT r = ERROR_SUCCESS;
1237 if (!val)
1238 return ERROR_UNKNOWN_PROPERTY;
1240 if (out)
1242 if (strlenW(val) >= *size)
1244 r = ERROR_MORE_DATA;
1245 if (*size > 0)
1246 *out = '\0';
1248 else
1249 lstrcpyW(out, val);
1252 if (size)
1253 *size = lstrlenW(val);
1255 return r;
1258 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1259 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1260 LPWSTR szValue, LPDWORD pcchValue)
1262 WCHAR squished_pc[GUID_SIZE];
1263 LPWSTR val = NULL;
1264 LPCWSTR package = NULL;
1265 HKEY props = NULL, prod;
1266 HKEY classes = NULL, managed;
1267 HKEY hkey = NULL;
1268 DWORD type;
1269 UINT r = ERROR_UNKNOWN_PRODUCT;
1271 static const WCHAR five[] = {'5',0};
1272 static const WCHAR displayname[] = {
1273 'D','i','s','p','l','a','y','N','a','m','e',0};
1274 static const WCHAR displayversion[] = {
1275 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1276 static const WCHAR managed_local_package[] = {
1277 'M','a','n','a','g','e','d','L','o','c','a','l',
1278 'P','a','c','k','a','g','e',0};
1280 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1281 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1282 szValue, pcchValue);
1284 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1285 return ERROR_INVALID_PARAMETER;
1287 if (szValue && !pcchValue)
1288 return ERROR_INVALID_PARAMETER;
1290 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1291 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1292 dwContext != MSIINSTALLCONTEXT_MACHINE)
1293 return ERROR_INVALID_PARAMETER;
1295 if (!szProperty || !*szProperty)
1296 return ERROR_INVALID_PARAMETER;
1298 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1299 return ERROR_INVALID_PARAMETER;
1301 /* FIXME: dwContext is provided, no need to search for it */
1302 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1303 &managed, FALSE);
1304 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1305 &prod, FALSE);
1307 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1309 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1311 package = INSTALLPROPERTY_LOCALPACKAGEW;
1313 if (!props && !prod)
1314 goto done;
1316 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1318 package = managed_local_package;
1320 if (!props && !managed)
1321 goto done;
1323 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1325 package = INSTALLPROPERTY_LOCALPACKAGEW;
1326 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1328 if (!props && !classes)
1329 goto done;
1332 if (!strcmpW( szProperty, INSTALLPROPERTY_HELPLINKW ) ||
1333 !strcmpW( szProperty, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1334 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ) ||
1335 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1336 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1337 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1338 !strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1339 !strcmpW( szProperty, INSTALLPROPERTY_PUBLISHERW ) ||
1340 !strcmpW( szProperty, INSTALLPROPERTY_URLINFOABOUTW ) ||
1341 !strcmpW( szProperty, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1342 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMINORW ) ||
1343 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMAJORW ) ||
1344 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1345 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTIDW ) ||
1346 !strcmpW( szProperty, INSTALLPROPERTY_REGCOMPANYW ) ||
1347 !strcmpW( szProperty, INSTALLPROPERTY_REGOWNERW ) ||
1348 !strcmpW( szProperty, INSTALLPROPERTY_INSTANCETYPEW ))
1350 val = msi_reg_get_value(props, package, &type);
1351 if (!val)
1353 if (prod || classes)
1354 r = ERROR_UNKNOWN_PROPERTY;
1356 goto done;
1359 msi_free(val);
1361 if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1362 szProperty = displayname;
1363 else if (!strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ))
1364 szProperty = displayversion;
1366 val = msi_reg_get_value(props, szProperty, &type);
1367 if (!val)
1368 val = strdupW(szEmpty);
1370 r = msi_copy_outval(val, szValue, pcchValue);
1372 else if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ) ||
1373 !strcmpW( szProperty, INSTALLPROPERTY_LANGUAGEW ) ||
1374 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1375 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGECODEW ) ||
1376 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONW ) ||
1377 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTICONW ) ||
1378 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ) ||
1379 !strcmpW( szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1381 if (!prod && !classes)
1382 goto done;
1384 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1385 hkey = prod;
1386 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1387 hkey = managed;
1388 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1389 hkey = classes;
1391 val = msi_reg_get_value(hkey, szProperty, &type);
1392 if (!val)
1393 val = strdupW(szEmpty);
1395 r = msi_copy_outval(val, szValue, pcchValue);
1397 else if (!strcmpW( szProperty, INSTALLPROPERTY_PRODUCTSTATEW ))
1399 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1401 if (props)
1403 val = msi_reg_get_value(props, package, &type);
1404 if (!val)
1405 goto done;
1407 msi_free(val);
1408 val = strdupW(five);
1410 else
1411 val = strdupW(szOne);
1413 r = msi_copy_outval(val, szValue, pcchValue);
1414 goto done;
1416 else if (props && (val = msi_reg_get_value(props, package, &type)))
1418 msi_free(val);
1419 val = strdupW(five);
1420 r = msi_copy_outval(val, szValue, pcchValue);
1421 goto done;
1424 if (prod || managed)
1425 val = strdupW(szOne);
1426 else
1427 goto done;
1429 r = msi_copy_outval(val, szValue, pcchValue);
1431 else if (!strcmpW( szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1433 if (!prod && !classes)
1434 goto done;
1436 /* FIXME */
1437 val = strdupW(szEmpty);
1438 r = msi_copy_outval(val, szValue, pcchValue);
1440 else
1441 r = ERROR_UNKNOWN_PROPERTY;
1443 done:
1444 RegCloseKey(props);
1445 RegCloseKey(prod);
1446 RegCloseKey(managed);
1447 RegCloseKey(classes);
1448 msi_free(val);
1450 return r;
1453 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1454 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1455 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1457 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1458 LPWSTR property = NULL, val = NULL;
1459 DWORD len;
1460 UINT r;
1462 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1463 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1464 debugstr_a(szProperty), lpValue, pcchValue);
1466 if (lpValue && !pcchValue)
1467 return ERROR_INVALID_PARAMETER;
1469 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1470 if (szProductCode) product = strdupAtoW(szProductCode);
1471 if (szUserSid) usersid = strdupAtoW(szUserSid);
1472 if (szProperty) property = strdupAtoW(szProperty);
1474 len = 0;
1475 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1476 NULL, &len);
1477 if (r != ERROR_SUCCESS)
1478 goto done;
1480 val = msi_alloc(++len * sizeof(WCHAR));
1481 if (!val)
1483 r = ERROR_OUTOFMEMORY;
1484 goto done;
1487 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1488 val, &len);
1489 if (r != ERROR_SUCCESS || !pcchValue)
1490 goto done;
1492 if (lpValue)
1493 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1494 *pcchValue - 1, NULL, NULL);
1496 len = lstrlenW(val);
1497 if ((*val && *pcchValue < len + 1) || !lpValue)
1499 if (lpValue)
1501 r = ERROR_MORE_DATA;
1502 lpValue[*pcchValue - 1] = '\0';
1505 *pcchValue = len * sizeof(WCHAR);
1507 else
1508 *pcchValue = len;
1510 done:
1511 msi_free(val);
1512 msi_free(patch);
1513 msi_free(product);
1514 msi_free(usersid);
1515 msi_free(property);
1517 return r;
1520 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1521 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1522 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1524 WCHAR squished_pc[GUID_SIZE];
1525 WCHAR squished_patch[GUID_SIZE];
1526 HKEY udprod = 0, prod = 0, props = 0;
1527 HKEY patch = 0, patches = 0;
1528 HKEY udpatch = 0, datakey = 0;
1529 HKEY prodpatches = 0;
1530 LPWSTR val = NULL;
1531 UINT r = ERROR_UNKNOWN_PRODUCT;
1532 DWORD len;
1533 LONG res;
1535 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1536 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1538 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1539 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1540 debugstr_w(szProperty), lpValue, pcchValue);
1542 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1543 return ERROR_INVALID_PARAMETER;
1545 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1546 return ERROR_INVALID_PARAMETER;
1548 if (!szProperty)
1549 return ERROR_INVALID_PARAMETER;
1551 if (lpValue && !pcchValue)
1552 return ERROR_INVALID_PARAMETER;
1554 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1555 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1556 dwContext != MSIINSTALLCONTEXT_MACHINE)
1557 return ERROR_INVALID_PARAMETER;
1559 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1560 return ERROR_INVALID_PARAMETER;
1562 if (szUserSid && !strcmpW( szUserSid, szLocalSid ))
1563 return ERROR_INVALID_PARAMETER;
1565 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1566 &udprod, FALSE) != ERROR_SUCCESS)
1567 goto done;
1569 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1570 &props, FALSE) != ERROR_SUCCESS)
1571 goto done;
1573 r = ERROR_UNKNOWN_PATCH;
1575 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_WOW64_64KEY|KEY_READ, &patches);
1576 if (res != ERROR_SUCCESS)
1577 goto done;
1579 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_WOW64_64KEY|KEY_READ, &patch);
1580 if (res != ERROR_SUCCESS)
1581 goto done;
1583 if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ))
1585 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1586 &prod, FALSE) != ERROR_SUCCESS)
1587 goto done;
1589 res = RegOpenKeyExW(prod, szPatches, 0, KEY_WOW64_64KEY|KEY_ALL_ACCESS, &prodpatches);
1590 if (res != ERROR_SUCCESS)
1591 goto done;
1593 datakey = prodpatches;
1594 szProperty = squished_patch;
1596 else
1598 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1599 &udpatch, FALSE) != ERROR_SUCCESS)
1600 goto done;
1602 if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1604 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1605 szProperty = szManagedPackage;
1606 datakey = udpatch;
1608 else if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ))
1610 datakey = patch;
1611 szProperty = szInstalled;
1613 else if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1615 datakey = udpatch;
1617 else if (!strcmpW( szProperty, INSTALLPROPERTY_UNINSTALLABLEW ) ||
1618 !strcmpW( szProperty, INSTALLPROPERTY_PATCHSTATEW ) ||
1619 !strcmpW( szProperty, INSTALLPROPERTY_DISPLAYNAMEW ) ||
1620 !strcmpW( szProperty, INSTALLPROPERTY_MOREINFOURLW ))
1622 datakey = patch;
1624 else
1626 r = ERROR_UNKNOWN_PROPERTY;
1627 goto done;
1631 val = msi_reg_get_val_str(datakey, szProperty);
1632 if (!val)
1633 val = strdupW(szEmpty);
1635 r = ERROR_SUCCESS;
1637 if (!pcchValue)
1638 goto done;
1640 if (lpValue)
1641 lstrcpynW(lpValue, val, *pcchValue);
1643 len = lstrlenW(val);
1644 if ((*val && *pcchValue < len + 1) || !lpValue)
1646 if (lpValue)
1647 r = ERROR_MORE_DATA;
1649 *pcchValue = len * sizeof(WCHAR);
1652 *pcchValue = len;
1654 done:
1655 msi_free(val);
1656 RegCloseKey(prodpatches);
1657 RegCloseKey(prod);
1658 RegCloseKey(patch);
1659 RegCloseKey(patches);
1660 RegCloseKey(udpatch);
1661 RegCloseKey(props);
1662 RegCloseKey(udprod);
1664 return r;
1667 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1669 UINT r = ERROR_OUTOFMEMORY;
1670 DWORD size;
1671 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1673 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1675 if (!patch || !attr)
1676 return ERROR_INVALID_PARAMETER;
1678 if (!(patchW = strdupAtoW( patch )))
1679 goto done;
1681 if (!(attrW = strdupAtoW( attr )))
1682 goto done;
1684 size = 0;
1685 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1686 if (r != ERROR_SUCCESS)
1687 goto done;
1689 size++;
1690 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1692 r = ERROR_OUTOFMEMORY;
1693 goto done;
1696 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1697 if (r == ERROR_SUCCESS)
1699 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1700 if (len > *buflen)
1701 r = ERROR_MORE_DATA;
1702 else if (buffer)
1703 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1705 *buflen = len - 1;
1708 done:
1709 msi_free( patchW );
1710 msi_free( attrW );
1711 msi_free( bufferW );
1712 return r;
1715 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1717 UINT r;
1718 WCHAR product[GUID_SIZE];
1719 DWORD index;
1721 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1723 if (!patch || !attr)
1724 return ERROR_INVALID_PARAMETER;
1726 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1727 return ERROR_UNKNOWN_PROPERTY;
1729 index = 0;
1730 while (1)
1732 r = MsiEnumProductsW( index, product );
1733 if (r != ERROR_SUCCESS)
1734 break;
1736 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1737 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1738 return r;
1740 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1741 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1742 return r;
1744 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1745 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1746 return r;
1748 index++;
1751 return ERROR_UNKNOWN_PRODUCT;
1754 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1756 LPWSTR szwLogFile = NULL;
1757 UINT r;
1759 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1761 if( szLogFile )
1763 szwLogFile = strdupAtoW( szLogFile );
1764 if( !szwLogFile )
1765 return ERROR_OUTOFMEMORY;
1767 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1768 msi_free( szwLogFile );
1769 return r;
1772 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1774 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1776 msi_free(gszLogFile);
1777 gszLogFile = NULL;
1778 if (szLogFile)
1780 HANDLE file;
1782 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1783 DeleteFileW(szLogFile);
1784 file = CreateFileW(szLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
1785 FILE_ATTRIBUTE_NORMAL, NULL);
1786 if (file != INVALID_HANDLE_VALUE)
1788 gszLogFile = strdupW(szLogFile);
1789 CloseHandle(file);
1791 else
1792 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile), GetLastError());
1795 return ERROR_SUCCESS;
1798 UINT WINAPI MsiEnumComponentCostsA( MSIHANDLE handle, LPCSTR component, DWORD index,
1799 INSTALLSTATE state, LPSTR drive, DWORD *buflen,
1800 int *cost, int *temp )
1802 UINT r;
1803 DWORD len;
1804 WCHAR *driveW, *componentW = NULL;
1806 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_a(component), index,
1807 state, drive, buflen, cost, temp);
1809 if (!drive || !buflen) return ERROR_INVALID_PARAMETER;
1810 if (component && !(componentW = strdupAtoW( component ))) return ERROR_OUTOFMEMORY;
1812 len = *buflen;
1813 if (!(driveW = msi_alloc( len * sizeof(WCHAR) )))
1815 msi_free( componentW );
1816 return ERROR_OUTOFMEMORY;
1818 r = MsiEnumComponentCostsW( handle, componentW, index, state, driveW, buflen, cost, temp );
1819 if (!r)
1821 WideCharToMultiByte( CP_ACP, 0, driveW, -1, drive, len, NULL, NULL );
1823 msi_free( componentW );
1824 msi_free( driveW );
1825 return r;
1828 UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, LPCWSTR component, DWORD index,
1829 INSTALLSTATE state, LPWSTR drive, DWORD *buflen,
1830 int *cost, int *temp )
1832 UINT r = ERROR_NO_MORE_ITEMS;
1833 MSICOMPONENT *comp = NULL;
1834 MSIPACKAGE *package;
1835 MSIFILE *file;
1836 STATSTG stat = {0};
1837 WCHAR path[MAX_PATH];
1839 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_w(component), index,
1840 state, drive, buflen, cost, temp);
1842 if (!drive || !buflen || !cost || !temp) return ERROR_INVALID_PARAMETER;
1843 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1845 HRESULT hr;
1846 IWineMsiRemotePackage *remote_package;
1847 BSTR bname;
1849 if (!(remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle )))
1850 return ERROR_INVALID_HANDLE;
1852 bname = SysAllocString( component );
1853 if (!bname)
1855 IWineMsiRemotePackage_Release( remote_package );
1856 return ERROR_OUTOFMEMORY;
1858 hr = IWineMsiRemotePackage_EnumComponentCosts( remote_package, bname, index, state, drive, buflen, cost, temp );
1859 IWineMsiRemotePackage_Release( remote_package );
1860 SysFreeString( bname );
1861 if (FAILED(hr))
1863 if (HRESULT_FACILITY(hr) == FACILITY_WIN32) return HRESULT_CODE(hr);
1864 return ERROR_FUNCTION_FAILED;
1866 return ERROR_SUCCESS;
1869 if (!msi_get_property_int( package->db, szCostingComplete, 0 ))
1871 msiobj_release( &package->hdr );
1872 return ERROR_FUNCTION_NOT_CALLED;
1874 if (component && component[0] && !(comp = get_loaded_component( package, component )))
1876 msiobj_release( &package->hdr );
1877 return ERROR_UNKNOWN_COMPONENT;
1879 if (*buflen < 3)
1881 *buflen = 2;
1882 msiobj_release( &package->hdr );
1883 return ERROR_MORE_DATA;
1885 if (index)
1887 msiobj_release( &package->hdr );
1888 return ERROR_NO_MORE_ITEMS;
1891 drive[0] = 0;
1892 *cost = *temp = 0;
1893 GetWindowsDirectoryW( path, MAX_PATH );
1894 if (component && component[0])
1896 if (comp->assembly && !comp->assembly->application) *temp = comp->Cost;
1897 if (!comp->Enabled || !comp->KeyPath)
1899 *cost = 0;
1900 drive[0] = path[0];
1901 drive[1] = ':';
1902 drive[2] = 0;
1903 *buflen = 2;
1904 r = ERROR_SUCCESS;
1906 else if ((file = get_loaded_file( package, comp->KeyPath )))
1908 *cost = max( 8, comp->Cost / 512 );
1909 drive[0] = file->TargetPath[0];
1910 drive[1] = ':';
1911 drive[2] = 0;
1912 *buflen = 2;
1913 r = ERROR_SUCCESS;
1916 else if (IStorage_Stat( package->db->storage, &stat, STATFLAG_NONAME ) == S_OK)
1918 *temp = max( 8, stat.cbSize.QuadPart / 512 );
1919 drive[0] = path[0];
1920 drive[1] = ':';
1921 drive[2] = 0;
1922 *buflen = 2;
1923 r = ERROR_SUCCESS;
1925 msiobj_release( &package->hdr );
1926 return r;
1929 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1930 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1931 LPCSTR szComponent, INSTALLSTATE *pdwState)
1933 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1934 UINT r;
1936 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1937 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1939 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1940 return ERROR_OUTOFMEMORY;
1942 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1943 return ERROR_OUTOFMEMORY;
1945 if (szComponent && !(comp = strdupAtoW(szComponent)))
1946 return ERROR_OUTOFMEMORY;
1948 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1950 msi_free(prodcode);
1951 msi_free(usersid);
1952 msi_free(comp);
1954 return r;
1957 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1959 UINT r;
1960 HKEY hkey;
1962 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
1963 RegCloseKey(hkey);
1964 return (r == ERROR_SUCCESS);
1967 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1969 LPCWSTR package;
1970 HKEY hkey;
1971 DWORD sz;
1972 LONG res;
1973 UINT r;
1975 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1976 static const WCHAR managed_local_package[] = {
1977 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1980 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
1981 if (r != ERROR_SUCCESS)
1982 return FALSE;
1984 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1985 package = managed_local_package;
1986 else
1987 package = local_package;
1989 sz = 0;
1990 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1991 RegCloseKey(hkey);
1993 return (res == ERROR_SUCCESS);
1996 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1997 MSIINSTALLCONTEXT context,
1998 LPCWSTR comp, LPWSTR val, DWORD *sz)
2000 HKEY hkey;
2001 LONG res;
2002 UINT r;
2004 if (context == MSIINSTALLCONTEXT_MACHINE)
2005 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2006 else
2007 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2009 if (r != ERROR_SUCCESS)
2010 return FALSE;
2012 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
2013 if (res != ERROR_SUCCESS)
2014 return FALSE;
2016 RegCloseKey(hkey);
2017 return TRUE;
2020 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
2021 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2022 LPCWSTR szComponent, INSTALLSTATE *pdwState)
2024 WCHAR squished_pc[GUID_SIZE];
2025 WCHAR val[MAX_PATH];
2026 BOOL found;
2027 DWORD sz;
2029 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
2030 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
2032 if (!pdwState || !szComponent)
2033 return ERROR_INVALID_PARAMETER;
2035 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
2036 return ERROR_INVALID_PARAMETER;
2038 if (!squash_guid(szProductCode, squished_pc))
2039 return ERROR_INVALID_PARAMETER;
2041 found = msi_comp_find_prod_key(szProductCode, dwContext);
2043 if (!msi_comp_find_package(szProductCode, dwContext))
2045 if (found)
2047 *pdwState = INSTALLSTATE_UNKNOWN;
2048 return ERROR_UNKNOWN_COMPONENT;
2051 return ERROR_UNKNOWN_PRODUCT;
2054 *pdwState = INSTALLSTATE_UNKNOWN;
2056 sz = MAX_PATH;
2057 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
2058 return ERROR_UNKNOWN_COMPONENT;
2060 if (sz == 0)
2061 *pdwState = INSTALLSTATE_NOTUSED;
2062 else
2064 if (lstrlenW(val) > 2 &&
2065 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
2067 *pdwState = INSTALLSTATE_SOURCE;
2069 else
2070 *pdwState = INSTALLSTATE_LOCAL;
2073 TRACE("-> %d\n", *pdwState);
2074 return ERROR_SUCCESS;
2077 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
2079 LPWSTR szwProduct = NULL;
2080 INSTALLSTATE r;
2082 if( szProduct )
2084 szwProduct = strdupAtoW( szProduct );
2085 if( !szwProduct )
2086 return ERROR_OUTOFMEMORY;
2088 r = MsiQueryProductStateW( szwProduct );
2089 msi_free( szwProduct );
2090 return r;
2093 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
2095 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
2096 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
2097 HKEY prodkey = 0, userdata = 0;
2098 DWORD val;
2099 UINT r;
2101 static const WCHAR szWindowsInstaller[] = {
2102 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2104 TRACE("%s\n", debugstr_w(szProduct));
2106 if (!szProduct || !*szProduct)
2107 return INSTALLSTATE_INVALIDARG;
2109 if (lstrlenW(szProduct) != GUID_SIZE - 1)
2110 return INSTALLSTATE_INVALIDARG;
2112 if (szProduct[0] != '{' || szProduct[37] != '}')
2113 return INSTALLSTATE_UNKNOWN;
2115 SetLastError( ERROR_SUCCESS );
2117 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2118 &prodkey, FALSE) != ERROR_SUCCESS &&
2119 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2120 &prodkey, FALSE) != ERROR_SUCCESS &&
2121 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2122 &prodkey, FALSE) == ERROR_SUCCESS)
2124 context = MSIINSTALLCONTEXT_MACHINE;
2127 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
2128 if (r != ERROR_SUCCESS)
2129 goto done;
2131 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
2132 goto done;
2134 if (val)
2135 state = INSTALLSTATE_DEFAULT;
2136 else
2137 state = INSTALLSTATE_UNKNOWN;
2139 done:
2140 if (!prodkey)
2142 state = INSTALLSTATE_UNKNOWN;
2144 if (userdata)
2145 state = INSTALLSTATE_ABSENT;
2148 RegCloseKey(prodkey);
2149 RegCloseKey(userdata);
2150 TRACE("-> %d\n", state);
2151 return state;
2154 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2156 INSTALLUILEVEL old = gUILevel;
2157 HWND oldwnd = gUIhwnd;
2159 TRACE("%08x %p\n", dwUILevel, phWnd);
2161 gUILevel = dwUILevel;
2162 if (phWnd)
2164 gUIhwnd = *phWnd;
2165 *phWnd = oldwnd;
2167 return old;
2170 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2171 DWORD dwMessageFilter, LPVOID pvContext)
2173 INSTALLUI_HANDLERA prev = gUIHandlerA;
2175 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2177 gUIHandlerA = puiHandler;
2178 gUIHandlerW = NULL;
2179 gUIFilter = dwMessageFilter;
2180 gUIContext = pvContext;
2182 return prev;
2185 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2186 DWORD dwMessageFilter, LPVOID pvContext)
2188 INSTALLUI_HANDLERW prev = gUIHandlerW;
2190 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2192 gUIHandlerA = NULL;
2193 gUIHandlerW = puiHandler;
2194 gUIFilter = dwMessageFilter;
2195 gUIContext = pvContext;
2197 return prev;
2200 /******************************************************************
2201 * MsiLoadStringW [MSI.@]
2203 * Loads a string from MSI's string resources.
2205 * PARAMS
2207 * handle [I] only -1 is handled currently
2208 * id [I] id of the string to be loaded
2209 * lpBuffer [O] buffer for the string to be written to
2210 * nBufferMax [I] maximum size of the buffer in characters
2211 * lang [I] the preferred language for the string
2213 * RETURNS
2215 * If successful, this function returns the language id of the string loaded
2216 * If the function fails, the function returns zero.
2218 * NOTES
2220 * The type of the first parameter is unknown. LoadString's prototype
2221 * suggests that it might be a module handle. I have made it an MSI handle
2222 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2223 * handle. Maybe strings can be stored in an MSI database somehow.
2225 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2226 int nBufferMax, LANGID lang )
2228 HRSRC hres;
2229 HGLOBAL hResData;
2230 LPWSTR p;
2231 DWORD i, len;
2233 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2235 if( handle != -1 )
2236 FIXME("don't know how to deal with handle = %08x\n", handle);
2238 if( !lang )
2239 lang = GetUserDefaultLangID();
2241 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2242 (LPWSTR)1, lang );
2243 if( !hres )
2244 return 0;
2245 hResData = LoadResource( msi_hInstance, hres );
2246 if( !hResData )
2247 return 0;
2248 p = LockResource( hResData );
2249 if( !p )
2250 return 0;
2252 for (i = 0; i < (id&0xf); i++)
2253 p += *p + 1;
2254 len = *p;
2256 if( nBufferMax <= len )
2257 return 0;
2259 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2260 lpBuffer[ len ] = 0;
2262 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2264 return lang;
2267 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2268 int nBufferMax, LANGID lang )
2270 LPWSTR bufW;
2271 LANGID r;
2272 INT len;
2274 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2275 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2276 if( r )
2278 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2279 if( len <= nBufferMax )
2280 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2281 lpBuffer, nBufferMax, NULL, NULL );
2282 else
2283 r = 0;
2285 msi_free(bufW);
2286 return r;
2289 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2290 LPDWORD pcchBuf)
2292 char szProduct[GUID_SIZE];
2294 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2296 if (!szComponent || !pcchBuf)
2297 return INSTALLSTATE_INVALIDARG;
2299 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2300 return INSTALLSTATE_UNKNOWN;
2302 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2305 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2306 LPDWORD pcchBuf)
2308 WCHAR szProduct[GUID_SIZE];
2310 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2312 if (!szComponent || !pcchBuf)
2313 return INSTALLSTATE_INVALIDARG;
2315 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2316 return INSTALLSTATE_UNKNOWN;
2318 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2321 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2322 WORD wLanguageId, DWORD f)
2324 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2325 uType, wLanguageId, f);
2326 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2329 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2330 WORD wLanguageId, DWORD f)
2332 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2333 uType, wLanguageId, f);
2334 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2337 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2338 DWORD unknown, WORD wLanguageId, DWORD f)
2340 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2341 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2342 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2345 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2346 DWORD unknown, WORD wLanguageId, DWORD f)
2348 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2349 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2350 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2353 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2354 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2355 LPDWORD pcchPathBuf )
2357 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2358 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2359 pcchPathBuf);
2360 return ERROR_CALL_NOT_IMPLEMENTED;
2363 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2364 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2365 LPDWORD pcchPathBuf )
2367 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2368 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2369 pcchPathBuf);
2370 return ERROR_CALL_NOT_IMPLEMENTED;
2373 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2374 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2376 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2377 return ERROR_CALL_NOT_IMPLEMENTED;
2380 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2381 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2383 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2384 return ERROR_CALL_NOT_IMPLEMENTED;
2387 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2388 LPBYTE hash, LPDWORD hashlen )
2390 UINT r;
2391 WCHAR *pathW = NULL;
2393 TRACE("%s %08x %p %p %p\n", debugstr_a(path), flags, cert, hash, hashlen);
2395 if (path && !(pathW = strdupAtoW( path ))) return ERROR_OUTOFMEMORY;
2396 r = MsiGetFileSignatureInformationW( pathW, flags, cert, hash, hashlen );
2397 msi_free( pathW );
2398 return r;
2401 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2402 LPBYTE hash, LPDWORD hashlen )
2404 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
2405 HRESULT hr;
2406 WINTRUST_DATA data;
2407 WINTRUST_FILE_INFO info;
2408 CRYPT_PROVIDER_SGNR *signer;
2409 CRYPT_PROVIDER_CERT *provider;
2411 TRACE("%s %08x %p %p %p\n", debugstr_w(path), flags, cert, hash, hashlen);
2413 if (!path || !cert) return E_INVALIDARG;
2415 info.cbStruct = sizeof(info);
2416 info.pcwszFilePath = path;
2417 info.hFile = NULL;
2418 info.pgKnownSubject = NULL;
2420 data.cbStruct = sizeof(data);
2421 data.pPolicyCallbackData = NULL;
2422 data.pSIPClientData = NULL;
2423 data.dwUIChoice = WTD_UI_NONE;
2424 data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
2425 data.dwUnionChoice = WTD_CHOICE_FILE;
2426 data.u.pFile = &info;
2427 data.dwStateAction = WTD_STATEACTION_VERIFY;
2428 data.hWVTStateData = NULL;
2429 data.pwszURLReference = NULL;
2430 data.dwProvFlags = 0;
2431 data.dwUIContext = WTD_UICONTEXT_INSTALL;
2432 hr = WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2433 if (FAILED(hr)) goto done;
2435 if (!(signer = WTHelperGetProvSignerFromChain( data.hWVTStateData, 0, FALSE, 0 )))
2437 hr = TRUST_E_NOSIGNATURE;
2438 goto done;
2440 if (hash)
2442 DWORD len = signer->psSigner->EncryptedHash.cbData;
2443 if (*hashlen < len)
2445 *hashlen = len;
2446 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
2447 goto done;
2449 memcpy( hash, signer->psSigner->EncryptedHash.pbData, len );
2450 *hashlen = len;
2452 if (!(provider = WTHelperGetProvCertFromChain( signer, 0 )))
2454 hr = TRUST_E_PROVIDER_UNKNOWN;
2455 goto done;
2457 *cert = CertDuplicateCertificateContext( provider->pCert );
2459 done:
2460 data.dwStateAction = WTD_STATEACTION_CLOSE;
2461 WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2462 return hr;
2465 /******************************************************************
2466 * MsiGetProductPropertyA [MSI.@]
2468 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2469 LPSTR szValue, LPDWORD pccbValue)
2471 LPWSTR prop = NULL, val = NULL;
2472 DWORD len;
2473 UINT r;
2475 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2476 szValue, pccbValue);
2478 if (szValue && !pccbValue)
2479 return ERROR_INVALID_PARAMETER;
2481 if (szProperty) prop = strdupAtoW(szProperty);
2483 len = 0;
2484 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2485 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2486 goto done;
2488 if (r == ERROR_SUCCESS)
2490 if (szValue) *szValue = '\0';
2491 if (pccbValue) *pccbValue = 0;
2492 goto done;
2495 val = msi_alloc(++len * sizeof(WCHAR));
2496 if (!val)
2498 r = ERROR_OUTOFMEMORY;
2499 goto done;
2502 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2503 if (r != ERROR_SUCCESS)
2504 goto done;
2506 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2508 if (szValue)
2509 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2510 *pccbValue, NULL, NULL);
2512 if (pccbValue)
2514 if (len > *pccbValue)
2515 r = ERROR_MORE_DATA;
2517 *pccbValue = len - 1;
2520 done:
2521 msi_free(prop);
2522 msi_free(val);
2524 return r;
2527 /******************************************************************
2528 * MsiGetProductPropertyW [MSI.@]
2530 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2531 LPWSTR szValue, LPDWORD pccbValue)
2533 MSIPACKAGE *package;
2534 MSIQUERY *view = NULL;
2535 MSIRECORD *rec = NULL;
2536 LPCWSTR val;
2537 UINT r;
2539 static const WCHAR query[] = {
2540 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2541 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2542 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2544 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2545 szValue, pccbValue);
2547 if (!szProperty)
2548 return ERROR_INVALID_PARAMETER;
2550 if (szValue && !pccbValue)
2551 return ERROR_INVALID_PARAMETER;
2553 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2554 if (!package)
2555 return ERROR_INVALID_HANDLE;
2557 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2558 if (r != ERROR_SUCCESS)
2559 goto done;
2561 r = MSI_ViewExecute(view, 0);
2562 if (r != ERROR_SUCCESS)
2563 goto done;
2565 r = MSI_ViewFetch(view, &rec);
2566 if (r != ERROR_SUCCESS)
2567 goto done;
2569 val = MSI_RecordGetString(rec, 2);
2570 if (!val)
2571 goto done;
2573 if (lstrlenW(val) >= *pccbValue)
2575 lstrcpynW(szValue, val, *pccbValue);
2576 *pccbValue = lstrlenW(val);
2577 r = ERROR_MORE_DATA;
2579 else
2581 lstrcpyW(szValue, val);
2582 *pccbValue = lstrlenW(val);
2583 r = ERROR_SUCCESS;
2586 done:
2587 if (view)
2589 MSI_ViewClose(view);
2590 msiobj_release(&view->hdr);
2591 if (rec) msiobj_release(&rec->hdr);
2594 if (!rec)
2596 if (szValue) *szValue = '\0';
2597 if (pccbValue) *pccbValue = 0;
2598 r = ERROR_SUCCESS;
2601 msiobj_release(&package->hdr);
2602 return r;
2605 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2607 UINT r;
2608 LPWSTR szPack = NULL;
2610 TRACE("%s\n", debugstr_a(szPackage) );
2612 if( szPackage )
2614 szPack = strdupAtoW( szPackage );
2615 if( !szPack )
2616 return ERROR_OUTOFMEMORY;
2619 r = MsiVerifyPackageW( szPack );
2621 msi_free( szPack );
2623 return r;
2626 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2628 MSIHANDLE handle;
2629 UINT r;
2631 TRACE("%s\n", debugstr_w(szPackage) );
2633 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2634 MsiCloseHandle( handle );
2636 return r;
2639 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2640 awstring* lpPathBuf, LPDWORD pcchBuf)
2642 WCHAR squished_pc[GUID_SIZE];
2643 WCHAR squished_comp[GUID_SIZE];
2644 HKEY hkey;
2645 LPWSTR path = NULL;
2646 INSTALLSTATE state;
2647 DWORD version;
2649 static const WCHAR wininstaller[] = {
2650 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2652 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
2653 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
2655 if (!szProduct || !szComponent)
2656 return INSTALLSTATE_INVALIDARG;
2658 if (lpPathBuf->str.w && !pcchBuf)
2659 return INSTALLSTATE_INVALIDARG;
2661 if (!squash_guid(szProduct, squished_pc) ||
2662 !squash_guid(szComponent, squished_comp))
2663 return INSTALLSTATE_INVALIDARG;
2665 state = INSTALLSTATE_UNKNOWN;
2667 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2668 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2670 path = msi_reg_get_val_str(hkey, squished_pc);
2671 RegCloseKey(hkey);
2673 state = INSTALLSTATE_ABSENT;
2675 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2676 &hkey, FALSE) == ERROR_SUCCESS ||
2677 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2678 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2679 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2680 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2682 RegCloseKey(hkey);
2683 state = INSTALLSTATE_LOCAL;
2687 if (state != INSTALLSTATE_LOCAL &&
2688 (MSIREG_OpenProductKey(szProduct, NULL,
2689 MSIINSTALLCONTEXT_USERUNMANAGED,
2690 &hkey, FALSE) == ERROR_SUCCESS ||
2691 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2692 &hkey, FALSE) == ERROR_SUCCESS))
2694 RegCloseKey(hkey);
2696 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2697 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2699 msi_free(path);
2700 path = msi_reg_get_val_str(hkey, squished_pc);
2701 RegCloseKey(hkey);
2703 state = INSTALLSTATE_ABSENT;
2705 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2706 state = INSTALLSTATE_LOCAL;
2710 if (!path)
2711 return INSTALLSTATE_UNKNOWN;
2713 if (state == INSTALLSTATE_LOCAL && !*path)
2714 state = INSTALLSTATE_NOTUSED;
2716 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
2717 msi_free(path);
2718 return state;
2721 /******************************************************************
2722 * MsiGetComponentPathW [MSI.@]
2724 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2725 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2727 awstring path;
2729 path.unicode = TRUE;
2730 path.str.w = lpPathBuf;
2732 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2735 /******************************************************************
2736 * MsiGetComponentPathA [MSI.@]
2738 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2739 LPSTR lpPathBuf, LPDWORD pcchBuf)
2741 LPWSTR szwProduct, szwComponent = NULL;
2742 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2743 awstring path;
2745 szwProduct = strdupAtoW( szProduct );
2746 if( szProduct && !szwProduct)
2747 goto end;
2749 szwComponent = strdupAtoW( szComponent );
2750 if( szComponent && !szwComponent )
2751 goto end;
2753 path.unicode = FALSE;
2754 path.str.a = lpPathBuf;
2756 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2758 end:
2759 msi_free( szwProduct );
2760 msi_free( szwComponent );
2762 return r;
2765 /******************************************************************
2766 * MsiQueryFeatureStateA [MSI.@]
2768 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
2770 LPWSTR szwProduct = NULL, szwFeature= NULL;
2771 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
2773 szwProduct = strdupAtoW( szProduct );
2774 if ( szProduct && !szwProduct )
2775 goto end;
2777 szwFeature = strdupAtoW( szFeature );
2778 if ( szFeature && !szwFeature )
2779 goto end;
2781 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
2783 end:
2784 msi_free( szwProduct);
2785 msi_free( szwFeature);
2787 return rc;
2790 /******************************************************************
2791 * MsiQueryFeatureStateW [MSI.@]
2793 * Checks the state of a feature
2795 * PARAMS
2796 * szProduct [I] Product's GUID string
2797 * szFeature [I] Feature's GUID string
2799 * RETURNS
2800 * INSTALLSTATE_LOCAL Feature is installed and usable
2801 * INSTALLSTATE_ABSENT Feature is absent
2802 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2803 * INSTALLSTATE_UNKNOWN An error occurred
2804 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2807 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
2809 WCHAR squishProduct[33], comp[GUID_SIZE];
2810 GUID guid;
2811 LPWSTR components, p, parent_feature, path;
2812 UINT rc;
2813 HKEY hkey;
2814 INSTALLSTATE r;
2815 BOOL missing = FALSE;
2816 BOOL machine = FALSE;
2817 BOOL source = FALSE;
2819 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
2821 if (!szProduct || !szFeature)
2822 return INSTALLSTATE_INVALIDARG;
2824 if (!squash_guid( szProduct, squishProduct ))
2825 return INSTALLSTATE_INVALIDARG;
2827 SetLastError( ERROR_SUCCESS );
2829 if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2830 &hkey, FALSE) != ERROR_SUCCESS &&
2831 MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2832 &hkey, FALSE) != ERROR_SUCCESS)
2834 rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2835 &hkey, FALSE);
2836 if (rc != ERROR_SUCCESS)
2837 return INSTALLSTATE_UNKNOWN;
2839 machine = TRUE;
2842 parent_feature = msi_reg_get_val_str( hkey, szFeature );
2843 RegCloseKey(hkey);
2845 if (!parent_feature)
2846 return INSTALLSTATE_UNKNOWN;
2848 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2849 msi_free(parent_feature);
2850 if (r == INSTALLSTATE_ABSENT)
2851 return r;
2853 if (machine)
2854 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2855 MSIINSTALLCONTEXT_MACHINE,
2856 &hkey, FALSE);
2857 else
2858 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2859 MSIINSTALLCONTEXT_USERUNMANAGED,
2860 &hkey, FALSE);
2862 if (rc != ERROR_SUCCESS)
2863 return INSTALLSTATE_ADVERTISED;
2865 components = msi_reg_get_val_str( hkey, szFeature );
2866 RegCloseKey(hkey);
2868 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
2870 if (!components)
2871 return INSTALLSTATE_ADVERTISED;
2873 for( p = components; *p && *p != 2 ; p += 20)
2875 if (!decode_base85_guid( p, &guid ))
2877 if (p != components)
2878 break;
2880 msi_free(components);
2881 return INSTALLSTATE_BADCONFIG;
2884 StringFromGUID2(&guid, comp, GUID_SIZE);
2886 if (machine)
2887 rc = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2888 else
2889 rc = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2891 if (rc != ERROR_SUCCESS)
2893 msi_free(components);
2894 return INSTALLSTATE_ADVERTISED;
2897 path = msi_reg_get_val_str(hkey, squishProduct);
2898 if (!path)
2899 missing = TRUE;
2900 else if (lstrlenW(path) > 2 &&
2901 path[0] >= '0' && path[0] <= '9' &&
2902 path[1] >= '0' && path[1] <= '9')
2904 source = TRUE;
2907 msi_free(path);
2909 msi_free(components);
2911 if (missing)
2912 r = INSTALLSTATE_ADVERTISED;
2913 else if (source)
2914 r = INSTALLSTATE_SOURCE;
2915 else
2916 r = INSTALLSTATE_LOCAL;
2918 TRACE("-> %d\n", r);
2919 return r;
2922 /******************************************************************
2923 * MsiGetFileVersionA [MSI.@]
2925 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
2926 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
2928 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
2929 UINT ret = ERROR_OUTOFMEMORY;
2931 if ((lpVersionBuf && !pcchVersionBuf) ||
2932 (lpLangBuf && !pcchLangBuf))
2933 return ERROR_INVALID_PARAMETER;
2935 if( szFilePath )
2937 szwFilePath = strdupAtoW( szFilePath );
2938 if( !szwFilePath )
2939 goto end;
2942 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
2944 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
2945 if( !lpwVersionBuff )
2946 goto end;
2949 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
2951 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
2952 if( !lpwLangBuff )
2953 goto end;
2956 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
2957 lpwLangBuff, pcchLangBuf);
2959 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
2960 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
2961 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
2962 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
2963 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
2964 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
2966 end:
2967 msi_free(szwFilePath);
2968 msi_free(lpwVersionBuff);
2969 msi_free(lpwLangBuff);
2971 return ret;
2974 /******************************************************************
2975 * MsiGetFileVersionW [MSI.@]
2977 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
2978 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
2980 static const WCHAR szVersionResource[] = {'\\',0};
2981 static const WCHAR szVersionFormat[] = {
2982 '%','d','.','%','d','.','%','d','.','%','d',0};
2983 static const WCHAR szLangResource[] = {
2984 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2985 'T','r','a','n','s','l','a','t','i','o','n',0};
2986 static const WCHAR szLangFormat[] = {'%','d',0};
2987 UINT ret = 0;
2988 DWORD dwVerLen, gle;
2989 LPVOID lpVer = NULL;
2990 VS_FIXEDFILEINFO *ffi;
2991 USHORT *lang;
2992 UINT puLen;
2993 WCHAR tmp[32];
2995 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
2996 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
2997 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
2999 if ((lpVersionBuf && !pcchVersionBuf) ||
3000 (lpLangBuf && !pcchLangBuf))
3001 return ERROR_INVALID_PARAMETER;
3003 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
3004 if( !dwVerLen )
3006 gle = GetLastError();
3007 if (gle == ERROR_BAD_PATHNAME)
3008 return ERROR_FILE_NOT_FOUND;
3009 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
3010 return ERROR_FILE_INVALID;
3012 return gle;
3015 lpVer = msi_alloc(dwVerLen);
3016 if( !lpVer )
3018 ret = ERROR_OUTOFMEMORY;
3019 goto end;
3022 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
3024 ret = GetLastError();
3025 goto end;
3028 if (pcchVersionBuf)
3030 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
3031 (puLen > 0) )
3033 wsprintfW(tmp, szVersionFormat,
3034 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
3035 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
3036 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
3038 if (strlenW(tmp) >= *pcchVersionBuf)
3039 ret = ERROR_MORE_DATA;
3041 *pcchVersionBuf = lstrlenW(tmp);
3043 else
3045 if (lpVersionBuf) *lpVersionBuf = 0;
3046 *pcchVersionBuf = 0;
3050 if (pcchLangBuf)
3052 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
3053 (puLen > 0))
3055 wsprintfW(tmp, szLangFormat, *lang);
3056 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
3058 if (strlenW(tmp) >= *pcchLangBuf)
3059 ret = ERROR_MORE_DATA;
3061 *pcchLangBuf = lstrlenW(tmp);
3063 else
3065 if (lpLangBuf) *lpLangBuf = 0;
3066 *pcchLangBuf = 0;
3070 end:
3071 msi_free(lpVer);
3072 return ret;
3075 /***********************************************************************
3076 * MsiGetFeatureUsageW [MSI.@]
3078 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
3079 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3081 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
3082 pdwUseCount, pwDateUsed);
3083 return ERROR_CALL_NOT_IMPLEMENTED;
3086 /***********************************************************************
3087 * MsiGetFeatureUsageA [MSI.@]
3089 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
3090 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3092 LPWSTR prod = NULL, feat = NULL;
3093 UINT ret = ERROR_OUTOFMEMORY;
3095 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
3096 pdwUseCount, pwDateUsed);
3098 prod = strdupAtoW( szProduct );
3099 if (szProduct && !prod)
3100 goto end;
3102 feat = strdupAtoW( szFeature );
3103 if (szFeature && !feat)
3104 goto end;
3106 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
3108 end:
3109 msi_free( prod );
3110 msi_free( feat );
3112 return ret;
3115 /***********************************************************************
3116 * MsiUseFeatureExW [MSI.@]
3118 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
3119 DWORD dwInstallMode, DWORD dwReserved )
3121 INSTALLSTATE state;
3123 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3124 dwInstallMode, dwReserved);
3126 state = MsiQueryFeatureStateW( szProduct, szFeature );
3128 if (dwReserved)
3129 return INSTALLSTATE_INVALIDARG;
3131 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
3133 FIXME("mark product %s feature %s as used\n",
3134 debugstr_w(szProduct), debugstr_w(szFeature) );
3137 return state;
3140 /***********************************************************************
3141 * MsiUseFeatureExA [MSI.@]
3143 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
3144 DWORD dwInstallMode, DWORD dwReserved )
3146 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
3147 LPWSTR prod = NULL, feat = NULL;
3149 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3150 dwInstallMode, dwReserved);
3152 prod = strdupAtoW( szProduct );
3153 if (szProduct && !prod)
3154 goto end;
3156 feat = strdupAtoW( szFeature );
3157 if (szFeature && !feat)
3158 goto end;
3160 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
3162 end:
3163 msi_free( prod );
3164 msi_free( feat );
3166 return ret;
3169 /***********************************************************************
3170 * MsiUseFeatureW [MSI.@]
3172 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
3174 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
3177 /***********************************************************************
3178 * MsiUseFeatureA [MSI.@]
3180 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
3182 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
3185 /***********************************************************************
3186 * MSI_ProvideQualifiedComponentEx [internal]
3188 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
3189 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3190 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
3191 LPDWORD pcchPathBuf)
3193 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
3194 feature[MAX_FEATURE_CHARS+1];
3195 LPWSTR info;
3196 HKEY hkey;
3197 DWORD sz;
3198 UINT rc;
3200 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
3201 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
3202 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3204 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
3205 if (rc != ERROR_SUCCESS)
3206 return ERROR_INDEX_ABSENT;
3208 info = msi_reg_get_val_str( hkey, szQualifier );
3209 RegCloseKey(hkey);
3211 if (!info)
3212 return ERROR_INDEX_ABSENT;
3214 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
3216 if (!szProduct)
3217 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
3218 else
3219 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
3221 msi_free( info );
3223 if (rc != INSTALLSTATE_LOCAL)
3224 return ERROR_FILE_NOT_FOUND;
3226 return ERROR_SUCCESS;
3229 /***********************************************************************
3230 * MsiProvideQualifiedComponentExW [MSI.@]
3232 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
3233 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3234 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
3235 LPDWORD pcchPathBuf)
3237 awstring path;
3239 path.unicode = TRUE;
3240 path.str.w = lpPathBuf;
3242 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
3243 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
3246 /***********************************************************************
3247 * MsiProvideQualifiedComponentExA [MSI.@]
3249 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
3250 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
3251 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
3252 LPDWORD pcchPathBuf)
3254 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
3255 UINT r = ERROR_OUTOFMEMORY;
3256 awstring path;
3258 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
3259 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
3260 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3262 szwComponent = strdupAtoW( szComponent );
3263 if (szComponent && !szwComponent)
3264 goto end;
3266 szwQualifier = strdupAtoW( szQualifier );
3267 if (szQualifier && !szwQualifier)
3268 goto end;
3270 szwProduct = strdupAtoW( szProduct );
3271 if (szProduct && !szwProduct)
3272 goto end;
3274 path.unicode = FALSE;
3275 path.str.a = lpPathBuf;
3277 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
3278 dwInstallMode, szwProduct, Unused1,
3279 Unused2, &path, pcchPathBuf);
3280 end:
3281 msi_free(szwProduct);
3282 msi_free(szwComponent);
3283 msi_free(szwQualifier);
3285 return r;
3288 /***********************************************************************
3289 * MsiProvideQualifiedComponentW [MSI.@]
3291 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
3292 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
3293 LPDWORD pcchPathBuf)
3295 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
3296 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3299 /***********************************************************************
3300 * MsiProvideQualifiedComponentA [MSI.@]
3302 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
3303 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
3304 LPDWORD pcchPathBuf)
3306 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
3307 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3310 /***********************************************************************
3311 * MSI_GetUserInfo [internal]
3313 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
3314 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
3315 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3316 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
3318 WCHAR squished_pc[SQUISH_GUID_SIZE];
3319 LPWSTR user, org, serial;
3320 USERINFOSTATE state;
3321 HKEY hkey, props;
3322 LPCWSTR orgptr;
3323 UINT r;
3325 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
3326 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
3327 pcchSerialBuf);
3329 if (!szProduct || !squash_guid(szProduct, squished_pc))
3330 return USERINFOSTATE_INVALIDARG;
3332 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
3333 &hkey, FALSE) != ERROR_SUCCESS &&
3334 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3335 &hkey, FALSE) != ERROR_SUCCESS &&
3336 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
3337 &hkey, FALSE) != ERROR_SUCCESS)
3339 return USERINFOSTATE_UNKNOWN;
3342 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
3343 NULL, &props, FALSE) != ERROR_SUCCESS &&
3344 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
3345 NULL, &props, FALSE) != ERROR_SUCCESS)
3347 RegCloseKey(hkey);
3348 return USERINFOSTATE_ABSENT;
3351 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3352 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3353 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3354 state = USERINFOSTATE_ABSENT;
3356 RegCloseKey(hkey);
3357 RegCloseKey(props);
3359 if (user && serial)
3360 state = USERINFOSTATE_PRESENT;
3362 if (pcchUserNameBuf)
3364 if (lpUserNameBuf && !user)
3366 (*pcchUserNameBuf)--;
3367 goto done;
3370 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
3371 if (r == ERROR_MORE_DATA)
3373 state = USERINFOSTATE_MOREDATA;
3374 goto done;
3378 if (pcchOrgNameBuf)
3380 orgptr = org;
3381 if (!orgptr) orgptr = szEmpty;
3383 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
3384 if (r == ERROR_MORE_DATA)
3386 state = USERINFOSTATE_MOREDATA;
3387 goto done;
3391 if (pcchSerialBuf)
3393 if (!serial)
3395 (*pcchSerialBuf)--;
3396 goto done;
3399 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
3400 if (r == ERROR_MORE_DATA)
3401 state = USERINFOSTATE_MOREDATA;
3404 done:
3405 msi_free(user);
3406 msi_free(org);
3407 msi_free(serial);
3409 return state;
3412 /***********************************************************************
3413 * MsiGetUserInfoW [MSI.@]
3415 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3416 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3417 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3418 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3420 awstring user, org, serial;
3422 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3423 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3424 (lpSerialBuf && !pcchSerialBuf))
3425 return USERINFOSTATE_INVALIDARG;
3427 user.unicode = TRUE;
3428 user.str.w = lpUserNameBuf;
3429 org.unicode = TRUE;
3430 org.str.w = lpOrgNameBuf;
3431 serial.unicode = TRUE;
3432 serial.str.w = lpSerialBuf;
3434 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3435 &org, pcchOrgNameBuf,
3436 &serial, pcchSerialBuf );
3439 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3440 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3441 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3442 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3444 awstring user, org, serial;
3445 LPWSTR prod;
3446 UINT r;
3448 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3449 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3450 (lpSerialBuf && !pcchSerialBuf))
3451 return USERINFOSTATE_INVALIDARG;
3453 prod = strdupAtoW( szProduct );
3454 if (szProduct && !prod)
3455 return ERROR_OUTOFMEMORY;
3457 user.unicode = FALSE;
3458 user.str.a = lpUserNameBuf;
3459 org.unicode = FALSE;
3460 org.str.a = lpOrgNameBuf;
3461 serial.unicode = FALSE;
3462 serial.str.a = lpSerialBuf;
3464 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3465 &org, pcchOrgNameBuf,
3466 &serial, pcchSerialBuf );
3468 msi_free( prod );
3470 return r;
3473 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3475 MSIHANDLE handle;
3476 UINT rc;
3477 MSIPACKAGE *package;
3478 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3480 TRACE("(%s)\n",debugstr_w(szProduct));
3482 rc = MsiOpenProductW(szProduct,&handle);
3483 if (rc != ERROR_SUCCESS)
3484 return ERROR_INVALID_PARAMETER;
3486 /* MsiCollectUserInfo cannot be called from a custom action. */
3487 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3488 if (!package)
3489 return ERROR_CALL_NOT_IMPLEMENTED;
3491 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3492 msiobj_release( &package->hdr );
3494 MsiCloseHandle(handle);
3496 return rc;
3499 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3501 MSIHANDLE handle;
3502 UINT rc;
3503 MSIPACKAGE *package;
3504 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3506 TRACE("(%s)\n",debugstr_a(szProduct));
3508 rc = MsiOpenProductA(szProduct,&handle);
3509 if (rc != ERROR_SUCCESS)
3510 return ERROR_INVALID_PARAMETER;
3512 /* MsiCollectUserInfo cannot be called from a custom action. */
3513 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3514 if (!package)
3515 return ERROR_CALL_NOT_IMPLEMENTED;
3517 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3518 msiobj_release( &package->hdr );
3520 MsiCloseHandle(handle);
3522 return rc;
3525 /***********************************************************************
3526 * MsiConfigureFeatureA [MSI.@]
3528 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3530 LPWSTR prod, feat = NULL;
3531 UINT r = ERROR_OUTOFMEMORY;
3533 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3535 prod = strdupAtoW( szProduct );
3536 if (szProduct && !prod)
3537 goto end;
3539 feat = strdupAtoW( szFeature );
3540 if (szFeature && !feat)
3541 goto end;
3543 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3545 end:
3546 msi_free(feat);
3547 msi_free(prod);
3549 return r;
3552 /***********************************************************************
3553 * MsiConfigureFeatureW [MSI.@]
3555 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3557 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3558 MSIPACKAGE *package = NULL;
3559 UINT r;
3560 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3561 DWORD sz;
3563 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3565 if (!szProduct || !szFeature)
3566 return ERROR_INVALID_PARAMETER;
3568 switch (eInstallState)
3570 case INSTALLSTATE_DEFAULT:
3571 /* FIXME: how do we figure out the default location? */
3572 eInstallState = INSTALLSTATE_LOCAL;
3573 break;
3574 case INSTALLSTATE_LOCAL:
3575 case INSTALLSTATE_SOURCE:
3576 case INSTALLSTATE_ABSENT:
3577 case INSTALLSTATE_ADVERTISED:
3578 break;
3579 default:
3580 return ERROR_INVALID_PARAMETER;
3583 r = MSI_OpenProductW( szProduct, &package );
3584 if (r != ERROR_SUCCESS)
3585 return r;
3587 sz = sizeof(sourcepath);
3588 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3589 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3591 sz = sizeof(filename);
3592 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3593 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3595 lstrcatW( sourcepath, filename );
3597 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3599 r = ACTION_PerformUIAction( package, szCostInit, -1 );
3600 if (r != ERROR_SUCCESS)
3601 goto end;
3603 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3604 if (r != ERROR_SUCCESS)
3605 goto end;
3607 r = MSI_InstallPackage( package, sourcepath, NULL );
3609 end:
3610 msiobj_release( &package->hdr );
3612 return r;
3615 /***********************************************************************
3616 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3618 * Notes: undocumented
3620 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3622 WCHAR path[MAX_PATH];
3624 TRACE("%d\n", dwReserved);
3626 if (dwReserved)
3628 FIXME("dwReserved=%d\n", dwReserved);
3629 return ERROR_INVALID_PARAMETER;
3632 if (!GetWindowsDirectoryW(path, MAX_PATH))
3633 return ERROR_FUNCTION_FAILED;
3635 lstrcatW(path, installerW);
3637 if (!CreateDirectoryW(path, NULL))
3638 return ERROR_FUNCTION_FAILED;
3640 return ERROR_SUCCESS;
3643 /***********************************************************************
3644 * MsiGetShortcutTargetA [MSI.@]
3646 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3647 LPSTR szProductCode, LPSTR szFeatureId,
3648 LPSTR szComponentCode )
3650 LPWSTR target;
3651 const int len = MAX_FEATURE_CHARS+1;
3652 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3653 UINT r;
3655 target = strdupAtoW( szShortcutTarget );
3656 if (szShortcutTarget && !target )
3657 return ERROR_OUTOFMEMORY;
3658 product[0] = 0;
3659 feature[0] = 0;
3660 component[0] = 0;
3661 r = MsiGetShortcutTargetW( target, product, feature, component );
3662 msi_free( target );
3663 if (r == ERROR_SUCCESS)
3665 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3666 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3667 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3669 return r;
3672 /***********************************************************************
3673 * MsiGetShortcutTargetW [MSI.@]
3675 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3676 LPWSTR szProductCode, LPWSTR szFeatureId,
3677 LPWSTR szComponentCode )
3679 IShellLinkDataList *dl = NULL;
3680 IPersistFile *pf = NULL;
3681 LPEXP_DARWIN_LINK darwin = NULL;
3682 HRESULT r, init;
3684 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3685 szProductCode, szFeatureId, szComponentCode );
3687 init = CoInitialize(NULL);
3689 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3690 &IID_IPersistFile, (LPVOID*) &pf );
3691 if( SUCCEEDED( r ) )
3693 r = IPersistFile_Load( pf, szShortcutTarget,
3694 STGM_READ | STGM_SHARE_DENY_WRITE );
3695 if( SUCCEEDED( r ) )
3697 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3698 (LPVOID*) &dl );
3699 if( SUCCEEDED( r ) )
3701 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3702 (LPVOID) &darwin );
3703 IShellLinkDataList_Release( dl );
3706 IPersistFile_Release( pf );
3709 if (SUCCEEDED(init))
3710 CoUninitialize();
3712 TRACE("darwin = %p\n", darwin);
3714 if (darwin)
3716 DWORD sz;
3717 UINT ret;
3719 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3720 szProductCode, szFeatureId, szComponentCode, &sz );
3721 LocalFree( darwin );
3722 return ret;
3725 return ERROR_FUNCTION_FAILED;
3728 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
3729 DWORD dwReinstallMode )
3731 MSIPACKAGE* package = NULL;
3732 UINT r;
3733 WCHAR sourcepath[MAX_PATH];
3734 WCHAR filename[MAX_PATH];
3735 static const WCHAR szLogVerbose[] = {
3736 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3737 WCHAR reinstallmode[11];
3738 LPWSTR ptr;
3739 DWORD sz;
3741 FIXME("%s %s 0x%08x\n",
3742 debugstr_w(szProduct), debugstr_w(szFeature), dwReinstallMode);
3744 ptr = reinstallmode;
3746 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3747 *ptr++ = 'p';
3748 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3749 *ptr++ = 'o';
3750 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3751 *ptr++ = 'w';
3752 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3753 *ptr++ = 'd';
3754 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3755 *ptr++ = 'c';
3756 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3757 *ptr++ = 'a';
3758 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3759 *ptr++ = 'u';
3760 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3761 *ptr++ = 'm';
3762 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3763 *ptr++ = 's';
3764 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3765 *ptr++ = 'v';
3766 *ptr = 0;
3768 sz = sizeof(sourcepath);
3769 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3770 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3772 sz = sizeof(filename);
3773 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3774 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3776 lstrcatW( sourcepath, filename );
3778 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3779 r = MSI_OpenPackageW( sourcepath, &package );
3780 else
3781 r = MSI_OpenProductW( szProduct, &package );
3783 if (r != ERROR_SUCCESS)
3784 return r;
3786 msi_set_property( package->db, szReinstallMode, reinstallmode );
3787 msi_set_property( package->db, szInstalled, szOne );
3788 msi_set_property( package->db, szLogVerbose, szOne );
3789 msi_set_property( package->db, szReinstall, szFeature );
3791 r = MSI_InstallPackage( package, sourcepath, NULL );
3793 msiobj_release( &package->hdr );
3795 return r;
3798 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3799 DWORD dwReinstallMode )
3801 LPWSTR wszProduct;
3802 LPWSTR wszFeature;
3803 UINT rc;
3805 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3806 dwReinstallMode);
3808 wszProduct = strdupAtoW(szProduct);
3809 wszFeature = strdupAtoW(szFeature);
3811 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3813 msi_free(wszProduct);
3814 msi_free(wszFeature);
3815 return rc;
3818 typedef struct
3820 unsigned int i[2];
3821 unsigned int buf[4];
3822 unsigned char in[64];
3823 unsigned char digest[16];
3824 } MD5_CTX;
3826 extern VOID WINAPI MD5Init( MD5_CTX *);
3827 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
3828 extern VOID WINAPI MD5Final( MD5_CTX *);
3830 /***********************************************************************
3831 * MsiGetFileHashW [MSI.@]
3833 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
3834 PMSIFILEHASHINFO pHash )
3836 HANDLE handle, mapping;
3837 void *p;
3838 DWORD length;
3839 UINT r = ERROR_FUNCTION_FAILED;
3841 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
3843 if (!szFilePath)
3844 return ERROR_INVALID_PARAMETER;
3846 if (!*szFilePath)
3847 return ERROR_PATH_NOT_FOUND;
3849 if (dwOptions)
3850 return ERROR_INVALID_PARAMETER;
3851 if (!pHash)
3852 return ERROR_INVALID_PARAMETER;
3853 if (pHash->dwFileHashInfoSize < sizeof *pHash)
3854 return ERROR_INVALID_PARAMETER;
3856 handle = CreateFileW( szFilePath, GENERIC_READ,
3857 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
3858 if (handle == INVALID_HANDLE_VALUE)
3860 WARN("can't open file %u\n", GetLastError());
3861 return ERROR_FILE_NOT_FOUND;
3863 length = GetFileSize( handle, NULL );
3865 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
3866 if (mapping)
3868 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
3869 if (p)
3871 MD5_CTX ctx;
3873 MD5Init( &ctx );
3874 MD5Update( &ctx, p, length );
3875 MD5Final( &ctx );
3876 UnmapViewOfFile( p );
3878 memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
3879 r = ERROR_SUCCESS;
3881 CloseHandle( mapping );
3883 CloseHandle( handle );
3885 return r;
3888 /***********************************************************************
3889 * MsiGetFileHashA [MSI.@]
3891 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
3892 PMSIFILEHASHINFO pHash )
3894 LPWSTR file;
3895 UINT r;
3897 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
3899 file = strdupAtoW( szFilePath );
3900 if (szFilePath && !file)
3901 return ERROR_OUTOFMEMORY;
3903 r = MsiGetFileHashW( file, dwOptions, pHash );
3904 msi_free( file );
3905 return r;
3908 /***********************************************************************
3909 * MsiAdvertiseScriptW [MSI.@]
3911 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
3912 PHKEY phRegData, BOOL fRemoveItems )
3914 FIXME("%s %08x %p %d\n",
3915 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3916 return ERROR_CALL_NOT_IMPLEMENTED;
3919 /***********************************************************************
3920 * MsiAdvertiseScriptA [MSI.@]
3922 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
3923 PHKEY phRegData, BOOL fRemoveItems )
3925 FIXME("%s %08x %p %d\n",
3926 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3927 return ERROR_CALL_NOT_IMPLEMENTED;
3930 /***********************************************************************
3931 * MsiIsProductElevatedW [MSI.@]
3933 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
3935 FIXME("%s %p - stub\n",
3936 debugstr_w( szProduct ), pfElevated );
3937 *pfElevated = TRUE;
3938 return ERROR_SUCCESS;
3941 /***********************************************************************
3942 * MsiIsProductElevatedA [MSI.@]
3944 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
3946 FIXME("%s %p - stub\n",
3947 debugstr_a( szProduct ), pfElevated );
3948 *pfElevated = TRUE;
3949 return ERROR_SUCCESS;
3952 /***********************************************************************
3953 * MsiSetExternalUIRecord [MSI.@]
3955 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler,
3956 DWORD filter, LPVOID context,
3957 PINSTALLUI_HANDLER_RECORD prev )
3959 TRACE("%p %08x %p %p\n", handler, filter, context, prev);
3961 if (prev)
3962 *prev = gUIHandlerRecord;
3964 gUIHandlerRecord = handler;
3965 gUIFilter = filter;
3966 gUIContext = context;
3968 return ERROR_SUCCESS;
3971 /***********************************************************************
3972 * MsiInstallMissingComponentA [MSI.@]
3974 UINT WINAPI MsiInstallMissingComponentA( LPCSTR product, LPCSTR component, INSTALLSTATE state )
3976 UINT r;
3977 WCHAR *productW = NULL, *componentW = NULL;
3979 TRACE("%s, %s, %d\n", debugstr_a(product), debugstr_a(component), state);
3981 if (product && !(productW = strdupAtoW( product )))
3982 return ERROR_OUTOFMEMORY;
3984 if (component && !(componentW = strdupAtoW( component )))
3986 msi_free( productW );
3987 return ERROR_OUTOFMEMORY;
3990 r = MsiInstallMissingComponentW( productW, componentW, state );
3991 msi_free( productW );
3992 msi_free( componentW );
3993 return r;
3996 /***********************************************************************
3997 * MsiInstallMissingComponentW [MSI.@]
3999 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
4001 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
4002 return ERROR_SUCCESS;
4005 /***********************************************************************
4006 * MsiBeginTransactionA [MSI.@]
4008 UINT WINAPI MsiBeginTransactionA( LPCSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4010 WCHAR *nameW;
4011 UINT r;
4013 FIXME("%s %u %p %p\n", debugstr_a(name), attrs, id, event);
4015 nameW = strdupAtoW( name );
4016 if (name && !nameW)
4017 return ERROR_OUTOFMEMORY;
4019 r = MsiBeginTransactionW( nameW, attrs, id, event );
4020 msi_free( nameW );
4021 return r;
4024 /***********************************************************************
4025 * MsiBeginTransactionW [MSI.@]
4027 UINT WINAPI MsiBeginTransactionW( LPCWSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4029 FIXME("%s %u %p %p\n", debugstr_w(name), attrs, id, event);
4031 *id = (MSIHANDLE)0xdeadbeef;
4032 *event = (HANDLE)0xdeadbeef;
4034 return ERROR_SUCCESS;
4037 /***********************************************************************
4038 * MsiEndTransaction [MSI.@]
4040 UINT WINAPI MsiEndTransaction( DWORD state )
4042 FIXME("%u\n", state);
4043 return ERROR_SUCCESS;