mshtml: Improve debug messages for timer invocation.
[wine/wine-gecko.git] / dlls / msi / msi.c
blobba9d8bf6b11e4816a8592f5047adf99c2edfe37c
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 static const WCHAR szAll[] = {'A','L','L',0};
269 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
271 return MsiReinstallFeatureW(szProduct, szAll, dwReinstallMode);
274 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
275 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
277 LPWSTR patch_package = NULL;
278 LPWSTR install_package = NULL;
279 LPWSTR command_line = NULL;
280 UINT r = ERROR_OUTOFMEMORY;
282 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
283 eInstallType, debugstr_a(szCommandLine));
285 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
286 goto done;
288 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
289 goto done;
291 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
292 goto done;
294 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
296 done:
297 msi_free(patch_package);
298 msi_free(install_package);
299 msi_free(command_line);
301 return r;
304 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
306 MSIHANDLE patch = 0, info = 0;
307 UINT r = ERROR_SUCCESS, type;
308 DWORD size = 0;
309 LPCWSTR cmd_ptr = szCommandLine;
310 LPCWSTR product_code = szProductCode;
311 LPWSTR beg, end;
312 LPWSTR cmd = NULL, codes = NULL;
314 static const WCHAR space[] = {' ',0};
315 static const WCHAR patcheq[] = {'P','A','T','C','H','=',0};
316 static WCHAR empty[] = {0};
318 if (!szPatchPackage || !szPatchPackage[0])
319 return ERROR_INVALID_PARAMETER;
321 if (!szProductCode)
323 r = MsiOpenDatabaseW(szPatchPackage, MSIDBOPEN_READONLY, &patch);
324 if (r != ERROR_SUCCESS)
325 return r;
327 r = MsiGetSummaryInformationW(patch, NULL, 0, &info);
328 if (r != ERROR_SUCCESS)
329 goto done;
331 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, empty, &size);
332 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
334 ERR("Failed to read product codes from patch\n");
335 goto done;
338 codes = msi_alloc(++size * sizeof(WCHAR));
339 if (!codes)
341 r = ERROR_OUTOFMEMORY;
342 goto done;
345 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, codes, &size);
346 if (r != ERROR_SUCCESS)
347 goto done;
349 product_code = codes;
352 if (!szCommandLine)
353 cmd_ptr = empty;
355 size = lstrlenW(cmd_ptr) + lstrlenW(patcheq) + lstrlenW(szPatchPackage) + 1;
356 cmd = msi_alloc(size * sizeof(WCHAR));
357 if (!cmd)
359 r = ERROR_OUTOFMEMORY;
360 goto done;
363 lstrcpyW(cmd, cmd_ptr);
364 if (szCommandLine) lstrcatW(cmd, space);
365 lstrcatW(cmd, patcheq);
366 lstrcatW(cmd, szPatchPackage);
368 beg = codes;
369 while ((end = strchrW(beg, '}')))
371 *(end + 1) = '\0';
373 r = MsiConfigureProductExW(beg, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
374 if (r != ERROR_SUCCESS)
375 goto done;
377 beg = end + 2;
380 done:
381 msi_free(cmd);
382 msi_free(codes);
384 MsiCloseHandle(info);
385 MsiCloseHandle(patch);
387 return r;
390 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
391 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
393 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
394 eInstallType, debugstr_w(szCommandLine));
396 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
397 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
399 FIXME("Only reading target products from patch\n");
400 return ERROR_CALL_NOT_IMPLEMENTED;
403 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
406 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
407 LPCSTR szProductCode, LPCSTR szPropertiesList)
409 LPWSTR patch_packages = NULL;
410 LPWSTR product_code = NULL;
411 LPWSTR properties_list = NULL;
412 UINT r = ERROR_OUTOFMEMORY;
414 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
415 debugstr_a(szPropertiesList));
417 if (!szPatchPackages || !szPatchPackages[0])
418 return ERROR_INVALID_PARAMETER;
420 if (!(patch_packages = strdupAtoW(szPatchPackages)))
421 return ERROR_OUTOFMEMORY;
423 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
424 goto done;
426 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
427 goto done;
429 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
431 done:
432 msi_free(patch_packages);
433 msi_free(product_code);
434 msi_free(properties_list);
436 return r;
439 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
440 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
442 UINT r = ERROR_SUCCESS;
443 LPCWSTR beg, end;
445 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
446 debugstr_w(szPropertiesList));
448 if (!szPatchPackages || !szPatchPackages[0])
449 return ERROR_INVALID_PARAMETER;
451 beg = end = szPatchPackages;
452 while (*beg)
454 DWORD len;
455 LPWSTR patch;
457 while (*beg == ' ') beg++;
458 while (*end && *end != ';') end++;
460 len = end - beg;
461 while (len && beg[len - 1] == ' ') len--;
463 if (!len) return ERROR_INVALID_NAME;
465 patch = msi_alloc((len + 1) * sizeof(WCHAR));
466 if (!patch)
467 return ERROR_OUTOFMEMORY;
469 memcpy(patch, beg, len * sizeof(WCHAR));
470 patch[len] = '\0';
472 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
473 msi_free(patch);
475 if (r != ERROR_SUCCESS)
476 break;
478 beg = ++end;
480 return r;
483 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
484 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
486 FIXME("(%s, %d, %p): stub!\n", debugstr_a(szProductPackagePath),
487 cPatchInfo, pPatchInfo);
489 return ERROR_CALL_NOT_IMPLEMENTED;
492 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
494 MSISUMMARYINFO *si;
495 MSIDATABASE *patch_db;
496 UINT r = ERROR_SUCCESS;
498 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
499 if (r != ERROR_SUCCESS)
501 WARN("failed to open patch file %s\n", debugstr_w(patch));
502 return r;
505 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
506 if (!si)
508 r = ERROR_FUNCTION_FAILED;
509 goto done;
512 r = msi_check_patch_applicable( package, si );
513 if (r != ERROR_SUCCESS)
514 TRACE("patch not applicable\n");
516 done:
517 msiobj_release( &patch_db->hdr );
518 msiobj_release( &si->hdr );
519 return r;
522 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
523 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
525 UINT i, r, ret = ERROR_FUNCTION_FAILED;
526 MSIPACKAGE *package;
528 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
530 r = MSI_OpenPackageW( szProductPackagePath, &package );
531 if (r != ERROR_SUCCESS)
533 ERR("failed to open package %u\n", r);
534 return r;
537 for (i = 0; i < cPatchInfo; i++)
539 switch (pPatchInfo[i].ePatchDataType)
541 case MSIPATCH_DATATYPE_PATCHFILE:
543 FIXME("patch ordering not supported\n");
544 r = MSI_ApplicablePatchW( package, pPatchInfo[i].szPatchData );
545 if (r != ERROR_SUCCESS)
547 pPatchInfo[i].dwOrder = ~0u;
548 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
550 else
552 pPatchInfo[i].dwOrder = i;
553 pPatchInfo[i].uStatus = ret = ERROR_SUCCESS;
555 break;
557 default:
559 FIXME("patch data type %u not supported\n", pPatchInfo[i].ePatchDataType);
560 pPatchInfo[i].dwOrder = ~0u;
561 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
562 break;
566 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo[i].szPatchData));
567 TRACE("ePatchDataType: %u\n", pPatchInfo[i].ePatchDataType);
568 TRACE(" dwOrder: %u\n", pPatchInfo[i].dwOrder);
569 TRACE(" uStatus: %u\n", pPatchInfo[i].uStatus);
571 return ret;
574 UINT WINAPI MsiDeterminePatchSequenceA(LPCSTR szProductCode, LPCSTR szUserSid,
575 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
577 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode),
578 debugstr_a(szUserSid), dwContext, cPatchInfo, pPatchInfo);
580 return ERROR_CALL_NOT_IMPLEMENTED;
583 UINT WINAPI MsiDeterminePatchSequenceW(LPCWSTR szProductCode, LPCWSTR szUserSid,
584 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
586 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode),
587 debugstr_w(szUserSid), dwContext, cPatchInfo, pPatchInfo);
589 return ERROR_CALL_NOT_IMPLEMENTED;
592 static UINT msi_open_package(LPCWSTR product, MSIINSTALLCONTEXT context,
593 MSIPACKAGE **package)
595 UINT r;
596 DWORD sz;
597 HKEY props;
598 LPWSTR localpack;
599 WCHAR sourcepath[MAX_PATH];
600 WCHAR filename[MAX_PATH];
602 static const WCHAR szLocalPackage[] = {
603 'L','o','c','a','l','P','a','c','k','a','g','e',0};
606 r = MSIREG_OpenInstallProps(product, context, NULL, &props, FALSE);
607 if (r != ERROR_SUCCESS)
608 return ERROR_BAD_CONFIGURATION;
610 localpack = msi_reg_get_val_str(props, szLocalPackage);
611 if (localpack)
613 lstrcpyW(sourcepath, localpack);
614 msi_free(localpack);
617 if (!localpack || GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
619 sz = sizeof(sourcepath);
620 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
621 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
623 sz = sizeof(filename);
624 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
625 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
627 lstrcatW(sourcepath, filename);
630 if (GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
631 return ERROR_INSTALL_SOURCE_ABSENT;
633 return MSI_OpenPackageW(sourcepath, package);
636 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
637 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
639 MSIPACKAGE* package = NULL;
640 MSIINSTALLCONTEXT context;
641 UINT r;
642 DWORD sz;
643 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
644 LPWSTR commandline;
646 static const WCHAR szInstalled[] = {
647 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
648 static const WCHAR szRemoveAll[] = {
649 ' ','R','E','M','O','V','E','=','A','L','L',0};
650 static const WCHAR szMachine[] = {
651 ' ','A','L','L','U','S','E','R','S','=','1',0};
653 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
654 debugstr_w(szCommandLine));
656 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
657 return ERROR_INVALID_PARAMETER;
659 if (eInstallState == INSTALLSTATE_ADVERTISED ||
660 eInstallState == INSTALLSTATE_SOURCE)
662 FIXME("State %d not implemented\n", eInstallState);
663 return ERROR_CALL_NOT_IMPLEMENTED;
666 r = msi_locate_product(szProduct, &context);
667 if (r != ERROR_SUCCESS)
668 return r;
670 r = msi_open_package(szProduct, context, &package);
671 if (r != ERROR_SUCCESS)
672 return r;
674 sz = lstrlenW(szInstalled) + 1;
676 if (szCommandLine)
677 sz += lstrlenW(szCommandLine);
679 if (eInstallState == INSTALLSTATE_ABSENT)
680 sz += lstrlenW(szRemoveAll);
682 if (context == MSIINSTALLCONTEXT_MACHINE)
683 sz += lstrlenW(szMachine);
685 commandline = msi_alloc(sz * sizeof(WCHAR));
686 if (!commandline)
688 r = ERROR_OUTOFMEMORY;
689 goto end;
692 commandline[0] = 0;
693 if (szCommandLine)
694 lstrcpyW(commandline,szCommandLine);
696 if (MsiQueryProductStateW(szProduct) != INSTALLSTATE_UNKNOWN)
697 lstrcatW(commandline,szInstalled);
699 if (eInstallState == INSTALLSTATE_ABSENT)
700 lstrcatW(commandline, szRemoveAll);
702 if (context == MSIINSTALLCONTEXT_MACHINE)
703 lstrcatW(commandline, szMachine);
705 sz = sizeof(sourcepath);
706 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
707 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
709 sz = sizeof(filename);
710 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
711 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
713 strcatW(sourcepath, filename);
715 r = MSI_InstallPackage( package, sourcepath, commandline );
717 msi_free(commandline);
719 end:
720 msiobj_release( &package->hdr );
722 return r;
725 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
726 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
728 LPWSTR szwProduct = NULL;
729 LPWSTR szwCommandLine = NULL;
730 UINT r = ERROR_OUTOFMEMORY;
732 if( szProduct )
734 szwProduct = strdupAtoW( szProduct );
735 if( !szwProduct )
736 goto end;
739 if( szCommandLine)
741 szwCommandLine = strdupAtoW( szCommandLine );
742 if( !szwCommandLine)
743 goto end;
746 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
747 szwCommandLine );
748 end:
749 msi_free( szwProduct );
750 msi_free( szwCommandLine);
752 return r;
755 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
756 INSTALLSTATE eInstallState)
758 LPWSTR szwProduct = NULL;
759 UINT r;
761 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
763 if( szProduct )
765 szwProduct = strdupAtoW( szProduct );
766 if( !szwProduct )
767 return ERROR_OUTOFMEMORY;
770 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
771 msi_free( szwProduct );
773 return r;
776 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
777 INSTALLSTATE eInstallState)
779 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
782 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
784 LPWSTR szwComponent = NULL;
785 UINT r;
786 WCHAR szwBuffer[GUID_SIZE];
788 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
790 if( szComponent )
792 szwComponent = strdupAtoW( szComponent );
793 if( !szwComponent )
794 return ERROR_OUTOFMEMORY;
797 *szwBuffer = '\0';
798 r = MsiGetProductCodeW( szwComponent, szwBuffer );
800 if(*szwBuffer)
801 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
803 msi_free( szwComponent );
805 return r;
808 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
810 UINT rc, index;
811 HKEY compkey, prodkey;
812 WCHAR squished_comp[GUID_SIZE];
813 WCHAR squished_prod[GUID_SIZE];
814 DWORD sz = GUID_SIZE;
816 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
818 if (!szComponent || !*szComponent)
819 return ERROR_INVALID_PARAMETER;
821 if (!squash_guid(szComponent, squished_comp))
822 return ERROR_INVALID_PARAMETER;
824 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
825 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
827 return ERROR_UNKNOWN_COMPONENT;
830 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
831 if (rc != ERROR_SUCCESS)
833 RegCloseKey(compkey);
834 return ERROR_UNKNOWN_COMPONENT;
837 /* check simple case, only one product */
838 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
839 if (rc == ERROR_NO_MORE_ITEMS)
841 rc = ERROR_SUCCESS;
842 goto done;
845 index = 0;
846 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
847 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
849 index++;
850 sz = GUID_SIZE;
851 unsquash_guid(squished_prod, szBuffer);
853 if (MSIREG_OpenProductKey(szBuffer, NULL,
854 MSIINSTALLCONTEXT_USERMANAGED,
855 &prodkey, FALSE) == ERROR_SUCCESS ||
856 MSIREG_OpenProductKey(szBuffer, NULL,
857 MSIINSTALLCONTEXT_USERUNMANAGED,
858 &prodkey, FALSE) == ERROR_SUCCESS ||
859 MSIREG_OpenProductKey(szBuffer, NULL,
860 MSIINSTALLCONTEXT_MACHINE,
861 &prodkey, FALSE) == ERROR_SUCCESS)
863 RegCloseKey(prodkey);
864 rc = ERROR_SUCCESS;
865 goto done;
869 rc = ERROR_INSTALL_FAILURE;
871 done:
872 RegCloseKey(compkey);
873 unsquash_guid(squished_prod, szBuffer);
874 return rc;
877 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
879 DWORD dval;
880 LONG res;
881 WCHAR temp[20];
883 static const WCHAR format[] = {'%','d',0};
885 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
886 if (res != ERROR_SUCCESS)
887 return NULL;
889 if (*type == REG_SZ)
890 return msi_reg_get_val_str(hkey, name);
892 if (!msi_reg_get_val_dword(hkey, name, &dval))
893 return NULL;
895 sprintfW(temp, format, dval);
896 return strdupW(temp);
899 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
900 awstring *szValue, LPDWORD pcchValueBuf)
902 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
903 UINT r = ERROR_UNKNOWN_PROPERTY;
904 HKEY prodkey, userdata, source;
905 LPWSTR val = NULL;
906 WCHAR squished_pc[GUID_SIZE];
907 WCHAR packagecode[GUID_SIZE];
908 BOOL badconfig = FALSE;
909 LONG res;
910 DWORD save, type = REG_NONE;
912 static WCHAR empty[] = {0};
913 static const WCHAR sourcelist[] = {
914 'S','o','u','r','c','e','L','i','s','t',0};
915 static const WCHAR display_name[] = {
916 'D','i','s','p','l','a','y','N','a','m','e',0};
917 static const WCHAR display_version[] = {
918 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
919 static const WCHAR assignment[] = {
920 'A','s','s','i','g','n','m','e','n','t',0};
922 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
923 debugstr_w(szAttribute), szValue, pcchValueBuf);
925 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
926 return ERROR_INVALID_PARAMETER;
928 if (!squash_guid(szProduct, squished_pc))
929 return ERROR_INVALID_PARAMETER;
931 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
932 MSIINSTALLCONTEXT_USERMANAGED,
933 &prodkey, FALSE)) != ERROR_SUCCESS &&
934 (r = MSIREG_OpenProductKey(szProduct, NULL,
935 MSIINSTALLCONTEXT_USERUNMANAGED,
936 &prodkey, FALSE)) != ERROR_SUCCESS &&
937 (r = MSIREG_OpenProductKey(szProduct, NULL,
938 MSIINSTALLCONTEXT_MACHINE,
939 &prodkey, FALSE)) == ERROR_SUCCESS)
941 context = MSIINSTALLCONTEXT_MACHINE;
944 MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
946 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPLINKW) ||
947 !lstrcmpW(szAttribute, INSTALLPROPERTY_HELPTELEPHONEW) ||
948 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLDATEW) ||
949 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
950 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW) ||
951 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLSOURCEW) ||
952 !lstrcmpW(szAttribute, INSTALLPROPERTY_LOCALPACKAGEW) ||
953 !lstrcmpW(szAttribute, INSTALLPROPERTY_PUBLISHERW) ||
954 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLINFOABOUTW) ||
955 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLUPDATEINFOW) ||
956 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMINORW) ||
957 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMAJORW) ||
958 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW) ||
959 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTIDW) ||
960 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGCOMPANYW) ||
961 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGOWNERW))
963 if (!prodkey)
965 r = ERROR_UNKNOWN_PRODUCT;
966 goto done;
969 if (!userdata)
970 return ERROR_UNKNOWN_PROPERTY;
972 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
973 szAttribute = display_name;
974 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW))
975 szAttribute = display_version;
977 val = msi_reg_get_value(userdata, szAttribute, &type);
978 if (!val)
979 val = empty;
981 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTANCETYPEW) ||
982 !lstrcmpW(szAttribute, INSTALLPROPERTY_TRANSFORMSW) ||
983 !lstrcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEW) ||
984 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTNAMEW) ||
985 !lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW) ||
986 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW) ||
987 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONW) ||
988 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTICONW) ||
989 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW) ||
990 !lstrcmpW(szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
992 if (!prodkey)
994 r = ERROR_UNKNOWN_PRODUCT;
995 goto done;
998 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW))
999 szAttribute = assignment;
1001 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW))
1003 res = RegOpenKeyW(prodkey, sourcelist, &source);
1004 if (res != ERROR_SUCCESS)
1006 r = ERROR_UNKNOWN_PRODUCT;
1007 goto done;
1010 val = msi_reg_get_value(source, szAttribute, &type);
1011 if (!val)
1012 val = empty;
1014 RegCloseKey(source);
1016 else
1018 val = msi_reg_get_value(prodkey, szAttribute, &type);
1019 if (!val)
1020 val = empty;
1023 if (val != empty && type != REG_DWORD &&
1024 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW))
1026 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1027 badconfig = TRUE;
1028 else
1030 unsquash_guid(val, packagecode);
1031 msi_free(val);
1032 val = strdupW(packagecode);
1037 if (!val)
1039 r = ERROR_UNKNOWN_PROPERTY;
1040 goto done;
1043 if (pcchValueBuf)
1045 save = *pcchValueBuf;
1047 if (strlenW(val) < *pcchValueBuf)
1048 r = msi_strcpy_to_awstring(val, szValue, pcchValueBuf);
1049 else if (szValue->str.a || szValue->str.w)
1050 r = ERROR_MORE_DATA;
1052 if (!badconfig)
1053 *pcchValueBuf = lstrlenW(val);
1054 else if (r == ERROR_SUCCESS)
1056 *pcchValueBuf = save;
1057 r = ERROR_BAD_CONFIGURATION;
1060 else 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 one[] = {'1',0};
1223 static const WCHAR five[] = {'5',0};
1224 static const WCHAR empty[] = {0};
1225 static const WCHAR displayname[] = {
1226 'D','i','s','p','l','a','y','N','a','m','e',0};
1227 static const WCHAR displayversion[] = {
1228 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1229 static const WCHAR managed_local_package[] = {
1230 'M','a','n','a','g','e','d','L','o','c','a','l',
1231 'P','a','c','k','a','g','e',0};
1233 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1234 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1235 szValue, pcchValue);
1237 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1238 return ERROR_INVALID_PARAMETER;
1240 if (szValue && !pcchValue)
1241 return ERROR_INVALID_PARAMETER;
1243 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1244 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1245 dwContext != MSIINSTALLCONTEXT_MACHINE)
1246 return ERROR_INVALID_PARAMETER;
1248 if (!szProperty || !*szProperty)
1249 return ERROR_INVALID_PARAMETER;
1251 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1252 return ERROR_INVALID_PARAMETER;
1254 /* FIXME: dwContext is provided, no need to search for it */
1255 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1256 &managed, FALSE);
1257 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1258 &prod, FALSE);
1260 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1262 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1264 package = INSTALLPROPERTY_LOCALPACKAGEW;
1266 if (!props && !prod)
1267 goto done;
1269 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1271 package = managed_local_package;
1273 if (!props && !managed)
1274 goto done;
1276 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1278 package = INSTALLPROPERTY_LOCALPACKAGEW;
1279 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1281 if (!props && !classes)
1282 goto done;
1285 if (!lstrcmpW(szProperty, INSTALLPROPERTY_HELPLINKW) ||
1286 !lstrcmpW(szProperty, INSTALLPROPERTY_HELPTELEPHONEW) ||
1287 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW) ||
1288 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
1289 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLLOCATIONW) ||
1290 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLSOURCEW) ||
1291 !lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW) ||
1292 !lstrcmpW(szProperty, INSTALLPROPERTY_PUBLISHERW) ||
1293 !lstrcmpW(szProperty, INSTALLPROPERTY_URLINFOABOUTW) ||
1294 !lstrcmpW(szProperty, INSTALLPROPERTY_URLUPDATEINFOW) ||
1295 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMINORW) ||
1296 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMAJORW) ||
1297 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW) ||
1298 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTIDW) ||
1299 !lstrcmpW(szProperty, INSTALLPROPERTY_REGCOMPANYW) ||
1300 !lstrcmpW(szProperty, INSTALLPROPERTY_REGOWNERW) ||
1301 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTANCETYPEW))
1303 val = msi_reg_get_value(props, package, &type);
1304 if (!val)
1306 if (prod || classes)
1307 r = ERROR_UNKNOWN_PROPERTY;
1309 goto done;
1312 msi_free(val);
1314 if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
1315 szProperty = displayname;
1316 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW))
1317 szProperty = displayversion;
1319 val = msi_reg_get_value(props, szProperty, &type);
1320 if (!val)
1321 val = strdupW(empty);
1323 r = msi_copy_outval(val, szValue, pcchValue);
1325 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW) ||
1326 !lstrcmpW(szProperty, INSTALLPROPERTY_LANGUAGEW) ||
1327 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTNAMEW) ||
1328 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGECODEW) ||
1329 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONW) ||
1330 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTICONW) ||
1331 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGENAMEW) ||
1332 !lstrcmpW(szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
1334 if (!prod && !classes)
1335 goto done;
1337 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1338 hkey = prod;
1339 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1340 hkey = managed;
1341 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1342 hkey = classes;
1344 val = msi_reg_get_value(hkey, szProperty, &type);
1345 if (!val)
1346 val = strdupW(empty);
1348 r = msi_copy_outval(val, szValue, pcchValue);
1350 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTSTATEW))
1352 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1354 if (props)
1356 val = msi_reg_get_value(props, package, &type);
1357 if (!val)
1358 goto done;
1360 msi_free(val);
1361 val = strdupW(five);
1363 else
1364 val = strdupW(one);
1366 r = msi_copy_outval(val, szValue, pcchValue);
1367 goto done;
1369 else if (props && (val = msi_reg_get_value(props, package, &type)))
1371 msi_free(val);
1372 val = strdupW(five);
1373 r = msi_copy_outval(val, szValue, pcchValue);
1374 goto done;
1377 if (prod || managed)
1378 val = strdupW(one);
1379 else
1380 goto done;
1382 r = msi_copy_outval(val, szValue, pcchValue);
1384 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW))
1386 if (!prod && !classes)
1387 goto done;
1389 /* FIXME */
1390 val = strdupW(empty);
1391 r = msi_copy_outval(val, szValue, pcchValue);
1393 else
1394 r = ERROR_UNKNOWN_PROPERTY;
1396 done:
1397 RegCloseKey(props);
1398 RegCloseKey(prod);
1399 RegCloseKey(managed);
1400 RegCloseKey(classes);
1401 msi_free(val);
1403 return r;
1406 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1407 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1408 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1410 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1411 LPWSTR property = NULL, val = NULL;
1412 DWORD len;
1413 UINT r;
1415 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1416 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1417 debugstr_a(szProperty), lpValue, pcchValue);
1419 if (lpValue && !pcchValue)
1420 return ERROR_INVALID_PARAMETER;
1422 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1423 if (szProductCode) product = strdupAtoW(szProductCode);
1424 if (szUserSid) usersid = strdupAtoW(szUserSid);
1425 if (szProperty) property = strdupAtoW(szProperty);
1427 len = 0;
1428 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1429 NULL, &len);
1430 if (r != ERROR_SUCCESS)
1431 goto done;
1433 val = msi_alloc(++len * sizeof(WCHAR));
1434 if (!val)
1436 r = ERROR_OUTOFMEMORY;
1437 goto done;
1440 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1441 val, &len);
1442 if (r != ERROR_SUCCESS || !pcchValue)
1443 goto done;
1445 if (lpValue)
1446 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1447 *pcchValue - 1, NULL, NULL);
1449 len = lstrlenW(val);
1450 if ((*val && *pcchValue < len + 1) || !lpValue)
1452 if (lpValue)
1454 r = ERROR_MORE_DATA;
1455 lpValue[*pcchValue - 1] = '\0';
1458 *pcchValue = len * sizeof(WCHAR);
1460 else
1461 *pcchValue = len;
1463 done:
1464 msi_free(val);
1465 msi_free(patch);
1466 msi_free(product);
1467 msi_free(usersid);
1468 msi_free(property);
1470 return r;
1473 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1474 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1475 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1477 WCHAR squished_pc[GUID_SIZE];
1478 WCHAR squished_patch[GUID_SIZE];
1479 HKEY udprod = 0, prod = 0, props = 0;
1480 HKEY patch = 0, patches = 0;
1481 HKEY udpatch = 0, datakey = 0;
1482 HKEY prodpatches = 0;
1483 LPWSTR val = NULL;
1484 UINT r = ERROR_UNKNOWN_PRODUCT;
1485 DWORD len;
1486 LONG res;
1488 static const WCHAR szEmpty[] = {0};
1489 static const WCHAR szPatches[] = {'P','a','t','c','h','e','s',0};
1490 static const WCHAR szInstalled[] = {'I','n','s','t','a','l','l','e','d',0};
1491 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1492 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1494 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1495 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1496 debugstr_w(szProperty), lpValue, pcchValue);
1498 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1499 return ERROR_INVALID_PARAMETER;
1501 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1502 return ERROR_INVALID_PARAMETER;
1504 if (!szProperty)
1505 return ERROR_INVALID_PARAMETER;
1507 if (lpValue && !pcchValue)
1508 return ERROR_INVALID_PARAMETER;
1510 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1511 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1512 dwContext != MSIINSTALLCONTEXT_MACHINE)
1513 return ERROR_INVALID_PARAMETER;
1515 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1516 return ERROR_INVALID_PARAMETER;
1518 if (!lstrcmpW(szUserSid, szLocalSid))
1519 return ERROR_INVALID_PARAMETER;
1521 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1522 &udprod, FALSE) != ERROR_SUCCESS)
1523 goto done;
1525 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1526 &props, FALSE) != ERROR_SUCCESS)
1527 goto done;
1529 r = ERROR_UNKNOWN_PATCH;
1531 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_READ, &patches);
1532 if (res != ERROR_SUCCESS)
1533 goto done;
1535 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_READ, &patch);
1536 if (res != ERROR_SUCCESS)
1537 goto done;
1539 if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW))
1541 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1542 &prod, FALSE) != ERROR_SUCCESS)
1543 goto done;
1545 res = RegOpenKeyExW(prod, szPatches, 0, KEY_ALL_ACCESS, &prodpatches);
1546 if (res != ERROR_SUCCESS)
1547 goto done;
1549 datakey = prodpatches;
1550 szProperty = squished_patch;
1552 else
1554 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1555 &udpatch, FALSE) != ERROR_SUCCESS)
1556 goto done;
1558 if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1560 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1561 szProperty = szManagedPackage;
1562 datakey = udpatch;
1564 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW))
1566 datakey = patch;
1567 szProperty = szInstalled;
1569 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1571 datakey = udpatch;
1573 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_UNINSTALLABLEW) ||
1574 !lstrcmpW(szProperty, INSTALLPROPERTY_PATCHSTATEW) ||
1575 !lstrcmpW(szProperty, INSTALLPROPERTY_DISPLAYNAMEW) ||
1576 !lstrcmpW(szProperty, INSTALLPROPERTY_MOREINFOURLW))
1578 datakey = patch;
1580 else
1582 r = ERROR_UNKNOWN_PROPERTY;
1583 goto done;
1587 val = msi_reg_get_val_str(datakey, szProperty);
1588 if (!val)
1589 val = strdupW(szEmpty);
1591 r = ERROR_SUCCESS;
1593 if (!pcchValue)
1594 goto done;
1596 if (lpValue)
1597 lstrcpynW(lpValue, val, *pcchValue);
1599 len = lstrlenW(val);
1600 if ((*val && *pcchValue < len + 1) || !lpValue)
1602 if (lpValue)
1603 r = ERROR_MORE_DATA;
1605 *pcchValue = len * sizeof(WCHAR);
1608 *pcchValue = len;
1610 done:
1611 msi_free(val);
1612 RegCloseKey(prodpatches);
1613 RegCloseKey(prod);
1614 RegCloseKey(patch);
1615 RegCloseKey(patches);
1616 RegCloseKey(udpatch);
1617 RegCloseKey(props);
1618 RegCloseKey(udprod);
1620 return r;
1623 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1625 LPWSTR szwLogFile = NULL;
1626 UINT r;
1628 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1630 if( szLogFile )
1632 szwLogFile = strdupAtoW( szLogFile );
1633 if( !szwLogFile )
1634 return ERROR_OUTOFMEMORY;
1636 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1637 msi_free( szwLogFile );
1638 return r;
1641 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1643 HANDLE file = INVALID_HANDLE_VALUE;
1645 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1647 if (szLogFile)
1649 lstrcpyW(gszLogFile,szLogFile);
1650 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1651 DeleteFileW(szLogFile);
1652 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
1653 FILE_ATTRIBUTE_NORMAL, NULL);
1654 if (file != INVALID_HANDLE_VALUE)
1655 CloseHandle(file);
1656 else
1657 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
1659 else
1660 gszLogFile[0] = '\0';
1662 return ERROR_SUCCESS;
1665 UINT WINAPI MsiEnumComponentCostsW(MSIHANDLE hInstall, LPCWSTR szComponent,
1666 DWORD dwIndex, INSTALLSTATE iState,
1667 LPWSTR lpDriveBuf, DWORD *pcchDriveBuf,
1668 int *piCost, int *pTempCost)
1670 FIXME("(%d, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall,
1671 debugstr_w(szComponent), dwIndex, iState, lpDriveBuf,
1672 pcchDriveBuf, piCost, pTempCost);
1674 return ERROR_NO_MORE_ITEMS;
1677 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1678 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1679 LPCSTR szComponent, INSTALLSTATE *pdwState)
1681 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1682 UINT r;
1684 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1685 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1687 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1688 return ERROR_OUTOFMEMORY;
1690 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1691 return ERROR_OUTOFMEMORY;
1693 if (szComponent && !(comp = strdupAtoW(szComponent)))
1694 return ERROR_OUTOFMEMORY;
1696 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1698 msi_free(prodcode);
1699 msi_free(usersid);
1700 msi_free(comp);
1702 return r;
1705 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1707 UINT r;
1708 HKEY hkey;
1710 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
1711 RegCloseKey(hkey);
1712 return (r == ERROR_SUCCESS);
1715 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1717 LPCWSTR package;
1718 HKEY hkey;
1719 DWORD sz;
1720 LONG res;
1721 UINT r;
1723 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1724 static const WCHAR managed_local_package[] = {
1725 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1728 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
1729 if (r != ERROR_SUCCESS)
1730 return FALSE;
1732 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1733 package = managed_local_package;
1734 else
1735 package = local_package;
1737 sz = 0;
1738 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1739 RegCloseKey(hkey);
1741 return (res == ERROR_SUCCESS);
1744 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1745 MSIINSTALLCONTEXT context,
1746 LPCWSTR comp, LPWSTR val, DWORD *sz)
1748 HKEY hkey;
1749 LONG res;
1750 UINT r;
1752 if (context == MSIINSTALLCONTEXT_MACHINE)
1753 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
1754 else
1755 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
1757 if (r != ERROR_SUCCESS)
1758 return FALSE;
1760 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
1761 if (res != ERROR_SUCCESS)
1762 return FALSE;
1764 RegCloseKey(hkey);
1765 return TRUE;
1768 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
1769 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1770 LPCWSTR szComponent, INSTALLSTATE *pdwState)
1772 WCHAR squished_pc[GUID_SIZE];
1773 WCHAR val[MAX_PATH];
1774 BOOL found;
1775 DWORD sz;
1777 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
1778 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
1780 if (!pdwState || !szComponent)
1781 return ERROR_INVALID_PARAMETER;
1783 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
1784 return ERROR_INVALID_PARAMETER;
1786 if (!squash_guid(szProductCode, squished_pc))
1787 return ERROR_INVALID_PARAMETER;
1789 found = msi_comp_find_prod_key(szProductCode, dwContext);
1791 if (!msi_comp_find_package(szProductCode, dwContext))
1793 if (found)
1795 *pdwState = INSTALLSTATE_UNKNOWN;
1796 return ERROR_UNKNOWN_COMPONENT;
1799 return ERROR_UNKNOWN_PRODUCT;
1802 *pdwState = INSTALLSTATE_UNKNOWN;
1804 sz = MAX_PATH;
1805 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
1806 return ERROR_UNKNOWN_COMPONENT;
1808 if (sz == 0)
1809 *pdwState = INSTALLSTATE_NOTUSED;
1810 else
1812 if (lstrlenW(val) > 2 &&
1813 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
1815 *pdwState = INSTALLSTATE_SOURCE;
1817 else
1818 *pdwState = INSTALLSTATE_LOCAL;
1821 return ERROR_SUCCESS;
1824 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
1826 LPWSTR szwProduct = NULL;
1827 INSTALLSTATE r;
1829 if( szProduct )
1831 szwProduct = strdupAtoW( szProduct );
1832 if( !szwProduct )
1833 return ERROR_OUTOFMEMORY;
1835 r = MsiQueryProductStateW( szwProduct );
1836 msi_free( szwProduct );
1837 return r;
1840 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
1842 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1843 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
1844 HKEY prodkey = 0, userdata = 0;
1845 DWORD val;
1846 UINT r;
1848 static const WCHAR szWindowsInstaller[] = {
1849 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1851 TRACE("%s\n", debugstr_w(szProduct));
1853 if (!szProduct || !*szProduct)
1854 return INSTALLSTATE_INVALIDARG;
1856 if (lstrlenW(szProduct) != GUID_SIZE - 1)
1857 return INSTALLSTATE_INVALIDARG;
1859 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1860 &prodkey, FALSE) != ERROR_SUCCESS &&
1861 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1862 &prodkey, FALSE) != ERROR_SUCCESS &&
1863 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
1864 &prodkey, FALSE) == ERROR_SUCCESS)
1866 context = MSIINSTALLCONTEXT_MACHINE;
1869 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
1870 if (r != ERROR_SUCCESS)
1871 goto done;
1873 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
1874 goto done;
1876 if (val)
1877 state = INSTALLSTATE_DEFAULT;
1878 else
1879 state = INSTALLSTATE_UNKNOWN;
1881 done:
1882 if (!prodkey)
1884 state = INSTALLSTATE_UNKNOWN;
1886 if (userdata)
1887 state = INSTALLSTATE_ABSENT;
1890 RegCloseKey(prodkey);
1891 RegCloseKey(userdata);
1892 return state;
1895 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
1897 INSTALLUILEVEL old = gUILevel;
1898 HWND oldwnd = gUIhwnd;
1900 TRACE("%08x %p\n", dwUILevel, phWnd);
1902 gUILevel = dwUILevel;
1903 if (phWnd)
1905 gUIhwnd = *phWnd;
1906 *phWnd = oldwnd;
1908 return old;
1911 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
1912 DWORD dwMessageFilter, LPVOID pvContext)
1914 INSTALLUI_HANDLERA prev = gUIHandlerA;
1916 TRACE("%p %x %p\n",puiHandler, dwMessageFilter,pvContext);
1917 gUIHandlerA = puiHandler;
1918 gUIFilter = dwMessageFilter;
1919 gUIContext = pvContext;
1921 return prev;
1924 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
1925 DWORD dwMessageFilter, LPVOID pvContext)
1927 INSTALLUI_HANDLERW prev = gUIHandlerW;
1929 TRACE("%p %x %p\n",puiHandler,dwMessageFilter,pvContext);
1930 gUIHandlerW = puiHandler;
1931 gUIFilter = dwMessageFilter;
1932 gUIContext = pvContext;
1934 return prev;
1937 /******************************************************************
1938 * MsiLoadStringW [MSI.@]
1940 * Loads a string from MSI's string resources.
1942 * PARAMS
1944 * handle [I] only -1 is handled currently
1945 * id [I] id of the string to be loaded
1946 * lpBuffer [O] buffer for the string to be written to
1947 * nBufferMax [I] maximum size of the buffer in characters
1948 * lang [I] the preferred language for the string
1950 * RETURNS
1952 * If successful, this function returns the language id of the string loaded
1953 * If the function fails, the function returns zero.
1955 * NOTES
1957 * The type of the first parameter is unknown. LoadString's prototype
1958 * suggests that it might be a module handle. I have made it an MSI handle
1959 * for starters, as -1 is an invalid MSI handle, but not an invalid module
1960 * handle. Maybe strings can be stored in an MSI database somehow.
1962 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
1963 int nBufferMax, LANGID lang )
1965 HRSRC hres;
1966 HGLOBAL hResData;
1967 LPWSTR p;
1968 DWORD i, len;
1970 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
1972 if( handle != -1 )
1973 FIXME("don't know how to deal with handle = %08x\n", handle);
1975 if( !lang )
1976 lang = GetUserDefaultLangID();
1978 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
1979 (LPWSTR)1, lang );
1980 if( !hres )
1981 return 0;
1982 hResData = LoadResource( msi_hInstance, hres );
1983 if( !hResData )
1984 return 0;
1985 p = LockResource( hResData );
1986 if( !p )
1987 return 0;
1989 for (i = 0; i < (id&0xf); i++)
1990 p += *p + 1;
1991 len = *p;
1993 if( nBufferMax <= len )
1994 return 0;
1996 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
1997 lpBuffer[ len ] = 0;
1999 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2001 return lang;
2004 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2005 int nBufferMax, LANGID lang )
2007 LPWSTR bufW;
2008 LANGID r;
2009 INT len;
2011 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2012 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2013 if( r )
2015 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2016 if( len <= nBufferMax )
2017 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2018 lpBuffer, nBufferMax, NULL, NULL );
2019 else
2020 r = 0;
2022 msi_free(bufW);
2023 return r;
2026 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2027 LPDWORD pcchBuf)
2029 char szProduct[GUID_SIZE];
2031 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2033 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2034 return INSTALLSTATE_UNKNOWN;
2036 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2039 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2040 LPDWORD pcchBuf)
2042 WCHAR szProduct[GUID_SIZE];
2044 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2046 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2047 return INSTALLSTATE_UNKNOWN;
2049 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2052 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2053 WORD wLanguageId, DWORD f)
2055 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2056 uType, wLanguageId, f);
2057 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2060 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2061 WORD wLanguageId, DWORD f)
2063 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2064 uType, wLanguageId, f);
2065 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2068 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2069 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2070 LPDWORD pcchPathBuf )
2072 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2073 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2074 pcchPathBuf);
2075 return ERROR_CALL_NOT_IMPLEMENTED;
2078 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2079 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2080 LPDWORD pcchPathBuf )
2082 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2083 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2084 pcchPathBuf);
2085 return ERROR_CALL_NOT_IMPLEMENTED;
2088 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2089 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2091 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2092 return ERROR_CALL_NOT_IMPLEMENTED;
2095 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2096 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2098 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2099 return ERROR_CALL_NOT_IMPLEMENTED;
2102 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
2103 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2104 LPDWORD pcbHashData)
2106 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
2107 ppcCertContext, pbHashData, pcbHashData);
2108 return ERROR_CALL_NOT_IMPLEMENTED;
2111 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
2112 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2113 LPDWORD pcbHashData)
2115 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
2116 ppcCertContext, pbHashData, pcbHashData);
2117 return ERROR_CALL_NOT_IMPLEMENTED;
2120 /******************************************************************
2121 * MsiGetProductPropertyA [MSI.@]
2123 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2124 LPSTR szValue, LPDWORD pccbValue)
2126 LPWSTR prop = NULL, val = NULL;
2127 DWORD len;
2128 UINT r;
2130 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2131 szValue, pccbValue);
2133 if (szValue && !pccbValue)
2134 return ERROR_INVALID_PARAMETER;
2136 if (szProperty) prop = strdupAtoW(szProperty);
2138 len = 0;
2139 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2140 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2141 goto done;
2143 if (r == ERROR_SUCCESS)
2145 if (szValue) *szValue = '\0';
2146 if (pccbValue) *pccbValue = 0;
2147 goto done;
2150 val = msi_alloc(++len * sizeof(WCHAR));
2151 if (!val)
2153 r = ERROR_OUTOFMEMORY;
2154 goto done;
2157 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2158 if (r != ERROR_SUCCESS)
2159 goto done;
2161 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2163 if (szValue)
2164 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2165 *pccbValue, NULL, NULL);
2167 if (pccbValue)
2169 if (len > *pccbValue)
2170 r = ERROR_MORE_DATA;
2172 *pccbValue = len - 1;
2175 done:
2176 msi_free(prop);
2177 msi_free(val);
2179 return r;
2182 /******************************************************************
2183 * MsiGetProductPropertyW [MSI.@]
2185 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2186 LPWSTR szValue, LPDWORD pccbValue)
2188 MSIPACKAGE *package;
2189 MSIQUERY *view = NULL;
2190 MSIRECORD *rec = NULL;
2191 LPCWSTR val;
2192 UINT r;
2194 static const WCHAR query[] = {
2195 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2196 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2197 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2199 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2200 szValue, pccbValue);
2202 if (!szProperty)
2203 return ERROR_INVALID_PARAMETER;
2205 if (szValue && !pccbValue)
2206 return ERROR_INVALID_PARAMETER;
2208 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2209 if (!package)
2210 return ERROR_INVALID_HANDLE;
2212 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2213 if (r != ERROR_SUCCESS)
2214 goto done;
2216 r = MSI_ViewExecute(view, 0);
2217 if (r != ERROR_SUCCESS)
2218 goto done;
2220 r = MSI_ViewFetch(view, &rec);
2221 if (r != ERROR_SUCCESS)
2222 goto done;
2224 val = MSI_RecordGetString(rec, 2);
2225 if (!val)
2226 goto done;
2228 if (lstrlenW(val) >= *pccbValue)
2230 lstrcpynW(szValue, val, *pccbValue);
2231 *pccbValue = lstrlenW(val);
2232 r = ERROR_MORE_DATA;
2234 else
2236 lstrcpyW(szValue, val);
2237 *pccbValue = lstrlenW(val);
2238 r = ERROR_SUCCESS;
2241 done:
2242 if (view)
2244 MSI_ViewClose(view);
2245 msiobj_release(&view->hdr);
2246 if (rec) msiobj_release(&rec->hdr);
2249 if (!rec)
2251 if (szValue) *szValue = '\0';
2252 if (pccbValue) *pccbValue = 0;
2253 r = ERROR_SUCCESS;
2256 return r;
2259 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2261 UINT r;
2262 LPWSTR szPack = NULL;
2264 TRACE("%s\n", debugstr_a(szPackage) );
2266 if( szPackage )
2268 szPack = strdupAtoW( szPackage );
2269 if( !szPack )
2270 return ERROR_OUTOFMEMORY;
2273 r = MsiVerifyPackageW( szPack );
2275 msi_free( szPack );
2277 return r;
2280 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2282 MSIHANDLE handle;
2283 UINT r;
2285 TRACE("%s\n", debugstr_w(szPackage) );
2287 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2288 MsiCloseHandle( handle );
2290 return r;
2293 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2294 awstring* lpPathBuf, LPDWORD pcchBuf)
2296 WCHAR squished_pc[GUID_SIZE];
2297 WCHAR squished_comp[GUID_SIZE];
2298 HKEY hkey;
2299 LPWSTR path = NULL;
2300 INSTALLSTATE state;
2301 DWORD version;
2303 static const WCHAR wininstaller[] = {
2304 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2306 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
2307 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
2309 if (!szProduct || !szComponent)
2310 return INSTALLSTATE_INVALIDARG;
2312 if (lpPathBuf->str.w && !pcchBuf)
2313 return INSTALLSTATE_INVALIDARG;
2315 if (!squash_guid(szProduct, squished_pc) ||
2316 !squash_guid(szComponent, squished_comp))
2317 return INSTALLSTATE_INVALIDARG;
2319 state = INSTALLSTATE_UNKNOWN;
2321 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2322 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2324 path = msi_reg_get_val_str(hkey, squished_pc);
2325 RegCloseKey(hkey);
2327 state = INSTALLSTATE_ABSENT;
2329 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2330 &hkey, FALSE) == ERROR_SUCCESS ||
2331 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2332 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2333 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2334 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2336 RegCloseKey(hkey);
2337 state = INSTALLSTATE_LOCAL;
2341 if (state != INSTALLSTATE_LOCAL &&
2342 (MSIREG_OpenProductKey(szProduct, NULL,
2343 MSIINSTALLCONTEXT_USERUNMANAGED,
2344 &hkey, FALSE) == ERROR_SUCCESS ||
2345 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2346 &hkey, FALSE) == ERROR_SUCCESS))
2348 RegCloseKey(hkey);
2350 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2351 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2353 msi_free(path);
2354 path = msi_reg_get_val_str(hkey, squished_pc);
2355 RegCloseKey(hkey);
2357 state = INSTALLSTATE_ABSENT;
2359 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2360 state = INSTALLSTATE_LOCAL;
2364 if (!path)
2365 return INSTALLSTATE_UNKNOWN;
2367 if (state == INSTALLSTATE_LOCAL && !*path)
2368 state = INSTALLSTATE_NOTUSED;
2370 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
2371 msi_free(path);
2372 return state;
2375 /******************************************************************
2376 * MsiGetComponentPathW [MSI.@]
2378 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2379 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2381 awstring path;
2383 path.unicode = TRUE;
2384 path.str.w = lpPathBuf;
2386 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2389 /******************************************************************
2390 * MsiGetComponentPathA [MSI.@]
2392 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2393 LPSTR lpPathBuf, LPDWORD pcchBuf)
2395 LPWSTR szwProduct, szwComponent = NULL;
2396 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2397 awstring path;
2399 szwProduct = strdupAtoW( szProduct );
2400 if( szProduct && !szwProduct)
2401 goto end;
2403 szwComponent = strdupAtoW( szComponent );
2404 if( szComponent && !szwComponent )
2405 goto end;
2407 path.unicode = FALSE;
2408 path.str.a = lpPathBuf;
2410 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2412 end:
2413 msi_free( szwProduct );
2414 msi_free( szwComponent );
2416 return r;
2419 /******************************************************************
2420 * MsiQueryFeatureStateA [MSI.@]
2422 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
2424 LPWSTR szwProduct = NULL, szwFeature= NULL;
2425 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
2427 szwProduct = strdupAtoW( szProduct );
2428 if ( szProduct && !szwProduct )
2429 goto end;
2431 szwFeature = strdupAtoW( szFeature );
2432 if ( szFeature && !szwFeature )
2433 goto end;
2435 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
2437 end:
2438 msi_free( szwProduct);
2439 msi_free( szwFeature);
2441 return rc;
2444 /******************************************************************
2445 * MsiQueryFeatureStateW [MSI.@]
2447 * Checks the state of a feature
2449 * PARAMS
2450 * szProduct [I] Product's GUID string
2451 * szFeature [I] Feature's GUID string
2453 * RETURNS
2454 * INSTALLSTATE_LOCAL Feature is installed and usable
2455 * INSTALLSTATE_ABSENT Feature is absent
2456 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2457 * INSTALLSTATE_UNKNOWN An error occurred
2458 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2461 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
2463 WCHAR squishProduct[33], comp[GUID_SIZE];
2464 GUID guid;
2465 LPWSTR components, p, parent_feature, path;
2466 UINT rc;
2467 HKEY hkey;
2468 INSTALLSTATE r;
2469 BOOL missing = FALSE;
2470 BOOL machine = FALSE;
2471 BOOL source = FALSE;
2473 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
2475 if (!szProduct || !szFeature)
2476 return INSTALLSTATE_INVALIDARG;
2478 if (!squash_guid( szProduct, squishProduct ))
2479 return INSTALLSTATE_INVALIDARG;
2481 if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2482 &hkey, FALSE) != ERROR_SUCCESS &&
2483 MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2484 &hkey, FALSE) != ERROR_SUCCESS)
2486 rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2487 &hkey, FALSE);
2488 if (rc != ERROR_SUCCESS)
2489 return INSTALLSTATE_UNKNOWN;
2491 machine = TRUE;
2494 parent_feature = msi_reg_get_val_str( hkey, szFeature );
2495 RegCloseKey(hkey);
2497 if (!parent_feature)
2498 return INSTALLSTATE_UNKNOWN;
2500 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2501 msi_free(parent_feature);
2502 if (r == INSTALLSTATE_ABSENT)
2503 return r;
2505 if (machine)
2506 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2507 MSIINSTALLCONTEXT_MACHINE,
2508 &hkey, FALSE);
2509 else
2510 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2511 MSIINSTALLCONTEXT_USERUNMANAGED,
2512 &hkey, FALSE);
2514 if (rc != ERROR_SUCCESS)
2515 return INSTALLSTATE_ADVERTISED;
2517 components = msi_reg_get_val_str( hkey, szFeature );
2518 RegCloseKey(hkey);
2520 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
2522 if (!components)
2523 return INSTALLSTATE_ADVERTISED;
2525 for( p = components; *p && *p != 2 ; p += 20)
2527 if (!decode_base85_guid( p, &guid ))
2529 if (p != components)
2530 break;
2532 msi_free(components);
2533 return INSTALLSTATE_BADCONFIG;
2536 StringFromGUID2(&guid, comp, GUID_SIZE);
2538 if (machine)
2539 rc = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2540 else
2541 rc = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2543 if (rc != ERROR_SUCCESS)
2545 msi_free(components);
2546 return INSTALLSTATE_ADVERTISED;
2549 path = msi_reg_get_val_str(hkey, squishProduct);
2550 if (!path)
2551 missing = TRUE;
2552 else if (lstrlenW(path) > 2 &&
2553 path[0] >= '0' && path[0] <= '9' &&
2554 path[1] >= '0' && path[1] <= '9')
2556 source = TRUE;
2559 msi_free(path);
2562 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
2563 msi_free(components);
2565 if (missing)
2566 return INSTALLSTATE_ADVERTISED;
2568 if (source)
2569 return INSTALLSTATE_SOURCE;
2571 return INSTALLSTATE_LOCAL;
2574 /******************************************************************
2575 * MsiGetFileVersionA [MSI.@]
2577 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
2578 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
2580 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
2581 UINT ret = ERROR_OUTOFMEMORY;
2583 if ((lpVersionBuf && !pcchVersionBuf) ||
2584 (lpLangBuf && !pcchLangBuf))
2585 return ERROR_INVALID_PARAMETER;
2587 if( szFilePath )
2589 szwFilePath = strdupAtoW( szFilePath );
2590 if( !szwFilePath )
2591 goto end;
2594 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
2596 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
2597 if( !lpwVersionBuff )
2598 goto end;
2601 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
2603 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
2604 if( !lpwLangBuff )
2605 goto end;
2608 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
2609 lpwLangBuff, pcchLangBuf);
2611 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
2612 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
2613 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
2614 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
2615 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
2616 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
2618 end:
2619 msi_free(szwFilePath);
2620 msi_free(lpwVersionBuff);
2621 msi_free(lpwLangBuff);
2623 return ret;
2626 /******************************************************************
2627 * MsiGetFileVersionW [MSI.@]
2629 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
2630 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
2632 static const WCHAR szVersionResource[] = {'\\',0};
2633 static const WCHAR szVersionFormat[] = {
2634 '%','d','.','%','d','.','%','d','.','%','d',0};
2635 static const WCHAR szLangResource[] = {
2636 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2637 'T','r','a','n','s','l','a','t','i','o','n',0};
2638 static const WCHAR szLangFormat[] = {'%','d',0};
2639 UINT ret = 0;
2640 DWORD dwVerLen, gle;
2641 LPVOID lpVer = NULL;
2642 VS_FIXEDFILEINFO *ffi;
2643 USHORT *lang;
2644 UINT puLen;
2645 WCHAR tmp[32];
2647 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
2648 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
2649 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
2651 if ((lpVersionBuf && !pcchVersionBuf) ||
2652 (lpLangBuf && !pcchLangBuf))
2653 return ERROR_INVALID_PARAMETER;
2655 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
2656 if( !dwVerLen )
2658 gle = GetLastError();
2659 if (gle == ERROR_BAD_PATHNAME)
2660 return ERROR_FILE_NOT_FOUND;
2661 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
2662 return ERROR_FILE_INVALID;
2664 return gle;
2667 lpVer = msi_alloc(dwVerLen);
2668 if( !lpVer )
2670 ret = ERROR_OUTOFMEMORY;
2671 goto end;
2674 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
2676 ret = GetLastError();
2677 goto end;
2680 if (pcchVersionBuf)
2682 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
2683 (puLen > 0) )
2685 wsprintfW(tmp, szVersionFormat,
2686 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
2687 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
2688 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
2690 if (strlenW(tmp) >= *pcchVersionBuf)
2691 ret = ERROR_MORE_DATA;
2693 *pcchVersionBuf = lstrlenW(tmp);
2695 else
2697 if (lpVersionBuf) *lpVersionBuf = 0;
2698 *pcchVersionBuf = 0;
2702 if (pcchLangBuf)
2704 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
2705 (puLen > 0))
2707 wsprintfW(tmp, szLangFormat, *lang);
2708 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
2710 if (strlenW(tmp) >= *pcchLangBuf)
2711 ret = ERROR_MORE_DATA;
2713 *pcchLangBuf = lstrlenW(tmp);
2715 else
2717 if (lpLangBuf) *lpLangBuf = 0;
2718 *pcchLangBuf = 0;
2722 end:
2723 msi_free(lpVer);
2724 return ret;
2727 /***********************************************************************
2728 * MsiGetFeatureUsageW [MSI.@]
2730 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
2731 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2733 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
2734 pdwUseCount, pwDateUsed);
2735 return ERROR_CALL_NOT_IMPLEMENTED;
2738 /***********************************************************************
2739 * MsiGetFeatureUsageA [MSI.@]
2741 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
2742 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2744 LPWSTR prod = NULL, feat = NULL;
2745 UINT ret = ERROR_OUTOFMEMORY;
2747 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
2748 pdwUseCount, pwDateUsed);
2750 prod = strdupAtoW( szProduct );
2751 if (szProduct && !prod)
2752 goto end;
2754 feat = strdupAtoW( szFeature );
2755 if (szFeature && !feat)
2756 goto end;
2758 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
2760 end:
2761 msi_free( prod );
2762 msi_free( feat );
2764 return ret;
2767 /***********************************************************************
2768 * MsiUseFeatureExW [MSI.@]
2770 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
2771 DWORD dwInstallMode, DWORD dwReserved )
2773 INSTALLSTATE state;
2775 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2776 dwInstallMode, dwReserved);
2778 state = MsiQueryFeatureStateW( szProduct, szFeature );
2780 if (dwReserved)
2781 return INSTALLSTATE_INVALIDARG;
2783 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
2785 FIXME("mark product %s feature %s as used\n",
2786 debugstr_w(szProduct), debugstr_w(szFeature) );
2789 return state;
2792 /***********************************************************************
2793 * MsiUseFeatureExA [MSI.@]
2795 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
2796 DWORD dwInstallMode, DWORD dwReserved )
2798 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
2799 LPWSTR prod = NULL, feat = NULL;
2801 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2802 dwInstallMode, dwReserved);
2804 prod = strdupAtoW( szProduct );
2805 if (szProduct && !prod)
2806 goto end;
2808 feat = strdupAtoW( szFeature );
2809 if (szFeature && !feat)
2810 goto end;
2812 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
2814 end:
2815 msi_free( prod );
2816 msi_free( feat );
2818 return ret;
2821 /***********************************************************************
2822 * MsiUseFeatureW [MSI.@]
2824 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
2826 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
2829 /***********************************************************************
2830 * MsiUseFeatureA [MSI.@]
2832 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
2834 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
2837 /***********************************************************************
2838 * MSI_ProvideQualifiedComponentEx [internal]
2840 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
2841 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2842 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
2843 LPDWORD pcchPathBuf)
2845 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
2846 feature[MAX_FEATURE_CHARS+1];
2847 LPWSTR info;
2848 HKEY hkey;
2849 DWORD sz;
2850 UINT rc;
2852 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
2853 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
2854 Unused1, Unused2, lpPathBuf, pcchPathBuf);
2856 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
2857 if (rc != ERROR_SUCCESS)
2858 return ERROR_INDEX_ABSENT;
2860 info = msi_reg_get_val_str( hkey, szQualifier );
2861 RegCloseKey(hkey);
2863 if (!info)
2864 return ERROR_INDEX_ABSENT;
2866 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
2868 if (!szProduct)
2869 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
2870 else
2871 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
2873 msi_free( info );
2875 if (rc != INSTALLSTATE_LOCAL)
2876 return ERROR_FILE_NOT_FOUND;
2878 return ERROR_SUCCESS;
2881 /***********************************************************************
2882 * MsiProvideQualifiedComponentExW [MSI.@]
2884 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
2885 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2886 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
2887 LPDWORD pcchPathBuf)
2889 awstring path;
2891 path.unicode = TRUE;
2892 path.str.w = lpPathBuf;
2894 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
2895 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
2898 /***********************************************************************
2899 * MsiProvideQualifiedComponentExA [MSI.@]
2901 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
2902 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
2903 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
2904 LPDWORD pcchPathBuf)
2906 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
2907 UINT r = ERROR_OUTOFMEMORY;
2908 awstring path;
2910 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
2911 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
2912 Unused1, Unused2, lpPathBuf, pcchPathBuf);
2914 szwComponent = strdupAtoW( szComponent );
2915 if (szComponent && !szwComponent)
2916 goto end;
2918 szwQualifier = strdupAtoW( szQualifier );
2919 if (szQualifier && !szwQualifier)
2920 goto end;
2922 szwProduct = strdupAtoW( szProduct );
2923 if (szProduct && !szwProduct)
2924 goto end;
2926 path.unicode = FALSE;
2927 path.str.a = lpPathBuf;
2929 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
2930 dwInstallMode, szwProduct, Unused1,
2931 Unused2, &path, pcchPathBuf);
2932 end:
2933 msi_free(szwProduct);
2934 msi_free(szwComponent);
2935 msi_free(szwQualifier);
2937 return r;
2940 /***********************************************************************
2941 * MsiProvideQualifiedComponentW [MSI.@]
2943 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
2944 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
2945 LPDWORD pcchPathBuf)
2947 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
2948 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
2951 /***********************************************************************
2952 * MsiProvideQualifiedComponentA [MSI.@]
2954 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
2955 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
2956 LPDWORD pcchPathBuf)
2958 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
2959 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
2962 /***********************************************************************
2963 * MSI_GetUserInfo [internal]
2965 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
2966 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
2967 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2968 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
2970 WCHAR squished_pc[SQUISH_GUID_SIZE];
2971 LPWSTR user, org, serial;
2972 USERINFOSTATE state;
2973 HKEY hkey, props;
2974 LPCWSTR orgptr;
2975 UINT r;
2977 static const WCHAR szEmpty[] = {0};
2979 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
2980 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
2981 pcchSerialBuf);
2983 if (!szProduct || !squash_guid(szProduct, squished_pc))
2984 return USERINFOSTATE_INVALIDARG;
2986 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2987 &hkey, FALSE) != ERROR_SUCCESS &&
2988 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2989 &hkey, FALSE) != ERROR_SUCCESS &&
2990 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2991 &hkey, FALSE) != ERROR_SUCCESS)
2993 return USERINFOSTATE_UNKNOWN;
2996 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2997 NULL, &props, FALSE) != ERROR_SUCCESS &&
2998 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
2999 NULL, &props, FALSE) != ERROR_SUCCESS)
3001 RegCloseKey(hkey);
3002 return USERINFOSTATE_ABSENT;
3005 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3006 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3007 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3008 state = USERINFOSTATE_ABSENT;
3010 RegCloseKey(hkey);
3011 RegCloseKey(props);
3013 if (user && serial)
3014 state = USERINFOSTATE_PRESENT;
3016 if (pcchUserNameBuf)
3018 if (lpUserNameBuf && !user)
3020 (*pcchUserNameBuf)--;
3021 goto done;
3024 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
3025 if (r == ERROR_MORE_DATA)
3027 state = USERINFOSTATE_MOREDATA;
3028 goto done;
3032 if (pcchOrgNameBuf)
3034 orgptr = org;
3035 if (!orgptr) orgptr = szEmpty;
3037 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
3038 if (r == ERROR_MORE_DATA)
3040 state = USERINFOSTATE_MOREDATA;
3041 goto done;
3045 if (pcchSerialBuf)
3047 if (!serial)
3049 (*pcchSerialBuf)--;
3050 goto done;
3053 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
3054 if (r == ERROR_MORE_DATA)
3055 state = USERINFOSTATE_MOREDATA;
3058 done:
3059 msi_free(user);
3060 msi_free(org);
3061 msi_free(serial);
3063 return state;
3066 /***********************************************************************
3067 * MsiGetUserInfoW [MSI.@]
3069 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3070 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3071 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3072 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3074 awstring user, org, serial;
3076 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3077 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3078 (lpSerialBuf && !pcchSerialBuf))
3079 return USERINFOSTATE_INVALIDARG;
3081 user.unicode = TRUE;
3082 user.str.w = lpUserNameBuf;
3083 org.unicode = TRUE;
3084 org.str.w = lpOrgNameBuf;
3085 serial.unicode = TRUE;
3086 serial.str.w = lpSerialBuf;
3088 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3089 &org, pcchOrgNameBuf,
3090 &serial, pcchSerialBuf );
3093 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3094 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3095 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3096 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3098 awstring user, org, serial;
3099 LPWSTR prod;
3100 UINT r;
3102 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3103 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3104 (lpSerialBuf && !pcchSerialBuf))
3105 return USERINFOSTATE_INVALIDARG;
3107 prod = strdupAtoW( szProduct );
3108 if (szProduct && !prod)
3109 return ERROR_OUTOFMEMORY;
3111 user.unicode = FALSE;
3112 user.str.a = lpUserNameBuf;
3113 org.unicode = FALSE;
3114 org.str.a = lpOrgNameBuf;
3115 serial.unicode = FALSE;
3116 serial.str.a = lpSerialBuf;
3118 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3119 &org, pcchOrgNameBuf,
3120 &serial, pcchSerialBuf );
3122 msi_free( prod );
3124 return r;
3127 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3129 MSIHANDLE handle;
3130 UINT rc;
3131 MSIPACKAGE *package;
3132 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3134 TRACE("(%s)\n",debugstr_w(szProduct));
3136 rc = MsiOpenProductW(szProduct,&handle);
3137 if (rc != ERROR_SUCCESS)
3138 return ERROR_INVALID_PARAMETER;
3140 /* MsiCollectUserInfo cannot be called from a custom action. */
3141 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3142 if (!package)
3143 return ERROR_CALL_NOT_IMPLEMENTED;
3145 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3146 msiobj_release( &package->hdr );
3148 MsiCloseHandle(handle);
3150 return rc;
3153 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3155 MSIHANDLE handle;
3156 UINT rc;
3157 MSIPACKAGE *package;
3158 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3160 TRACE("(%s)\n",debugstr_a(szProduct));
3162 rc = MsiOpenProductA(szProduct,&handle);
3163 if (rc != ERROR_SUCCESS)
3164 return ERROR_INVALID_PARAMETER;
3166 /* MsiCollectUserInfo cannot be called from a custom action. */
3167 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3168 if (!package)
3169 return ERROR_CALL_NOT_IMPLEMENTED;
3171 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3172 msiobj_release( &package->hdr );
3174 MsiCloseHandle(handle);
3176 return rc;
3179 /***********************************************************************
3180 * MsiConfigureFeatureA [MSI.@]
3182 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3184 LPWSTR prod, feat = NULL;
3185 UINT r = ERROR_OUTOFMEMORY;
3187 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3189 prod = strdupAtoW( szProduct );
3190 if (szProduct && !prod)
3191 goto end;
3193 feat = strdupAtoW( szFeature );
3194 if (szFeature && !feat)
3195 goto end;
3197 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3199 end:
3200 msi_free(feat);
3201 msi_free(prod);
3203 return r;
3206 /***********************************************************************
3207 * MsiConfigureFeatureW [MSI.@]
3209 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3211 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3212 MSIPACKAGE *package = NULL;
3213 UINT r;
3214 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3215 DWORD sz;
3217 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3219 if (!szProduct || !szFeature)
3220 return ERROR_INVALID_PARAMETER;
3222 switch (eInstallState)
3224 case INSTALLSTATE_DEFAULT:
3225 /* FIXME: how do we figure out the default location? */
3226 eInstallState = INSTALLSTATE_LOCAL;
3227 break;
3228 case INSTALLSTATE_LOCAL:
3229 case INSTALLSTATE_SOURCE:
3230 case INSTALLSTATE_ABSENT:
3231 case INSTALLSTATE_ADVERTISED:
3232 break;
3233 default:
3234 return ERROR_INVALID_PARAMETER;
3237 r = MSI_OpenProductW( szProduct, &package );
3238 if (r != ERROR_SUCCESS)
3239 return r;
3241 sz = sizeof(sourcepath);
3242 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3243 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3245 sz = sizeof(filename);
3246 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3247 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3249 lstrcatW( sourcepath, filename );
3251 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3253 r = ACTION_PerformUIAction( package, szCostInit, -1 );
3254 if (r != ERROR_SUCCESS)
3255 goto end;
3257 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3258 if (r != ERROR_SUCCESS)
3259 goto end;
3261 r = MSI_InstallPackage( package, sourcepath, NULL );
3263 end:
3264 msiobj_release( &package->hdr );
3266 return r;
3269 /***********************************************************************
3270 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3272 * Notes: undocumented
3274 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3276 WCHAR path[MAX_PATH];
3278 TRACE("%d\n", dwReserved);
3280 if (dwReserved)
3282 FIXME("dwReserved=%d\n", dwReserved);
3283 return ERROR_INVALID_PARAMETER;
3286 if (!GetWindowsDirectoryW(path, MAX_PATH))
3287 return ERROR_FUNCTION_FAILED;
3289 lstrcatW(path, installerW);
3291 if (!CreateDirectoryW(path, NULL))
3292 return ERROR_FUNCTION_FAILED;
3294 return ERROR_SUCCESS;
3297 /***********************************************************************
3298 * MsiGetShortcutTargetA [MSI.@]
3300 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3301 LPSTR szProductCode, LPSTR szFeatureId,
3302 LPSTR szComponentCode )
3304 LPWSTR target;
3305 const int len = MAX_FEATURE_CHARS+1;
3306 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3307 UINT r;
3309 target = strdupAtoW( szShortcutTarget );
3310 if (szShortcutTarget && !target )
3311 return ERROR_OUTOFMEMORY;
3312 product[0] = 0;
3313 feature[0] = 0;
3314 component[0] = 0;
3315 r = MsiGetShortcutTargetW( target, product, feature, component );
3316 msi_free( target );
3317 if (r == ERROR_SUCCESS)
3319 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3320 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3321 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3323 return r;
3326 /***********************************************************************
3327 * MsiGetShortcutTargetW [MSI.@]
3329 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3330 LPWSTR szProductCode, LPWSTR szFeatureId,
3331 LPWSTR szComponentCode )
3333 IShellLinkDataList *dl = NULL;
3334 IPersistFile *pf = NULL;
3335 LPEXP_DARWIN_LINK darwin = NULL;
3336 HRESULT r, init;
3338 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3339 szProductCode, szFeatureId, szComponentCode );
3341 init = CoInitialize(NULL);
3343 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3344 &IID_IPersistFile, (LPVOID*) &pf );
3345 if( SUCCEEDED( r ) )
3347 r = IPersistFile_Load( pf, szShortcutTarget,
3348 STGM_READ | STGM_SHARE_DENY_WRITE );
3349 if( SUCCEEDED( r ) )
3351 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3352 (LPVOID*) &dl );
3353 if( SUCCEEDED( r ) )
3355 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3356 (LPVOID) &darwin );
3357 IShellLinkDataList_Release( dl );
3360 IPersistFile_Release( pf );
3363 if (SUCCEEDED(init))
3364 CoUninitialize();
3366 TRACE("darwin = %p\n", darwin);
3368 if (darwin)
3370 DWORD sz;
3371 UINT ret;
3373 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3374 szProductCode, szFeatureId, szComponentCode, &sz );
3375 LocalFree( darwin );
3376 return ret;
3379 return ERROR_FUNCTION_FAILED;
3382 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
3383 DWORD dwReinstallMode )
3385 MSIPACKAGE* package = NULL;
3386 UINT r;
3387 WCHAR sourcepath[MAX_PATH];
3388 WCHAR filename[MAX_PATH];
3389 static const WCHAR szLogVerbose[] = {
3390 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3391 static const WCHAR szInstalled[] = { 'I','n','s','t','a','l','l','e','d',0};
3392 static const WCHAR szReinstall[] = {'R','E','I','N','S','T','A','L','L',0};
3393 static const WCHAR szReinstallMode[] = {'R','E','I','N','S','T','A','L','L','M','O','D','E',0};
3394 static const WCHAR szOne[] = {'1',0};
3395 WCHAR reinstallmode[11];
3396 LPWSTR ptr;
3397 DWORD sz;
3399 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3400 dwReinstallMode);
3402 ptr = reinstallmode;
3404 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3405 *ptr++ = 'p';
3406 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3407 *ptr++ = 'o';
3408 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3409 *ptr++ = 'w';
3410 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3411 *ptr++ = 'd';
3412 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3413 *ptr++ = 'c';
3414 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3415 *ptr++ = 'a';
3416 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3417 *ptr++ = 'u';
3418 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3419 *ptr++ = 'm';
3420 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3421 *ptr++ = 's';
3422 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3423 *ptr++ = 'v';
3424 *ptr = 0;
3426 sz = sizeof(sourcepath);
3427 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3428 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3430 sz = sizeof(filename);
3431 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3432 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3434 lstrcatW( sourcepath, filename );
3436 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3437 r = MSI_OpenPackageW( sourcepath, &package );
3438 else
3439 r = MSI_OpenProductW( szProduct, &package );
3441 if (r != ERROR_SUCCESS)
3442 return r;
3444 MSI_SetPropertyW( package, szReinstallMode, reinstallmode );
3445 MSI_SetPropertyW( package, szInstalled, szOne );
3446 MSI_SetPropertyW( package, szLogVerbose, szOne );
3447 MSI_SetPropertyW( package, szReinstall, szFeature );
3449 r = MSI_InstallPackage( package, sourcepath, NULL );
3451 msiobj_release( &package->hdr );
3453 return r;
3456 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3457 DWORD dwReinstallMode )
3459 LPWSTR wszProduct;
3460 LPWSTR wszFeature;
3461 UINT rc;
3463 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3464 dwReinstallMode);
3466 wszProduct = strdupAtoW(szProduct);
3467 wszFeature = strdupAtoW(szFeature);
3469 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3471 msi_free(wszProduct);
3472 msi_free(wszFeature);
3473 return rc;
3476 typedef struct
3478 unsigned int i[2];
3479 unsigned int buf[4];
3480 unsigned char in[64];
3481 unsigned char digest[16];
3482 } MD5_CTX;
3484 extern VOID WINAPI MD5Init( MD5_CTX *);
3485 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
3486 extern VOID WINAPI MD5Final( MD5_CTX *);
3488 /***********************************************************************
3489 * MsiGetFileHashW [MSI.@]
3491 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
3492 PMSIFILEHASHINFO pHash )
3494 HANDLE handle, mapping;
3495 void *p;
3496 DWORD length;
3497 UINT r = ERROR_FUNCTION_FAILED;
3499 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
3501 if (!szFilePath)
3502 return ERROR_INVALID_PARAMETER;
3504 if (!*szFilePath)
3505 return ERROR_PATH_NOT_FOUND;
3507 if (dwOptions)
3508 return ERROR_INVALID_PARAMETER;
3509 if (!pHash)
3510 return ERROR_INVALID_PARAMETER;
3511 if (pHash->dwFileHashInfoSize < sizeof *pHash)
3512 return ERROR_INVALID_PARAMETER;
3514 handle = CreateFileW( szFilePath, GENERIC_READ,
3515 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
3516 if (handle == INVALID_HANDLE_VALUE)
3517 return ERROR_FILE_NOT_FOUND;
3519 length = GetFileSize( handle, NULL );
3521 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
3522 if (mapping)
3524 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
3525 if (p)
3527 MD5_CTX ctx;
3529 MD5Init( &ctx );
3530 MD5Update( &ctx, p, length );
3531 MD5Final( &ctx );
3532 UnmapViewOfFile( p );
3534 memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
3535 r = ERROR_SUCCESS;
3537 CloseHandle( mapping );
3539 CloseHandle( handle );
3541 return r;
3544 /***********************************************************************
3545 * MsiGetFileHashA [MSI.@]
3547 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
3548 PMSIFILEHASHINFO pHash )
3550 LPWSTR file;
3551 UINT r;
3553 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
3555 file = strdupAtoW( szFilePath );
3556 if (szFilePath && !file)
3557 return ERROR_OUTOFMEMORY;
3559 r = MsiGetFileHashW( file, dwOptions, pHash );
3560 msi_free( file );
3561 return r;
3564 /***********************************************************************
3565 * MsiAdvertiseScriptW [MSI.@]
3567 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
3568 PHKEY phRegData, BOOL fRemoveItems )
3570 FIXME("%s %08x %p %d\n",
3571 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3572 return ERROR_CALL_NOT_IMPLEMENTED;
3575 /***********************************************************************
3576 * MsiAdvertiseScriptA [MSI.@]
3578 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
3579 PHKEY phRegData, BOOL fRemoveItems )
3581 FIXME("%s %08x %p %d\n",
3582 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3583 return ERROR_CALL_NOT_IMPLEMENTED;
3586 /***********************************************************************
3587 * MsiIsProductElevatedW [MSI.@]
3589 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
3591 FIXME("%s %p - stub\n",
3592 debugstr_w( szProduct ), pfElevated );
3593 *pfElevated = TRUE;
3594 return ERROR_SUCCESS;
3597 /***********************************************************************
3598 * MsiIsProductElevatedA [MSI.@]
3600 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
3602 FIXME("%s %p - stub\n",
3603 debugstr_a( szProduct ), pfElevated );
3604 *pfElevated = TRUE;
3605 return ERROR_SUCCESS;
3608 /***********************************************************************
3609 * MsiSetExternalUIRecord [MSI.@]
3611 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD puiHandler,
3612 DWORD dwMessageFilter, LPVOID pvContext,
3613 PINSTALLUI_HANDLER_RECORD ppuiPrevHandler)
3615 FIXME("%p %08x %p %p\n", puiHandler, dwMessageFilter ,pvContext,
3616 ppuiPrevHandler);
3617 return ERROR_CALL_NOT_IMPLEMENTED;
3620 /***********************************************************************
3621 * MsiInstallMissingComponentW [MSI.@]
3623 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
3625 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
3626 return ERROR_SUCCESS;