msi: Register more patch details.
[wine/multimedia.git] / dlls / msi / msi.c
blob2d33487b0cf1e1d58768d53c47c3710be03baa10
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "shlwapi.h"
31 #include "wine/debug.h"
32 #include "msi.h"
33 #include "msidefs.h"
34 #include "msiquery.h"
35 #include "msipriv.h"
36 #include "wincrypt.h"
37 #include "winver.h"
38 #include "winuser.h"
39 #include "shlobj.h"
40 #include "shobjidl.h"
41 #include "objidl.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi);
46 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
48 static UINT msi_locate_product(LPCWSTR szProduct, MSIINSTALLCONTEXT *context)
50 HKEY hkey = NULL;
52 *context = MSIINSTALLCONTEXT_NONE;
54 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
55 &hkey, FALSE) == ERROR_SUCCESS)
56 *context = MSIINSTALLCONTEXT_USERMANAGED;
57 else if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
58 &hkey, FALSE) == ERROR_SUCCESS)
59 *context = MSIINSTALLCONTEXT_MACHINE;
60 else if (MSIREG_OpenProductKey(szProduct, NULL,
61 MSIINSTALLCONTEXT_USERUNMANAGED,
62 &hkey, FALSE) == ERROR_SUCCESS)
63 *context = MSIINSTALLCONTEXT_USERUNMANAGED;
65 RegCloseKey(hkey);
67 if (*context == MSIINSTALLCONTEXT_NONE)
68 return ERROR_UNKNOWN_PRODUCT;
70 return ERROR_SUCCESS;
73 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
75 UINT r;
76 LPWSTR szwProd = NULL;
78 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
80 if( szProduct )
82 szwProd = strdupAtoW( szProduct );
83 if( !szwProd )
84 return ERROR_OUTOFMEMORY;
87 r = MsiOpenProductW( szwProd, phProduct );
89 msi_free( szwProd );
91 return r;
94 static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
96 UINT r;
97 HKEY props;
98 LPWSTR path;
99 MSIINSTALLCONTEXT context;
101 static const WCHAR managed[] = {
102 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
103 static const WCHAR local[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
105 TRACE("%s %p\n", debugstr_w(szProduct), package);
107 r = msi_locate_product(szProduct, &context);
108 if (r != ERROR_SUCCESS)
109 return r;
111 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &props, FALSE);
112 if (r != ERROR_SUCCESS)
113 return ERROR_UNKNOWN_PRODUCT;
115 if (context == MSIINSTALLCONTEXT_USERMANAGED)
116 path = msi_reg_get_val_str(props, managed);
117 else
118 path = msi_reg_get_val_str(props, local);
120 r = ERROR_UNKNOWN_PRODUCT;
122 if (!path || GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
123 goto done;
125 if (PathIsRelativeW(path))
127 r = ERROR_INSTALL_PACKAGE_OPEN_FAILED;
128 goto done;
131 r = MSI_OpenPackageW(path, package);
133 done:
134 RegCloseKey(props);
135 msi_free(path);
136 return r;
139 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
141 MSIPACKAGE *package = NULL;
142 WCHAR squished_pc[GUID_SIZE];
143 UINT r;
145 if (!szProduct || !squash_guid(szProduct, squished_pc))
146 return ERROR_INVALID_PARAMETER;
148 if (!phProduct)
149 return ERROR_INVALID_PARAMETER;
151 r = MSI_OpenProductW(szProduct, &package);
152 if (r != ERROR_SUCCESS)
153 return r;
155 *phProduct = alloc_msihandle(&package->hdr);
156 if (!*phProduct)
157 r = ERROR_NOT_ENOUGH_MEMORY;
159 msiobj_release(&package->hdr);
160 return r;
163 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
164 LPCSTR szTransforms, LANGID lgidLanguage)
166 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
167 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
168 return ERROR_CALL_NOT_IMPLEMENTED;
171 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
172 LPCWSTR szTransforms, LANGID lgidLanguage)
174 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
175 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
176 return ERROR_CALL_NOT_IMPLEMENTED;
179 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
180 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
182 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
183 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
184 lgidLanguage, dwPlatform, dwOptions);
185 return ERROR_CALL_NOT_IMPLEMENTED;
188 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
189 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
191 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
192 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
193 lgidLanguage, dwPlatform, dwOptions);
194 return ERROR_CALL_NOT_IMPLEMENTED;
197 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
199 LPWSTR szwPath = NULL, szwCommand = NULL;
200 UINT r = ERROR_OUTOFMEMORY;
202 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
204 if( szPackagePath )
206 szwPath = strdupAtoW( szPackagePath );
207 if( !szwPath )
208 goto end;
211 if( szCommandLine )
213 szwCommand = strdupAtoW( szCommandLine );
214 if( !szwCommand )
215 goto end;
218 r = MsiInstallProductW( szwPath, szwCommand );
220 end:
221 msi_free( szwPath );
222 msi_free( szwCommand );
224 return r;
227 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
229 MSIPACKAGE *package = NULL;
230 UINT r;
232 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
234 if (!szPackagePath)
235 return ERROR_INVALID_PARAMETER;
237 if (!*szPackagePath)
238 return ERROR_PATH_NOT_FOUND;
240 r = MSI_OpenPackageW( szPackagePath, &package );
241 if (r == ERROR_SUCCESS)
243 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
244 msiobj_release( &package->hdr );
247 return r;
250 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
252 LPWSTR wszProduct;
253 UINT rc;
255 TRACE("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
257 wszProduct = strdupAtoW(szProduct);
259 rc = MsiReinstallProductW(wszProduct, dwReinstallMode);
261 msi_free(wszProduct);
262 return rc;
265 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
267 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
269 return MsiReinstallFeatureW(szProduct, szAll, dwReinstallMode);
272 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
273 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
275 LPWSTR patch_package = NULL;
276 LPWSTR install_package = NULL;
277 LPWSTR command_line = NULL;
278 UINT r = ERROR_OUTOFMEMORY;
280 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
281 eInstallType, debugstr_a(szCommandLine));
283 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
284 goto done;
286 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
287 goto done;
289 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
290 goto done;
292 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
294 done:
295 msi_free(patch_package);
296 msi_free(install_package);
297 msi_free(command_line);
299 return r;
302 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
304 MSIHANDLE patch = 0, info = 0;
305 UINT r = ERROR_SUCCESS, type;
306 DWORD size = 0;
307 LPCWSTR cmd_ptr = szCommandLine;
308 LPWSTR beg, end, cmd = NULL, codes = NULL;
309 BOOL succeeded = FALSE;
311 static const WCHAR patcheq[] = {'P','A','T','C','H','=',0};
312 static WCHAR empty[] = {0};
314 if (!szPatchPackage || !szPatchPackage[0])
315 return ERROR_INVALID_PARAMETER;
317 if (!szProductCode)
319 r = MsiOpenDatabaseW(szPatchPackage, MSIDBOPEN_READONLY, &patch);
320 if (r != ERROR_SUCCESS)
321 return r;
323 r = MsiGetSummaryInformationW(patch, NULL, 0, &info);
324 if (r != ERROR_SUCCESS)
325 goto done;
327 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, empty, &size);
328 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
330 ERR("Failed to read product codes from patch\n");
331 goto done;
334 codes = msi_alloc(++size * sizeof(WCHAR));
335 if (!codes)
337 r = ERROR_OUTOFMEMORY;
338 goto done;
341 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, codes, &size);
342 if (r != ERROR_SUCCESS)
343 goto done;
346 if (!szCommandLine)
347 cmd_ptr = empty;
349 size = lstrlenW(cmd_ptr) + lstrlenW(patcheq) + lstrlenW(szPatchPackage) + 1;
350 cmd = msi_alloc(size * sizeof(WCHAR));
351 if (!cmd)
353 r = ERROR_OUTOFMEMORY;
354 goto done;
357 lstrcpyW(cmd, cmd_ptr);
358 if (szCommandLine) lstrcatW(cmd, szSpace);
359 lstrcatW(cmd, patcheq);
360 lstrcatW(cmd, szPatchPackage);
362 if (szProductCode)
363 r = MsiConfigureProductExW(szProductCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
364 else
366 beg = codes;
367 while ((end = strchrW(beg, '}')))
369 *(end + 1) = '\0';
370 r = MsiConfigureProductExW(beg, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
371 if (r == ERROR_SUCCESS)
373 TRACE("patch applied\n");
374 succeeded = TRUE;
376 beg = end + 2;
379 if (succeeded)
380 r = ERROR_SUCCESS;
383 done:
384 msi_free(cmd);
385 msi_free(codes);
387 MsiCloseHandle(info);
388 MsiCloseHandle(patch);
390 return r;
393 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
394 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
396 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
397 eInstallType, debugstr_w(szCommandLine));
399 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
400 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
402 FIXME("Only reading target products from patch\n");
403 return ERROR_CALL_NOT_IMPLEMENTED;
406 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
409 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
410 LPCSTR szProductCode, LPCSTR szPropertiesList)
412 LPWSTR patch_packages = NULL;
413 LPWSTR product_code = NULL;
414 LPWSTR properties_list = NULL;
415 UINT r = ERROR_OUTOFMEMORY;
417 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
418 debugstr_a(szPropertiesList));
420 if (!szPatchPackages || !szPatchPackages[0])
421 return ERROR_INVALID_PARAMETER;
423 if (!(patch_packages = strdupAtoW(szPatchPackages)))
424 return ERROR_OUTOFMEMORY;
426 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
427 goto done;
429 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
430 goto done;
432 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
434 done:
435 msi_free(patch_packages);
436 msi_free(product_code);
437 msi_free(properties_list);
439 return r;
442 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
443 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
445 UINT r = ERROR_SUCCESS;
446 LPCWSTR beg, end;
448 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
449 debugstr_w(szPropertiesList));
451 if (!szPatchPackages || !szPatchPackages[0])
452 return ERROR_INVALID_PARAMETER;
454 beg = end = szPatchPackages;
455 while (*beg)
457 DWORD len;
458 LPWSTR patch;
460 while (*beg == ' ') beg++;
461 while (*end && *end != ';') end++;
463 len = end - beg;
464 while (len && beg[len - 1] == ' ') len--;
466 if (!len) return ERROR_INVALID_NAME;
468 patch = msi_alloc((len + 1) * sizeof(WCHAR));
469 if (!patch)
470 return ERROR_OUTOFMEMORY;
472 memcpy(patch, beg, len * sizeof(WCHAR));
473 patch[len] = '\0';
475 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
476 msi_free(patch);
478 if (r != ERROR_SUCCESS)
479 break;
481 beg = ++end;
483 return r;
486 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
487 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
489 FIXME("(%s, %d, %p): stub!\n", debugstr_a(szProductPackagePath),
490 cPatchInfo, pPatchInfo);
492 return ERROR_CALL_NOT_IMPLEMENTED;
495 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
497 MSISUMMARYINFO *si;
498 MSIDATABASE *patch_db;
499 UINT r = ERROR_SUCCESS;
501 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
502 if (r != ERROR_SUCCESS)
504 WARN("failed to open patch file %s\n", debugstr_w(patch));
505 return r;
508 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
509 if (!si)
511 r = ERROR_FUNCTION_FAILED;
512 goto done;
515 r = msi_check_patch_applicable( package, si );
516 if (r != ERROR_SUCCESS)
517 TRACE("patch not applicable\n");
519 done:
520 msiobj_release( &patch_db->hdr );
521 msiobj_release( &si->hdr );
522 return r;
525 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
526 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
528 UINT i, r, ret = ERROR_FUNCTION_FAILED;
529 MSIPACKAGE *package;
531 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
533 r = MSI_OpenPackageW( szProductPackagePath, &package );
534 if (r != ERROR_SUCCESS)
536 ERR("failed to open package %u\n", r);
537 return r;
540 for (i = 0; i < cPatchInfo; i++)
542 switch (pPatchInfo[i].ePatchDataType)
544 case MSIPATCH_DATATYPE_PATCHFILE:
546 FIXME("patch ordering not supported\n");
547 r = MSI_ApplicablePatchW( package, pPatchInfo[i].szPatchData );
548 if (r != ERROR_SUCCESS)
550 pPatchInfo[i].dwOrder = ~0u;
551 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
553 else
555 pPatchInfo[i].dwOrder = i;
556 pPatchInfo[i].uStatus = ret = ERROR_SUCCESS;
558 break;
560 default:
562 FIXME("patch data type %u not supported\n", pPatchInfo[i].ePatchDataType);
563 pPatchInfo[i].dwOrder = ~0u;
564 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
565 break;
569 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo[i].szPatchData));
570 TRACE("ePatchDataType: %u\n", pPatchInfo[i].ePatchDataType);
571 TRACE(" dwOrder: %u\n", pPatchInfo[i].dwOrder);
572 TRACE(" uStatus: %u\n", pPatchInfo[i].uStatus);
574 return ret;
577 UINT WINAPI MsiDeterminePatchSequenceA(LPCSTR szProductCode, LPCSTR szUserSid,
578 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
580 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode),
581 debugstr_a(szUserSid), dwContext, cPatchInfo, pPatchInfo);
583 return ERROR_CALL_NOT_IMPLEMENTED;
586 UINT WINAPI MsiDeterminePatchSequenceW(LPCWSTR szProductCode, LPCWSTR szUserSid,
587 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
589 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode),
590 debugstr_w(szUserSid), dwContext, cPatchInfo, pPatchInfo);
592 return ERROR_CALL_NOT_IMPLEMENTED;
595 static UINT msi_open_package(LPCWSTR product, MSIINSTALLCONTEXT context,
596 MSIPACKAGE **package)
598 UINT r;
599 DWORD sz;
600 HKEY props;
601 LPWSTR localpack;
602 WCHAR sourcepath[MAX_PATH];
603 WCHAR filename[MAX_PATH];
605 r = MSIREG_OpenInstallProps(product, context, NULL, &props, FALSE);
606 if (r != ERROR_SUCCESS)
607 return ERROR_BAD_CONFIGURATION;
609 localpack = msi_reg_get_val_str(props, szLocalPackage);
610 if (localpack)
612 lstrcpyW(sourcepath, localpack);
613 msi_free(localpack);
616 if (!localpack || GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
618 sz = sizeof(sourcepath);
619 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
620 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
622 sz = sizeof(filename);
623 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
624 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
626 lstrcatW(sourcepath, filename);
629 if (GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
630 return ERROR_INSTALL_SOURCE_ABSENT;
632 return MSI_OpenPackageW(sourcepath, package);
635 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
636 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
638 MSIPACKAGE* package = NULL;
639 MSIINSTALLCONTEXT context;
640 UINT r;
641 DWORD sz;
642 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
643 LPWSTR commandline;
645 static const WCHAR szInstalled[] = {
646 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
647 static const WCHAR szRemoveAll[] = {
648 ' ','R','E','M','O','V','E','=','A','L','L',0};
649 static const WCHAR szMachine[] = {
650 ' ','A','L','L','U','S','E','R','S','=','1',0};
652 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
653 debugstr_w(szCommandLine));
655 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
656 return ERROR_INVALID_PARAMETER;
658 if (eInstallState == INSTALLSTATE_ADVERTISED ||
659 eInstallState == INSTALLSTATE_SOURCE)
661 FIXME("State %d not implemented\n", eInstallState);
662 return ERROR_CALL_NOT_IMPLEMENTED;
665 r = msi_locate_product(szProduct, &context);
666 if (r != ERROR_SUCCESS)
667 return r;
669 r = msi_open_package(szProduct, context, &package);
670 if (r != ERROR_SUCCESS)
671 return r;
673 sz = lstrlenW(szInstalled) + 1;
675 if (szCommandLine)
676 sz += lstrlenW(szCommandLine);
678 if (eInstallState == INSTALLSTATE_ABSENT)
679 sz += lstrlenW(szRemoveAll);
681 if (context == MSIINSTALLCONTEXT_MACHINE)
682 sz += lstrlenW(szMachine);
684 commandline = msi_alloc(sz * sizeof(WCHAR));
685 if (!commandline)
687 r = ERROR_OUTOFMEMORY;
688 goto end;
691 commandline[0] = 0;
692 if (szCommandLine)
693 lstrcpyW(commandline,szCommandLine);
695 if (eInstallState == INSTALLSTATE_ABSENT)
696 lstrcatW(commandline, szRemoveAll);
698 if (context == MSIINSTALLCONTEXT_MACHINE)
699 lstrcatW(commandline, szMachine);
701 sz = sizeof(sourcepath);
702 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
703 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
705 sz = sizeof(filename);
706 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
707 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
709 strcatW(sourcepath, filename);
711 r = MSI_InstallPackage( package, sourcepath, commandline );
713 msi_free(commandline);
715 end:
716 msiobj_release( &package->hdr );
718 return r;
721 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
722 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
724 LPWSTR szwProduct = NULL;
725 LPWSTR szwCommandLine = NULL;
726 UINT r = ERROR_OUTOFMEMORY;
728 if( szProduct )
730 szwProduct = strdupAtoW( szProduct );
731 if( !szwProduct )
732 goto end;
735 if( szCommandLine)
737 szwCommandLine = strdupAtoW( szCommandLine );
738 if( !szwCommandLine)
739 goto end;
742 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
743 szwCommandLine );
744 end:
745 msi_free( szwProduct );
746 msi_free( szwCommandLine);
748 return r;
751 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
752 INSTALLSTATE eInstallState)
754 LPWSTR szwProduct = NULL;
755 UINT r;
757 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
759 if( szProduct )
761 szwProduct = strdupAtoW( szProduct );
762 if( !szwProduct )
763 return ERROR_OUTOFMEMORY;
766 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
767 msi_free( szwProduct );
769 return r;
772 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
773 INSTALLSTATE eInstallState)
775 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
778 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
780 LPWSTR szwComponent = NULL;
781 UINT r;
782 WCHAR szwBuffer[GUID_SIZE];
784 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
786 if( szComponent )
788 szwComponent = strdupAtoW( szComponent );
789 if( !szwComponent )
790 return ERROR_OUTOFMEMORY;
793 *szwBuffer = '\0';
794 r = MsiGetProductCodeW( szwComponent, szwBuffer );
796 if(*szwBuffer)
797 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
799 msi_free( szwComponent );
801 return r;
804 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
806 UINT rc, index;
807 HKEY compkey, prodkey;
808 WCHAR squished_comp[GUID_SIZE];
809 WCHAR squished_prod[GUID_SIZE];
810 DWORD sz = GUID_SIZE;
812 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
814 if (!szComponent || !*szComponent)
815 return ERROR_INVALID_PARAMETER;
817 if (!squash_guid(szComponent, squished_comp))
818 return ERROR_INVALID_PARAMETER;
820 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
821 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
823 return ERROR_UNKNOWN_COMPONENT;
826 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
827 if (rc != ERROR_SUCCESS)
829 RegCloseKey(compkey);
830 return ERROR_UNKNOWN_COMPONENT;
833 /* check simple case, only one product */
834 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
835 if (rc == ERROR_NO_MORE_ITEMS)
837 rc = ERROR_SUCCESS;
838 goto done;
841 index = 0;
842 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
843 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
845 index++;
846 sz = GUID_SIZE;
847 unsquash_guid(squished_prod, szBuffer);
849 if (MSIREG_OpenProductKey(szBuffer, NULL,
850 MSIINSTALLCONTEXT_USERMANAGED,
851 &prodkey, FALSE) == ERROR_SUCCESS ||
852 MSIREG_OpenProductKey(szBuffer, NULL,
853 MSIINSTALLCONTEXT_USERUNMANAGED,
854 &prodkey, FALSE) == ERROR_SUCCESS ||
855 MSIREG_OpenProductKey(szBuffer, NULL,
856 MSIINSTALLCONTEXT_MACHINE,
857 &prodkey, FALSE) == ERROR_SUCCESS)
859 RegCloseKey(prodkey);
860 rc = ERROR_SUCCESS;
861 goto done;
865 rc = ERROR_INSTALL_FAILURE;
867 done:
868 RegCloseKey(compkey);
869 unsquash_guid(squished_prod, szBuffer);
870 return rc;
873 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
875 DWORD dval;
876 LONG res;
877 WCHAR temp[20];
879 static const WCHAR format[] = {'%','d',0};
881 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
882 if (res != ERROR_SUCCESS)
883 return NULL;
885 if (*type == REG_SZ)
886 return msi_reg_get_val_str(hkey, name);
888 if (!msi_reg_get_val_dword(hkey, name, &dval))
889 return NULL;
891 sprintfW(temp, format, dval);
892 return strdupW(temp);
895 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
896 awstring *szValue, LPDWORD pcchValueBuf)
898 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
899 UINT r = ERROR_UNKNOWN_PROPERTY;
900 HKEY prodkey, userdata, source;
901 LPWSTR val = NULL;
902 WCHAR squished_pc[GUID_SIZE];
903 WCHAR packagecode[GUID_SIZE];
904 BOOL badconfig = FALSE;
905 LONG res;
906 DWORD type = REG_NONE;
908 static WCHAR empty[] = {0};
909 static const WCHAR sourcelist[] = {
910 'S','o','u','r','c','e','L','i','s','t',0};
911 static const WCHAR display_name[] = {
912 'D','i','s','p','l','a','y','N','a','m','e',0};
913 static const WCHAR display_version[] = {
914 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
915 static const WCHAR assignment[] = {
916 'A','s','s','i','g','n','m','e','n','t',0};
918 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
919 debugstr_w(szAttribute), szValue, pcchValueBuf);
921 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
922 return ERROR_INVALID_PARAMETER;
924 if (!squash_guid(szProduct, squished_pc))
925 return ERROR_INVALID_PARAMETER;
927 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
928 MSIINSTALLCONTEXT_USERMANAGED,
929 &prodkey, FALSE)) != ERROR_SUCCESS &&
930 (r = MSIREG_OpenProductKey(szProduct, NULL,
931 MSIINSTALLCONTEXT_USERUNMANAGED,
932 &prodkey, FALSE)) != ERROR_SUCCESS &&
933 (r = MSIREG_OpenProductKey(szProduct, NULL,
934 MSIINSTALLCONTEXT_MACHINE,
935 &prodkey, FALSE)) == ERROR_SUCCESS)
937 context = MSIINSTALLCONTEXT_MACHINE;
940 MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
942 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPLINKW) ||
943 !lstrcmpW(szAttribute, INSTALLPROPERTY_HELPTELEPHONEW) ||
944 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLDATEW) ||
945 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
946 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW) ||
947 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLSOURCEW) ||
948 !lstrcmpW(szAttribute, INSTALLPROPERTY_LOCALPACKAGEW) ||
949 !lstrcmpW(szAttribute, INSTALLPROPERTY_PUBLISHERW) ||
950 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLINFOABOUTW) ||
951 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLUPDATEINFOW) ||
952 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMINORW) ||
953 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMAJORW) ||
954 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW) ||
955 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTIDW) ||
956 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGCOMPANYW) ||
957 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGOWNERW))
959 if (!prodkey)
961 r = ERROR_UNKNOWN_PRODUCT;
962 goto done;
965 if (!userdata)
966 return ERROR_UNKNOWN_PROPERTY;
968 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
969 szAttribute = display_name;
970 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW))
971 szAttribute = display_version;
973 val = msi_reg_get_value(userdata, szAttribute, &type);
974 if (!val)
975 val = empty;
977 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTANCETYPEW) ||
978 !lstrcmpW(szAttribute, INSTALLPROPERTY_TRANSFORMSW) ||
979 !lstrcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEW) ||
980 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTNAMEW) ||
981 !lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW) ||
982 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW) ||
983 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONW) ||
984 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTICONW) ||
985 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW) ||
986 !lstrcmpW(szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
988 if (!prodkey)
990 r = ERROR_UNKNOWN_PRODUCT;
991 goto done;
994 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW))
995 szAttribute = assignment;
997 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW))
999 res = RegOpenKeyW(prodkey, sourcelist, &source);
1000 if (res != ERROR_SUCCESS)
1002 r = ERROR_UNKNOWN_PRODUCT;
1003 goto done;
1006 val = msi_reg_get_value(source, szAttribute, &type);
1007 if (!val)
1008 val = empty;
1010 RegCloseKey(source);
1012 else
1014 val = msi_reg_get_value(prodkey, szAttribute, &type);
1015 if (!val)
1016 val = empty;
1019 if (val != empty && type != REG_DWORD &&
1020 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW))
1022 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1023 badconfig = TRUE;
1024 else
1026 unsquash_guid(val, packagecode);
1027 msi_free(val);
1028 val = strdupW(packagecode);
1033 if (!val)
1035 r = ERROR_UNKNOWN_PROPERTY;
1036 goto done;
1039 if (pcchValueBuf)
1041 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1042 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1043 * can't rely on its value.
1045 if (szValue->str.a || szValue->str.w)
1047 DWORD size = *pcchValueBuf;
1048 if (strlenW(val) < size)
1049 r = msi_strcpy_to_awstring(val, szValue, &size);
1050 else
1052 r = ERROR_MORE_DATA;
1056 if (!badconfig)
1057 *pcchValueBuf = lstrlenW(val);
1060 if (badconfig)
1061 r = ERROR_BAD_CONFIGURATION;
1063 if (val != empty)
1064 msi_free(val);
1066 done:
1067 RegCloseKey(prodkey);
1068 RegCloseKey(userdata);
1069 return r;
1072 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1073 LPSTR szBuffer, LPDWORD pcchValueBuf)
1075 LPWSTR szwProduct, szwAttribute = NULL;
1076 UINT r = ERROR_OUTOFMEMORY;
1077 awstring buffer;
1079 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1080 szBuffer, pcchValueBuf);
1082 szwProduct = strdupAtoW( szProduct );
1083 if( szProduct && !szwProduct )
1084 goto end;
1086 szwAttribute = strdupAtoW( szAttribute );
1087 if( szAttribute && !szwAttribute )
1088 goto end;
1090 buffer.unicode = FALSE;
1091 buffer.str.a = szBuffer;
1093 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1094 &buffer, pcchValueBuf );
1096 end:
1097 msi_free( szwProduct );
1098 msi_free( szwAttribute );
1100 return r;
1103 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1104 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1106 awstring buffer;
1108 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1109 szBuffer, pcchValueBuf);
1111 buffer.unicode = TRUE;
1112 buffer.str.w = szBuffer;
1114 return MSI_GetProductInfo( szProduct, szAttribute,
1115 &buffer, pcchValueBuf );
1118 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1119 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1120 LPSTR szValue, LPDWORD pcchValue)
1122 LPWSTR product = NULL;
1123 LPWSTR usersid = NULL;
1124 LPWSTR property = NULL;
1125 LPWSTR value = NULL;
1126 DWORD len = 0;
1127 UINT r;
1129 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1130 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1131 szValue, pcchValue);
1133 if (szValue && !pcchValue)
1134 return ERROR_INVALID_PARAMETER;
1136 if (szProductCode) product = strdupAtoW(szProductCode);
1137 if (szUserSid) usersid = strdupAtoW(szUserSid);
1138 if (szProperty) property = strdupAtoW(szProperty);
1140 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1141 NULL, &len);
1142 if (r != ERROR_SUCCESS)
1143 goto done;
1145 value = msi_alloc(++len * sizeof(WCHAR));
1146 if (!value)
1148 r = ERROR_OUTOFMEMORY;
1149 goto done;
1152 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1153 value, &len);
1154 if (r != ERROR_SUCCESS)
1155 goto done;
1157 if (!pcchValue)
1158 goto done;
1160 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1161 if (*pcchValue >= len)
1162 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1163 else if (szValue)
1165 r = ERROR_MORE_DATA;
1166 if (*pcchValue > 0)
1167 *szValue = '\0';
1170 if (*pcchValue <= len || !szValue)
1171 len = len * sizeof(WCHAR) - 1;
1173 *pcchValue = len - 1;
1175 done:
1176 msi_free(product);
1177 msi_free(usersid);
1178 msi_free(property);
1179 msi_free(value);
1181 return r;
1184 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1186 UINT r;
1188 if (!val)
1189 return ERROR_UNKNOWN_PROPERTY;
1191 if (out)
1193 if (strlenW(val) >= *size)
1195 r = ERROR_MORE_DATA;
1196 if (*size > 0)
1197 *out = '\0';
1199 else
1200 lstrcpyW(out, val);
1203 if (size)
1204 *size = lstrlenW(val);
1206 return ERROR_SUCCESS;
1209 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1210 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1211 LPWSTR szValue, LPDWORD pcchValue)
1213 WCHAR squished_pc[GUID_SIZE];
1214 LPWSTR val = NULL;
1215 LPCWSTR package = NULL;
1216 HKEY props = NULL, prod;
1217 HKEY classes = NULL, managed;
1218 HKEY hkey = NULL;
1219 DWORD type;
1220 UINT r = ERROR_UNKNOWN_PRODUCT;
1222 static const WCHAR five[] = {'5',0};
1223 static const WCHAR displayname[] = {
1224 'D','i','s','p','l','a','y','N','a','m','e',0};
1225 static const WCHAR displayversion[] = {
1226 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1227 static const WCHAR managed_local_package[] = {
1228 'M','a','n','a','g','e','d','L','o','c','a','l',
1229 'P','a','c','k','a','g','e',0};
1231 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1232 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1233 szValue, pcchValue);
1235 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1236 return ERROR_INVALID_PARAMETER;
1238 if (szValue && !pcchValue)
1239 return ERROR_INVALID_PARAMETER;
1241 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1242 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1243 dwContext != MSIINSTALLCONTEXT_MACHINE)
1244 return ERROR_INVALID_PARAMETER;
1246 if (!szProperty || !*szProperty)
1247 return ERROR_INVALID_PARAMETER;
1249 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1250 return ERROR_INVALID_PARAMETER;
1252 /* FIXME: dwContext is provided, no need to search for it */
1253 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1254 &managed, FALSE);
1255 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1256 &prod, FALSE);
1258 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1260 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1262 package = INSTALLPROPERTY_LOCALPACKAGEW;
1264 if (!props && !prod)
1265 goto done;
1267 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1269 package = managed_local_package;
1271 if (!props && !managed)
1272 goto done;
1274 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1276 package = INSTALLPROPERTY_LOCALPACKAGEW;
1277 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1279 if (!props && !classes)
1280 goto done;
1283 if (!lstrcmpW(szProperty, INSTALLPROPERTY_HELPLINKW) ||
1284 !lstrcmpW(szProperty, INSTALLPROPERTY_HELPTELEPHONEW) ||
1285 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW) ||
1286 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
1287 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLLOCATIONW) ||
1288 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLSOURCEW) ||
1289 !lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW) ||
1290 !lstrcmpW(szProperty, INSTALLPROPERTY_PUBLISHERW) ||
1291 !lstrcmpW(szProperty, INSTALLPROPERTY_URLINFOABOUTW) ||
1292 !lstrcmpW(szProperty, INSTALLPROPERTY_URLUPDATEINFOW) ||
1293 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMINORW) ||
1294 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMAJORW) ||
1295 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW) ||
1296 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTIDW) ||
1297 !lstrcmpW(szProperty, INSTALLPROPERTY_REGCOMPANYW) ||
1298 !lstrcmpW(szProperty, INSTALLPROPERTY_REGOWNERW) ||
1299 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTANCETYPEW))
1301 val = msi_reg_get_value(props, package, &type);
1302 if (!val)
1304 if (prod || classes)
1305 r = ERROR_UNKNOWN_PROPERTY;
1307 goto done;
1310 msi_free(val);
1312 if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
1313 szProperty = displayname;
1314 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW))
1315 szProperty = displayversion;
1317 val = msi_reg_get_value(props, szProperty, &type);
1318 if (!val)
1319 val = strdupW(szEmpty);
1321 r = msi_copy_outval(val, szValue, pcchValue);
1323 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW) ||
1324 !lstrcmpW(szProperty, INSTALLPROPERTY_LANGUAGEW) ||
1325 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTNAMEW) ||
1326 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGECODEW) ||
1327 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONW) ||
1328 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTICONW) ||
1329 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGENAMEW) ||
1330 !lstrcmpW(szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
1332 if (!prod && !classes)
1333 goto done;
1335 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1336 hkey = prod;
1337 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1338 hkey = managed;
1339 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1340 hkey = classes;
1342 val = msi_reg_get_value(hkey, szProperty, &type);
1343 if (!val)
1344 val = strdupW(szEmpty);
1346 r = msi_copy_outval(val, szValue, pcchValue);
1348 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTSTATEW))
1350 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1352 if (props)
1354 val = msi_reg_get_value(props, package, &type);
1355 if (!val)
1356 goto done;
1358 msi_free(val);
1359 val = strdupW(five);
1361 else
1362 val = strdupW(szOne);
1364 r = msi_copy_outval(val, szValue, pcchValue);
1365 goto done;
1367 else if (props && (val = msi_reg_get_value(props, package, &type)))
1369 msi_free(val);
1370 val = strdupW(five);
1371 r = msi_copy_outval(val, szValue, pcchValue);
1372 goto done;
1375 if (prod || managed)
1376 val = strdupW(szOne);
1377 else
1378 goto done;
1380 r = msi_copy_outval(val, szValue, pcchValue);
1382 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW))
1384 if (!prod && !classes)
1385 goto done;
1387 /* FIXME */
1388 val = strdupW(szEmpty);
1389 r = msi_copy_outval(val, szValue, pcchValue);
1391 else
1392 r = ERROR_UNKNOWN_PROPERTY;
1394 done:
1395 RegCloseKey(props);
1396 RegCloseKey(prod);
1397 RegCloseKey(managed);
1398 RegCloseKey(classes);
1399 msi_free(val);
1401 return r;
1404 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1405 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1406 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1408 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1409 LPWSTR property = NULL, val = NULL;
1410 DWORD len;
1411 UINT r;
1413 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1414 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1415 debugstr_a(szProperty), lpValue, pcchValue);
1417 if (lpValue && !pcchValue)
1418 return ERROR_INVALID_PARAMETER;
1420 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1421 if (szProductCode) product = strdupAtoW(szProductCode);
1422 if (szUserSid) usersid = strdupAtoW(szUserSid);
1423 if (szProperty) property = strdupAtoW(szProperty);
1425 len = 0;
1426 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1427 NULL, &len);
1428 if (r != ERROR_SUCCESS)
1429 goto done;
1431 val = msi_alloc(++len * sizeof(WCHAR));
1432 if (!val)
1434 r = ERROR_OUTOFMEMORY;
1435 goto done;
1438 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1439 val, &len);
1440 if (r != ERROR_SUCCESS || !pcchValue)
1441 goto done;
1443 if (lpValue)
1444 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1445 *pcchValue - 1, NULL, NULL);
1447 len = lstrlenW(val);
1448 if ((*val && *pcchValue < len + 1) || !lpValue)
1450 if (lpValue)
1452 r = ERROR_MORE_DATA;
1453 lpValue[*pcchValue - 1] = '\0';
1456 *pcchValue = len * sizeof(WCHAR);
1458 else
1459 *pcchValue = len;
1461 done:
1462 msi_free(val);
1463 msi_free(patch);
1464 msi_free(product);
1465 msi_free(usersid);
1466 msi_free(property);
1468 return r;
1471 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1472 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1473 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1475 WCHAR squished_pc[GUID_SIZE];
1476 WCHAR squished_patch[GUID_SIZE];
1477 HKEY udprod = 0, prod = 0, props = 0;
1478 HKEY patch = 0, patches = 0;
1479 HKEY udpatch = 0, datakey = 0;
1480 HKEY prodpatches = 0;
1481 LPWSTR val = NULL;
1482 UINT r = ERROR_UNKNOWN_PRODUCT;
1483 DWORD len;
1484 LONG res;
1486 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1487 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1489 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1490 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1491 debugstr_w(szProperty), lpValue, pcchValue);
1493 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1494 return ERROR_INVALID_PARAMETER;
1496 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1497 return ERROR_INVALID_PARAMETER;
1499 if (!szProperty)
1500 return ERROR_INVALID_PARAMETER;
1502 if (lpValue && !pcchValue)
1503 return ERROR_INVALID_PARAMETER;
1505 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1506 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1507 dwContext != MSIINSTALLCONTEXT_MACHINE)
1508 return ERROR_INVALID_PARAMETER;
1510 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1511 return ERROR_INVALID_PARAMETER;
1513 if (!lstrcmpW(szUserSid, szLocalSid))
1514 return ERROR_INVALID_PARAMETER;
1516 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1517 &udprod, FALSE) != ERROR_SUCCESS)
1518 goto done;
1520 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1521 &props, FALSE) != ERROR_SUCCESS)
1522 goto done;
1524 r = ERROR_UNKNOWN_PATCH;
1526 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_READ, &patches);
1527 if (res != ERROR_SUCCESS)
1528 goto done;
1530 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_READ, &patch);
1531 if (res != ERROR_SUCCESS)
1532 goto done;
1534 if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW))
1536 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1537 &prod, FALSE) != ERROR_SUCCESS)
1538 goto done;
1540 res = RegOpenKeyExW(prod, szPatches, 0, KEY_ALL_ACCESS, &prodpatches);
1541 if (res != ERROR_SUCCESS)
1542 goto done;
1544 datakey = prodpatches;
1545 szProperty = squished_patch;
1547 else
1549 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1550 &udpatch, FALSE) != ERROR_SUCCESS)
1551 goto done;
1553 if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1555 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1556 szProperty = szManagedPackage;
1557 datakey = udpatch;
1559 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW))
1561 datakey = patch;
1562 szProperty = szInstalled;
1564 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1566 datakey = udpatch;
1568 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_UNINSTALLABLEW) ||
1569 !lstrcmpW(szProperty, INSTALLPROPERTY_PATCHSTATEW) ||
1570 !lstrcmpW(szProperty, INSTALLPROPERTY_DISPLAYNAMEW) ||
1571 !lstrcmpW(szProperty, INSTALLPROPERTY_MOREINFOURLW))
1573 datakey = patch;
1575 else
1577 r = ERROR_UNKNOWN_PROPERTY;
1578 goto done;
1582 val = msi_reg_get_val_str(datakey, szProperty);
1583 if (!val)
1584 val = strdupW(szEmpty);
1586 r = ERROR_SUCCESS;
1588 if (!pcchValue)
1589 goto done;
1591 if (lpValue)
1592 lstrcpynW(lpValue, val, *pcchValue);
1594 len = lstrlenW(val);
1595 if ((*val && *pcchValue < len + 1) || !lpValue)
1597 if (lpValue)
1598 r = ERROR_MORE_DATA;
1600 *pcchValue = len * sizeof(WCHAR);
1603 *pcchValue = len;
1605 done:
1606 msi_free(val);
1607 RegCloseKey(prodpatches);
1608 RegCloseKey(prod);
1609 RegCloseKey(patch);
1610 RegCloseKey(patches);
1611 RegCloseKey(udpatch);
1612 RegCloseKey(props);
1613 RegCloseKey(udprod);
1615 return r;
1618 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1620 UINT r = ERROR_OUTOFMEMORY;
1621 DWORD size;
1622 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1624 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1626 if (!patch || !attr)
1627 return ERROR_INVALID_PARAMETER;
1629 if (!(patchW = strdupAtoW( patch )))
1630 goto done;
1632 if (!(attrW = strdupAtoW( attr )))
1633 goto done;
1635 size = 0;
1636 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1637 if (r != ERROR_SUCCESS)
1638 goto done;
1640 size++;
1641 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1643 r = ERROR_OUTOFMEMORY;
1644 goto done;
1647 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1648 if (r == ERROR_SUCCESS)
1650 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1651 if (len > *buflen)
1652 r = ERROR_MORE_DATA;
1653 else if (buffer)
1654 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1656 *buflen = len - 1;
1659 done:
1660 msi_free( patchW );
1661 msi_free( attrW );
1662 msi_free( bufferW );
1663 return r;
1666 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1668 UINT r;
1669 WCHAR product[GUID_SIZE];
1670 DWORD index;
1672 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1674 if (!patch || !attr)
1675 return ERROR_INVALID_PARAMETER;
1677 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1678 return ERROR_UNKNOWN_PROPERTY;
1680 index = 0;
1681 while (1)
1683 r = MsiEnumProductsW( index, product );
1684 if (r != ERROR_SUCCESS)
1685 break;
1687 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1688 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1689 return r;
1691 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1692 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1693 return r;
1695 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1696 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1697 return r;
1699 index++;
1702 return ERROR_UNKNOWN_PRODUCT;
1705 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1707 LPWSTR szwLogFile = NULL;
1708 UINT r;
1710 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1712 if( szLogFile )
1714 szwLogFile = strdupAtoW( szLogFile );
1715 if( !szwLogFile )
1716 return ERROR_OUTOFMEMORY;
1718 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1719 msi_free( szwLogFile );
1720 return r;
1723 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1725 HANDLE file = INVALID_HANDLE_VALUE;
1727 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1729 if (szLogFile)
1731 lstrcpyW(gszLogFile,szLogFile);
1732 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1733 DeleteFileW(szLogFile);
1734 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
1735 FILE_ATTRIBUTE_NORMAL, NULL);
1736 if (file != INVALID_HANDLE_VALUE)
1737 CloseHandle(file);
1738 else
1739 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
1741 else
1742 gszLogFile[0] = '\0';
1744 return ERROR_SUCCESS;
1747 UINT WINAPI MsiEnumComponentCostsW(MSIHANDLE hInstall, LPCWSTR szComponent,
1748 DWORD dwIndex, INSTALLSTATE iState,
1749 LPWSTR lpDriveBuf, DWORD *pcchDriveBuf,
1750 int *piCost, int *pTempCost)
1752 FIXME("(%d, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall,
1753 debugstr_w(szComponent), dwIndex, iState, lpDriveBuf,
1754 pcchDriveBuf, piCost, pTempCost);
1756 return ERROR_NO_MORE_ITEMS;
1759 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1760 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1761 LPCSTR szComponent, INSTALLSTATE *pdwState)
1763 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1764 UINT r;
1766 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1767 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1769 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1770 return ERROR_OUTOFMEMORY;
1772 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1773 return ERROR_OUTOFMEMORY;
1775 if (szComponent && !(comp = strdupAtoW(szComponent)))
1776 return ERROR_OUTOFMEMORY;
1778 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1780 msi_free(prodcode);
1781 msi_free(usersid);
1782 msi_free(comp);
1784 return r;
1787 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1789 UINT r;
1790 HKEY hkey;
1792 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
1793 RegCloseKey(hkey);
1794 return (r == ERROR_SUCCESS);
1797 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1799 LPCWSTR package;
1800 HKEY hkey;
1801 DWORD sz;
1802 LONG res;
1803 UINT r;
1805 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1806 static const WCHAR managed_local_package[] = {
1807 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1810 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
1811 if (r != ERROR_SUCCESS)
1812 return FALSE;
1814 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1815 package = managed_local_package;
1816 else
1817 package = local_package;
1819 sz = 0;
1820 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1821 RegCloseKey(hkey);
1823 return (res == ERROR_SUCCESS);
1826 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1827 MSIINSTALLCONTEXT context,
1828 LPCWSTR comp, LPWSTR val, DWORD *sz)
1830 HKEY hkey;
1831 LONG res;
1832 UINT r;
1834 if (context == MSIINSTALLCONTEXT_MACHINE)
1835 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
1836 else
1837 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
1839 if (r != ERROR_SUCCESS)
1840 return FALSE;
1842 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
1843 if (res != ERROR_SUCCESS)
1844 return FALSE;
1846 RegCloseKey(hkey);
1847 return TRUE;
1850 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
1851 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1852 LPCWSTR szComponent, INSTALLSTATE *pdwState)
1854 WCHAR squished_pc[GUID_SIZE];
1855 WCHAR val[MAX_PATH];
1856 BOOL found;
1857 DWORD sz;
1859 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
1860 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
1862 if (!pdwState || !szComponent)
1863 return ERROR_INVALID_PARAMETER;
1865 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
1866 return ERROR_INVALID_PARAMETER;
1868 if (!squash_guid(szProductCode, squished_pc))
1869 return ERROR_INVALID_PARAMETER;
1871 found = msi_comp_find_prod_key(szProductCode, dwContext);
1873 if (!msi_comp_find_package(szProductCode, dwContext))
1875 if (found)
1877 *pdwState = INSTALLSTATE_UNKNOWN;
1878 return ERROR_UNKNOWN_COMPONENT;
1881 return ERROR_UNKNOWN_PRODUCT;
1884 *pdwState = INSTALLSTATE_UNKNOWN;
1886 sz = MAX_PATH;
1887 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
1888 return ERROR_UNKNOWN_COMPONENT;
1890 if (sz == 0)
1891 *pdwState = INSTALLSTATE_NOTUSED;
1892 else
1894 if (lstrlenW(val) > 2 &&
1895 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
1897 *pdwState = INSTALLSTATE_SOURCE;
1899 else
1900 *pdwState = INSTALLSTATE_LOCAL;
1903 return ERROR_SUCCESS;
1906 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
1908 LPWSTR szwProduct = NULL;
1909 INSTALLSTATE r;
1911 if( szProduct )
1913 szwProduct = strdupAtoW( szProduct );
1914 if( !szwProduct )
1915 return ERROR_OUTOFMEMORY;
1917 r = MsiQueryProductStateW( szwProduct );
1918 msi_free( szwProduct );
1919 return r;
1922 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
1924 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1925 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
1926 HKEY prodkey = 0, userdata = 0;
1927 DWORD val;
1928 UINT r;
1930 static const WCHAR szWindowsInstaller[] = {
1931 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1933 TRACE("%s\n", debugstr_w(szProduct));
1935 if (!szProduct || !*szProduct)
1936 return INSTALLSTATE_INVALIDARG;
1938 if (lstrlenW(szProduct) != GUID_SIZE - 1)
1939 return INSTALLSTATE_INVALIDARG;
1941 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1942 &prodkey, FALSE) != ERROR_SUCCESS &&
1943 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1944 &prodkey, FALSE) != ERROR_SUCCESS &&
1945 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
1946 &prodkey, FALSE) == ERROR_SUCCESS)
1948 context = MSIINSTALLCONTEXT_MACHINE;
1951 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
1952 if (r != ERROR_SUCCESS)
1953 goto done;
1955 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
1956 goto done;
1958 if (val)
1959 state = INSTALLSTATE_DEFAULT;
1960 else
1961 state = INSTALLSTATE_UNKNOWN;
1963 done:
1964 if (!prodkey)
1966 state = INSTALLSTATE_UNKNOWN;
1968 if (userdata)
1969 state = INSTALLSTATE_ABSENT;
1972 RegCloseKey(prodkey);
1973 RegCloseKey(userdata);
1974 return state;
1977 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
1979 INSTALLUILEVEL old = gUILevel;
1980 HWND oldwnd = gUIhwnd;
1982 TRACE("%08x %p\n", dwUILevel, phWnd);
1984 gUILevel = dwUILevel;
1985 if (phWnd)
1987 gUIhwnd = *phWnd;
1988 *phWnd = oldwnd;
1990 return old;
1993 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
1994 DWORD dwMessageFilter, LPVOID pvContext)
1996 INSTALLUI_HANDLERA prev = gUIHandlerA;
1998 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2000 gUIHandlerA = puiHandler;
2001 gUIHandlerW = NULL;
2002 gUIFilter = dwMessageFilter;
2003 gUIContext = pvContext;
2005 return prev;
2008 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2009 DWORD dwMessageFilter, LPVOID pvContext)
2011 INSTALLUI_HANDLERW prev = gUIHandlerW;
2013 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2015 gUIHandlerA = NULL;
2016 gUIHandlerW = puiHandler;
2017 gUIFilter = dwMessageFilter;
2018 gUIContext = pvContext;
2020 return prev;
2023 /******************************************************************
2024 * MsiLoadStringW [MSI.@]
2026 * Loads a string from MSI's string resources.
2028 * PARAMS
2030 * handle [I] only -1 is handled currently
2031 * id [I] id of the string to be loaded
2032 * lpBuffer [O] buffer for the string to be written to
2033 * nBufferMax [I] maximum size of the buffer in characters
2034 * lang [I] the preferred language for the string
2036 * RETURNS
2038 * If successful, this function returns the language id of the string loaded
2039 * If the function fails, the function returns zero.
2041 * NOTES
2043 * The type of the first parameter is unknown. LoadString's prototype
2044 * suggests that it might be a module handle. I have made it an MSI handle
2045 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2046 * handle. Maybe strings can be stored in an MSI database somehow.
2048 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2049 int nBufferMax, LANGID lang )
2051 HRSRC hres;
2052 HGLOBAL hResData;
2053 LPWSTR p;
2054 DWORD i, len;
2056 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2058 if( handle != -1 )
2059 FIXME("don't know how to deal with handle = %08x\n", handle);
2061 if( !lang )
2062 lang = GetUserDefaultLangID();
2064 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2065 (LPWSTR)1, lang );
2066 if( !hres )
2067 return 0;
2068 hResData = LoadResource( msi_hInstance, hres );
2069 if( !hResData )
2070 return 0;
2071 p = LockResource( hResData );
2072 if( !p )
2073 return 0;
2075 for (i = 0; i < (id&0xf); i++)
2076 p += *p + 1;
2077 len = *p;
2079 if( nBufferMax <= len )
2080 return 0;
2082 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2083 lpBuffer[ len ] = 0;
2085 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2087 return lang;
2090 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2091 int nBufferMax, LANGID lang )
2093 LPWSTR bufW;
2094 LANGID r;
2095 INT len;
2097 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2098 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2099 if( r )
2101 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2102 if( len <= nBufferMax )
2103 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2104 lpBuffer, nBufferMax, NULL, NULL );
2105 else
2106 r = 0;
2108 msi_free(bufW);
2109 return r;
2112 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2113 LPDWORD pcchBuf)
2115 char szProduct[GUID_SIZE];
2117 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2119 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2120 return INSTALLSTATE_UNKNOWN;
2122 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2125 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2126 LPDWORD pcchBuf)
2128 WCHAR szProduct[GUID_SIZE];
2130 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2132 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2133 return INSTALLSTATE_UNKNOWN;
2135 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2138 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2139 WORD wLanguageId, DWORD f)
2141 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2142 uType, wLanguageId, f);
2143 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2146 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2147 WORD wLanguageId, DWORD f)
2149 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2150 uType, wLanguageId, f);
2151 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2154 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2155 DWORD unknown, WORD wLanguageId, DWORD f)
2157 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2158 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2159 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2162 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2163 DWORD unknown, WORD wLanguageId, DWORD f)
2165 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2166 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2167 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2170 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2171 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2172 LPDWORD pcchPathBuf )
2174 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2175 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2176 pcchPathBuf);
2177 return ERROR_CALL_NOT_IMPLEMENTED;
2180 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2181 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2182 LPDWORD pcchPathBuf )
2184 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2185 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2186 pcchPathBuf);
2187 return ERROR_CALL_NOT_IMPLEMENTED;
2190 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2191 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2193 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2194 return ERROR_CALL_NOT_IMPLEMENTED;
2197 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2198 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2200 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2201 return ERROR_CALL_NOT_IMPLEMENTED;
2204 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
2205 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2206 LPDWORD pcbHashData)
2208 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
2209 ppcCertContext, pbHashData, pcbHashData);
2210 return ERROR_CALL_NOT_IMPLEMENTED;
2213 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
2214 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2215 LPDWORD pcbHashData)
2217 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
2218 ppcCertContext, pbHashData, pcbHashData);
2219 return ERROR_CALL_NOT_IMPLEMENTED;
2222 /******************************************************************
2223 * MsiGetProductPropertyA [MSI.@]
2225 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2226 LPSTR szValue, LPDWORD pccbValue)
2228 LPWSTR prop = NULL, val = NULL;
2229 DWORD len;
2230 UINT r;
2232 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2233 szValue, pccbValue);
2235 if (szValue && !pccbValue)
2236 return ERROR_INVALID_PARAMETER;
2238 if (szProperty) prop = strdupAtoW(szProperty);
2240 len = 0;
2241 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2242 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2243 goto done;
2245 if (r == ERROR_SUCCESS)
2247 if (szValue) *szValue = '\0';
2248 if (pccbValue) *pccbValue = 0;
2249 goto done;
2252 val = msi_alloc(++len * sizeof(WCHAR));
2253 if (!val)
2255 r = ERROR_OUTOFMEMORY;
2256 goto done;
2259 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2260 if (r != ERROR_SUCCESS)
2261 goto done;
2263 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2265 if (szValue)
2266 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2267 *pccbValue, NULL, NULL);
2269 if (pccbValue)
2271 if (len > *pccbValue)
2272 r = ERROR_MORE_DATA;
2274 *pccbValue = len - 1;
2277 done:
2278 msi_free(prop);
2279 msi_free(val);
2281 return r;
2284 /******************************************************************
2285 * MsiGetProductPropertyW [MSI.@]
2287 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2288 LPWSTR szValue, LPDWORD pccbValue)
2290 MSIPACKAGE *package;
2291 MSIQUERY *view = NULL;
2292 MSIRECORD *rec = NULL;
2293 LPCWSTR val;
2294 UINT r;
2296 static const WCHAR query[] = {
2297 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2298 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2299 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2301 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2302 szValue, pccbValue);
2304 if (!szProperty)
2305 return ERROR_INVALID_PARAMETER;
2307 if (szValue && !pccbValue)
2308 return ERROR_INVALID_PARAMETER;
2310 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2311 if (!package)
2312 return ERROR_INVALID_HANDLE;
2314 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2315 if (r != ERROR_SUCCESS)
2316 goto done;
2318 r = MSI_ViewExecute(view, 0);
2319 if (r != ERROR_SUCCESS)
2320 goto done;
2322 r = MSI_ViewFetch(view, &rec);
2323 if (r != ERROR_SUCCESS)
2324 goto done;
2326 val = MSI_RecordGetString(rec, 2);
2327 if (!val)
2328 goto done;
2330 if (lstrlenW(val) >= *pccbValue)
2332 lstrcpynW(szValue, val, *pccbValue);
2333 *pccbValue = lstrlenW(val);
2334 r = ERROR_MORE_DATA;
2336 else
2338 lstrcpyW(szValue, val);
2339 *pccbValue = lstrlenW(val);
2340 r = ERROR_SUCCESS;
2343 done:
2344 if (view)
2346 MSI_ViewClose(view);
2347 msiobj_release(&view->hdr);
2348 if (rec) msiobj_release(&rec->hdr);
2351 if (!rec)
2353 if (szValue) *szValue = '\0';
2354 if (pccbValue) *pccbValue = 0;
2355 r = ERROR_SUCCESS;
2358 return r;
2361 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2363 UINT r;
2364 LPWSTR szPack = NULL;
2366 TRACE("%s\n", debugstr_a(szPackage) );
2368 if( szPackage )
2370 szPack = strdupAtoW( szPackage );
2371 if( !szPack )
2372 return ERROR_OUTOFMEMORY;
2375 r = MsiVerifyPackageW( szPack );
2377 msi_free( szPack );
2379 return r;
2382 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2384 MSIHANDLE handle;
2385 UINT r;
2387 TRACE("%s\n", debugstr_w(szPackage) );
2389 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2390 MsiCloseHandle( handle );
2392 return r;
2395 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2396 awstring* lpPathBuf, LPDWORD pcchBuf)
2398 WCHAR squished_pc[GUID_SIZE];
2399 WCHAR squished_comp[GUID_SIZE];
2400 HKEY hkey;
2401 LPWSTR path = NULL;
2402 INSTALLSTATE state;
2403 DWORD version;
2405 static const WCHAR wininstaller[] = {
2406 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2408 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
2409 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
2411 if (!szProduct || !szComponent)
2412 return INSTALLSTATE_INVALIDARG;
2414 if (lpPathBuf->str.w && !pcchBuf)
2415 return INSTALLSTATE_INVALIDARG;
2417 if (!squash_guid(szProduct, squished_pc) ||
2418 !squash_guid(szComponent, squished_comp))
2419 return INSTALLSTATE_INVALIDARG;
2421 state = INSTALLSTATE_UNKNOWN;
2423 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2424 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2426 path = msi_reg_get_val_str(hkey, squished_pc);
2427 RegCloseKey(hkey);
2429 state = INSTALLSTATE_ABSENT;
2431 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2432 &hkey, FALSE) == ERROR_SUCCESS ||
2433 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2434 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2435 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2436 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2438 RegCloseKey(hkey);
2439 state = INSTALLSTATE_LOCAL;
2443 if (state != INSTALLSTATE_LOCAL &&
2444 (MSIREG_OpenProductKey(szProduct, NULL,
2445 MSIINSTALLCONTEXT_USERUNMANAGED,
2446 &hkey, FALSE) == ERROR_SUCCESS ||
2447 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2448 &hkey, FALSE) == ERROR_SUCCESS))
2450 RegCloseKey(hkey);
2452 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2453 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2455 msi_free(path);
2456 path = msi_reg_get_val_str(hkey, squished_pc);
2457 RegCloseKey(hkey);
2459 state = INSTALLSTATE_ABSENT;
2461 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2462 state = INSTALLSTATE_LOCAL;
2466 if (!path)
2467 return INSTALLSTATE_UNKNOWN;
2469 if (state == INSTALLSTATE_LOCAL && !*path)
2470 state = INSTALLSTATE_NOTUSED;
2472 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
2473 msi_free(path);
2474 return state;
2477 /******************************************************************
2478 * MsiGetComponentPathW [MSI.@]
2480 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2481 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2483 awstring path;
2485 path.unicode = TRUE;
2486 path.str.w = lpPathBuf;
2488 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2491 /******************************************************************
2492 * MsiGetComponentPathA [MSI.@]
2494 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2495 LPSTR lpPathBuf, LPDWORD pcchBuf)
2497 LPWSTR szwProduct, szwComponent = NULL;
2498 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2499 awstring path;
2501 szwProduct = strdupAtoW( szProduct );
2502 if( szProduct && !szwProduct)
2503 goto end;
2505 szwComponent = strdupAtoW( szComponent );
2506 if( szComponent && !szwComponent )
2507 goto end;
2509 path.unicode = FALSE;
2510 path.str.a = lpPathBuf;
2512 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2514 end:
2515 msi_free( szwProduct );
2516 msi_free( szwComponent );
2518 return r;
2521 /******************************************************************
2522 * MsiQueryFeatureStateA [MSI.@]
2524 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
2526 LPWSTR szwProduct = NULL, szwFeature= NULL;
2527 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
2529 szwProduct = strdupAtoW( szProduct );
2530 if ( szProduct && !szwProduct )
2531 goto end;
2533 szwFeature = strdupAtoW( szFeature );
2534 if ( szFeature && !szwFeature )
2535 goto end;
2537 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
2539 end:
2540 msi_free( szwProduct);
2541 msi_free( szwFeature);
2543 return rc;
2546 /******************************************************************
2547 * MsiQueryFeatureStateW [MSI.@]
2549 * Checks the state of a feature
2551 * PARAMS
2552 * szProduct [I] Product's GUID string
2553 * szFeature [I] Feature's GUID string
2555 * RETURNS
2556 * INSTALLSTATE_LOCAL Feature is installed and usable
2557 * INSTALLSTATE_ABSENT Feature is absent
2558 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2559 * INSTALLSTATE_UNKNOWN An error occurred
2560 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2563 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
2565 WCHAR squishProduct[33], comp[GUID_SIZE];
2566 GUID guid;
2567 LPWSTR components, p, parent_feature, path;
2568 UINT rc;
2569 HKEY hkey;
2570 INSTALLSTATE r;
2571 BOOL missing = FALSE;
2572 BOOL machine = FALSE;
2573 BOOL source = FALSE;
2575 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
2577 if (!szProduct || !szFeature)
2578 return INSTALLSTATE_INVALIDARG;
2580 if (!squash_guid( szProduct, squishProduct ))
2581 return INSTALLSTATE_INVALIDARG;
2583 if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2584 &hkey, FALSE) != ERROR_SUCCESS &&
2585 MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2586 &hkey, FALSE) != ERROR_SUCCESS)
2588 rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2589 &hkey, FALSE);
2590 if (rc != ERROR_SUCCESS)
2591 return INSTALLSTATE_UNKNOWN;
2593 machine = TRUE;
2596 parent_feature = msi_reg_get_val_str( hkey, szFeature );
2597 RegCloseKey(hkey);
2599 if (!parent_feature)
2600 return INSTALLSTATE_UNKNOWN;
2602 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2603 msi_free(parent_feature);
2604 if (r == INSTALLSTATE_ABSENT)
2605 return r;
2607 if (machine)
2608 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2609 MSIINSTALLCONTEXT_MACHINE,
2610 &hkey, FALSE);
2611 else
2612 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2613 MSIINSTALLCONTEXT_USERUNMANAGED,
2614 &hkey, FALSE);
2616 if (rc != ERROR_SUCCESS)
2617 return INSTALLSTATE_ADVERTISED;
2619 components = msi_reg_get_val_str( hkey, szFeature );
2620 RegCloseKey(hkey);
2622 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
2624 if (!components)
2625 return INSTALLSTATE_ADVERTISED;
2627 for( p = components; *p && *p != 2 ; p += 20)
2629 if (!decode_base85_guid( p, &guid ))
2631 if (p != components)
2632 break;
2634 msi_free(components);
2635 return INSTALLSTATE_BADCONFIG;
2638 StringFromGUID2(&guid, comp, GUID_SIZE);
2640 if (machine)
2641 rc = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2642 else
2643 rc = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2645 if (rc != ERROR_SUCCESS)
2647 msi_free(components);
2648 return INSTALLSTATE_ADVERTISED;
2651 path = msi_reg_get_val_str(hkey, squishProduct);
2652 if (!path)
2653 missing = TRUE;
2654 else if (lstrlenW(path) > 2 &&
2655 path[0] >= '0' && path[0] <= '9' &&
2656 path[1] >= '0' && path[1] <= '9')
2658 source = TRUE;
2661 msi_free(path);
2664 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
2665 msi_free(components);
2667 if (missing)
2668 return INSTALLSTATE_ADVERTISED;
2670 if (source)
2671 return INSTALLSTATE_SOURCE;
2673 return INSTALLSTATE_LOCAL;
2676 /******************************************************************
2677 * MsiGetFileVersionA [MSI.@]
2679 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
2680 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
2682 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
2683 UINT ret = ERROR_OUTOFMEMORY;
2685 if ((lpVersionBuf && !pcchVersionBuf) ||
2686 (lpLangBuf && !pcchLangBuf))
2687 return ERROR_INVALID_PARAMETER;
2689 if( szFilePath )
2691 szwFilePath = strdupAtoW( szFilePath );
2692 if( !szwFilePath )
2693 goto end;
2696 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
2698 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
2699 if( !lpwVersionBuff )
2700 goto end;
2703 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
2705 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
2706 if( !lpwLangBuff )
2707 goto end;
2710 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
2711 lpwLangBuff, pcchLangBuf);
2713 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
2714 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
2715 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
2716 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
2717 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
2718 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
2720 end:
2721 msi_free(szwFilePath);
2722 msi_free(lpwVersionBuff);
2723 msi_free(lpwLangBuff);
2725 return ret;
2728 /******************************************************************
2729 * MsiGetFileVersionW [MSI.@]
2731 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
2732 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
2734 static const WCHAR szVersionResource[] = {'\\',0};
2735 static const WCHAR szVersionFormat[] = {
2736 '%','d','.','%','d','.','%','d','.','%','d',0};
2737 static const WCHAR szLangResource[] = {
2738 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2739 'T','r','a','n','s','l','a','t','i','o','n',0};
2740 static const WCHAR szLangFormat[] = {'%','d',0};
2741 UINT ret = 0;
2742 DWORD dwVerLen, gle;
2743 LPVOID lpVer = NULL;
2744 VS_FIXEDFILEINFO *ffi;
2745 USHORT *lang;
2746 UINT puLen;
2747 WCHAR tmp[32];
2749 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
2750 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
2751 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
2753 if ((lpVersionBuf && !pcchVersionBuf) ||
2754 (lpLangBuf && !pcchLangBuf))
2755 return ERROR_INVALID_PARAMETER;
2757 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
2758 if( !dwVerLen )
2760 gle = GetLastError();
2761 if (gle == ERROR_BAD_PATHNAME)
2762 return ERROR_FILE_NOT_FOUND;
2763 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
2764 return ERROR_FILE_INVALID;
2766 return gle;
2769 lpVer = msi_alloc(dwVerLen);
2770 if( !lpVer )
2772 ret = ERROR_OUTOFMEMORY;
2773 goto end;
2776 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
2778 ret = GetLastError();
2779 goto end;
2782 if (pcchVersionBuf)
2784 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
2785 (puLen > 0) )
2787 wsprintfW(tmp, szVersionFormat,
2788 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
2789 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
2790 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
2792 if (strlenW(tmp) >= *pcchVersionBuf)
2793 ret = ERROR_MORE_DATA;
2795 *pcchVersionBuf = lstrlenW(tmp);
2797 else
2799 if (lpVersionBuf) *lpVersionBuf = 0;
2800 *pcchVersionBuf = 0;
2804 if (pcchLangBuf)
2806 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
2807 (puLen > 0))
2809 wsprintfW(tmp, szLangFormat, *lang);
2810 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
2812 if (strlenW(tmp) >= *pcchLangBuf)
2813 ret = ERROR_MORE_DATA;
2815 *pcchLangBuf = lstrlenW(tmp);
2817 else
2819 if (lpLangBuf) *lpLangBuf = 0;
2820 *pcchLangBuf = 0;
2824 end:
2825 msi_free(lpVer);
2826 return ret;
2829 /***********************************************************************
2830 * MsiGetFeatureUsageW [MSI.@]
2832 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
2833 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2835 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
2836 pdwUseCount, pwDateUsed);
2837 return ERROR_CALL_NOT_IMPLEMENTED;
2840 /***********************************************************************
2841 * MsiGetFeatureUsageA [MSI.@]
2843 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
2844 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2846 LPWSTR prod = NULL, feat = NULL;
2847 UINT ret = ERROR_OUTOFMEMORY;
2849 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
2850 pdwUseCount, pwDateUsed);
2852 prod = strdupAtoW( szProduct );
2853 if (szProduct && !prod)
2854 goto end;
2856 feat = strdupAtoW( szFeature );
2857 if (szFeature && !feat)
2858 goto end;
2860 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
2862 end:
2863 msi_free( prod );
2864 msi_free( feat );
2866 return ret;
2869 /***********************************************************************
2870 * MsiUseFeatureExW [MSI.@]
2872 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
2873 DWORD dwInstallMode, DWORD dwReserved )
2875 INSTALLSTATE state;
2877 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2878 dwInstallMode, dwReserved);
2880 state = MsiQueryFeatureStateW( szProduct, szFeature );
2882 if (dwReserved)
2883 return INSTALLSTATE_INVALIDARG;
2885 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
2887 FIXME("mark product %s feature %s as used\n",
2888 debugstr_w(szProduct), debugstr_w(szFeature) );
2891 return state;
2894 /***********************************************************************
2895 * MsiUseFeatureExA [MSI.@]
2897 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
2898 DWORD dwInstallMode, DWORD dwReserved )
2900 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
2901 LPWSTR prod = NULL, feat = NULL;
2903 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2904 dwInstallMode, dwReserved);
2906 prod = strdupAtoW( szProduct );
2907 if (szProduct && !prod)
2908 goto end;
2910 feat = strdupAtoW( szFeature );
2911 if (szFeature && !feat)
2912 goto end;
2914 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
2916 end:
2917 msi_free( prod );
2918 msi_free( feat );
2920 return ret;
2923 /***********************************************************************
2924 * MsiUseFeatureW [MSI.@]
2926 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
2928 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
2931 /***********************************************************************
2932 * MsiUseFeatureA [MSI.@]
2934 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
2936 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
2939 /***********************************************************************
2940 * MSI_ProvideQualifiedComponentEx [internal]
2942 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
2943 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2944 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
2945 LPDWORD pcchPathBuf)
2947 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
2948 feature[MAX_FEATURE_CHARS+1];
2949 LPWSTR info;
2950 HKEY hkey;
2951 DWORD sz;
2952 UINT rc;
2954 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
2955 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
2956 Unused1, Unused2, lpPathBuf, pcchPathBuf);
2958 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
2959 if (rc != ERROR_SUCCESS)
2960 return ERROR_INDEX_ABSENT;
2962 info = msi_reg_get_val_str( hkey, szQualifier );
2963 RegCloseKey(hkey);
2965 if (!info)
2966 return ERROR_INDEX_ABSENT;
2968 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
2970 if (!szProduct)
2971 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
2972 else
2973 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
2975 msi_free( info );
2977 if (rc != INSTALLSTATE_LOCAL)
2978 return ERROR_FILE_NOT_FOUND;
2980 return ERROR_SUCCESS;
2983 /***********************************************************************
2984 * MsiProvideQualifiedComponentExW [MSI.@]
2986 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
2987 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2988 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
2989 LPDWORD pcchPathBuf)
2991 awstring path;
2993 path.unicode = TRUE;
2994 path.str.w = lpPathBuf;
2996 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
2997 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
3000 /***********************************************************************
3001 * MsiProvideQualifiedComponentExA [MSI.@]
3003 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
3004 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
3005 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
3006 LPDWORD pcchPathBuf)
3008 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
3009 UINT r = ERROR_OUTOFMEMORY;
3010 awstring path;
3012 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
3013 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
3014 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3016 szwComponent = strdupAtoW( szComponent );
3017 if (szComponent && !szwComponent)
3018 goto end;
3020 szwQualifier = strdupAtoW( szQualifier );
3021 if (szQualifier && !szwQualifier)
3022 goto end;
3024 szwProduct = strdupAtoW( szProduct );
3025 if (szProduct && !szwProduct)
3026 goto end;
3028 path.unicode = FALSE;
3029 path.str.a = lpPathBuf;
3031 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
3032 dwInstallMode, szwProduct, Unused1,
3033 Unused2, &path, pcchPathBuf);
3034 end:
3035 msi_free(szwProduct);
3036 msi_free(szwComponent);
3037 msi_free(szwQualifier);
3039 return r;
3042 /***********************************************************************
3043 * MsiProvideQualifiedComponentW [MSI.@]
3045 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
3046 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
3047 LPDWORD pcchPathBuf)
3049 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
3050 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3053 /***********************************************************************
3054 * MsiProvideQualifiedComponentA [MSI.@]
3056 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
3057 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
3058 LPDWORD pcchPathBuf)
3060 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
3061 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3064 /***********************************************************************
3065 * MSI_GetUserInfo [internal]
3067 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
3068 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
3069 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3070 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
3072 WCHAR squished_pc[SQUISH_GUID_SIZE];
3073 LPWSTR user, org, serial;
3074 USERINFOSTATE state;
3075 HKEY hkey, props;
3076 LPCWSTR orgptr;
3077 UINT r;
3079 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
3080 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
3081 pcchSerialBuf);
3083 if (!szProduct || !squash_guid(szProduct, squished_pc))
3084 return USERINFOSTATE_INVALIDARG;
3086 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
3087 &hkey, FALSE) != ERROR_SUCCESS &&
3088 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3089 &hkey, FALSE) != ERROR_SUCCESS &&
3090 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
3091 &hkey, FALSE) != ERROR_SUCCESS)
3093 return USERINFOSTATE_UNKNOWN;
3096 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
3097 NULL, &props, FALSE) != ERROR_SUCCESS &&
3098 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
3099 NULL, &props, FALSE) != ERROR_SUCCESS)
3101 RegCloseKey(hkey);
3102 return USERINFOSTATE_ABSENT;
3105 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3106 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3107 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3108 state = USERINFOSTATE_ABSENT;
3110 RegCloseKey(hkey);
3111 RegCloseKey(props);
3113 if (user && serial)
3114 state = USERINFOSTATE_PRESENT;
3116 if (pcchUserNameBuf)
3118 if (lpUserNameBuf && !user)
3120 (*pcchUserNameBuf)--;
3121 goto done;
3124 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
3125 if (r == ERROR_MORE_DATA)
3127 state = USERINFOSTATE_MOREDATA;
3128 goto done;
3132 if (pcchOrgNameBuf)
3134 orgptr = org;
3135 if (!orgptr) orgptr = szEmpty;
3137 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
3138 if (r == ERROR_MORE_DATA)
3140 state = USERINFOSTATE_MOREDATA;
3141 goto done;
3145 if (pcchSerialBuf)
3147 if (!serial)
3149 (*pcchSerialBuf)--;
3150 goto done;
3153 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
3154 if (r == ERROR_MORE_DATA)
3155 state = USERINFOSTATE_MOREDATA;
3158 done:
3159 msi_free(user);
3160 msi_free(org);
3161 msi_free(serial);
3163 return state;
3166 /***********************************************************************
3167 * MsiGetUserInfoW [MSI.@]
3169 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3170 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3171 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3172 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3174 awstring user, org, serial;
3176 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3177 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3178 (lpSerialBuf && !pcchSerialBuf))
3179 return USERINFOSTATE_INVALIDARG;
3181 user.unicode = TRUE;
3182 user.str.w = lpUserNameBuf;
3183 org.unicode = TRUE;
3184 org.str.w = lpOrgNameBuf;
3185 serial.unicode = TRUE;
3186 serial.str.w = lpSerialBuf;
3188 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3189 &org, pcchOrgNameBuf,
3190 &serial, pcchSerialBuf );
3193 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3194 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3195 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3196 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3198 awstring user, org, serial;
3199 LPWSTR prod;
3200 UINT r;
3202 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3203 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3204 (lpSerialBuf && !pcchSerialBuf))
3205 return USERINFOSTATE_INVALIDARG;
3207 prod = strdupAtoW( szProduct );
3208 if (szProduct && !prod)
3209 return ERROR_OUTOFMEMORY;
3211 user.unicode = FALSE;
3212 user.str.a = lpUserNameBuf;
3213 org.unicode = FALSE;
3214 org.str.a = lpOrgNameBuf;
3215 serial.unicode = FALSE;
3216 serial.str.a = lpSerialBuf;
3218 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3219 &org, pcchOrgNameBuf,
3220 &serial, pcchSerialBuf );
3222 msi_free( prod );
3224 return r;
3227 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3229 MSIHANDLE handle;
3230 UINT rc;
3231 MSIPACKAGE *package;
3232 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3234 TRACE("(%s)\n",debugstr_w(szProduct));
3236 rc = MsiOpenProductW(szProduct,&handle);
3237 if (rc != ERROR_SUCCESS)
3238 return ERROR_INVALID_PARAMETER;
3240 /* MsiCollectUserInfo cannot be called from a custom action. */
3241 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3242 if (!package)
3243 return ERROR_CALL_NOT_IMPLEMENTED;
3245 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3246 msiobj_release( &package->hdr );
3248 MsiCloseHandle(handle);
3250 return rc;
3253 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3255 MSIHANDLE handle;
3256 UINT rc;
3257 MSIPACKAGE *package;
3258 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3260 TRACE("(%s)\n",debugstr_a(szProduct));
3262 rc = MsiOpenProductA(szProduct,&handle);
3263 if (rc != ERROR_SUCCESS)
3264 return ERROR_INVALID_PARAMETER;
3266 /* MsiCollectUserInfo cannot be called from a custom action. */
3267 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3268 if (!package)
3269 return ERROR_CALL_NOT_IMPLEMENTED;
3271 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3272 msiobj_release( &package->hdr );
3274 MsiCloseHandle(handle);
3276 return rc;
3279 /***********************************************************************
3280 * MsiConfigureFeatureA [MSI.@]
3282 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3284 LPWSTR prod, feat = NULL;
3285 UINT r = ERROR_OUTOFMEMORY;
3287 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3289 prod = strdupAtoW( szProduct );
3290 if (szProduct && !prod)
3291 goto end;
3293 feat = strdupAtoW( szFeature );
3294 if (szFeature && !feat)
3295 goto end;
3297 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3299 end:
3300 msi_free(feat);
3301 msi_free(prod);
3303 return r;
3306 /***********************************************************************
3307 * MsiConfigureFeatureW [MSI.@]
3309 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3311 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3312 MSIPACKAGE *package = NULL;
3313 UINT r;
3314 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3315 DWORD sz;
3317 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3319 if (!szProduct || !szFeature)
3320 return ERROR_INVALID_PARAMETER;
3322 switch (eInstallState)
3324 case INSTALLSTATE_DEFAULT:
3325 /* FIXME: how do we figure out the default location? */
3326 eInstallState = INSTALLSTATE_LOCAL;
3327 break;
3328 case INSTALLSTATE_LOCAL:
3329 case INSTALLSTATE_SOURCE:
3330 case INSTALLSTATE_ABSENT:
3331 case INSTALLSTATE_ADVERTISED:
3332 break;
3333 default:
3334 return ERROR_INVALID_PARAMETER;
3337 r = MSI_OpenProductW( szProduct, &package );
3338 if (r != ERROR_SUCCESS)
3339 return r;
3341 sz = sizeof(sourcepath);
3342 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3343 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3345 sz = sizeof(filename);
3346 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3347 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3349 lstrcatW( sourcepath, filename );
3351 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3353 r = ACTION_PerformUIAction( package, szCostInit, -1 );
3354 if (r != ERROR_SUCCESS)
3355 goto end;
3357 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3358 if (r != ERROR_SUCCESS)
3359 goto end;
3361 r = MSI_InstallPackage( package, sourcepath, NULL );
3363 end:
3364 msiobj_release( &package->hdr );
3366 return r;
3369 /***********************************************************************
3370 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3372 * Notes: undocumented
3374 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3376 WCHAR path[MAX_PATH];
3378 TRACE("%d\n", dwReserved);
3380 if (dwReserved)
3382 FIXME("dwReserved=%d\n", dwReserved);
3383 return ERROR_INVALID_PARAMETER;
3386 if (!GetWindowsDirectoryW(path, MAX_PATH))
3387 return ERROR_FUNCTION_FAILED;
3389 lstrcatW(path, installerW);
3391 if (!CreateDirectoryW(path, NULL))
3392 return ERROR_FUNCTION_FAILED;
3394 return ERROR_SUCCESS;
3397 /***********************************************************************
3398 * MsiGetShortcutTargetA [MSI.@]
3400 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3401 LPSTR szProductCode, LPSTR szFeatureId,
3402 LPSTR szComponentCode )
3404 LPWSTR target;
3405 const int len = MAX_FEATURE_CHARS+1;
3406 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3407 UINT r;
3409 target = strdupAtoW( szShortcutTarget );
3410 if (szShortcutTarget && !target )
3411 return ERROR_OUTOFMEMORY;
3412 product[0] = 0;
3413 feature[0] = 0;
3414 component[0] = 0;
3415 r = MsiGetShortcutTargetW( target, product, feature, component );
3416 msi_free( target );
3417 if (r == ERROR_SUCCESS)
3419 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3420 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3421 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3423 return r;
3426 /***********************************************************************
3427 * MsiGetShortcutTargetW [MSI.@]
3429 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3430 LPWSTR szProductCode, LPWSTR szFeatureId,
3431 LPWSTR szComponentCode )
3433 IShellLinkDataList *dl = NULL;
3434 IPersistFile *pf = NULL;
3435 LPEXP_DARWIN_LINK darwin = NULL;
3436 HRESULT r, init;
3438 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3439 szProductCode, szFeatureId, szComponentCode );
3441 init = CoInitialize(NULL);
3443 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3444 &IID_IPersistFile, (LPVOID*) &pf );
3445 if( SUCCEEDED( r ) )
3447 r = IPersistFile_Load( pf, szShortcutTarget,
3448 STGM_READ | STGM_SHARE_DENY_WRITE );
3449 if( SUCCEEDED( r ) )
3451 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3452 (LPVOID*) &dl );
3453 if( SUCCEEDED( r ) )
3455 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3456 (LPVOID) &darwin );
3457 IShellLinkDataList_Release( dl );
3460 IPersistFile_Release( pf );
3463 if (SUCCEEDED(init))
3464 CoUninitialize();
3466 TRACE("darwin = %p\n", darwin);
3468 if (darwin)
3470 DWORD sz;
3471 UINT ret;
3473 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3474 szProductCode, szFeatureId, szComponentCode, &sz );
3475 LocalFree( darwin );
3476 return ret;
3479 return ERROR_FUNCTION_FAILED;
3482 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
3483 DWORD dwReinstallMode )
3485 MSIPACKAGE* package = NULL;
3486 UINT r;
3487 WCHAR sourcepath[MAX_PATH];
3488 WCHAR filename[MAX_PATH];
3489 static const WCHAR szLogVerbose[] = {
3490 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3491 WCHAR reinstallmode[11];
3492 LPWSTR ptr;
3493 DWORD sz;
3495 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3496 dwReinstallMode);
3498 ptr = reinstallmode;
3500 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3501 *ptr++ = 'p';
3502 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3503 *ptr++ = 'o';
3504 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3505 *ptr++ = 'w';
3506 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3507 *ptr++ = 'd';
3508 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3509 *ptr++ = 'c';
3510 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3511 *ptr++ = 'a';
3512 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3513 *ptr++ = 'u';
3514 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3515 *ptr++ = 'm';
3516 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3517 *ptr++ = 's';
3518 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3519 *ptr++ = 'v';
3520 *ptr = 0;
3522 sz = sizeof(sourcepath);
3523 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3524 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3526 sz = sizeof(filename);
3527 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3528 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3530 lstrcatW( sourcepath, filename );
3532 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3533 r = MSI_OpenPackageW( sourcepath, &package );
3534 else
3535 r = MSI_OpenProductW( szProduct, &package );
3537 if (r != ERROR_SUCCESS)
3538 return r;
3540 msi_set_property( package->db, szReinstallMode, reinstallmode );
3541 msi_set_property( package->db, szInstalled, szOne );
3542 msi_set_property( package->db, szLogVerbose, szOne );
3543 msi_set_property( package->db, szReinstall, szFeature );
3545 r = MSI_InstallPackage( package, sourcepath, NULL );
3547 msiobj_release( &package->hdr );
3549 return r;
3552 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3553 DWORD dwReinstallMode )
3555 LPWSTR wszProduct;
3556 LPWSTR wszFeature;
3557 UINT rc;
3559 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3560 dwReinstallMode);
3562 wszProduct = strdupAtoW(szProduct);
3563 wszFeature = strdupAtoW(szFeature);
3565 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3567 msi_free(wszProduct);
3568 msi_free(wszFeature);
3569 return rc;
3572 typedef struct
3574 unsigned int i[2];
3575 unsigned int buf[4];
3576 unsigned char in[64];
3577 unsigned char digest[16];
3578 } MD5_CTX;
3580 extern VOID WINAPI MD5Init( MD5_CTX *);
3581 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
3582 extern VOID WINAPI MD5Final( MD5_CTX *);
3584 /***********************************************************************
3585 * MsiGetFileHashW [MSI.@]
3587 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
3588 PMSIFILEHASHINFO pHash )
3590 HANDLE handle, mapping;
3591 void *p;
3592 DWORD length;
3593 UINT r = ERROR_FUNCTION_FAILED;
3595 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
3597 if (!szFilePath)
3598 return ERROR_INVALID_PARAMETER;
3600 if (!*szFilePath)
3601 return ERROR_PATH_NOT_FOUND;
3603 if (dwOptions)
3604 return ERROR_INVALID_PARAMETER;
3605 if (!pHash)
3606 return ERROR_INVALID_PARAMETER;
3607 if (pHash->dwFileHashInfoSize < sizeof *pHash)
3608 return ERROR_INVALID_PARAMETER;
3610 handle = CreateFileW( szFilePath, GENERIC_READ,
3611 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
3612 if (handle == INVALID_HANDLE_VALUE)
3613 return ERROR_FILE_NOT_FOUND;
3615 length = GetFileSize( handle, NULL );
3617 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
3618 if (mapping)
3620 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
3621 if (p)
3623 MD5_CTX ctx;
3625 MD5Init( &ctx );
3626 MD5Update( &ctx, p, length );
3627 MD5Final( &ctx );
3628 UnmapViewOfFile( p );
3630 memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
3631 r = ERROR_SUCCESS;
3633 CloseHandle( mapping );
3635 CloseHandle( handle );
3637 return r;
3640 /***********************************************************************
3641 * MsiGetFileHashA [MSI.@]
3643 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
3644 PMSIFILEHASHINFO pHash )
3646 LPWSTR file;
3647 UINT r;
3649 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
3651 file = strdupAtoW( szFilePath );
3652 if (szFilePath && !file)
3653 return ERROR_OUTOFMEMORY;
3655 r = MsiGetFileHashW( file, dwOptions, pHash );
3656 msi_free( file );
3657 return r;
3660 /***********************************************************************
3661 * MsiAdvertiseScriptW [MSI.@]
3663 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
3664 PHKEY phRegData, BOOL fRemoveItems )
3666 FIXME("%s %08x %p %d\n",
3667 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3668 return ERROR_CALL_NOT_IMPLEMENTED;
3671 /***********************************************************************
3672 * MsiAdvertiseScriptA [MSI.@]
3674 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
3675 PHKEY phRegData, BOOL fRemoveItems )
3677 FIXME("%s %08x %p %d\n",
3678 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3679 return ERROR_CALL_NOT_IMPLEMENTED;
3682 /***********************************************************************
3683 * MsiIsProductElevatedW [MSI.@]
3685 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
3687 FIXME("%s %p - stub\n",
3688 debugstr_w( szProduct ), pfElevated );
3689 *pfElevated = TRUE;
3690 return ERROR_SUCCESS;
3693 /***********************************************************************
3694 * MsiIsProductElevatedA [MSI.@]
3696 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
3698 FIXME("%s %p - stub\n",
3699 debugstr_a( szProduct ), pfElevated );
3700 *pfElevated = TRUE;
3701 return ERROR_SUCCESS;
3704 /***********************************************************************
3705 * MsiSetExternalUIRecord [MSI.@]
3707 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler,
3708 DWORD filter, LPVOID context,
3709 PINSTALLUI_HANDLER_RECORD prev )
3711 TRACE("%p %08x %p %p\n", handler, filter, context, prev);
3713 if (prev)
3714 *prev = gUIHandlerRecord;
3716 gUIHandlerRecord = handler;
3717 gUIFilter = filter;
3718 gUIContext = context;
3720 return ERROR_SUCCESS;
3723 /***********************************************************************
3724 * MsiInstallMissingComponentW [MSI.@]
3726 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
3728 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
3729 return ERROR_SUCCESS;