msi: Implement MsiApplyMultiplePatchesA/W.
[wine/multimedia.git] / dlls / msi / msi.c
blob43436bd757d6dc4c49e9814bc0450ec43b76ab00
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, info;
307 UINT r, 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 (!szProductCode)
320 r = MsiOpenDatabaseW(szPatchPackage, MSIDBOPEN_READONLY, &patch);
321 if (r != ERROR_SUCCESS)
322 return r;
324 r = MsiGetSummaryInformationW(patch, NULL, 0, &info);
325 if (r != ERROR_SUCCESS)
326 goto done;
328 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, empty, &size);
329 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
331 ERR("Failed to read product codes from patch\n");
332 goto done;
335 codes = msi_alloc(++size * sizeof(WCHAR));
336 if (!codes)
338 r = ERROR_OUTOFMEMORY;
339 goto done;
342 r = MsiSummaryInfoGetPropertyW(info, PID_TEMPLATE, &type, NULL, NULL, codes, &size);
343 if (r != ERROR_SUCCESS)
344 goto done;
346 product_code = codes;
349 if (!szCommandLine)
350 cmd_ptr = empty;
352 size = lstrlenW(cmd_ptr) + lstrlenW(patcheq) + lstrlenW(szPatchPackage) + 1;
353 cmd = msi_alloc(size * sizeof(WCHAR));
354 if (!cmd)
356 r = ERROR_OUTOFMEMORY;
357 goto done;
360 lstrcpyW(cmd, cmd_ptr);
361 if (szCommandLine) lstrcatW(cmd, space);
362 lstrcatW(cmd, patcheq);
363 lstrcatW(cmd, szPatchPackage);
365 beg = codes;
366 while ((end = strchrW(beg, '}')))
368 *(end + 1) = '\0';
370 r = MsiConfigureProductExW(beg, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
371 if (r != ERROR_SUCCESS)
372 goto done;
374 beg = end + 2;
377 done:
378 msi_free(cmd);
379 msi_free(codes);
381 MsiCloseHandle(info);
382 MsiCloseHandle(patch);
384 return r;
387 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
388 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
390 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
391 eInstallType, debugstr_w(szCommandLine));
393 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
394 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
396 FIXME("Only reading target products from patch\n");
397 return ERROR_CALL_NOT_IMPLEMENTED;
400 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
403 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
404 LPCSTR szProductCode, LPCSTR szPropertiesList)
406 LPWSTR patch_packages = NULL;
407 LPWSTR product_code = NULL;
408 LPWSTR properties_list = NULL;
409 UINT r = ERROR_OUTOFMEMORY;
411 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
412 debugstr_a(szPropertiesList));
414 if (!szPatchPackages || !szPatchPackages[0])
415 return ERROR_INVALID_PARAMETER;
417 if (!(patch_packages = strdupAtoW(szPatchPackages)))
418 return ERROR_OUTOFMEMORY;
420 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
421 goto done;
423 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
424 goto done;
426 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
428 done:
429 msi_free(patch_packages);
430 msi_free(product_code);
431 msi_free(properties_list);
433 return r;
436 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
437 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
439 UINT r = ERROR_SUCCESS;
440 LPCWSTR beg, end;
442 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
443 debugstr_w(szPropertiesList));
445 if (!szPatchPackages || !szPatchPackages[0])
446 return ERROR_INVALID_PARAMETER;
448 beg = end = szPatchPackages;
449 while (*beg)
451 DWORD len;
452 LPWSTR patch;
454 while (*beg == ' ') beg++;
455 while (*end && *end != ';') end++;
457 len = end - beg;
458 while (len && beg[len - 1] == ' ') len--;
460 if (!len) return ERROR_INVALID_NAME;
462 patch = msi_alloc((len + 1) * sizeof(WCHAR));
463 if (!patch)
464 return ERROR_OUTOFMEMORY;
466 memcpy(patch, beg, len * sizeof(WCHAR));
467 patch[len] = '\0';
469 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
470 msi_free(patch);
472 if (r != ERROR_SUCCESS)
473 break;
475 beg = ++end;
477 return r;
480 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
481 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
483 FIXME("(%s, %d, %p): stub!\n", debugstr_a(szProductPackagePath),
484 cPatchInfo, pPatchInfo);
486 return ERROR_CALL_NOT_IMPLEMENTED;
489 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
490 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
492 FIXME("(%s, %d, %p): stub!\n", debugstr_w(szProductPackagePath),
493 cPatchInfo, pPatchInfo);
495 return ERROR_CALL_NOT_IMPLEMENTED;
498 UINT WINAPI MsiDeterminePatchSequenceA(LPCSTR szProductCode, LPCSTR szUserSid,
499 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
501 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode),
502 debugstr_a(szUserSid), dwContext, cPatchInfo, pPatchInfo);
504 return ERROR_CALL_NOT_IMPLEMENTED;
507 UINT WINAPI MsiDeterminePatchSequenceW(LPCWSTR szProductCode, LPCWSTR szUserSid,
508 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
510 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode),
511 debugstr_w(szUserSid), dwContext, cPatchInfo, pPatchInfo);
513 return ERROR_CALL_NOT_IMPLEMENTED;
516 static UINT msi_open_package(LPCWSTR product, MSIINSTALLCONTEXT context,
517 MSIPACKAGE **package)
519 UINT r;
520 DWORD sz;
521 HKEY props;
522 LPWSTR localpack;
523 WCHAR sourcepath[MAX_PATH];
524 WCHAR filename[MAX_PATH];
526 static const WCHAR szLocalPackage[] = {
527 'L','o','c','a','l','P','a','c','k','a','g','e',0};
530 r = MSIREG_OpenInstallProps(product, context, NULL, &props, FALSE);
531 if (r != ERROR_SUCCESS)
532 return ERROR_BAD_CONFIGURATION;
534 localpack = msi_reg_get_val_str(props, szLocalPackage);
535 if (localpack)
537 lstrcpyW(sourcepath, localpack);
538 msi_free(localpack);
541 if (!localpack || GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
543 sz = sizeof(sourcepath);
544 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
545 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
547 sz = sizeof(filename);
548 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
549 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
551 lstrcatW(sourcepath, filename);
554 if (GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
555 return ERROR_INSTALL_SOURCE_ABSENT;
557 return MSI_OpenPackageW(sourcepath, package);
560 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
561 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
563 MSIPACKAGE* package = NULL;
564 MSIINSTALLCONTEXT context;
565 UINT r;
566 DWORD sz;
567 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
568 LPWSTR commandline;
570 static const WCHAR szInstalled[] = {
571 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
572 static const WCHAR szRemoveAll[] = {
573 ' ','R','E','M','O','V','E','=','A','L','L',0};
574 static const WCHAR szMachine[] = {
575 ' ','A','L','L','U','S','E','R','S','=','1',0};
577 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
578 debugstr_w(szCommandLine));
580 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
581 return ERROR_INVALID_PARAMETER;
583 if (eInstallState == INSTALLSTATE_ADVERTISED ||
584 eInstallState == INSTALLSTATE_SOURCE)
586 FIXME("State %d not implemented\n", eInstallState);
587 return ERROR_CALL_NOT_IMPLEMENTED;
590 r = msi_locate_product(szProduct, &context);
591 if (r != ERROR_SUCCESS)
592 return r;
594 r = msi_open_package(szProduct, context, &package);
595 if (r != ERROR_SUCCESS)
596 return r;
598 sz = lstrlenW(szInstalled) + 1;
600 if (szCommandLine)
601 sz += lstrlenW(szCommandLine);
603 if (eInstallState == INSTALLSTATE_ABSENT)
604 sz += lstrlenW(szRemoveAll);
606 if (context == MSIINSTALLCONTEXT_MACHINE)
607 sz += lstrlenW(szMachine);
609 commandline = msi_alloc(sz * sizeof(WCHAR));
610 if (!commandline)
612 r = ERROR_OUTOFMEMORY;
613 goto end;
616 commandline[0] = 0;
617 if (szCommandLine)
618 lstrcpyW(commandline,szCommandLine);
620 if (MsiQueryProductStateW(szProduct) != INSTALLSTATE_UNKNOWN)
621 lstrcatW(commandline,szInstalled);
623 if (eInstallState == INSTALLSTATE_ABSENT)
624 lstrcatW(commandline, szRemoveAll);
626 if (context == MSIINSTALLCONTEXT_MACHINE)
627 lstrcatW(commandline, szMachine);
629 sz = sizeof(sourcepath);
630 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
631 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
633 sz = sizeof(filename);
634 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
635 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
637 strcatW(sourcepath, filename);
639 r = MSI_InstallPackage( package, sourcepath, commandline );
641 msi_free(commandline);
643 end:
644 msiobj_release( &package->hdr );
646 return r;
649 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
650 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
652 LPWSTR szwProduct = NULL;
653 LPWSTR szwCommandLine = NULL;
654 UINT r = ERROR_OUTOFMEMORY;
656 if( szProduct )
658 szwProduct = strdupAtoW( szProduct );
659 if( !szwProduct )
660 goto end;
663 if( szCommandLine)
665 szwCommandLine = strdupAtoW( szCommandLine );
666 if( !szwCommandLine)
667 goto end;
670 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
671 szwCommandLine );
672 end:
673 msi_free( szwProduct );
674 msi_free( szwCommandLine);
676 return r;
679 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
680 INSTALLSTATE eInstallState)
682 LPWSTR szwProduct = NULL;
683 UINT r;
685 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
687 if( szProduct )
689 szwProduct = strdupAtoW( szProduct );
690 if( !szwProduct )
691 return ERROR_OUTOFMEMORY;
694 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
695 msi_free( szwProduct );
697 return r;
700 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
701 INSTALLSTATE eInstallState)
703 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
706 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
708 LPWSTR szwComponent = NULL;
709 UINT r;
710 WCHAR szwBuffer[GUID_SIZE];
712 TRACE("%s %s\n",debugstr_a(szComponent), debugstr_a(szBuffer));
714 if( szComponent )
716 szwComponent = strdupAtoW( szComponent );
717 if( !szwComponent )
718 return ERROR_OUTOFMEMORY;
721 *szwBuffer = '\0';
722 r = MsiGetProductCodeW( szwComponent, szwBuffer );
724 if(*szwBuffer)
725 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
727 msi_free( szwComponent );
729 return r;
732 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
734 UINT rc, index;
735 HKEY compkey, prodkey;
736 WCHAR squished_comp[GUID_SIZE];
737 WCHAR squished_prod[GUID_SIZE];
738 DWORD sz = GUID_SIZE;
740 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
742 if (!szComponent || !*szComponent)
743 return ERROR_INVALID_PARAMETER;
745 if (!squash_guid(szComponent, squished_comp))
746 return ERROR_INVALID_PARAMETER;
748 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
749 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
751 return ERROR_UNKNOWN_COMPONENT;
754 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
755 if (rc != ERROR_SUCCESS)
757 RegCloseKey(compkey);
758 return ERROR_UNKNOWN_COMPONENT;
761 /* check simple case, only one product */
762 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
763 if (rc == ERROR_NO_MORE_ITEMS)
765 rc = ERROR_SUCCESS;
766 goto done;
769 index = 0;
770 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
771 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
773 index++;
774 sz = GUID_SIZE;
775 unsquash_guid(squished_prod, szBuffer);
777 if (MSIREG_OpenProductKey(szBuffer, NULL,
778 MSIINSTALLCONTEXT_USERMANAGED,
779 &prodkey, FALSE) == ERROR_SUCCESS ||
780 MSIREG_OpenProductKey(szBuffer, NULL,
781 MSIINSTALLCONTEXT_USERUNMANAGED,
782 &prodkey, FALSE) == ERROR_SUCCESS ||
783 MSIREG_OpenProductKey(szBuffer, NULL,
784 MSIINSTALLCONTEXT_MACHINE,
785 &prodkey, FALSE) == ERROR_SUCCESS)
787 RegCloseKey(prodkey);
788 rc = ERROR_SUCCESS;
789 goto done;
793 rc = ERROR_INSTALL_FAILURE;
795 done:
796 RegCloseKey(compkey);
797 unsquash_guid(squished_prod, szBuffer);
798 return rc;
801 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
803 DWORD dval;
804 LONG res;
805 WCHAR temp[20];
807 static const WCHAR format[] = {'%','d',0};
809 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
810 if (res != ERROR_SUCCESS)
811 return NULL;
813 if (*type == REG_SZ)
814 return msi_reg_get_val_str(hkey, name);
816 if (!msi_reg_get_val_dword(hkey, name, &dval))
817 return NULL;
819 sprintfW(temp, format, dval);
820 return strdupW(temp);
823 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
824 awstring *szValue, LPDWORD pcchValueBuf)
826 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
827 UINT r = ERROR_UNKNOWN_PROPERTY;
828 HKEY prodkey, userdata, source;
829 LPWSTR val = NULL;
830 WCHAR squished_pc[GUID_SIZE];
831 WCHAR packagecode[GUID_SIZE];
832 BOOL badconfig = FALSE;
833 LONG res;
834 DWORD save, type = REG_NONE;
836 static WCHAR empty[] = {0};
837 static const WCHAR sourcelist[] = {
838 'S','o','u','r','c','e','L','i','s','t',0};
839 static const WCHAR display_name[] = {
840 'D','i','s','p','l','a','y','N','a','m','e',0};
841 static const WCHAR display_version[] = {
842 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
843 static const WCHAR assignment[] = {
844 'A','s','s','i','g','n','m','e','n','t',0};
846 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
847 debugstr_w(szAttribute), szValue, pcchValueBuf);
849 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
850 return ERROR_INVALID_PARAMETER;
852 if (!squash_guid(szProduct, squished_pc))
853 return ERROR_INVALID_PARAMETER;
855 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
856 MSIINSTALLCONTEXT_USERMANAGED,
857 &prodkey, FALSE)) != ERROR_SUCCESS &&
858 (r = MSIREG_OpenProductKey(szProduct, NULL,
859 MSIINSTALLCONTEXT_USERUNMANAGED,
860 &prodkey, FALSE)) != ERROR_SUCCESS &&
861 (r = MSIREG_OpenProductKey(szProduct, NULL,
862 MSIINSTALLCONTEXT_MACHINE,
863 &prodkey, FALSE)) == ERROR_SUCCESS)
865 context = MSIINSTALLCONTEXT_MACHINE;
868 MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
870 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_HELPLINKW) ||
871 !lstrcmpW(szAttribute, INSTALLPROPERTY_HELPTELEPHONEW) ||
872 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLDATEW) ||
873 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
874 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW) ||
875 !lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLSOURCEW) ||
876 !lstrcmpW(szAttribute, INSTALLPROPERTY_LOCALPACKAGEW) ||
877 !lstrcmpW(szAttribute, INSTALLPROPERTY_PUBLISHERW) ||
878 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLINFOABOUTW) ||
879 !lstrcmpW(szAttribute, INSTALLPROPERTY_URLUPDATEINFOW) ||
880 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMINORW) ||
881 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONMAJORW) ||
882 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW) ||
883 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTIDW) ||
884 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGCOMPANYW) ||
885 !lstrcmpW(szAttribute, INSTALLPROPERTY_REGOWNERW))
887 if (!prodkey)
889 r = ERROR_UNKNOWN_PRODUCT;
890 goto done;
893 if (!userdata)
894 return ERROR_UNKNOWN_PROPERTY;
896 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
897 szAttribute = display_name;
898 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONSTRINGW))
899 szAttribute = display_version;
901 val = msi_reg_get_value(userdata, szAttribute, &type);
902 if (!val)
903 val = empty;
905 else if (!lstrcmpW(szAttribute, INSTALLPROPERTY_INSTANCETYPEW) ||
906 !lstrcmpW(szAttribute, INSTALLPROPERTY_TRANSFORMSW) ||
907 !lstrcmpW(szAttribute, INSTALLPROPERTY_LANGUAGEW) ||
908 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTNAMEW) ||
909 !lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW) ||
910 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW) ||
911 !lstrcmpW(szAttribute, INSTALLPROPERTY_VERSIONW) ||
912 !lstrcmpW(szAttribute, INSTALLPROPERTY_PRODUCTICONW) ||
913 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW) ||
914 !lstrcmpW(szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
916 if (!prodkey)
918 r = ERROR_UNKNOWN_PRODUCT;
919 goto done;
922 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW))
923 szAttribute = assignment;
925 if (!lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGENAMEW))
927 res = RegOpenKeyW(prodkey, sourcelist, &source);
928 if (res != ERROR_SUCCESS)
930 r = ERROR_UNKNOWN_PRODUCT;
931 goto done;
934 val = msi_reg_get_value(source, szAttribute, &type);
935 if (!val)
936 val = empty;
938 RegCloseKey(source);
940 else
942 val = msi_reg_get_value(prodkey, szAttribute, &type);
943 if (!val)
944 val = empty;
947 if (val != empty && type != REG_DWORD &&
948 !lstrcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW))
950 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
951 badconfig = TRUE;
952 else
954 unsquash_guid(val, packagecode);
955 msi_free(val);
956 val = strdupW(packagecode);
961 if (!val)
963 r = ERROR_UNKNOWN_PROPERTY;
964 goto done;
967 if (pcchValueBuf)
969 save = *pcchValueBuf;
971 if (strlenW(val) < *pcchValueBuf)
972 r = msi_strcpy_to_awstring(val, szValue, pcchValueBuf);
973 else if (szValue->str.a || szValue->str.w)
974 r = ERROR_MORE_DATA;
976 if (!badconfig)
977 *pcchValueBuf = lstrlenW(val);
978 else if (r == ERROR_SUCCESS)
980 *pcchValueBuf = save;
981 r = ERROR_BAD_CONFIGURATION;
984 else if (badconfig)
985 r = ERROR_BAD_CONFIGURATION;
987 if (val != empty)
988 msi_free(val);
990 done:
991 RegCloseKey(prodkey);
992 RegCloseKey(userdata);
993 return r;
996 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
997 LPSTR szBuffer, LPDWORD pcchValueBuf)
999 LPWSTR szwProduct, szwAttribute = NULL;
1000 UINT r = ERROR_OUTOFMEMORY;
1001 awstring buffer;
1003 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1004 szBuffer, pcchValueBuf);
1006 szwProduct = strdupAtoW( szProduct );
1007 if( szProduct && !szwProduct )
1008 goto end;
1010 szwAttribute = strdupAtoW( szAttribute );
1011 if( szAttribute && !szwAttribute )
1012 goto end;
1014 buffer.unicode = FALSE;
1015 buffer.str.a = szBuffer;
1017 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1018 &buffer, pcchValueBuf );
1020 end:
1021 msi_free( szwProduct );
1022 msi_free( szwAttribute );
1024 return r;
1027 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1028 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1030 awstring buffer;
1032 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1033 szBuffer, pcchValueBuf);
1035 buffer.unicode = TRUE;
1036 buffer.str.w = szBuffer;
1038 return MSI_GetProductInfo( szProduct, szAttribute,
1039 &buffer, pcchValueBuf );
1042 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1043 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1044 LPSTR szValue, LPDWORD pcchValue)
1046 LPWSTR product = NULL;
1047 LPWSTR usersid = NULL;
1048 LPWSTR property = NULL;
1049 LPWSTR value = NULL;
1050 DWORD len = 0;
1051 UINT r;
1053 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1054 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1055 szValue, pcchValue);
1057 if (szValue && !pcchValue)
1058 return ERROR_INVALID_PARAMETER;
1060 if (szProductCode) product = strdupAtoW(szProductCode);
1061 if (szUserSid) usersid = strdupAtoW(szUserSid);
1062 if (szProperty) property = strdupAtoW(szProperty);
1064 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1065 NULL, &len);
1066 if (r != ERROR_SUCCESS)
1067 goto done;
1069 value = msi_alloc(++len * sizeof(WCHAR));
1070 if (!value)
1072 r = ERROR_OUTOFMEMORY;
1073 goto done;
1076 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1077 value, &len);
1078 if (r != ERROR_SUCCESS)
1079 goto done;
1081 if (!pcchValue)
1082 goto done;
1084 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1085 if (*pcchValue >= len)
1086 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1087 else if (szValue)
1089 r = ERROR_MORE_DATA;
1090 if (*pcchValue > 0)
1091 *szValue = '\0';
1094 if (*pcchValue <= len || !szValue)
1095 len = len * sizeof(WCHAR) - 1;
1097 *pcchValue = len - 1;
1099 done:
1100 msi_free(product);
1101 msi_free(usersid);
1102 msi_free(property);
1103 msi_free(value);
1105 return r;
1108 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1110 UINT r;
1112 if (!val)
1113 return ERROR_UNKNOWN_PROPERTY;
1115 if (out)
1117 if (strlenW(val) >= *size)
1119 r = ERROR_MORE_DATA;
1120 if (*size > 0)
1121 *out = '\0';
1123 else
1124 lstrcpyW(out, val);
1127 if (size)
1128 *size = lstrlenW(val);
1130 return ERROR_SUCCESS;
1133 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1134 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1135 LPWSTR szValue, LPDWORD pcchValue)
1137 WCHAR squished_pc[GUID_SIZE];
1138 LPWSTR val = NULL;
1139 LPCWSTR package = NULL;
1140 HKEY props = NULL, prod;
1141 HKEY classes = NULL, managed;
1142 HKEY hkey = NULL;
1143 DWORD type;
1144 UINT r = ERROR_UNKNOWN_PRODUCT;
1146 static const WCHAR one[] = {'1',0};
1147 static const WCHAR five[] = {'5',0};
1148 static const WCHAR empty[] = {0};
1149 static const WCHAR displayname[] = {
1150 'D','i','s','p','l','a','y','N','a','m','e',0};
1151 static const WCHAR displayversion[] = {
1152 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1153 static const WCHAR managed_local_package[] = {
1154 'M','a','n','a','g','e','d','L','o','c','a','l',
1155 'P','a','c','k','a','g','e',0};
1157 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1158 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1159 szValue, pcchValue);
1161 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1162 return ERROR_INVALID_PARAMETER;
1164 if (szValue && !pcchValue)
1165 return ERROR_INVALID_PARAMETER;
1167 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1168 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1169 dwContext != MSIINSTALLCONTEXT_MACHINE)
1170 return ERROR_INVALID_PARAMETER;
1172 if (!szProperty || !*szProperty)
1173 return ERROR_INVALID_PARAMETER;
1175 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1176 return ERROR_INVALID_PARAMETER;
1178 /* FIXME: dwContext is provided, no need to search for it */
1179 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1180 &managed, FALSE);
1181 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1182 &prod, FALSE);
1184 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1186 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1188 package = INSTALLPROPERTY_LOCALPACKAGEW;
1190 if (!props && !prod)
1191 goto done;
1193 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1195 package = managed_local_package;
1197 if (!props && !managed)
1198 goto done;
1200 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1202 package = INSTALLPROPERTY_LOCALPACKAGEW;
1203 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1205 if (!props && !classes)
1206 goto done;
1209 if (!lstrcmpW(szProperty, INSTALLPROPERTY_HELPLINKW) ||
1210 !lstrcmpW(szProperty, INSTALLPROPERTY_HELPTELEPHONEW) ||
1211 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW) ||
1212 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW) ||
1213 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLLOCATIONW) ||
1214 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLSOURCEW) ||
1215 !lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW) ||
1216 !lstrcmpW(szProperty, INSTALLPROPERTY_PUBLISHERW) ||
1217 !lstrcmpW(szProperty, INSTALLPROPERTY_URLINFOABOUTW) ||
1218 !lstrcmpW(szProperty, INSTALLPROPERTY_URLUPDATEINFOW) ||
1219 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMINORW) ||
1220 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONMAJORW) ||
1221 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW) ||
1222 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTIDW) ||
1223 !lstrcmpW(szProperty, INSTALLPROPERTY_REGCOMPANYW) ||
1224 !lstrcmpW(szProperty, INSTALLPROPERTY_REGOWNERW) ||
1225 !lstrcmpW(szProperty, INSTALLPROPERTY_INSTANCETYPEW))
1227 val = msi_reg_get_value(props, package, &type);
1228 if (!val)
1230 if (prod || classes)
1231 r = ERROR_UNKNOWN_PROPERTY;
1233 goto done;
1236 msi_free(val);
1238 if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW))
1239 szProperty = displayname;
1240 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONSTRINGW))
1241 szProperty = displayversion;
1243 val = msi_reg_get_value(props, szProperty, &type);
1244 if (!val)
1245 val = strdupW(empty);
1247 r = msi_copy_outval(val, szValue, pcchValue);
1249 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW) ||
1250 !lstrcmpW(szProperty, INSTALLPROPERTY_LANGUAGEW) ||
1251 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTNAMEW) ||
1252 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGECODEW) ||
1253 !lstrcmpW(szProperty, INSTALLPROPERTY_VERSIONW) ||
1254 !lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTICONW) ||
1255 !lstrcmpW(szProperty, INSTALLPROPERTY_PACKAGENAMEW) ||
1256 !lstrcmpW(szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW))
1258 if (!prod && !classes)
1259 goto done;
1261 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1262 hkey = prod;
1263 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1264 hkey = managed;
1265 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1266 hkey = classes;
1268 val = msi_reg_get_value(hkey, szProperty, &type);
1269 if (!val)
1270 val = strdupW(empty);
1272 r = msi_copy_outval(val, szValue, pcchValue);
1274 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_PRODUCTSTATEW))
1276 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1278 if (props)
1280 val = msi_reg_get_value(props, package, &type);
1281 if (!val)
1282 goto done;
1284 msi_free(val);
1285 val = strdupW(five);
1287 else
1288 val = strdupW(one);
1290 r = msi_copy_outval(val, szValue, pcchValue);
1291 goto done;
1293 else if (props && (val = msi_reg_get_value(props, package, &type)))
1295 msi_free(val);
1296 val = strdupW(five);
1297 r = msi_copy_outval(val, szValue, pcchValue);
1298 goto done;
1301 if (prod || managed)
1302 val = strdupW(one);
1303 else
1304 goto done;
1306 r = msi_copy_outval(val, szValue, pcchValue);
1308 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW))
1310 if (!prod && !classes)
1311 goto done;
1313 /* FIXME */
1314 val = strdupW(empty);
1315 r = msi_copy_outval(val, szValue, pcchValue);
1317 else
1318 r = ERROR_UNKNOWN_PROPERTY;
1320 done:
1321 RegCloseKey(props);
1322 RegCloseKey(prod);
1323 RegCloseKey(managed);
1324 RegCloseKey(classes);
1325 msi_free(val);
1327 return r;
1330 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1331 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1332 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1334 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1335 LPWSTR property = NULL, val = NULL;
1336 DWORD len;
1337 UINT r;
1339 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1340 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1341 debugstr_a(szProperty), lpValue, pcchValue);
1343 if (lpValue && !pcchValue)
1344 return ERROR_INVALID_PARAMETER;
1346 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1347 if (szProductCode) product = strdupAtoW(szProductCode);
1348 if (szUserSid) usersid = strdupAtoW(szUserSid);
1349 if (szProperty) property = strdupAtoW(szProperty);
1351 len = 0;
1352 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1353 NULL, &len);
1354 if (r != ERROR_SUCCESS)
1355 goto done;
1357 val = msi_alloc(++len * sizeof(WCHAR));
1358 if (!val)
1360 r = ERROR_OUTOFMEMORY;
1361 goto done;
1364 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1365 val, &len);
1366 if (r != ERROR_SUCCESS || !pcchValue)
1367 goto done;
1369 if (lpValue)
1370 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1371 *pcchValue - 1, NULL, NULL);
1373 len = lstrlenW(val);
1374 if ((*val && *pcchValue < len + 1) || !lpValue)
1376 if (lpValue)
1378 r = ERROR_MORE_DATA;
1379 lpValue[*pcchValue - 1] = '\0';
1382 *pcchValue = len * sizeof(WCHAR);
1384 else
1385 *pcchValue = len;
1387 done:
1388 msi_free(val);
1389 msi_free(patch);
1390 msi_free(product);
1391 msi_free(usersid);
1392 msi_free(property);
1394 return r;
1397 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1398 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1399 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1401 WCHAR squished_pc[GUID_SIZE];
1402 WCHAR squished_patch[GUID_SIZE];
1403 HKEY udprod = 0, prod = 0, props = 0;
1404 HKEY patch = 0, patches = 0;
1405 HKEY udpatch = 0, datakey = 0;
1406 HKEY prodpatches = 0;
1407 LPWSTR val = NULL;
1408 UINT r = ERROR_UNKNOWN_PRODUCT;
1409 DWORD len;
1410 LONG res;
1412 static const WCHAR szEmpty[] = {0};
1413 static const WCHAR szPatches[] = {'P','a','t','c','h','e','s',0};
1414 static const WCHAR szInstalled[] = {'I','n','s','t','a','l','l','e','d',0};
1415 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1416 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1418 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1419 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1420 debugstr_w(szProperty), lpValue, pcchValue);
1422 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1423 return ERROR_INVALID_PARAMETER;
1425 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1426 return ERROR_INVALID_PARAMETER;
1428 if (!szProperty)
1429 return ERROR_INVALID_PARAMETER;
1431 if (lpValue && !pcchValue)
1432 return ERROR_INVALID_PARAMETER;
1434 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1435 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1436 dwContext != MSIINSTALLCONTEXT_MACHINE)
1437 return ERROR_INVALID_PARAMETER;
1439 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1440 return ERROR_INVALID_PARAMETER;
1442 if (!lstrcmpW(szUserSid, szLocalSid))
1443 return ERROR_INVALID_PARAMETER;
1445 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1446 &udprod, FALSE) != ERROR_SUCCESS)
1447 goto done;
1449 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1450 &props, FALSE) != ERROR_SUCCESS)
1451 goto done;
1453 r = ERROR_UNKNOWN_PATCH;
1455 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_READ, &patches);
1456 if (res != ERROR_SUCCESS)
1457 goto done;
1459 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_READ, &patch);
1460 if (res != ERROR_SUCCESS)
1461 goto done;
1463 if (!lstrcmpW(szProperty, INSTALLPROPERTY_TRANSFORMSW))
1465 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1466 &prod, FALSE) != ERROR_SUCCESS)
1467 goto done;
1469 res = RegOpenKeyExW(prod, szPatches, 0, KEY_ALL_ACCESS, &prodpatches);
1470 if (res != ERROR_SUCCESS)
1471 goto done;
1473 datakey = prodpatches;
1474 szProperty = squished_patch;
1476 else
1478 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1479 &udpatch, FALSE) != ERROR_SUCCESS)
1480 goto done;
1482 if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1484 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1485 szProperty = szManagedPackage;
1486 datakey = udpatch;
1488 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_INSTALLDATEW))
1490 datakey = patch;
1491 szProperty = szInstalled;
1493 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_LOCALPACKAGEW))
1495 datakey = udpatch;
1497 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_UNINSTALLABLEW) ||
1498 !lstrcmpW(szProperty, INSTALLPROPERTY_PATCHSTATEW) ||
1499 !lstrcmpW(szProperty, INSTALLPROPERTY_DISPLAYNAMEW) ||
1500 !lstrcmpW(szProperty, INSTALLPROPERTY_MOREINFOURLW))
1502 datakey = patch;
1504 else
1506 r = ERROR_UNKNOWN_PROPERTY;
1507 goto done;
1511 val = msi_reg_get_val_str(datakey, szProperty);
1512 if (!val)
1513 val = strdupW(szEmpty);
1515 r = ERROR_SUCCESS;
1517 if (!pcchValue)
1518 goto done;
1520 if (lpValue)
1521 lstrcpynW(lpValue, val, *pcchValue);
1523 len = lstrlenW(val);
1524 if ((*val && *pcchValue < len + 1) || !lpValue)
1526 if (lpValue)
1527 r = ERROR_MORE_DATA;
1529 *pcchValue = len * sizeof(WCHAR);
1532 *pcchValue = len;
1534 done:
1535 msi_free(val);
1536 RegCloseKey(prodpatches);
1537 RegCloseKey(prod);
1538 RegCloseKey(patch);
1539 RegCloseKey(patches);
1540 RegCloseKey(udpatch);
1541 RegCloseKey(props);
1542 RegCloseKey(udprod);
1544 return r;
1547 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1549 LPWSTR szwLogFile = NULL;
1550 UINT r;
1552 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1554 if( szLogFile )
1556 szwLogFile = strdupAtoW( szLogFile );
1557 if( !szwLogFile )
1558 return ERROR_OUTOFMEMORY;
1560 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1561 msi_free( szwLogFile );
1562 return r;
1565 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1567 HANDLE file = INVALID_HANDLE_VALUE;
1569 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1571 if (szLogFile)
1573 lstrcpyW(gszLogFile,szLogFile);
1574 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1575 DeleteFileW(szLogFile);
1576 file = CreateFileW(szLogFile, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
1577 FILE_ATTRIBUTE_NORMAL, NULL);
1578 if (file != INVALID_HANDLE_VALUE)
1579 CloseHandle(file);
1580 else
1581 ERR("Unable to enable log %s\n",debugstr_w(szLogFile));
1583 else
1584 gszLogFile[0] = '\0';
1586 return ERROR_SUCCESS;
1589 UINT WINAPI MsiEnumComponentCostsW(MSIHANDLE hInstall, LPCWSTR szComponent,
1590 DWORD dwIndex, INSTALLSTATE iState,
1591 LPWSTR lpDriveBuf, DWORD *pcchDriveBuf,
1592 int *piCost, int *pTempCost)
1594 FIXME("(%d, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall,
1595 debugstr_w(szComponent), dwIndex, iState, lpDriveBuf,
1596 pcchDriveBuf, piCost, pTempCost);
1598 return ERROR_NO_MORE_ITEMS;
1601 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1602 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1603 LPCSTR szComponent, INSTALLSTATE *pdwState)
1605 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1606 UINT r;
1608 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1609 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1611 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1612 return ERROR_OUTOFMEMORY;
1614 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1615 return ERROR_OUTOFMEMORY;
1617 if (szComponent && !(comp = strdupAtoW(szComponent)))
1618 return ERROR_OUTOFMEMORY;
1620 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1622 msi_free(prodcode);
1623 msi_free(usersid);
1624 msi_free(comp);
1626 return r;
1629 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1631 UINT r;
1632 HKEY hkey;
1634 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
1635 RegCloseKey(hkey);
1636 return (r == ERROR_SUCCESS);
1639 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1641 LPCWSTR package;
1642 HKEY hkey;
1643 DWORD sz;
1644 LONG res;
1645 UINT r;
1647 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1648 static const WCHAR managed_local_package[] = {
1649 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1652 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
1653 if (r != ERROR_SUCCESS)
1654 return FALSE;
1656 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1657 package = managed_local_package;
1658 else
1659 package = local_package;
1661 sz = 0;
1662 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1663 RegCloseKey(hkey);
1665 return (res == ERROR_SUCCESS);
1668 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1669 MSIINSTALLCONTEXT context,
1670 LPCWSTR comp, LPWSTR val, DWORD *sz)
1672 HKEY hkey;
1673 LONG res;
1674 UINT r;
1676 if (context == MSIINSTALLCONTEXT_MACHINE)
1677 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
1678 else
1679 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
1681 if (r != ERROR_SUCCESS)
1682 return FALSE;
1684 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
1685 if (res != ERROR_SUCCESS)
1686 return FALSE;
1688 RegCloseKey(hkey);
1689 return TRUE;
1692 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
1693 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1694 LPCWSTR szComponent, INSTALLSTATE *pdwState)
1696 WCHAR squished_pc[GUID_SIZE];
1697 WCHAR val[MAX_PATH];
1698 BOOL found;
1699 DWORD sz;
1701 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
1702 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
1704 if (!pdwState || !szComponent)
1705 return ERROR_INVALID_PARAMETER;
1707 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
1708 return ERROR_INVALID_PARAMETER;
1710 if (!squash_guid(szProductCode, squished_pc))
1711 return ERROR_INVALID_PARAMETER;
1713 found = msi_comp_find_prod_key(szProductCode, dwContext);
1715 if (!msi_comp_find_package(szProductCode, dwContext))
1717 if (found)
1719 *pdwState = INSTALLSTATE_UNKNOWN;
1720 return ERROR_UNKNOWN_COMPONENT;
1723 return ERROR_UNKNOWN_PRODUCT;
1726 *pdwState = INSTALLSTATE_UNKNOWN;
1728 sz = MAX_PATH;
1729 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
1730 return ERROR_UNKNOWN_COMPONENT;
1732 if (sz == 0)
1733 *pdwState = INSTALLSTATE_NOTUSED;
1734 else
1736 if (lstrlenW(val) > 2 &&
1737 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
1739 *pdwState = INSTALLSTATE_SOURCE;
1741 else
1742 *pdwState = INSTALLSTATE_LOCAL;
1745 return ERROR_SUCCESS;
1748 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
1750 LPWSTR szwProduct = NULL;
1751 INSTALLSTATE r;
1753 if( szProduct )
1755 szwProduct = strdupAtoW( szProduct );
1756 if( !szwProduct )
1757 return ERROR_OUTOFMEMORY;
1759 r = MsiQueryProductStateW( szwProduct );
1760 msi_free( szwProduct );
1761 return r;
1764 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
1766 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1767 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
1768 HKEY prodkey = 0, userdata = 0;
1769 DWORD val;
1770 UINT r;
1772 static const WCHAR szWindowsInstaller[] = {
1773 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1775 TRACE("%s\n", debugstr_w(szProduct));
1777 if (!szProduct || !*szProduct)
1778 return INSTALLSTATE_INVALIDARG;
1780 if (lstrlenW(szProduct) != GUID_SIZE - 1)
1781 return INSTALLSTATE_INVALIDARG;
1783 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
1784 &prodkey, FALSE) != ERROR_SUCCESS &&
1785 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1786 &prodkey, FALSE) != ERROR_SUCCESS &&
1787 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
1788 &prodkey, FALSE) == ERROR_SUCCESS)
1790 context = MSIINSTALLCONTEXT_MACHINE;
1793 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
1794 if (r != ERROR_SUCCESS)
1795 goto done;
1797 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
1798 goto done;
1800 if (val)
1801 state = INSTALLSTATE_DEFAULT;
1802 else
1803 state = INSTALLSTATE_UNKNOWN;
1805 done:
1806 if (!prodkey)
1808 state = INSTALLSTATE_UNKNOWN;
1810 if (userdata)
1811 state = INSTALLSTATE_ABSENT;
1814 RegCloseKey(prodkey);
1815 RegCloseKey(userdata);
1816 return state;
1819 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
1821 INSTALLUILEVEL old = gUILevel;
1822 HWND oldwnd = gUIhwnd;
1824 TRACE("%08x %p\n", dwUILevel, phWnd);
1826 gUILevel = dwUILevel;
1827 if (phWnd)
1829 gUIhwnd = *phWnd;
1830 *phWnd = oldwnd;
1832 return old;
1835 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
1836 DWORD dwMessageFilter, LPVOID pvContext)
1838 INSTALLUI_HANDLERA prev = gUIHandlerA;
1840 TRACE("%p %x %p\n",puiHandler, dwMessageFilter,pvContext);
1841 gUIHandlerA = puiHandler;
1842 gUIFilter = dwMessageFilter;
1843 gUIContext = pvContext;
1845 return prev;
1848 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
1849 DWORD dwMessageFilter, LPVOID pvContext)
1851 INSTALLUI_HANDLERW prev = gUIHandlerW;
1853 TRACE("%p %x %p\n",puiHandler,dwMessageFilter,pvContext);
1854 gUIHandlerW = puiHandler;
1855 gUIFilter = dwMessageFilter;
1856 gUIContext = pvContext;
1858 return prev;
1861 /******************************************************************
1862 * MsiLoadStringW [MSI.@]
1864 * Loads a string from MSI's string resources.
1866 * PARAMS
1868 * handle [I] only -1 is handled currently
1869 * id [I] id of the string to be loaded
1870 * lpBuffer [O] buffer for the string to be written to
1871 * nBufferMax [I] maximum size of the buffer in characters
1872 * lang [I] the preferred language for the string
1874 * RETURNS
1876 * If successful, this function returns the language id of the string loaded
1877 * If the function fails, the function returns zero.
1879 * NOTES
1881 * The type of the first parameter is unknown. LoadString's prototype
1882 * suggests that it might be a module handle. I have made it an MSI handle
1883 * for starters, as -1 is an invalid MSI handle, but not an invalid module
1884 * handle. Maybe strings can be stored in an MSI database somehow.
1886 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
1887 int nBufferMax, LANGID lang )
1889 HRSRC hres;
1890 HGLOBAL hResData;
1891 LPWSTR p;
1892 DWORD i, len;
1894 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
1896 if( handle != -1 )
1897 FIXME("don't know how to deal with handle = %08x\n", handle);
1899 if( !lang )
1900 lang = GetUserDefaultLangID();
1902 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
1903 (LPWSTR)1, lang );
1904 if( !hres )
1905 return 0;
1906 hResData = LoadResource( msi_hInstance, hres );
1907 if( !hResData )
1908 return 0;
1909 p = LockResource( hResData );
1910 if( !p )
1911 return 0;
1913 for (i = 0; i < (id&0xf); i++)
1914 p += *p + 1;
1915 len = *p;
1917 if( nBufferMax <= len )
1918 return 0;
1920 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
1921 lpBuffer[ len ] = 0;
1923 TRACE("found -> %s\n", debugstr_w(lpBuffer));
1925 return lang;
1928 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
1929 int nBufferMax, LANGID lang )
1931 LPWSTR bufW;
1932 LANGID r;
1933 INT len;
1935 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
1936 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
1937 if( r )
1939 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
1940 if( len <= nBufferMax )
1941 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
1942 lpBuffer, nBufferMax, NULL, NULL );
1943 else
1944 r = 0;
1946 msi_free(bufW);
1947 return r;
1950 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
1951 LPDWORD pcchBuf)
1953 char szProduct[GUID_SIZE];
1955 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
1957 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
1958 return INSTALLSTATE_UNKNOWN;
1960 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
1963 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
1964 LPDWORD pcchBuf)
1966 WCHAR szProduct[GUID_SIZE];
1968 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
1970 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
1971 return INSTALLSTATE_UNKNOWN;
1973 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
1976 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
1977 WORD wLanguageId, DWORD f)
1979 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
1980 uType, wLanguageId, f);
1981 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
1984 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
1985 WORD wLanguageId, DWORD f)
1987 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
1988 uType, wLanguageId, f);
1989 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
1992 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
1993 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
1994 LPDWORD pcchPathBuf )
1996 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
1997 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
1998 pcchPathBuf);
1999 return ERROR_CALL_NOT_IMPLEMENTED;
2002 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2003 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2004 LPDWORD pcchPathBuf )
2006 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2007 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2008 pcchPathBuf);
2009 return ERROR_CALL_NOT_IMPLEMENTED;
2012 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2013 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2015 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2016 return ERROR_CALL_NOT_IMPLEMENTED;
2019 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2020 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2022 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2023 return ERROR_CALL_NOT_IMPLEMENTED;
2026 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath,
2027 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2028 LPDWORD pcbHashData)
2030 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath), dwFlags,
2031 ppcCertContext, pbHashData, pcbHashData);
2032 return ERROR_CALL_NOT_IMPLEMENTED;
2035 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath,
2036 DWORD dwFlags, PCCERT_CONTEXT* ppcCertContext, LPBYTE pbHashData,
2037 LPDWORD pcbHashData)
2039 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath), dwFlags,
2040 ppcCertContext, pbHashData, pcbHashData);
2041 return ERROR_CALL_NOT_IMPLEMENTED;
2044 /******************************************************************
2045 * MsiGetProductPropertyA [MSI.@]
2047 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2048 LPSTR szValue, LPDWORD pccbValue)
2050 LPWSTR prop = NULL, val = NULL;
2051 DWORD len;
2052 UINT r;
2054 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2055 szValue, pccbValue);
2057 if (szValue && !pccbValue)
2058 return ERROR_INVALID_PARAMETER;
2060 if (szProperty) prop = strdupAtoW(szProperty);
2062 len = 0;
2063 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2064 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2065 goto done;
2067 if (r == ERROR_SUCCESS)
2069 if (szValue) *szValue = '\0';
2070 if (pccbValue) *pccbValue = 0;
2071 goto done;
2074 val = msi_alloc(++len * sizeof(WCHAR));
2075 if (!val)
2077 r = ERROR_OUTOFMEMORY;
2078 goto done;
2081 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2082 if (r != ERROR_SUCCESS)
2083 goto done;
2085 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2087 if (szValue)
2088 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2089 *pccbValue, NULL, NULL);
2091 if (pccbValue)
2093 if (len > *pccbValue)
2094 r = ERROR_MORE_DATA;
2096 *pccbValue = len - 1;
2099 done:
2100 msi_free(prop);
2101 msi_free(val);
2103 return r;
2106 /******************************************************************
2107 * MsiGetProductPropertyW [MSI.@]
2109 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2110 LPWSTR szValue, LPDWORD pccbValue)
2112 MSIPACKAGE *package;
2113 MSIQUERY *view = NULL;
2114 MSIRECORD *rec = NULL;
2115 LPCWSTR val;
2116 UINT r;
2118 static const WCHAR query[] = {
2119 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2120 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2121 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2123 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2124 szValue, pccbValue);
2126 if (!szProperty)
2127 return ERROR_INVALID_PARAMETER;
2129 if (szValue && !pccbValue)
2130 return ERROR_INVALID_PARAMETER;
2132 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2133 if (!package)
2134 return ERROR_INVALID_HANDLE;
2136 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2137 if (r != ERROR_SUCCESS)
2138 goto done;
2140 r = MSI_ViewExecute(view, 0);
2141 if (r != ERROR_SUCCESS)
2142 goto done;
2144 r = MSI_ViewFetch(view, &rec);
2145 if (r != ERROR_SUCCESS)
2146 goto done;
2148 val = MSI_RecordGetString(rec, 2);
2149 if (!val)
2150 goto done;
2152 if (lstrlenW(val) >= *pccbValue)
2154 lstrcpynW(szValue, val, *pccbValue);
2155 *pccbValue = lstrlenW(val);
2156 r = ERROR_MORE_DATA;
2158 else
2160 lstrcpyW(szValue, val);
2161 *pccbValue = lstrlenW(val);
2162 r = ERROR_SUCCESS;
2165 done:
2166 if (view)
2168 MSI_ViewClose(view);
2169 msiobj_release(&view->hdr);
2170 if (rec) msiobj_release(&rec->hdr);
2173 if (!rec)
2175 if (szValue) *szValue = '\0';
2176 if (pccbValue) *pccbValue = 0;
2177 r = ERROR_SUCCESS;
2180 return r;
2183 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2185 UINT r;
2186 LPWSTR szPack = NULL;
2188 TRACE("%s\n", debugstr_a(szPackage) );
2190 if( szPackage )
2192 szPack = strdupAtoW( szPackage );
2193 if( !szPack )
2194 return ERROR_OUTOFMEMORY;
2197 r = MsiVerifyPackageW( szPack );
2199 msi_free( szPack );
2201 return r;
2204 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2206 MSIHANDLE handle;
2207 UINT r;
2209 TRACE("%s\n", debugstr_w(szPackage) );
2211 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2212 MsiCloseHandle( handle );
2214 return r;
2217 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2218 awstring* lpPathBuf, LPDWORD pcchBuf)
2220 WCHAR squished_pc[GUID_SIZE];
2221 WCHAR squished_comp[GUID_SIZE];
2222 HKEY hkey;
2223 LPWSTR path = NULL;
2224 INSTALLSTATE state;
2225 DWORD version;
2227 static const WCHAR wininstaller[] = {
2228 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2230 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
2231 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
2233 if (!szProduct || !szComponent)
2234 return INSTALLSTATE_INVALIDARG;
2236 if (lpPathBuf->str.w && !pcchBuf)
2237 return INSTALLSTATE_INVALIDARG;
2239 if (!squash_guid(szProduct, squished_pc) ||
2240 !squash_guid(szComponent, squished_comp))
2241 return INSTALLSTATE_INVALIDARG;
2243 state = INSTALLSTATE_UNKNOWN;
2245 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2246 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2248 path = msi_reg_get_val_str(hkey, squished_pc);
2249 RegCloseKey(hkey);
2251 state = INSTALLSTATE_ABSENT;
2253 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2254 &hkey, FALSE) == ERROR_SUCCESS ||
2255 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2256 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2257 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2258 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2260 RegCloseKey(hkey);
2261 state = INSTALLSTATE_LOCAL;
2265 if (state != INSTALLSTATE_LOCAL &&
2266 (MSIREG_OpenProductKey(szProduct, NULL,
2267 MSIINSTALLCONTEXT_USERUNMANAGED,
2268 &hkey, FALSE) == ERROR_SUCCESS ||
2269 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2270 &hkey, FALSE) == ERROR_SUCCESS))
2272 RegCloseKey(hkey);
2274 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2275 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2277 msi_free(path);
2278 path = msi_reg_get_val_str(hkey, squished_pc);
2279 RegCloseKey(hkey);
2281 state = INSTALLSTATE_ABSENT;
2283 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2284 state = INSTALLSTATE_LOCAL;
2288 if (!path)
2289 return INSTALLSTATE_UNKNOWN;
2291 if (state == INSTALLSTATE_LOCAL && !*path)
2292 state = INSTALLSTATE_NOTUSED;
2294 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
2295 msi_free(path);
2296 return state;
2299 /******************************************************************
2300 * MsiGetComponentPathW [MSI.@]
2302 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2303 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2305 awstring path;
2307 path.unicode = TRUE;
2308 path.str.w = lpPathBuf;
2310 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2313 /******************************************************************
2314 * MsiGetComponentPathA [MSI.@]
2316 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2317 LPSTR lpPathBuf, LPDWORD pcchBuf)
2319 LPWSTR szwProduct, szwComponent = NULL;
2320 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2321 awstring path;
2323 szwProduct = strdupAtoW( szProduct );
2324 if( szProduct && !szwProduct)
2325 goto end;
2327 szwComponent = strdupAtoW( szComponent );
2328 if( szComponent && !szwComponent )
2329 goto end;
2331 path.unicode = FALSE;
2332 path.str.a = lpPathBuf;
2334 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2336 end:
2337 msi_free( szwProduct );
2338 msi_free( szwComponent );
2340 return r;
2343 /******************************************************************
2344 * MsiQueryFeatureStateA [MSI.@]
2346 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
2348 LPWSTR szwProduct = NULL, szwFeature= NULL;
2349 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
2351 szwProduct = strdupAtoW( szProduct );
2352 if ( szProduct && !szwProduct )
2353 goto end;
2355 szwFeature = strdupAtoW( szFeature );
2356 if ( szFeature && !szwFeature )
2357 goto end;
2359 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
2361 end:
2362 msi_free( szwProduct);
2363 msi_free( szwFeature);
2365 return rc;
2368 /******************************************************************
2369 * MsiQueryFeatureStateW [MSI.@]
2371 * Checks the state of a feature
2373 * PARAMS
2374 * szProduct [I] Product's GUID string
2375 * szFeature [I] Feature's GUID string
2377 * RETURNS
2378 * INSTALLSTATE_LOCAL Feature is installed and usable
2379 * INSTALLSTATE_ABSENT Feature is absent
2380 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2381 * INSTALLSTATE_UNKNOWN An error occurred
2382 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2385 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
2387 WCHAR squishProduct[33], comp[GUID_SIZE];
2388 GUID guid;
2389 LPWSTR components, p, parent_feature, path;
2390 UINT rc;
2391 HKEY hkey;
2392 INSTALLSTATE r;
2393 BOOL missing = FALSE;
2394 BOOL machine = FALSE;
2395 BOOL source = FALSE;
2397 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
2399 if (!szProduct || !szFeature)
2400 return INSTALLSTATE_INVALIDARG;
2402 if (!squash_guid( szProduct, squishProduct ))
2403 return INSTALLSTATE_INVALIDARG;
2405 if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2406 &hkey, FALSE) != ERROR_SUCCESS &&
2407 MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2408 &hkey, FALSE) != ERROR_SUCCESS)
2410 rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2411 &hkey, FALSE);
2412 if (rc != ERROR_SUCCESS)
2413 return INSTALLSTATE_UNKNOWN;
2415 machine = TRUE;
2418 parent_feature = msi_reg_get_val_str( hkey, szFeature );
2419 RegCloseKey(hkey);
2421 if (!parent_feature)
2422 return INSTALLSTATE_UNKNOWN;
2424 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2425 msi_free(parent_feature);
2426 if (r == INSTALLSTATE_ABSENT)
2427 return r;
2429 if (machine)
2430 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2431 MSIINSTALLCONTEXT_MACHINE,
2432 &hkey, FALSE);
2433 else
2434 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2435 MSIINSTALLCONTEXT_USERUNMANAGED,
2436 &hkey, FALSE);
2438 if (rc != ERROR_SUCCESS)
2439 return INSTALLSTATE_ADVERTISED;
2441 components = msi_reg_get_val_str( hkey, szFeature );
2442 RegCloseKey(hkey);
2444 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
2446 if (!components)
2447 return INSTALLSTATE_ADVERTISED;
2449 for( p = components; *p && *p != 2 ; p += 20)
2451 if (!decode_base85_guid( p, &guid ))
2453 if (p != components)
2454 break;
2456 msi_free(components);
2457 return INSTALLSTATE_BADCONFIG;
2460 StringFromGUID2(&guid, comp, GUID_SIZE);
2462 if (machine)
2463 rc = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2464 else
2465 rc = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2467 if (rc != ERROR_SUCCESS)
2469 msi_free(components);
2470 return INSTALLSTATE_ADVERTISED;
2473 path = msi_reg_get_val_str(hkey, squishProduct);
2474 if (!path)
2475 missing = TRUE;
2476 else if (lstrlenW(path) > 2 &&
2477 path[0] >= '0' && path[0] <= '9' &&
2478 path[1] >= '0' && path[1] <= '9')
2480 source = TRUE;
2483 msi_free(path);
2486 TRACE("%s %s -> %d\n", debugstr_w(szProduct), debugstr_w(szFeature), r);
2487 msi_free(components);
2489 if (missing)
2490 return INSTALLSTATE_ADVERTISED;
2492 if (source)
2493 return INSTALLSTATE_SOURCE;
2495 return INSTALLSTATE_LOCAL;
2498 /******************************************************************
2499 * MsiGetFileVersionA [MSI.@]
2501 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
2502 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
2504 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
2505 UINT ret = ERROR_OUTOFMEMORY;
2507 if ((lpVersionBuf && !pcchVersionBuf) ||
2508 (lpLangBuf && !pcchLangBuf))
2509 return ERROR_INVALID_PARAMETER;
2511 if( szFilePath )
2513 szwFilePath = strdupAtoW( szFilePath );
2514 if( !szwFilePath )
2515 goto end;
2518 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
2520 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
2521 if( !lpwVersionBuff )
2522 goto end;
2525 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
2527 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
2528 if( !lpwLangBuff )
2529 goto end;
2532 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
2533 lpwLangBuff, pcchLangBuf);
2535 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
2536 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
2537 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
2538 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
2539 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
2540 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
2542 end:
2543 msi_free(szwFilePath);
2544 msi_free(lpwVersionBuff);
2545 msi_free(lpwLangBuff);
2547 return ret;
2550 /******************************************************************
2551 * MsiGetFileVersionW [MSI.@]
2553 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
2554 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
2556 static const WCHAR szVersionResource[] = {'\\',0};
2557 static const WCHAR szVersionFormat[] = {
2558 '%','d','.','%','d','.','%','d','.','%','d',0};
2559 static const WCHAR szLangResource[] = {
2560 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2561 'T','r','a','n','s','l','a','t','i','o','n',0};
2562 static const WCHAR szLangFormat[] = {'%','d',0};
2563 UINT ret = 0;
2564 DWORD dwVerLen, gle;
2565 LPVOID lpVer = NULL;
2566 VS_FIXEDFILEINFO *ffi;
2567 USHORT *lang;
2568 UINT puLen;
2569 WCHAR tmp[32];
2571 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
2572 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
2573 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
2575 if ((lpVersionBuf && !pcchVersionBuf) ||
2576 (lpLangBuf && !pcchLangBuf))
2577 return ERROR_INVALID_PARAMETER;
2579 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
2580 if( !dwVerLen )
2582 gle = GetLastError();
2583 if (gle == ERROR_BAD_PATHNAME)
2584 return ERROR_FILE_NOT_FOUND;
2585 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
2586 return ERROR_FILE_INVALID;
2588 return gle;
2591 lpVer = msi_alloc(dwVerLen);
2592 if( !lpVer )
2594 ret = ERROR_OUTOFMEMORY;
2595 goto end;
2598 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
2600 ret = GetLastError();
2601 goto end;
2604 if (pcchVersionBuf)
2606 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
2607 (puLen > 0) )
2609 wsprintfW(tmp, szVersionFormat,
2610 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
2611 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
2612 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
2614 if (strlenW(tmp) >= *pcchVersionBuf)
2615 ret = ERROR_MORE_DATA;
2617 *pcchVersionBuf = lstrlenW(tmp);
2619 else
2621 if (lpVersionBuf) *lpVersionBuf = 0;
2622 *pcchVersionBuf = 0;
2626 if (pcchLangBuf)
2628 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
2629 (puLen > 0))
2631 wsprintfW(tmp, szLangFormat, *lang);
2632 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
2634 if (strlenW(tmp) >= *pcchLangBuf)
2635 ret = ERROR_MORE_DATA;
2637 *pcchLangBuf = lstrlenW(tmp);
2639 else
2641 if (lpLangBuf) *lpLangBuf = 0;
2642 *pcchLangBuf = 0;
2646 end:
2647 msi_free(lpVer);
2648 return ret;
2651 /***********************************************************************
2652 * MsiGetFeatureUsageW [MSI.@]
2654 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
2655 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2657 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
2658 pdwUseCount, pwDateUsed);
2659 return ERROR_CALL_NOT_IMPLEMENTED;
2662 /***********************************************************************
2663 * MsiGetFeatureUsageA [MSI.@]
2665 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
2666 LPDWORD pdwUseCount, LPWORD pwDateUsed )
2668 LPWSTR prod = NULL, feat = NULL;
2669 UINT ret = ERROR_OUTOFMEMORY;
2671 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
2672 pdwUseCount, pwDateUsed);
2674 prod = strdupAtoW( szProduct );
2675 if (szProduct && !prod)
2676 goto end;
2678 feat = strdupAtoW( szFeature );
2679 if (szFeature && !feat)
2680 goto end;
2682 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
2684 end:
2685 msi_free( prod );
2686 msi_free( feat );
2688 return ret;
2691 /***********************************************************************
2692 * MsiUseFeatureExW [MSI.@]
2694 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
2695 DWORD dwInstallMode, DWORD dwReserved )
2697 INSTALLSTATE state;
2699 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
2700 dwInstallMode, dwReserved);
2702 state = MsiQueryFeatureStateW( szProduct, szFeature );
2704 if (dwReserved)
2705 return INSTALLSTATE_INVALIDARG;
2707 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
2709 FIXME("mark product %s feature %s as used\n",
2710 debugstr_w(szProduct), debugstr_w(szFeature) );
2713 return state;
2716 /***********************************************************************
2717 * MsiUseFeatureExA [MSI.@]
2719 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
2720 DWORD dwInstallMode, DWORD dwReserved )
2722 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
2723 LPWSTR prod = NULL, feat = NULL;
2725 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
2726 dwInstallMode, dwReserved);
2728 prod = strdupAtoW( szProduct );
2729 if (szProduct && !prod)
2730 goto end;
2732 feat = strdupAtoW( szFeature );
2733 if (szFeature && !feat)
2734 goto end;
2736 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
2738 end:
2739 msi_free( prod );
2740 msi_free( feat );
2742 return ret;
2745 /***********************************************************************
2746 * MsiUseFeatureW [MSI.@]
2748 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
2750 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
2753 /***********************************************************************
2754 * MsiUseFeatureA [MSI.@]
2756 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
2758 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
2761 /***********************************************************************
2762 * MSI_ProvideQualifiedComponentEx [internal]
2764 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
2765 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2766 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
2767 LPDWORD pcchPathBuf)
2769 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
2770 feature[MAX_FEATURE_CHARS+1];
2771 LPWSTR info;
2772 HKEY hkey;
2773 DWORD sz;
2774 UINT rc;
2776 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
2777 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
2778 Unused1, Unused2, lpPathBuf, pcchPathBuf);
2780 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
2781 if (rc != ERROR_SUCCESS)
2782 return ERROR_INDEX_ABSENT;
2784 info = msi_reg_get_val_str( hkey, szQualifier );
2785 RegCloseKey(hkey);
2787 if (!info)
2788 return ERROR_INDEX_ABSENT;
2790 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
2792 if (!szProduct)
2793 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
2794 else
2795 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
2797 msi_free( info );
2799 if (rc != INSTALLSTATE_LOCAL)
2800 return ERROR_FILE_NOT_FOUND;
2802 return ERROR_SUCCESS;
2805 /***********************************************************************
2806 * MsiProvideQualifiedComponentExW [MSI.@]
2808 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
2809 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
2810 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
2811 LPDWORD pcchPathBuf)
2813 awstring path;
2815 path.unicode = TRUE;
2816 path.str.w = lpPathBuf;
2818 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
2819 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
2822 /***********************************************************************
2823 * MsiProvideQualifiedComponentExA [MSI.@]
2825 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
2826 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
2827 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
2828 LPDWORD pcchPathBuf)
2830 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
2831 UINT r = ERROR_OUTOFMEMORY;
2832 awstring path;
2834 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
2835 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
2836 Unused1, Unused2, lpPathBuf, pcchPathBuf);
2838 szwComponent = strdupAtoW( szComponent );
2839 if (szComponent && !szwComponent)
2840 goto end;
2842 szwQualifier = strdupAtoW( szQualifier );
2843 if (szQualifier && !szwQualifier)
2844 goto end;
2846 szwProduct = strdupAtoW( szProduct );
2847 if (szProduct && !szwProduct)
2848 goto end;
2850 path.unicode = FALSE;
2851 path.str.a = lpPathBuf;
2853 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
2854 dwInstallMode, szwProduct, Unused1,
2855 Unused2, &path, pcchPathBuf);
2856 end:
2857 msi_free(szwProduct);
2858 msi_free(szwComponent);
2859 msi_free(szwQualifier);
2861 return r;
2864 /***********************************************************************
2865 * MsiProvideQualifiedComponentW [MSI.@]
2867 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
2868 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
2869 LPDWORD pcchPathBuf)
2871 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
2872 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
2875 /***********************************************************************
2876 * MsiProvideQualifiedComponentA [MSI.@]
2878 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
2879 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
2880 LPDWORD pcchPathBuf)
2882 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
2883 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
2886 /***********************************************************************
2887 * MSI_GetUserInfo [internal]
2889 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
2890 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
2891 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2892 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
2894 WCHAR squished_pc[SQUISH_GUID_SIZE];
2895 LPWSTR user, org, serial;
2896 USERINFOSTATE state;
2897 HKEY hkey, props;
2898 LPCWSTR orgptr;
2899 UINT r;
2901 static const WCHAR szEmpty[] = {0};
2903 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
2904 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
2905 pcchSerialBuf);
2907 if (!szProduct || !squash_guid(szProduct, squished_pc))
2908 return USERINFOSTATE_INVALIDARG;
2910 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2911 &hkey, FALSE) != ERROR_SUCCESS &&
2912 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2913 &hkey, FALSE) != ERROR_SUCCESS &&
2914 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2915 &hkey, FALSE) != ERROR_SUCCESS)
2917 return USERINFOSTATE_UNKNOWN;
2920 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2921 NULL, &props, FALSE) != ERROR_SUCCESS &&
2922 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
2923 NULL, &props, FALSE) != ERROR_SUCCESS)
2925 RegCloseKey(hkey);
2926 return USERINFOSTATE_ABSENT;
2929 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
2930 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
2931 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
2932 state = USERINFOSTATE_ABSENT;
2934 RegCloseKey(hkey);
2935 RegCloseKey(props);
2937 if (user && serial)
2938 state = USERINFOSTATE_PRESENT;
2940 if (pcchUserNameBuf)
2942 if (lpUserNameBuf && !user)
2944 (*pcchUserNameBuf)--;
2945 goto done;
2948 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
2949 if (r == ERROR_MORE_DATA)
2951 state = USERINFOSTATE_MOREDATA;
2952 goto done;
2956 if (pcchOrgNameBuf)
2958 orgptr = org;
2959 if (!orgptr) orgptr = szEmpty;
2961 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
2962 if (r == ERROR_MORE_DATA)
2964 state = USERINFOSTATE_MOREDATA;
2965 goto done;
2969 if (pcchSerialBuf)
2971 if (!serial)
2973 (*pcchSerialBuf)--;
2974 goto done;
2977 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
2978 if (r == ERROR_MORE_DATA)
2979 state = USERINFOSTATE_MOREDATA;
2982 done:
2983 msi_free(user);
2984 msi_free(org);
2985 msi_free(serial);
2987 return state;
2990 /***********************************************************************
2991 * MsiGetUserInfoW [MSI.@]
2993 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
2994 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
2995 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
2996 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
2998 awstring user, org, serial;
3000 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3001 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3002 (lpSerialBuf && !pcchSerialBuf))
3003 return USERINFOSTATE_INVALIDARG;
3005 user.unicode = TRUE;
3006 user.str.w = lpUserNameBuf;
3007 org.unicode = TRUE;
3008 org.str.w = lpOrgNameBuf;
3009 serial.unicode = TRUE;
3010 serial.str.w = lpSerialBuf;
3012 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3013 &org, pcchOrgNameBuf,
3014 &serial, pcchSerialBuf );
3017 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3018 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3019 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3020 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3022 awstring user, org, serial;
3023 LPWSTR prod;
3024 UINT r;
3026 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3027 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3028 (lpSerialBuf && !pcchSerialBuf))
3029 return USERINFOSTATE_INVALIDARG;
3031 prod = strdupAtoW( szProduct );
3032 if (szProduct && !prod)
3033 return ERROR_OUTOFMEMORY;
3035 user.unicode = FALSE;
3036 user.str.a = lpUserNameBuf;
3037 org.unicode = FALSE;
3038 org.str.a = lpOrgNameBuf;
3039 serial.unicode = FALSE;
3040 serial.str.a = lpSerialBuf;
3042 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3043 &org, pcchOrgNameBuf,
3044 &serial, pcchSerialBuf );
3046 msi_free( prod );
3048 return r;
3051 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3053 MSIHANDLE handle;
3054 UINT rc;
3055 MSIPACKAGE *package;
3056 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3058 TRACE("(%s)\n",debugstr_w(szProduct));
3060 rc = MsiOpenProductW(szProduct,&handle);
3061 if (rc != ERROR_SUCCESS)
3062 return ERROR_INVALID_PARAMETER;
3064 /* MsiCollectUserInfo cannot be called from a custom action. */
3065 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3066 if (!package)
3067 return ERROR_CALL_NOT_IMPLEMENTED;
3069 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3070 msiobj_release( &package->hdr );
3072 MsiCloseHandle(handle);
3074 return rc;
3077 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3079 MSIHANDLE handle;
3080 UINT rc;
3081 MSIPACKAGE *package;
3082 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3084 TRACE("(%s)\n",debugstr_a(szProduct));
3086 rc = MsiOpenProductA(szProduct,&handle);
3087 if (rc != ERROR_SUCCESS)
3088 return ERROR_INVALID_PARAMETER;
3090 /* MsiCollectUserInfo cannot be called from a custom action. */
3091 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3092 if (!package)
3093 return ERROR_CALL_NOT_IMPLEMENTED;
3095 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3096 msiobj_release( &package->hdr );
3098 MsiCloseHandle(handle);
3100 return rc;
3103 /***********************************************************************
3104 * MsiConfigureFeatureA [MSI.@]
3106 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3108 LPWSTR prod, feat = NULL;
3109 UINT r = ERROR_OUTOFMEMORY;
3111 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3113 prod = strdupAtoW( szProduct );
3114 if (szProduct && !prod)
3115 goto end;
3117 feat = strdupAtoW( szFeature );
3118 if (szFeature && !feat)
3119 goto end;
3121 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3123 end:
3124 msi_free(feat);
3125 msi_free(prod);
3127 return r;
3130 /***********************************************************************
3131 * MsiConfigureFeatureW [MSI.@]
3133 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3135 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3136 MSIPACKAGE *package = NULL;
3137 UINT r;
3138 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3139 DWORD sz;
3141 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3143 if (!szProduct || !szFeature)
3144 return ERROR_INVALID_PARAMETER;
3146 switch (eInstallState)
3148 case INSTALLSTATE_DEFAULT:
3149 /* FIXME: how do we figure out the default location? */
3150 eInstallState = INSTALLSTATE_LOCAL;
3151 break;
3152 case INSTALLSTATE_LOCAL:
3153 case INSTALLSTATE_SOURCE:
3154 case INSTALLSTATE_ABSENT:
3155 case INSTALLSTATE_ADVERTISED:
3156 break;
3157 default:
3158 return ERROR_INVALID_PARAMETER;
3161 r = MSI_OpenProductW( szProduct, &package );
3162 if (r != ERROR_SUCCESS)
3163 return r;
3165 sz = sizeof(sourcepath);
3166 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3167 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3169 sz = sizeof(filename);
3170 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3171 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3173 lstrcatW( sourcepath, filename );
3175 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3177 r = ACTION_PerformUIAction( package, szCostInit, -1 );
3178 if (r != ERROR_SUCCESS)
3179 goto end;
3181 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3182 if (r != ERROR_SUCCESS)
3183 goto end;
3185 r = MSI_InstallPackage( package, sourcepath, NULL );
3187 end:
3188 msiobj_release( &package->hdr );
3190 return r;
3193 /***********************************************************************
3194 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3196 * Notes: undocumented
3198 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3200 WCHAR path[MAX_PATH];
3202 TRACE("%d\n", dwReserved);
3204 if (dwReserved)
3206 FIXME("dwReserved=%d\n", dwReserved);
3207 return ERROR_INVALID_PARAMETER;
3210 if (!GetWindowsDirectoryW(path, MAX_PATH))
3211 return ERROR_FUNCTION_FAILED;
3213 lstrcatW(path, installerW);
3215 if (!CreateDirectoryW(path, NULL))
3216 return ERROR_FUNCTION_FAILED;
3218 return ERROR_SUCCESS;
3221 /***********************************************************************
3222 * MsiGetShortcutTargetA [MSI.@]
3224 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3225 LPSTR szProductCode, LPSTR szFeatureId,
3226 LPSTR szComponentCode )
3228 LPWSTR target;
3229 const int len = MAX_FEATURE_CHARS+1;
3230 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3231 UINT r;
3233 target = strdupAtoW( szShortcutTarget );
3234 if (szShortcutTarget && !target )
3235 return ERROR_OUTOFMEMORY;
3236 product[0] = 0;
3237 feature[0] = 0;
3238 component[0] = 0;
3239 r = MsiGetShortcutTargetW( target, product, feature, component );
3240 msi_free( target );
3241 if (r == ERROR_SUCCESS)
3243 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3244 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3245 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3247 return r;
3250 /***********************************************************************
3251 * MsiGetShortcutTargetW [MSI.@]
3253 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3254 LPWSTR szProductCode, LPWSTR szFeatureId,
3255 LPWSTR szComponentCode )
3257 IShellLinkDataList *dl = NULL;
3258 IPersistFile *pf = NULL;
3259 LPEXP_DARWIN_LINK darwin = NULL;
3260 HRESULT r, init;
3262 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3263 szProductCode, szFeatureId, szComponentCode );
3265 init = CoInitialize(NULL);
3267 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3268 &IID_IPersistFile, (LPVOID*) &pf );
3269 if( SUCCEEDED( r ) )
3271 r = IPersistFile_Load( pf, szShortcutTarget,
3272 STGM_READ | STGM_SHARE_DENY_WRITE );
3273 if( SUCCEEDED( r ) )
3275 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3276 (LPVOID*) &dl );
3277 if( SUCCEEDED( r ) )
3279 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3280 (LPVOID) &darwin );
3281 IShellLinkDataList_Release( dl );
3284 IPersistFile_Release( pf );
3287 if (SUCCEEDED(init))
3288 CoUninitialize();
3290 TRACE("darwin = %p\n", darwin);
3292 if (darwin)
3294 DWORD sz;
3295 UINT ret;
3297 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3298 szProductCode, szFeatureId, szComponentCode, &sz );
3299 LocalFree( darwin );
3300 return ret;
3303 return ERROR_FUNCTION_FAILED;
3306 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
3307 DWORD dwReinstallMode )
3309 MSIPACKAGE* package = NULL;
3310 UINT r;
3311 WCHAR sourcepath[MAX_PATH];
3312 WCHAR filename[MAX_PATH];
3313 static const WCHAR szLogVerbose[] = {
3314 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3315 static const WCHAR szInstalled[] = { 'I','n','s','t','a','l','l','e','d',0};
3316 static const WCHAR szReinstall[] = {'R','E','I','N','S','T','A','L','L',0};
3317 static const WCHAR szReinstallMode[] = {'R','E','I','N','S','T','A','L','L','M','O','D','E',0};
3318 static const WCHAR szOne[] = {'1',0};
3319 WCHAR reinstallmode[11];
3320 LPWSTR ptr;
3321 DWORD sz;
3323 FIXME("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3324 dwReinstallMode);
3326 ptr = reinstallmode;
3328 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3329 *ptr++ = 'p';
3330 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3331 *ptr++ = 'o';
3332 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3333 *ptr++ = 'w';
3334 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3335 *ptr++ = 'd';
3336 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3337 *ptr++ = 'c';
3338 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3339 *ptr++ = 'a';
3340 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3341 *ptr++ = 'u';
3342 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3343 *ptr++ = 'm';
3344 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3345 *ptr++ = 's';
3346 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3347 *ptr++ = 'v';
3348 *ptr = 0;
3350 sz = sizeof(sourcepath);
3351 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3352 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3354 sz = sizeof(filename);
3355 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3356 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3358 lstrcatW( sourcepath, filename );
3360 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3361 r = MSI_OpenPackageW( sourcepath, &package );
3362 else
3363 r = MSI_OpenProductW( szProduct, &package );
3365 if (r != ERROR_SUCCESS)
3366 return r;
3368 MSI_SetPropertyW( package, szReinstallMode, reinstallmode );
3369 MSI_SetPropertyW( package, szInstalled, szOne );
3370 MSI_SetPropertyW( package, szLogVerbose, szOne );
3371 MSI_SetPropertyW( package, szReinstall, szFeature );
3373 r = MSI_InstallPackage( package, sourcepath, NULL );
3375 msiobj_release( &package->hdr );
3377 return r;
3380 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3381 DWORD dwReinstallMode )
3383 LPWSTR wszProduct;
3384 LPWSTR wszFeature;
3385 UINT rc;
3387 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3388 dwReinstallMode);
3390 wszProduct = strdupAtoW(szProduct);
3391 wszFeature = strdupAtoW(szFeature);
3393 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3395 msi_free(wszProduct);
3396 msi_free(wszFeature);
3397 return rc;
3400 typedef struct
3402 unsigned int i[2];
3403 unsigned int buf[4];
3404 unsigned char in[64];
3405 unsigned char digest[16];
3406 } MD5_CTX;
3408 extern VOID WINAPI MD5Init( MD5_CTX *);
3409 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
3410 extern VOID WINAPI MD5Final( MD5_CTX *);
3412 /***********************************************************************
3413 * MsiGetFileHashW [MSI.@]
3415 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
3416 PMSIFILEHASHINFO pHash )
3418 HANDLE handle, mapping;
3419 void *p;
3420 DWORD length;
3421 UINT r = ERROR_FUNCTION_FAILED;
3423 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
3425 if (!szFilePath)
3426 return ERROR_INVALID_PARAMETER;
3428 if (!*szFilePath)
3429 return ERROR_PATH_NOT_FOUND;
3431 if (dwOptions)
3432 return ERROR_INVALID_PARAMETER;
3433 if (!pHash)
3434 return ERROR_INVALID_PARAMETER;
3435 if (pHash->dwFileHashInfoSize < sizeof *pHash)
3436 return ERROR_INVALID_PARAMETER;
3438 handle = CreateFileW( szFilePath, GENERIC_READ,
3439 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
3440 if (handle == INVALID_HANDLE_VALUE)
3441 return ERROR_FILE_NOT_FOUND;
3443 length = GetFileSize( handle, NULL );
3445 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
3446 if (mapping)
3448 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
3449 if (p)
3451 MD5_CTX ctx;
3453 MD5Init( &ctx );
3454 MD5Update( &ctx, p, length );
3455 MD5Final( &ctx );
3456 UnmapViewOfFile( p );
3458 memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
3459 r = ERROR_SUCCESS;
3461 CloseHandle( mapping );
3463 CloseHandle( handle );
3465 return r;
3468 /***********************************************************************
3469 * MsiGetFileHashA [MSI.@]
3471 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
3472 PMSIFILEHASHINFO pHash )
3474 LPWSTR file;
3475 UINT r;
3477 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
3479 file = strdupAtoW( szFilePath );
3480 if (szFilePath && !file)
3481 return ERROR_OUTOFMEMORY;
3483 r = MsiGetFileHashW( file, dwOptions, pHash );
3484 msi_free( file );
3485 return r;
3488 /***********************************************************************
3489 * MsiAdvertiseScriptW [MSI.@]
3491 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
3492 PHKEY phRegData, BOOL fRemoveItems )
3494 FIXME("%s %08x %p %d\n",
3495 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3496 return ERROR_CALL_NOT_IMPLEMENTED;
3499 /***********************************************************************
3500 * MsiAdvertiseScriptA [MSI.@]
3502 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
3503 PHKEY phRegData, BOOL fRemoveItems )
3505 FIXME("%s %08x %p %d\n",
3506 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3507 return ERROR_CALL_NOT_IMPLEMENTED;
3510 /***********************************************************************
3511 * MsiIsProductElevatedW [MSI.@]
3513 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
3515 FIXME("%s %p - stub\n",
3516 debugstr_w( szProduct ), pfElevated );
3517 *pfElevated = TRUE;
3518 return ERROR_SUCCESS;
3521 /***********************************************************************
3522 * MsiIsProductElevatedA [MSI.@]
3524 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
3526 FIXME("%s %p - stub\n",
3527 debugstr_a( szProduct ), pfElevated );
3528 *pfElevated = TRUE;
3529 return ERROR_SUCCESS;
3532 /***********************************************************************
3533 * MsiSetExternalUIRecord [MSI.@]
3535 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD puiHandler,
3536 DWORD dwMessageFilter, LPVOID pvContext,
3537 PINSTALLUI_HANDLER_RECORD ppuiPrevHandler)
3539 FIXME("%p %08x %p %p\n", puiHandler, dwMessageFilter ,pvContext,
3540 ppuiPrevHandler);
3541 return ERROR_CALL_NOT_IMPLEMENTED;
3544 /***********************************************************************
3545 * MsiInstallMissingComponentW [MSI.@]
3547 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
3549 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
3550 return ERROR_SUCCESS;