msi: Implement and test MsiEnumComponentCostsA/W.
[wine/wine-gecko.git] / dlls / msi / msi.c
blob44a4e210466da4fc8e2d4d4e83003f78eee4f9d1
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "shlwapi.h"
31 #include "msi.h"
32 #include "msidefs.h"
33 #include "msiquery.h"
34 #include "msipriv.h"
35 #include "wincrypt.h"
36 #include "winver.h"
37 #include "winuser.h"
38 #include "shlobj.h"
39 #include "shobjidl.h"
40 #include "objidl.h"
41 #include "wintrust.h"
42 #include "softpub.h"
44 #include "wine/debug.h"
45 #include "wine/unicode.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi);
49 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
51 static UINT msi_locate_product(LPCWSTR szProduct, MSIINSTALLCONTEXT *context)
53 HKEY hkey = NULL;
55 *context = MSIINSTALLCONTEXT_NONE;
57 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
58 &hkey, FALSE) == ERROR_SUCCESS)
59 *context = MSIINSTALLCONTEXT_USERMANAGED;
60 else if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
61 &hkey, FALSE) == ERROR_SUCCESS)
62 *context = MSIINSTALLCONTEXT_MACHINE;
63 else if (MSIREG_OpenProductKey(szProduct, NULL,
64 MSIINSTALLCONTEXT_USERUNMANAGED,
65 &hkey, FALSE) == ERROR_SUCCESS)
66 *context = MSIINSTALLCONTEXT_USERUNMANAGED;
68 RegCloseKey(hkey);
70 if (*context == MSIINSTALLCONTEXT_NONE)
71 return ERROR_UNKNOWN_PRODUCT;
73 return ERROR_SUCCESS;
76 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
78 UINT r;
79 LPWSTR szwProd = NULL;
81 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
83 if( szProduct )
85 szwProd = strdupAtoW( szProduct );
86 if( !szwProd )
87 return ERROR_OUTOFMEMORY;
90 r = MsiOpenProductW( szwProd, phProduct );
92 msi_free( szwProd );
94 return r;
97 static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
99 UINT r;
100 HKEY props;
101 LPWSTR path;
102 MSIINSTALLCONTEXT context;
104 static const WCHAR managed[] = {
105 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
106 static const WCHAR local[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
108 TRACE("%s %p\n", debugstr_w(szProduct), package);
110 r = msi_locate_product(szProduct, &context);
111 if (r != ERROR_SUCCESS)
112 return r;
114 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &props, FALSE);
115 if (r != ERROR_SUCCESS)
116 return ERROR_UNKNOWN_PRODUCT;
118 if (context == MSIINSTALLCONTEXT_USERMANAGED)
119 path = msi_reg_get_val_str(props, managed);
120 else
121 path = msi_reg_get_val_str(props, local);
123 r = ERROR_UNKNOWN_PRODUCT;
125 if (!path || GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
126 goto done;
128 if (PathIsRelativeW(path))
130 r = ERROR_INSTALL_PACKAGE_OPEN_FAILED;
131 goto done;
134 r = MSI_OpenPackageW(path, package);
136 done:
137 RegCloseKey(props);
138 msi_free(path);
139 return r;
142 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
144 MSIPACKAGE *package = NULL;
145 WCHAR squished_pc[GUID_SIZE];
146 UINT r;
148 if (!szProduct || !squash_guid(szProduct, squished_pc))
149 return ERROR_INVALID_PARAMETER;
151 if (!phProduct)
152 return ERROR_INVALID_PARAMETER;
154 r = MSI_OpenProductW(szProduct, &package);
155 if (r != ERROR_SUCCESS)
156 return r;
158 *phProduct = alloc_msihandle(&package->hdr);
159 if (!*phProduct)
160 r = ERROR_NOT_ENOUGH_MEMORY;
162 msiobj_release(&package->hdr);
163 return r;
166 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
167 LPCSTR szTransforms, LANGID lgidLanguage)
169 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
170 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
171 return ERROR_CALL_NOT_IMPLEMENTED;
174 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
175 LPCWSTR szTransforms, LANGID lgidLanguage)
177 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
178 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
179 return ERROR_CALL_NOT_IMPLEMENTED;
182 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
183 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
185 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
186 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
187 lgidLanguage, dwPlatform, dwOptions);
188 return ERROR_CALL_NOT_IMPLEMENTED;
191 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
192 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
194 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
195 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
196 lgidLanguage, dwPlatform, dwOptions);
197 return ERROR_CALL_NOT_IMPLEMENTED;
200 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
202 LPWSTR szwPath = NULL, szwCommand = NULL;
203 UINT r = ERROR_OUTOFMEMORY;
205 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
207 if( szPackagePath )
209 szwPath = strdupAtoW( szPackagePath );
210 if( !szwPath )
211 goto end;
214 if( szCommandLine )
216 szwCommand = strdupAtoW( szCommandLine );
217 if( !szwCommand )
218 goto end;
221 r = MsiInstallProductW( szwPath, szwCommand );
223 end:
224 msi_free( szwPath );
225 msi_free( szwCommand );
227 return r;
230 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
232 MSIPACKAGE *package = NULL;
233 UINT r;
235 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
237 if (!szPackagePath)
238 return ERROR_INVALID_PARAMETER;
240 if (!*szPackagePath)
241 return ERROR_PATH_NOT_FOUND;
243 r = MSI_OpenPackageW( szPackagePath, &package );
244 if (r == ERROR_SUCCESS)
246 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
247 msiobj_release( &package->hdr );
250 return r;
253 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
255 LPWSTR wszProduct;
256 UINT rc;
258 TRACE("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
260 wszProduct = strdupAtoW(szProduct);
262 rc = MsiReinstallProductW(wszProduct, dwReinstallMode);
264 msi_free(wszProduct);
265 return rc;
268 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
270 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
272 return MsiReinstallFeatureW(szProduct, szAll, dwReinstallMode);
275 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
276 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
278 LPWSTR patch_package = NULL;
279 LPWSTR install_package = NULL;
280 LPWSTR command_line = NULL;
281 UINT r = ERROR_OUTOFMEMORY;
283 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
284 eInstallType, debugstr_a(szCommandLine));
286 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
287 goto done;
289 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
290 goto done;
292 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
293 goto done;
295 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
297 done:
298 msi_free(patch_package);
299 msi_free(install_package);
300 msi_free(command_line);
302 return r;
306 static UINT get_patch_product_codes( LPCWSTR szPatchPackage, WCHAR ***product_codes )
308 MSIHANDLE patch, info = 0;
309 UINT r, type;
310 DWORD size;
311 static WCHAR empty[] = {0};
312 WCHAR *codes = NULL;
314 r = MsiOpenDatabaseW( szPatchPackage, MSIDBOPEN_READONLY, &patch );
315 if (r != ERROR_SUCCESS)
316 return r;
318 r = MsiGetSummaryInformationW( patch, NULL, 0, &info );
319 if (r != ERROR_SUCCESS)
320 goto done;
322 size = 0;
323 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, empty, &size );
324 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
326 ERR("Failed to read product codes from patch\n");
327 r = ERROR_FUNCTION_FAILED;
328 goto done;
331 codes = msi_alloc( ++size * sizeof(WCHAR) );
332 if (!codes)
334 r = ERROR_OUTOFMEMORY;
335 goto done;
338 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, codes, &size );
339 if (r == ERROR_SUCCESS)
340 *product_codes = msi_split_string( codes, ';' );
342 done:
343 MsiCloseHandle( info );
344 MsiCloseHandle( patch );
345 msi_free( codes );
346 return r;
349 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
351 UINT r, i;
352 DWORD size;
353 LPCWSTR cmd_ptr = szCommandLine;
354 LPWSTR cmd, *codes = NULL;
355 BOOL succeeded = FALSE;
357 static const WCHAR fmt[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
358 static WCHAR empty[] = {0};
360 if (!szPatchPackage || !szPatchPackage[0])
361 return ERROR_INVALID_PARAMETER;
363 if (!szProductCode && (r = get_patch_product_codes( szPatchPackage, &codes )))
364 return r;
366 if (!szCommandLine)
367 cmd_ptr = empty;
369 size = strlenW(cmd_ptr) + strlenW(fmt) + strlenW(szPatchPackage) + 1;
370 cmd = msi_alloc(size * sizeof(WCHAR));
371 if (!cmd)
373 msi_free(codes);
374 return ERROR_OUTOFMEMORY;
376 sprintfW(cmd, fmt, cmd_ptr, szPatchPackage);
378 if (szProductCode)
379 r = MsiConfigureProductExW(szProductCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
380 else
382 for (i = 0; codes[i]; i++)
384 r = MsiConfigureProductExW(codes[i], INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
385 if (r == ERROR_SUCCESS)
387 TRACE("patch applied\n");
388 succeeded = TRUE;
392 if (succeeded)
393 r = ERROR_SUCCESS;
396 msi_free(cmd);
397 msi_free(codes);
398 return r;
401 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
402 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
404 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
405 eInstallType, debugstr_w(szCommandLine));
407 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
408 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
410 FIXME("Only reading target products from patch\n");
411 return ERROR_CALL_NOT_IMPLEMENTED;
414 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
417 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
418 LPCSTR szProductCode, LPCSTR szPropertiesList)
420 LPWSTR patch_packages = NULL;
421 LPWSTR product_code = NULL;
422 LPWSTR properties_list = NULL;
423 UINT r = ERROR_OUTOFMEMORY;
425 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
426 debugstr_a(szPropertiesList));
428 if (!szPatchPackages || !szPatchPackages[0])
429 return ERROR_INVALID_PARAMETER;
431 if (!(patch_packages = strdupAtoW(szPatchPackages)))
432 return ERROR_OUTOFMEMORY;
434 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
435 goto done;
437 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
438 goto done;
440 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
442 done:
443 msi_free(patch_packages);
444 msi_free(product_code);
445 msi_free(properties_list);
447 return r;
450 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
451 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
453 UINT r = ERROR_SUCCESS;
454 LPCWSTR beg, end;
456 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
457 debugstr_w(szPropertiesList));
459 if (!szPatchPackages || !szPatchPackages[0])
460 return ERROR_INVALID_PARAMETER;
462 beg = end = szPatchPackages;
463 while (*beg)
465 DWORD len;
466 LPWSTR patch;
468 while (*beg == ' ') beg++;
469 while (*end && *end != ';') end++;
471 len = end - beg;
472 while (len && beg[len - 1] == ' ') len--;
474 if (!len) return ERROR_INVALID_NAME;
476 patch = msi_alloc((len + 1) * sizeof(WCHAR));
477 if (!patch)
478 return ERROR_OUTOFMEMORY;
480 memcpy(patch, beg, len * sizeof(WCHAR));
481 patch[len] = '\0';
483 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
484 msi_free(patch);
486 if (r != ERROR_SUCCESS)
487 break;
489 beg = ++end;
491 return r;
494 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
495 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
497 UINT i, r;
498 WCHAR *package_path = NULL;
499 MSIPATCHSEQUENCEINFOW *psi;
501 TRACE("(%s, %d, %p)\n", debugstr_a(szProductPackagePath), cPatchInfo, pPatchInfo);
503 if (szProductPackagePath && !(package_path = strdupAtoW( szProductPackagePath )))
504 return ERROR_OUTOFMEMORY;
506 psi = msi_alloc( cPatchInfo * sizeof(*psi) );
507 if (!psi)
509 msi_free( package_path );
510 return ERROR_OUTOFMEMORY;
513 for (i = 0; i < cPatchInfo; i++)
515 psi[i].szPatchData = strdupAtoW( pPatchInfo[i].szPatchData );
516 psi[i].ePatchDataType = pPatchInfo[i].ePatchDataType;
519 r = MsiDetermineApplicablePatchesW( package_path, cPatchInfo, psi );
520 if (r == ERROR_SUCCESS)
522 for (i = 0; i < cPatchInfo; i++)
524 pPatchInfo[i].dwOrder = psi[i].dwOrder;
525 pPatchInfo[i].uStatus = psi[i].uStatus;
529 msi_free( package_path );
530 for (i = 0; i < cPatchInfo; i++)
531 msi_free( (WCHAR *)psi[i].szPatchData );
532 msi_free( psi );
533 return r;
536 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
538 MSISUMMARYINFO *si;
539 MSIDATABASE *patch_db;
540 UINT r = ERROR_SUCCESS;
542 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
543 if (r != ERROR_SUCCESS)
545 WARN("failed to open patch file %s\n", debugstr_w(patch));
546 return r;
549 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
550 if (!si)
552 msiobj_release( &patch_db->hdr );
553 return ERROR_FUNCTION_FAILED;
556 r = msi_check_patch_applicable( package, si );
557 if (r != ERROR_SUCCESS)
558 TRACE("patch not applicable\n");
560 msiobj_release( &patch_db->hdr );
561 msiobj_release( &si->hdr );
562 return r;
565 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
566 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
568 UINT i, r, ret = ERROR_FUNCTION_FAILED;
569 MSIPACKAGE *package;
571 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
573 r = MSI_OpenPackageW( szProductPackagePath, &package );
574 if (r != ERROR_SUCCESS)
576 ERR("failed to open package %u\n", r);
577 return r;
580 for (i = 0; i < cPatchInfo; i++)
582 switch (pPatchInfo[i].ePatchDataType)
584 case MSIPATCH_DATATYPE_PATCHFILE:
586 FIXME("patch ordering not supported\n");
587 r = MSI_ApplicablePatchW( package, pPatchInfo[i].szPatchData );
588 if (r != ERROR_SUCCESS)
590 pPatchInfo[i].dwOrder = ~0u;
591 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
593 else
595 pPatchInfo[i].dwOrder = i;
596 pPatchInfo[i].uStatus = ret = ERROR_SUCCESS;
598 break;
600 default:
602 FIXME("patch data type %u not supported\n", pPatchInfo[i].ePatchDataType);
603 pPatchInfo[i].dwOrder = ~0u;
604 pPatchInfo[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
605 break;
609 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo[i].szPatchData));
610 TRACE("ePatchDataType: %u\n", pPatchInfo[i].ePatchDataType);
611 TRACE(" dwOrder: %u\n", pPatchInfo[i].dwOrder);
612 TRACE(" uStatus: %u\n", pPatchInfo[i].uStatus);
614 return ret;
617 UINT WINAPI MsiDeterminePatchSequenceA(LPCSTR szProductCode, LPCSTR szUserSid,
618 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
620 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode),
621 debugstr_a(szUserSid), dwContext, cPatchInfo, pPatchInfo);
623 return ERROR_CALL_NOT_IMPLEMENTED;
626 UINT WINAPI MsiDeterminePatchSequenceW(LPCWSTR szProductCode, LPCWSTR szUserSid,
627 MSIINSTALLCONTEXT dwContext, DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
629 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode),
630 debugstr_w(szUserSid), dwContext, cPatchInfo, pPatchInfo);
632 return ERROR_CALL_NOT_IMPLEMENTED;
635 static UINT msi_open_package(LPCWSTR product, MSIINSTALLCONTEXT context,
636 MSIPACKAGE **package)
638 UINT r;
639 DWORD sz;
640 HKEY props;
641 LPWSTR localpack;
642 WCHAR sourcepath[MAX_PATH];
643 WCHAR filename[MAX_PATH];
645 r = MSIREG_OpenInstallProps(product, context, NULL, &props, FALSE);
646 if (r != ERROR_SUCCESS)
647 return ERROR_BAD_CONFIGURATION;
649 localpack = msi_reg_get_val_str(props, szLocalPackage);
650 if (localpack)
652 lstrcpyW(sourcepath, localpack);
653 msi_free(localpack);
656 if (!localpack || GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
658 sz = sizeof(sourcepath);
659 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
660 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
662 sz = sizeof(filename);
663 MsiSourceListGetInfoW(product, NULL, context, MSICODE_PRODUCT,
664 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
666 lstrcatW(sourcepath, filename);
669 if (GetFileAttributesW(sourcepath) == INVALID_FILE_ATTRIBUTES)
670 return ERROR_INSTALL_SOURCE_ABSENT;
672 return MSI_OpenPackageW(sourcepath, package);
675 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
676 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
678 MSIPACKAGE* package = NULL;
679 MSIINSTALLCONTEXT context;
680 UINT r;
681 DWORD sz;
682 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
683 LPWSTR commandline;
685 static const WCHAR szInstalled[] = {
686 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
687 static const WCHAR szInstallLevel[] = {
688 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
689 static const WCHAR szRemoveAll[] = {
690 ' ','R','E','M','O','V','E','=','A','L','L',0};
691 static const WCHAR szMachine[] = {
692 ' ','A','L','L','U','S','E','R','S','=','1',0};
694 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
695 debugstr_w(szCommandLine));
697 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
698 return ERROR_INVALID_PARAMETER;
700 if (eInstallState == INSTALLSTATE_ADVERTISED ||
701 eInstallState == INSTALLSTATE_SOURCE)
703 FIXME("State %d not implemented\n", eInstallState);
704 return ERROR_CALL_NOT_IMPLEMENTED;
707 r = msi_locate_product(szProduct, &context);
708 if (r != ERROR_SUCCESS)
709 return r;
711 r = msi_open_package(szProduct, context, &package);
712 if (r != ERROR_SUCCESS)
713 return r;
715 sz = lstrlenW(szInstalled) + 1;
717 if (szCommandLine)
718 sz += lstrlenW(szCommandLine);
720 if (eInstallState != INSTALLSTATE_DEFAULT)
721 sz += lstrlenW(szInstallLevel);
723 if (eInstallState == INSTALLSTATE_ABSENT)
724 sz += lstrlenW(szRemoveAll);
726 if (context == MSIINSTALLCONTEXT_MACHINE)
727 sz += lstrlenW(szMachine);
729 commandline = msi_alloc(sz * sizeof(WCHAR));
730 if (!commandline)
732 r = ERROR_OUTOFMEMORY;
733 goto end;
736 commandline[0] = 0;
737 if (szCommandLine)
738 lstrcpyW(commandline,szCommandLine);
740 if (eInstallState != INSTALLSTATE_DEFAULT)
741 lstrcatW(commandline, szInstallLevel);
743 if (eInstallState == INSTALLSTATE_ABSENT)
744 lstrcatW(commandline, szRemoveAll);
746 if (context == MSIINSTALLCONTEXT_MACHINE)
747 lstrcatW(commandline, szMachine);
749 sz = sizeof(sourcepath);
750 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
751 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
753 sz = sizeof(filename);
754 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
755 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
757 strcatW(sourcepath, filename);
759 r = MSI_InstallPackage( package, sourcepath, commandline );
761 msi_free(commandline);
763 end:
764 msiobj_release( &package->hdr );
766 return r;
769 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
770 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
772 LPWSTR szwProduct = NULL;
773 LPWSTR szwCommandLine = NULL;
774 UINT r = ERROR_OUTOFMEMORY;
776 if( szProduct )
778 szwProduct = strdupAtoW( szProduct );
779 if( !szwProduct )
780 goto end;
783 if( szCommandLine)
785 szwCommandLine = strdupAtoW( szCommandLine );
786 if( !szwCommandLine)
787 goto end;
790 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
791 szwCommandLine );
792 end:
793 msi_free( szwProduct );
794 msi_free( szwCommandLine);
796 return r;
799 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
800 INSTALLSTATE eInstallState)
802 LPWSTR szwProduct = NULL;
803 UINT r;
805 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
807 if( szProduct )
809 szwProduct = strdupAtoW( szProduct );
810 if( !szwProduct )
811 return ERROR_OUTOFMEMORY;
814 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
815 msi_free( szwProduct );
817 return r;
820 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
821 INSTALLSTATE eInstallState)
823 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
826 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
828 LPWSTR szwComponent = NULL;
829 UINT r;
830 WCHAR szwBuffer[GUID_SIZE];
832 TRACE("%s %p\n", debugstr_a(szComponent), szBuffer);
834 if( szComponent )
836 szwComponent = strdupAtoW( szComponent );
837 if( !szwComponent )
838 return ERROR_OUTOFMEMORY;
841 *szwBuffer = '\0';
842 r = MsiGetProductCodeW( szwComponent, szwBuffer );
844 if(*szwBuffer)
845 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
847 msi_free( szwComponent );
849 return r;
852 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
854 UINT rc, index;
855 HKEY compkey, prodkey;
856 WCHAR squished_comp[GUID_SIZE];
857 WCHAR squished_prod[GUID_SIZE];
858 DWORD sz = GUID_SIZE;
860 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
862 if (!szComponent || !*szComponent)
863 return ERROR_INVALID_PARAMETER;
865 if (!squash_guid(szComponent, squished_comp))
866 return ERROR_INVALID_PARAMETER;
868 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
869 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
871 return ERROR_UNKNOWN_COMPONENT;
874 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
875 if (rc != ERROR_SUCCESS)
877 RegCloseKey(compkey);
878 return ERROR_UNKNOWN_COMPONENT;
881 /* check simple case, only one product */
882 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
883 if (rc == ERROR_NO_MORE_ITEMS)
885 rc = ERROR_SUCCESS;
886 goto done;
889 index = 0;
890 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
891 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
893 index++;
894 sz = GUID_SIZE;
895 unsquash_guid(squished_prod, szBuffer);
897 if (MSIREG_OpenProductKey(szBuffer, NULL,
898 MSIINSTALLCONTEXT_USERMANAGED,
899 &prodkey, FALSE) == ERROR_SUCCESS ||
900 MSIREG_OpenProductKey(szBuffer, NULL,
901 MSIINSTALLCONTEXT_USERUNMANAGED,
902 &prodkey, FALSE) == ERROR_SUCCESS ||
903 MSIREG_OpenProductKey(szBuffer, NULL,
904 MSIINSTALLCONTEXT_MACHINE,
905 &prodkey, FALSE) == ERROR_SUCCESS)
907 RegCloseKey(prodkey);
908 rc = ERROR_SUCCESS;
909 goto done;
913 rc = ERROR_INSTALL_FAILURE;
915 done:
916 RegCloseKey(compkey);
917 unsquash_guid(squished_prod, szBuffer);
918 return rc;
921 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
923 DWORD dval;
924 LONG res;
925 WCHAR temp[20];
927 static const WCHAR format[] = {'%','d',0};
929 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
930 if (res != ERROR_SUCCESS)
931 return NULL;
933 if (*type == REG_SZ)
934 return msi_reg_get_val_str(hkey, name);
936 if (!msi_reg_get_val_dword(hkey, name, &dval))
937 return NULL;
939 sprintfW(temp, format, dval);
940 return strdupW(temp);
943 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
944 awstring *szValue, LPDWORD pcchValueBuf)
946 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
947 UINT r = ERROR_UNKNOWN_PROPERTY;
948 HKEY prodkey, userdata, source;
949 LPWSTR val = NULL;
950 WCHAR squished_pc[GUID_SIZE];
951 WCHAR packagecode[GUID_SIZE];
952 BOOL badconfig = FALSE;
953 LONG res;
954 DWORD type = REG_NONE;
956 static WCHAR empty[] = {0};
957 static const WCHAR sourcelist[] = {
958 'S','o','u','r','c','e','L','i','s','t',0};
959 static const WCHAR display_name[] = {
960 'D','i','s','p','l','a','y','N','a','m','e',0};
961 static const WCHAR display_version[] = {
962 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
963 static const WCHAR assignment[] = {
964 'A','s','s','i','g','n','m','e','n','t',0};
966 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
967 debugstr_w(szAttribute), szValue, pcchValueBuf);
969 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
970 return ERROR_INVALID_PARAMETER;
972 if (!squash_guid(szProduct, squished_pc))
973 return ERROR_INVALID_PARAMETER;
975 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
976 MSIINSTALLCONTEXT_USERMANAGED,
977 &prodkey, FALSE)) != ERROR_SUCCESS &&
978 (r = MSIREG_OpenProductKey(szProduct, NULL,
979 MSIINSTALLCONTEXT_USERUNMANAGED,
980 &prodkey, FALSE)) != ERROR_SUCCESS &&
981 (r = MSIREG_OpenProductKey(szProduct, NULL,
982 MSIINSTALLCONTEXT_MACHINE,
983 &prodkey, FALSE)) == ERROR_SUCCESS)
985 context = MSIINSTALLCONTEXT_MACHINE;
988 MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
990 if (!strcmpW( szAttribute, INSTALLPROPERTY_HELPLINKW ) ||
991 !strcmpW( szAttribute, INSTALLPROPERTY_HELPTELEPHONEW ) ||
992 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLDATEW ) ||
993 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
994 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
995 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLSOURCEW ) ||
996 !strcmpW( szAttribute, INSTALLPROPERTY_LOCALPACKAGEW ) ||
997 !strcmpW( szAttribute, INSTALLPROPERTY_PUBLISHERW ) ||
998 !strcmpW( szAttribute, INSTALLPROPERTY_URLINFOABOUTW ) ||
999 !strcmpW( szAttribute, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1000 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMINORW ) ||
1001 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMAJORW ) ||
1002 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1003 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTIDW ) ||
1004 !strcmpW( szAttribute, INSTALLPROPERTY_REGCOMPANYW ) ||
1005 !strcmpW( szAttribute, INSTALLPROPERTY_REGOWNERW ))
1007 if (!prodkey)
1009 r = ERROR_UNKNOWN_PRODUCT;
1010 goto done;
1013 if (!userdata)
1014 return ERROR_UNKNOWN_PROPERTY;
1016 if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1017 szAttribute = display_name;
1018 else if (!strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ))
1019 szAttribute = display_version;
1021 val = msi_reg_get_value(userdata, szAttribute, &type);
1022 if (!val)
1023 val = empty;
1025 else if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTANCETYPEW ) ||
1026 !strcmpW( szAttribute, INSTALLPROPERTY_TRANSFORMSW ) ||
1027 !strcmpW( szAttribute, INSTALLPROPERTY_LANGUAGEW ) ||
1028 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1029 !strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ) ||
1030 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ) ||
1031 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONW ) ||
1032 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTICONW ) ||
1033 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ) ||
1034 !strcmpW( szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1036 if (!prodkey)
1038 r = ERROR_UNKNOWN_PRODUCT;
1039 goto done;
1042 if (!strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1043 szAttribute = assignment;
1045 if (!strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ))
1047 res = RegOpenKeyW(prodkey, sourcelist, &source);
1048 if (res != ERROR_SUCCESS)
1050 r = ERROR_UNKNOWN_PRODUCT;
1051 goto done;
1054 val = msi_reg_get_value(source, szAttribute, &type);
1055 if (!val)
1056 val = empty;
1058 RegCloseKey(source);
1060 else
1062 val = msi_reg_get_value(prodkey, szAttribute, &type);
1063 if (!val)
1064 val = empty;
1067 if (val != empty && type != REG_DWORD &&
1068 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ))
1070 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1071 badconfig = TRUE;
1072 else
1074 unsquash_guid(val, packagecode);
1075 msi_free(val);
1076 val = strdupW(packagecode);
1081 if (!val)
1083 r = ERROR_UNKNOWN_PROPERTY;
1084 goto done;
1087 if (pcchValueBuf)
1089 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1090 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1091 * can't rely on its value.
1093 if (szValue->str.a || szValue->str.w)
1095 DWORD size = *pcchValueBuf;
1096 if (strlenW(val) < size)
1097 r = msi_strcpy_to_awstring(val, szValue, &size);
1098 else
1100 r = ERROR_MORE_DATA;
1104 if (!badconfig)
1105 *pcchValueBuf = lstrlenW(val);
1108 if (badconfig)
1109 r = ERROR_BAD_CONFIGURATION;
1111 if (val != empty)
1112 msi_free(val);
1114 done:
1115 RegCloseKey(prodkey);
1116 RegCloseKey(userdata);
1117 return r;
1120 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1121 LPSTR szBuffer, LPDWORD pcchValueBuf)
1123 LPWSTR szwProduct, szwAttribute = NULL;
1124 UINT r = ERROR_OUTOFMEMORY;
1125 awstring buffer;
1127 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1128 szBuffer, pcchValueBuf);
1130 szwProduct = strdupAtoW( szProduct );
1131 if( szProduct && !szwProduct )
1132 goto end;
1134 szwAttribute = strdupAtoW( szAttribute );
1135 if( szAttribute && !szwAttribute )
1136 goto end;
1138 buffer.unicode = FALSE;
1139 buffer.str.a = szBuffer;
1141 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1142 &buffer, pcchValueBuf );
1144 end:
1145 msi_free( szwProduct );
1146 msi_free( szwAttribute );
1148 return r;
1151 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1152 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1154 awstring buffer;
1156 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1157 szBuffer, pcchValueBuf);
1159 buffer.unicode = TRUE;
1160 buffer.str.w = szBuffer;
1162 return MSI_GetProductInfo( szProduct, szAttribute,
1163 &buffer, pcchValueBuf );
1166 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1167 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1168 LPSTR szValue, LPDWORD pcchValue)
1170 LPWSTR product = NULL;
1171 LPWSTR usersid = NULL;
1172 LPWSTR property = NULL;
1173 LPWSTR value = NULL;
1174 DWORD len = 0;
1175 UINT r;
1177 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1178 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1179 szValue, pcchValue);
1181 if (szValue && !pcchValue)
1182 return ERROR_INVALID_PARAMETER;
1184 if (szProductCode) product = strdupAtoW(szProductCode);
1185 if (szUserSid) usersid = strdupAtoW(szUserSid);
1186 if (szProperty) property = strdupAtoW(szProperty);
1188 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1189 NULL, &len);
1190 if (r != ERROR_SUCCESS)
1191 goto done;
1193 value = msi_alloc(++len * sizeof(WCHAR));
1194 if (!value)
1196 r = ERROR_OUTOFMEMORY;
1197 goto done;
1200 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1201 value, &len);
1202 if (r != ERROR_SUCCESS)
1203 goto done;
1205 if (!pcchValue)
1206 goto done;
1208 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1209 if (*pcchValue >= len)
1210 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1211 else if (szValue)
1213 r = ERROR_MORE_DATA;
1214 if (*pcchValue > 0)
1215 *szValue = '\0';
1218 if (*pcchValue <= len || !szValue)
1219 len = len * sizeof(WCHAR) - 1;
1221 *pcchValue = len - 1;
1223 done:
1224 msi_free(product);
1225 msi_free(usersid);
1226 msi_free(property);
1227 msi_free(value);
1229 return r;
1232 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1234 UINT r = ERROR_SUCCESS;
1236 if (!val)
1237 return ERROR_UNKNOWN_PROPERTY;
1239 if (out)
1241 if (strlenW(val) >= *size)
1243 r = ERROR_MORE_DATA;
1244 if (*size > 0)
1245 *out = '\0';
1247 else
1248 lstrcpyW(out, val);
1251 if (size)
1252 *size = lstrlenW(val);
1254 return r;
1257 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1258 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1259 LPWSTR szValue, LPDWORD pcchValue)
1261 WCHAR squished_pc[GUID_SIZE];
1262 LPWSTR val = NULL;
1263 LPCWSTR package = NULL;
1264 HKEY props = NULL, prod;
1265 HKEY classes = NULL, managed;
1266 HKEY hkey = NULL;
1267 DWORD type;
1268 UINT r = ERROR_UNKNOWN_PRODUCT;
1270 static const WCHAR five[] = {'5',0};
1271 static const WCHAR displayname[] = {
1272 'D','i','s','p','l','a','y','N','a','m','e',0};
1273 static const WCHAR displayversion[] = {
1274 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1275 static const WCHAR managed_local_package[] = {
1276 'M','a','n','a','g','e','d','L','o','c','a','l',
1277 'P','a','c','k','a','g','e',0};
1279 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1280 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1281 szValue, pcchValue);
1283 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1284 return ERROR_INVALID_PARAMETER;
1286 if (szValue && !pcchValue)
1287 return ERROR_INVALID_PARAMETER;
1289 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1290 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1291 dwContext != MSIINSTALLCONTEXT_MACHINE)
1292 return ERROR_INVALID_PARAMETER;
1294 if (!szProperty || !*szProperty)
1295 return ERROR_INVALID_PARAMETER;
1297 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1298 return ERROR_INVALID_PARAMETER;
1300 /* FIXME: dwContext is provided, no need to search for it */
1301 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1302 &managed, FALSE);
1303 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1304 &prod, FALSE);
1306 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1308 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1310 package = INSTALLPROPERTY_LOCALPACKAGEW;
1312 if (!props && !prod)
1313 goto done;
1315 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1317 package = managed_local_package;
1319 if (!props && !managed)
1320 goto done;
1322 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1324 package = INSTALLPROPERTY_LOCALPACKAGEW;
1325 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1327 if (!props && !classes)
1328 goto done;
1331 if (!strcmpW( szProperty, INSTALLPROPERTY_HELPLINKW ) ||
1332 !strcmpW( szProperty, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1333 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ) ||
1334 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1335 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1336 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1337 !strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1338 !strcmpW( szProperty, INSTALLPROPERTY_PUBLISHERW ) ||
1339 !strcmpW( szProperty, INSTALLPROPERTY_URLINFOABOUTW ) ||
1340 !strcmpW( szProperty, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1341 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMINORW ) ||
1342 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMAJORW ) ||
1343 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1344 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTIDW ) ||
1345 !strcmpW( szProperty, INSTALLPROPERTY_REGCOMPANYW ) ||
1346 !strcmpW( szProperty, INSTALLPROPERTY_REGOWNERW ) ||
1347 !strcmpW( szProperty, INSTALLPROPERTY_INSTANCETYPEW ))
1349 val = msi_reg_get_value(props, package, &type);
1350 if (!val)
1352 if (prod || classes)
1353 r = ERROR_UNKNOWN_PROPERTY;
1355 goto done;
1358 msi_free(val);
1360 if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1361 szProperty = displayname;
1362 else if (!strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ))
1363 szProperty = displayversion;
1365 val = msi_reg_get_value(props, szProperty, &type);
1366 if (!val)
1367 val = strdupW(szEmpty);
1369 r = msi_copy_outval(val, szValue, pcchValue);
1371 else if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ) ||
1372 !strcmpW( szProperty, INSTALLPROPERTY_LANGUAGEW ) ||
1373 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1374 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGECODEW ) ||
1375 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONW ) ||
1376 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTICONW ) ||
1377 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ) ||
1378 !strcmpW( szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1380 if (!prod && !classes)
1381 goto done;
1383 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1384 hkey = prod;
1385 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1386 hkey = managed;
1387 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1388 hkey = classes;
1390 val = msi_reg_get_value(hkey, szProperty, &type);
1391 if (!val)
1392 val = strdupW(szEmpty);
1394 r = msi_copy_outval(val, szValue, pcchValue);
1396 else if (!strcmpW( szProperty, INSTALLPROPERTY_PRODUCTSTATEW ))
1398 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1400 if (props)
1402 val = msi_reg_get_value(props, package, &type);
1403 if (!val)
1404 goto done;
1406 msi_free(val);
1407 val = strdupW(five);
1409 else
1410 val = strdupW(szOne);
1412 r = msi_copy_outval(val, szValue, pcchValue);
1413 goto done;
1415 else if (props && (val = msi_reg_get_value(props, package, &type)))
1417 msi_free(val);
1418 val = strdupW(five);
1419 r = msi_copy_outval(val, szValue, pcchValue);
1420 goto done;
1423 if (prod || managed)
1424 val = strdupW(szOne);
1425 else
1426 goto done;
1428 r = msi_copy_outval(val, szValue, pcchValue);
1430 else if (!strcmpW( szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1432 if (!prod && !classes)
1433 goto done;
1435 /* FIXME */
1436 val = strdupW(szEmpty);
1437 r = msi_copy_outval(val, szValue, pcchValue);
1439 else
1440 r = ERROR_UNKNOWN_PROPERTY;
1442 done:
1443 RegCloseKey(props);
1444 RegCloseKey(prod);
1445 RegCloseKey(managed);
1446 RegCloseKey(classes);
1447 msi_free(val);
1449 return r;
1452 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1453 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1454 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1456 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1457 LPWSTR property = NULL, val = NULL;
1458 DWORD len;
1459 UINT r;
1461 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1462 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1463 debugstr_a(szProperty), lpValue, pcchValue);
1465 if (lpValue && !pcchValue)
1466 return ERROR_INVALID_PARAMETER;
1468 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1469 if (szProductCode) product = strdupAtoW(szProductCode);
1470 if (szUserSid) usersid = strdupAtoW(szUserSid);
1471 if (szProperty) property = strdupAtoW(szProperty);
1473 len = 0;
1474 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1475 NULL, &len);
1476 if (r != ERROR_SUCCESS)
1477 goto done;
1479 val = msi_alloc(++len * sizeof(WCHAR));
1480 if (!val)
1482 r = ERROR_OUTOFMEMORY;
1483 goto done;
1486 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1487 val, &len);
1488 if (r != ERROR_SUCCESS || !pcchValue)
1489 goto done;
1491 if (lpValue)
1492 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1493 *pcchValue - 1, NULL, NULL);
1495 len = lstrlenW(val);
1496 if ((*val && *pcchValue < len + 1) || !lpValue)
1498 if (lpValue)
1500 r = ERROR_MORE_DATA;
1501 lpValue[*pcchValue - 1] = '\0';
1504 *pcchValue = len * sizeof(WCHAR);
1506 else
1507 *pcchValue = len;
1509 done:
1510 msi_free(val);
1511 msi_free(patch);
1512 msi_free(product);
1513 msi_free(usersid);
1514 msi_free(property);
1516 return r;
1519 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1520 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1521 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1523 WCHAR squished_pc[GUID_SIZE];
1524 WCHAR squished_patch[GUID_SIZE];
1525 HKEY udprod = 0, prod = 0, props = 0;
1526 HKEY patch = 0, patches = 0;
1527 HKEY udpatch = 0, datakey = 0;
1528 HKEY prodpatches = 0;
1529 LPWSTR val = NULL;
1530 UINT r = ERROR_UNKNOWN_PRODUCT;
1531 DWORD len;
1532 LONG res;
1534 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1535 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1537 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1538 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1539 debugstr_w(szProperty), lpValue, pcchValue);
1541 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1542 return ERROR_INVALID_PARAMETER;
1544 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1545 return ERROR_INVALID_PARAMETER;
1547 if (!szProperty)
1548 return ERROR_INVALID_PARAMETER;
1550 if (lpValue && !pcchValue)
1551 return ERROR_INVALID_PARAMETER;
1553 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1554 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1555 dwContext != MSIINSTALLCONTEXT_MACHINE)
1556 return ERROR_INVALID_PARAMETER;
1558 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1559 return ERROR_INVALID_PARAMETER;
1561 if (szUserSid && !strcmpW( szUserSid, szLocalSid ))
1562 return ERROR_INVALID_PARAMETER;
1564 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1565 &udprod, FALSE) != ERROR_SUCCESS)
1566 goto done;
1568 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1569 &props, FALSE) != ERROR_SUCCESS)
1570 goto done;
1572 r = ERROR_UNKNOWN_PATCH;
1574 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_READ, &patches);
1575 if (res != ERROR_SUCCESS)
1576 goto done;
1578 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_READ, &patch);
1579 if (res != ERROR_SUCCESS)
1580 goto done;
1582 if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ))
1584 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1585 &prod, FALSE) != ERROR_SUCCESS)
1586 goto done;
1588 res = RegOpenKeyExW(prod, szPatches, 0, KEY_ALL_ACCESS, &prodpatches);
1589 if (res != ERROR_SUCCESS)
1590 goto done;
1592 datakey = prodpatches;
1593 szProperty = squished_patch;
1595 else
1597 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1598 &udpatch, FALSE) != ERROR_SUCCESS)
1599 goto done;
1601 if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1603 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1604 szProperty = szManagedPackage;
1605 datakey = udpatch;
1607 else if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ))
1609 datakey = patch;
1610 szProperty = szInstalled;
1612 else if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1614 datakey = udpatch;
1616 else if (!strcmpW( szProperty, INSTALLPROPERTY_UNINSTALLABLEW ) ||
1617 !strcmpW( szProperty, INSTALLPROPERTY_PATCHSTATEW ) ||
1618 !strcmpW( szProperty, INSTALLPROPERTY_DISPLAYNAMEW ) ||
1619 !strcmpW( szProperty, INSTALLPROPERTY_MOREINFOURLW ))
1621 datakey = patch;
1623 else
1625 r = ERROR_UNKNOWN_PROPERTY;
1626 goto done;
1630 val = msi_reg_get_val_str(datakey, szProperty);
1631 if (!val)
1632 val = strdupW(szEmpty);
1634 r = ERROR_SUCCESS;
1636 if (!pcchValue)
1637 goto done;
1639 if (lpValue)
1640 lstrcpynW(lpValue, val, *pcchValue);
1642 len = lstrlenW(val);
1643 if ((*val && *pcchValue < len + 1) || !lpValue)
1645 if (lpValue)
1646 r = ERROR_MORE_DATA;
1648 *pcchValue = len * sizeof(WCHAR);
1651 *pcchValue = len;
1653 done:
1654 msi_free(val);
1655 RegCloseKey(prodpatches);
1656 RegCloseKey(prod);
1657 RegCloseKey(patch);
1658 RegCloseKey(patches);
1659 RegCloseKey(udpatch);
1660 RegCloseKey(props);
1661 RegCloseKey(udprod);
1663 return r;
1666 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1668 UINT r = ERROR_OUTOFMEMORY;
1669 DWORD size;
1670 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1672 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1674 if (!patch || !attr)
1675 return ERROR_INVALID_PARAMETER;
1677 if (!(patchW = strdupAtoW( patch )))
1678 goto done;
1680 if (!(attrW = strdupAtoW( attr )))
1681 goto done;
1683 size = 0;
1684 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1685 if (r != ERROR_SUCCESS)
1686 goto done;
1688 size++;
1689 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1691 r = ERROR_OUTOFMEMORY;
1692 goto done;
1695 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1696 if (r == ERROR_SUCCESS)
1698 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1699 if (len > *buflen)
1700 r = ERROR_MORE_DATA;
1701 else if (buffer)
1702 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1704 *buflen = len - 1;
1707 done:
1708 msi_free( patchW );
1709 msi_free( attrW );
1710 msi_free( bufferW );
1711 return r;
1714 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1716 UINT r;
1717 WCHAR product[GUID_SIZE];
1718 DWORD index;
1720 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1722 if (!patch || !attr)
1723 return ERROR_INVALID_PARAMETER;
1725 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1726 return ERROR_UNKNOWN_PROPERTY;
1728 index = 0;
1729 while (1)
1731 r = MsiEnumProductsW( index, product );
1732 if (r != ERROR_SUCCESS)
1733 break;
1735 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1736 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1737 return r;
1739 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1740 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1741 return r;
1743 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1744 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1745 return r;
1747 index++;
1750 return ERROR_UNKNOWN_PRODUCT;
1753 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1755 LPWSTR szwLogFile = NULL;
1756 UINT r;
1758 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1760 if( szLogFile )
1762 szwLogFile = strdupAtoW( szLogFile );
1763 if( !szwLogFile )
1764 return ERROR_OUTOFMEMORY;
1766 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1767 msi_free( szwLogFile );
1768 return r;
1771 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1773 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1775 msi_free(gszLogFile);
1776 gszLogFile = NULL;
1777 if (szLogFile)
1779 HANDLE file;
1781 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1782 DeleteFileW(szLogFile);
1783 file = CreateFileW(szLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
1784 FILE_ATTRIBUTE_NORMAL, NULL);
1785 if (file != INVALID_HANDLE_VALUE)
1787 gszLogFile = strdupW(szLogFile);
1788 CloseHandle(file);
1790 else
1791 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile), GetLastError());
1794 return ERROR_SUCCESS;
1797 UINT WINAPI MsiEnumComponentCostsA( MSIHANDLE handle, LPCSTR component, DWORD index,
1798 INSTALLSTATE state, LPSTR drive, DWORD *buflen,
1799 int *cost, int *temp )
1801 UINT r;
1802 DWORD len;
1803 WCHAR *driveW, *componentW = NULL;
1805 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_a(component), index,
1806 state, drive, buflen, cost, temp);
1808 if (!drive || !buflen) return ERROR_INVALID_PARAMETER;
1809 if (component && !(componentW = strdupAtoW( component ))) return ERROR_OUTOFMEMORY;
1811 len = *buflen;
1812 if (!(driveW = msi_alloc( len * sizeof(WCHAR) )))
1814 msi_free( componentW );
1815 return ERROR_OUTOFMEMORY;
1817 r = MsiEnumComponentCostsW( handle, componentW, index, state, driveW, buflen, cost, temp );
1818 if (!r)
1820 WideCharToMultiByte( CP_ACP, 0, driveW, -1, drive, len, NULL, NULL );
1822 msi_free( componentW );
1823 msi_free( driveW );
1824 return r;
1827 UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, LPCWSTR component, DWORD index,
1828 INSTALLSTATE state, LPWSTR drive, DWORD *buflen,
1829 int *cost, int *temp )
1831 UINT r = ERROR_NO_MORE_ITEMS;
1832 MSICOMPONENT *comp = NULL;
1833 MSIPACKAGE *package;
1834 MSIFILE *file;
1835 STATSTG stat = {0};
1836 WCHAR path[MAX_PATH];
1838 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_w(component), index,
1839 state, drive, buflen, cost, temp);
1841 if (!drive || !buflen || !cost || !temp) return ERROR_INVALID_PARAMETER;
1842 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE ))) return ERROR_INVALID_HANDLE;
1843 if (!msi_get_property_int( package->db, szCostingComplete, 0 ))
1845 msiobj_release( &package->hdr );
1846 return ERROR_FUNCTION_NOT_CALLED;
1848 if (component && component[0] && !(comp = get_loaded_component( package, component )))
1850 msiobj_release( &package->hdr );
1851 return ERROR_UNKNOWN_COMPONENT;
1853 if (*buflen < 3)
1855 *buflen = 2;
1856 msiobj_release( &package->hdr );
1857 return ERROR_MORE_DATA;
1859 if (index)
1861 msiobj_release( &package->hdr );
1862 return ERROR_NO_MORE_ITEMS;
1865 drive[0] = 0;
1866 *cost = *temp = 0;
1867 if (component && component[0])
1869 *cost = max( 8, comp->Cost / 512 );
1870 if (comp->assembly && !comp->assembly->application) *temp = comp->Cost;
1871 if ((file = get_loaded_file( package, comp->KeyPath )))
1873 drive[0] = file->TargetPath[0];
1874 drive[1] = ':';
1875 drive[2] = 0;
1876 *buflen = 2;
1877 r = ERROR_SUCCESS;
1880 else if (IStorage_Stat( package->db->storage, &stat, STATFLAG_NONAME ) == S_OK)
1882 *temp = max( 8, stat.cbSize.QuadPart / 512 );
1883 GetWindowsDirectoryW( path, MAX_PATH );
1884 drive[0] = path[0];
1885 drive[1] = ':';
1886 drive[2] = 0;
1887 *buflen = 2;
1888 r = ERROR_SUCCESS;
1890 msiobj_release( &package->hdr );
1891 return r;
1894 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
1895 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1896 LPCSTR szComponent, INSTALLSTATE *pdwState)
1898 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
1899 UINT r;
1901 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
1902 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
1904 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
1905 return ERROR_OUTOFMEMORY;
1907 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
1908 return ERROR_OUTOFMEMORY;
1910 if (szComponent && !(comp = strdupAtoW(szComponent)))
1911 return ERROR_OUTOFMEMORY;
1913 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
1915 msi_free(prodcode);
1916 msi_free(usersid);
1917 msi_free(comp);
1919 return r;
1922 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1924 UINT r;
1925 HKEY hkey;
1927 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
1928 RegCloseKey(hkey);
1929 return (r == ERROR_SUCCESS);
1932 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
1934 LPCWSTR package;
1935 HKEY hkey;
1936 DWORD sz;
1937 LONG res;
1938 UINT r;
1940 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1941 static const WCHAR managed_local_package[] = {
1942 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1945 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
1946 if (r != ERROR_SUCCESS)
1947 return FALSE;
1949 if (context == MSIINSTALLCONTEXT_USERMANAGED)
1950 package = managed_local_package;
1951 else
1952 package = local_package;
1954 sz = 0;
1955 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
1956 RegCloseKey(hkey);
1958 return (res == ERROR_SUCCESS);
1961 static BOOL msi_comp_find_prodcode(LPWSTR squished_pc,
1962 MSIINSTALLCONTEXT context,
1963 LPCWSTR comp, LPWSTR val, DWORD *sz)
1965 HKEY hkey;
1966 LONG res;
1967 UINT r;
1969 if (context == MSIINSTALLCONTEXT_MACHINE)
1970 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
1971 else
1972 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
1974 if (r != ERROR_SUCCESS)
1975 return FALSE;
1977 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
1978 if (res != ERROR_SUCCESS)
1979 return FALSE;
1981 RegCloseKey(hkey);
1982 return TRUE;
1985 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
1986 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1987 LPCWSTR szComponent, INSTALLSTATE *pdwState)
1989 WCHAR squished_pc[GUID_SIZE];
1990 WCHAR val[MAX_PATH];
1991 BOOL found;
1992 DWORD sz;
1994 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
1995 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
1997 if (!pdwState || !szComponent)
1998 return ERROR_INVALID_PARAMETER;
2000 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
2001 return ERROR_INVALID_PARAMETER;
2003 if (!squash_guid(szProductCode, squished_pc))
2004 return ERROR_INVALID_PARAMETER;
2006 found = msi_comp_find_prod_key(szProductCode, dwContext);
2008 if (!msi_comp_find_package(szProductCode, dwContext))
2010 if (found)
2012 *pdwState = INSTALLSTATE_UNKNOWN;
2013 return ERROR_UNKNOWN_COMPONENT;
2016 return ERROR_UNKNOWN_PRODUCT;
2019 *pdwState = INSTALLSTATE_UNKNOWN;
2021 sz = MAX_PATH;
2022 if (!msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz))
2023 return ERROR_UNKNOWN_COMPONENT;
2025 if (sz == 0)
2026 *pdwState = INSTALLSTATE_NOTUSED;
2027 else
2029 if (lstrlenW(val) > 2 &&
2030 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9')
2032 *pdwState = INSTALLSTATE_SOURCE;
2034 else
2035 *pdwState = INSTALLSTATE_LOCAL;
2038 TRACE("-> %d\n", *pdwState);
2039 return ERROR_SUCCESS;
2042 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
2044 LPWSTR szwProduct = NULL;
2045 INSTALLSTATE r;
2047 if( szProduct )
2049 szwProduct = strdupAtoW( szProduct );
2050 if( !szwProduct )
2051 return ERROR_OUTOFMEMORY;
2053 r = MsiQueryProductStateW( szwProduct );
2054 msi_free( szwProduct );
2055 return r;
2058 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
2060 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
2061 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
2062 HKEY prodkey = 0, userdata = 0;
2063 DWORD val;
2064 UINT r;
2066 static const WCHAR szWindowsInstaller[] = {
2067 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2069 TRACE("%s\n", debugstr_w(szProduct));
2071 if (!szProduct || !*szProduct)
2072 return INSTALLSTATE_INVALIDARG;
2074 if (lstrlenW(szProduct) != GUID_SIZE - 1)
2075 return INSTALLSTATE_INVALIDARG;
2077 if (szProduct[0] != '{' || szProduct[37] != '}')
2078 return INSTALLSTATE_UNKNOWN;
2080 SetLastError( ERROR_SUCCESS );
2082 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2083 &prodkey, FALSE) != ERROR_SUCCESS &&
2084 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2085 &prodkey, FALSE) != ERROR_SUCCESS &&
2086 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2087 &prodkey, FALSE) == ERROR_SUCCESS)
2089 context = MSIINSTALLCONTEXT_MACHINE;
2092 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
2093 if (r != ERROR_SUCCESS)
2094 goto done;
2096 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
2097 goto done;
2099 if (val)
2100 state = INSTALLSTATE_DEFAULT;
2101 else
2102 state = INSTALLSTATE_UNKNOWN;
2104 done:
2105 if (!prodkey)
2107 state = INSTALLSTATE_UNKNOWN;
2109 if (userdata)
2110 state = INSTALLSTATE_ABSENT;
2113 RegCloseKey(prodkey);
2114 RegCloseKey(userdata);
2115 TRACE("-> %d\n", state);
2116 return state;
2119 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2121 INSTALLUILEVEL old = gUILevel;
2122 HWND oldwnd = gUIhwnd;
2124 TRACE("%08x %p\n", dwUILevel, phWnd);
2126 gUILevel = dwUILevel;
2127 if (phWnd)
2129 gUIhwnd = *phWnd;
2130 *phWnd = oldwnd;
2132 return old;
2135 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2136 DWORD dwMessageFilter, LPVOID pvContext)
2138 INSTALLUI_HANDLERA prev = gUIHandlerA;
2140 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2142 gUIHandlerA = puiHandler;
2143 gUIHandlerW = NULL;
2144 gUIFilter = dwMessageFilter;
2145 gUIContext = pvContext;
2147 return prev;
2150 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2151 DWORD dwMessageFilter, LPVOID pvContext)
2153 INSTALLUI_HANDLERW prev = gUIHandlerW;
2155 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2157 gUIHandlerA = NULL;
2158 gUIHandlerW = puiHandler;
2159 gUIFilter = dwMessageFilter;
2160 gUIContext = pvContext;
2162 return prev;
2165 /******************************************************************
2166 * MsiLoadStringW [MSI.@]
2168 * Loads a string from MSI's string resources.
2170 * PARAMS
2172 * handle [I] only -1 is handled currently
2173 * id [I] id of the string to be loaded
2174 * lpBuffer [O] buffer for the string to be written to
2175 * nBufferMax [I] maximum size of the buffer in characters
2176 * lang [I] the preferred language for the string
2178 * RETURNS
2180 * If successful, this function returns the language id of the string loaded
2181 * If the function fails, the function returns zero.
2183 * NOTES
2185 * The type of the first parameter is unknown. LoadString's prototype
2186 * suggests that it might be a module handle. I have made it an MSI handle
2187 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2188 * handle. Maybe strings can be stored in an MSI database somehow.
2190 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2191 int nBufferMax, LANGID lang )
2193 HRSRC hres;
2194 HGLOBAL hResData;
2195 LPWSTR p;
2196 DWORD i, len;
2198 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2200 if( handle != -1 )
2201 FIXME("don't know how to deal with handle = %08x\n", handle);
2203 if( !lang )
2204 lang = GetUserDefaultLangID();
2206 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2207 (LPWSTR)1, lang );
2208 if( !hres )
2209 return 0;
2210 hResData = LoadResource( msi_hInstance, hres );
2211 if( !hResData )
2212 return 0;
2213 p = LockResource( hResData );
2214 if( !p )
2215 return 0;
2217 for (i = 0; i < (id&0xf); i++)
2218 p += *p + 1;
2219 len = *p;
2221 if( nBufferMax <= len )
2222 return 0;
2224 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2225 lpBuffer[ len ] = 0;
2227 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2229 return lang;
2232 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2233 int nBufferMax, LANGID lang )
2235 LPWSTR bufW;
2236 LANGID r;
2237 INT len;
2239 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2240 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2241 if( r )
2243 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2244 if( len <= nBufferMax )
2245 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2246 lpBuffer, nBufferMax, NULL, NULL );
2247 else
2248 r = 0;
2250 msi_free(bufW);
2251 return r;
2254 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2255 LPDWORD pcchBuf)
2257 char szProduct[GUID_SIZE];
2259 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2261 if (!szComponent || !pcchBuf)
2262 return INSTALLSTATE_INVALIDARG;
2264 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2265 return INSTALLSTATE_UNKNOWN;
2267 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2270 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2271 LPDWORD pcchBuf)
2273 WCHAR szProduct[GUID_SIZE];
2275 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2277 if (!szComponent || !pcchBuf)
2278 return INSTALLSTATE_INVALIDARG;
2280 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2281 return INSTALLSTATE_UNKNOWN;
2283 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2286 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2287 WORD wLanguageId, DWORD f)
2289 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2290 uType, wLanguageId, f);
2291 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2294 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2295 WORD wLanguageId, DWORD f)
2297 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2298 uType, wLanguageId, f);
2299 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2302 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2303 DWORD unknown, WORD wLanguageId, DWORD f)
2305 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2306 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2307 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2310 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2311 DWORD unknown, WORD wLanguageId, DWORD f)
2313 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2314 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2315 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2318 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2319 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2320 LPDWORD pcchPathBuf )
2322 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2323 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2324 pcchPathBuf);
2325 return ERROR_CALL_NOT_IMPLEMENTED;
2328 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2329 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2330 LPDWORD pcchPathBuf )
2332 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2333 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2334 pcchPathBuf);
2335 return ERROR_CALL_NOT_IMPLEMENTED;
2338 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2339 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2341 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2342 return ERROR_CALL_NOT_IMPLEMENTED;
2345 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2346 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2348 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2349 return ERROR_CALL_NOT_IMPLEMENTED;
2352 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2353 LPBYTE hash, LPDWORD hashlen )
2355 UINT r;
2356 WCHAR *pathW = NULL;
2358 TRACE("%s %08x %p %p %p\n", debugstr_a(path), flags, cert, hash, hashlen);
2360 if (path && !(pathW = strdupAtoW( path ))) return ERROR_OUTOFMEMORY;
2361 r = MsiGetFileSignatureInformationW( pathW, flags, cert, hash, hashlen );
2362 msi_free( pathW );
2363 return r;
2366 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2367 LPBYTE hash, LPDWORD hashlen )
2369 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
2370 HRESULT hr;
2371 WINTRUST_DATA data;
2372 WINTRUST_FILE_INFO info;
2373 CRYPT_PROVIDER_SGNR *signer;
2374 CRYPT_PROVIDER_CERT *provider;
2376 TRACE("%s %08x %p %p %p\n", debugstr_w(path), flags, cert, hash, hashlen);
2378 if (!path || !cert) return E_INVALIDARG;
2380 info.cbStruct = sizeof(info);
2381 info.pcwszFilePath = path;
2382 info.hFile = NULL;
2383 info.pgKnownSubject = NULL;
2385 data.cbStruct = sizeof(data);
2386 data.pPolicyCallbackData = NULL;
2387 data.pSIPClientData = NULL;
2388 data.dwUIChoice = WTD_UI_NONE;
2389 data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
2390 data.dwUnionChoice = WTD_CHOICE_FILE;
2391 data.u.pFile = &info;
2392 data.dwStateAction = WTD_STATEACTION_VERIFY;
2393 data.hWVTStateData = NULL;
2394 data.pwszURLReference = NULL;
2395 data.dwProvFlags = 0;
2396 data.dwUIContext = WTD_UICONTEXT_INSTALL;
2397 hr = WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2398 if (FAILED(hr)) return hr;
2400 signer = WTHelperGetProvSignerFromChain( data.hWVTStateData, 0, FALSE, 0 );
2401 if (!signer) return TRUST_E_NOSIGNATURE;
2402 if (hash)
2404 DWORD len = signer->psSigner->EncryptedHash.cbData;
2405 if (*hashlen < len)
2407 *hashlen = len;
2408 return HRESULT_FROM_WIN32(ERROR_MORE_DATA);
2410 memcpy( hash, signer->psSigner->EncryptedHash.pbData, len );
2411 *hashlen = len;
2413 provider = WTHelperGetProvCertFromChain( signer, 0 );
2414 if (!provider) return TRUST_E_PROVIDER_UNKNOWN;
2415 *cert = CertDuplicateCertificateContext( provider->pCert );
2416 return S_OK;
2419 /******************************************************************
2420 * MsiGetProductPropertyA [MSI.@]
2422 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2423 LPSTR szValue, LPDWORD pccbValue)
2425 LPWSTR prop = NULL, val = NULL;
2426 DWORD len;
2427 UINT r;
2429 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2430 szValue, pccbValue);
2432 if (szValue && !pccbValue)
2433 return ERROR_INVALID_PARAMETER;
2435 if (szProperty) prop = strdupAtoW(szProperty);
2437 len = 0;
2438 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2439 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2440 goto done;
2442 if (r == ERROR_SUCCESS)
2444 if (szValue) *szValue = '\0';
2445 if (pccbValue) *pccbValue = 0;
2446 goto done;
2449 val = msi_alloc(++len * sizeof(WCHAR));
2450 if (!val)
2452 r = ERROR_OUTOFMEMORY;
2453 goto done;
2456 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2457 if (r != ERROR_SUCCESS)
2458 goto done;
2460 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2462 if (szValue)
2463 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2464 *pccbValue, NULL, NULL);
2466 if (pccbValue)
2468 if (len > *pccbValue)
2469 r = ERROR_MORE_DATA;
2471 *pccbValue = len - 1;
2474 done:
2475 msi_free(prop);
2476 msi_free(val);
2478 return r;
2481 /******************************************************************
2482 * MsiGetProductPropertyW [MSI.@]
2484 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2485 LPWSTR szValue, LPDWORD pccbValue)
2487 MSIPACKAGE *package;
2488 MSIQUERY *view = NULL;
2489 MSIRECORD *rec = NULL;
2490 LPCWSTR val;
2491 UINT r;
2493 static const WCHAR query[] = {
2494 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2495 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2496 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2498 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2499 szValue, pccbValue);
2501 if (!szProperty)
2502 return ERROR_INVALID_PARAMETER;
2504 if (szValue && !pccbValue)
2505 return ERROR_INVALID_PARAMETER;
2507 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2508 if (!package)
2509 return ERROR_INVALID_HANDLE;
2511 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2512 if (r != ERROR_SUCCESS)
2513 goto done;
2515 r = MSI_ViewExecute(view, 0);
2516 if (r != ERROR_SUCCESS)
2517 goto done;
2519 r = MSI_ViewFetch(view, &rec);
2520 if (r != ERROR_SUCCESS)
2521 goto done;
2523 val = MSI_RecordGetString(rec, 2);
2524 if (!val)
2525 goto done;
2527 if (lstrlenW(val) >= *pccbValue)
2529 lstrcpynW(szValue, val, *pccbValue);
2530 *pccbValue = lstrlenW(val);
2531 r = ERROR_MORE_DATA;
2533 else
2535 lstrcpyW(szValue, val);
2536 *pccbValue = lstrlenW(val);
2537 r = ERROR_SUCCESS;
2540 done:
2541 if (view)
2543 MSI_ViewClose(view);
2544 msiobj_release(&view->hdr);
2545 if (rec) msiobj_release(&rec->hdr);
2548 if (!rec)
2550 if (szValue) *szValue = '\0';
2551 if (pccbValue) *pccbValue = 0;
2552 r = ERROR_SUCCESS;
2555 msiobj_release(&package->hdr);
2556 return r;
2559 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2561 UINT r;
2562 LPWSTR szPack = NULL;
2564 TRACE("%s\n", debugstr_a(szPackage) );
2566 if( szPackage )
2568 szPack = strdupAtoW( szPackage );
2569 if( !szPack )
2570 return ERROR_OUTOFMEMORY;
2573 r = MsiVerifyPackageW( szPack );
2575 msi_free( szPack );
2577 return r;
2580 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2582 MSIHANDLE handle;
2583 UINT r;
2585 TRACE("%s\n", debugstr_w(szPackage) );
2587 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2588 MsiCloseHandle( handle );
2590 return r;
2593 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2594 awstring* lpPathBuf, LPDWORD pcchBuf)
2596 WCHAR squished_pc[GUID_SIZE];
2597 WCHAR squished_comp[GUID_SIZE];
2598 HKEY hkey;
2599 LPWSTR path = NULL;
2600 INSTALLSTATE state;
2601 DWORD version;
2603 static const WCHAR wininstaller[] = {
2604 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2606 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
2607 debugstr_w(szComponent), lpPathBuf->str.w, pcchBuf);
2609 if (!szProduct || !szComponent)
2610 return INSTALLSTATE_INVALIDARG;
2612 if (lpPathBuf->str.w && !pcchBuf)
2613 return INSTALLSTATE_INVALIDARG;
2615 if (!squash_guid(szProduct, squished_pc) ||
2616 !squash_guid(szComponent, squished_comp))
2617 return INSTALLSTATE_INVALIDARG;
2619 state = INSTALLSTATE_UNKNOWN;
2621 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2622 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2624 path = msi_reg_get_val_str(hkey, squished_pc);
2625 RegCloseKey(hkey);
2627 state = INSTALLSTATE_ABSENT;
2629 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2630 &hkey, FALSE) == ERROR_SUCCESS ||
2631 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2632 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2633 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2634 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2636 RegCloseKey(hkey);
2637 state = INSTALLSTATE_LOCAL;
2641 if (state != INSTALLSTATE_LOCAL &&
2642 (MSIREG_OpenProductKey(szProduct, NULL,
2643 MSIINSTALLCONTEXT_USERUNMANAGED,
2644 &hkey, FALSE) == ERROR_SUCCESS ||
2645 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2646 &hkey, FALSE) == ERROR_SUCCESS))
2648 RegCloseKey(hkey);
2650 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2651 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2653 msi_free(path);
2654 path = msi_reg_get_val_str(hkey, squished_pc);
2655 RegCloseKey(hkey);
2657 state = INSTALLSTATE_ABSENT;
2659 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2660 state = INSTALLSTATE_LOCAL;
2664 if (!path)
2665 return INSTALLSTATE_UNKNOWN;
2667 if (state == INSTALLSTATE_LOCAL && !*path)
2668 state = INSTALLSTATE_NOTUSED;
2670 msi_strcpy_to_awstring(path, lpPathBuf, pcchBuf);
2671 msi_free(path);
2672 return state;
2675 /******************************************************************
2676 * MsiGetComponentPathW [MSI.@]
2678 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2679 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2681 awstring path;
2683 path.unicode = TRUE;
2684 path.str.w = lpPathBuf;
2686 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2689 /******************************************************************
2690 * MsiGetComponentPathA [MSI.@]
2692 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2693 LPSTR lpPathBuf, LPDWORD pcchBuf)
2695 LPWSTR szwProduct, szwComponent = NULL;
2696 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2697 awstring path;
2699 szwProduct = strdupAtoW( szProduct );
2700 if( szProduct && !szwProduct)
2701 goto end;
2703 szwComponent = strdupAtoW( szComponent );
2704 if( szComponent && !szwComponent )
2705 goto end;
2707 path.unicode = FALSE;
2708 path.str.a = lpPathBuf;
2710 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2712 end:
2713 msi_free( szwProduct );
2714 msi_free( szwComponent );
2716 return r;
2719 /******************************************************************
2720 * MsiQueryFeatureStateA [MSI.@]
2722 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
2724 LPWSTR szwProduct = NULL, szwFeature= NULL;
2725 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
2727 szwProduct = strdupAtoW( szProduct );
2728 if ( szProduct && !szwProduct )
2729 goto end;
2731 szwFeature = strdupAtoW( szFeature );
2732 if ( szFeature && !szwFeature )
2733 goto end;
2735 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
2737 end:
2738 msi_free( szwProduct);
2739 msi_free( szwFeature);
2741 return rc;
2744 /******************************************************************
2745 * MsiQueryFeatureStateW [MSI.@]
2747 * Checks the state of a feature
2749 * PARAMS
2750 * szProduct [I] Product's GUID string
2751 * szFeature [I] Feature's GUID string
2753 * RETURNS
2754 * INSTALLSTATE_LOCAL Feature is installed and usable
2755 * INSTALLSTATE_ABSENT Feature is absent
2756 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2757 * INSTALLSTATE_UNKNOWN An error occurred
2758 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2761 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
2763 WCHAR squishProduct[33], comp[GUID_SIZE];
2764 GUID guid;
2765 LPWSTR components, p, parent_feature, path;
2766 UINT rc;
2767 HKEY hkey;
2768 INSTALLSTATE r;
2769 BOOL missing = FALSE;
2770 BOOL machine = FALSE;
2771 BOOL source = FALSE;
2773 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
2775 if (!szProduct || !szFeature)
2776 return INSTALLSTATE_INVALIDARG;
2778 if (!squash_guid( szProduct, squishProduct ))
2779 return INSTALLSTATE_INVALIDARG;
2781 SetLastError( ERROR_SUCCESS );
2783 if (MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERMANAGED,
2784 &hkey, FALSE) != ERROR_SUCCESS &&
2785 MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2786 &hkey, FALSE) != ERROR_SUCCESS)
2788 rc = MSIREG_OpenFeaturesKey(szProduct, MSIINSTALLCONTEXT_MACHINE,
2789 &hkey, FALSE);
2790 if (rc != ERROR_SUCCESS)
2791 return INSTALLSTATE_UNKNOWN;
2793 machine = TRUE;
2796 parent_feature = msi_reg_get_val_str( hkey, szFeature );
2797 RegCloseKey(hkey);
2799 if (!parent_feature)
2800 return INSTALLSTATE_UNKNOWN;
2802 r = (parent_feature[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2803 msi_free(parent_feature);
2804 if (r == INSTALLSTATE_ABSENT)
2805 return r;
2807 if (machine)
2808 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2809 MSIINSTALLCONTEXT_MACHINE,
2810 &hkey, FALSE);
2811 else
2812 rc = MSIREG_OpenUserDataFeaturesKey(szProduct,
2813 MSIINSTALLCONTEXT_USERUNMANAGED,
2814 &hkey, FALSE);
2816 if (rc != ERROR_SUCCESS)
2817 return INSTALLSTATE_ADVERTISED;
2819 components = msi_reg_get_val_str( hkey, szFeature );
2820 RegCloseKey(hkey);
2822 TRACE("rc = %d buffer = %s\n", rc, debugstr_w(components));
2824 if (!components)
2825 return INSTALLSTATE_ADVERTISED;
2827 for( p = components; *p && *p != 2 ; p += 20)
2829 if (!decode_base85_guid( p, &guid ))
2831 if (p != components)
2832 break;
2834 msi_free(components);
2835 return INSTALLSTATE_BADCONFIG;
2838 StringFromGUID2(&guid, comp, GUID_SIZE);
2840 if (machine)
2841 rc = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2842 else
2843 rc = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2845 if (rc != ERROR_SUCCESS)
2847 msi_free(components);
2848 return INSTALLSTATE_ADVERTISED;
2851 path = msi_reg_get_val_str(hkey, squishProduct);
2852 if (!path)
2853 missing = TRUE;
2854 else if (lstrlenW(path) > 2 &&
2855 path[0] >= '0' && path[0] <= '9' &&
2856 path[1] >= '0' && path[1] <= '9')
2858 source = TRUE;
2861 msi_free(path);
2863 msi_free(components);
2865 if (missing)
2866 r = INSTALLSTATE_ADVERTISED;
2867 else if (source)
2868 r = INSTALLSTATE_SOURCE;
2869 else
2870 r = INSTALLSTATE_LOCAL;
2872 TRACE("-> %d\n", r);
2873 return r;
2876 /******************************************************************
2877 * MsiGetFileVersionA [MSI.@]
2879 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
2880 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
2882 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
2883 UINT ret = ERROR_OUTOFMEMORY;
2885 if ((lpVersionBuf && !pcchVersionBuf) ||
2886 (lpLangBuf && !pcchLangBuf))
2887 return ERROR_INVALID_PARAMETER;
2889 if( szFilePath )
2891 szwFilePath = strdupAtoW( szFilePath );
2892 if( !szwFilePath )
2893 goto end;
2896 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
2898 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
2899 if( !lpwVersionBuff )
2900 goto end;
2903 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
2905 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
2906 if( !lpwLangBuff )
2907 goto end;
2910 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
2911 lpwLangBuff, pcchLangBuf);
2913 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
2914 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
2915 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
2916 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
2917 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
2918 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
2920 end:
2921 msi_free(szwFilePath);
2922 msi_free(lpwVersionBuff);
2923 msi_free(lpwLangBuff);
2925 return ret;
2928 /******************************************************************
2929 * MsiGetFileVersionW [MSI.@]
2931 UINT WINAPI MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf,
2932 LPDWORD pcchVersionBuf, LPWSTR lpLangBuf, LPDWORD pcchLangBuf)
2934 static const WCHAR szVersionResource[] = {'\\',0};
2935 static const WCHAR szVersionFormat[] = {
2936 '%','d','.','%','d','.','%','d','.','%','d',0};
2937 static const WCHAR szLangResource[] = {
2938 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2939 'T','r','a','n','s','l','a','t','i','o','n',0};
2940 static const WCHAR szLangFormat[] = {'%','d',0};
2941 UINT ret = 0;
2942 DWORD dwVerLen, gle;
2943 LPVOID lpVer = NULL;
2944 VS_FIXEDFILEINFO *ffi;
2945 USHORT *lang;
2946 UINT puLen;
2947 WCHAR tmp[32];
2949 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath),
2950 lpVersionBuf, pcchVersionBuf?*pcchVersionBuf:0,
2951 lpLangBuf, pcchLangBuf?*pcchLangBuf:0);
2953 if ((lpVersionBuf && !pcchVersionBuf) ||
2954 (lpLangBuf && !pcchLangBuf))
2955 return ERROR_INVALID_PARAMETER;
2957 dwVerLen = GetFileVersionInfoSizeW(szFilePath, NULL);
2958 if( !dwVerLen )
2960 gle = GetLastError();
2961 if (gle == ERROR_BAD_PATHNAME)
2962 return ERROR_FILE_NOT_FOUND;
2963 else if (gle == ERROR_RESOURCE_DATA_NOT_FOUND)
2964 return ERROR_FILE_INVALID;
2966 return gle;
2969 lpVer = msi_alloc(dwVerLen);
2970 if( !lpVer )
2972 ret = ERROR_OUTOFMEMORY;
2973 goto end;
2976 if( !GetFileVersionInfoW(szFilePath, 0, dwVerLen, lpVer) )
2978 ret = GetLastError();
2979 goto end;
2982 if (pcchVersionBuf)
2984 if( VerQueryValueW(lpVer, szVersionResource, (LPVOID*)&ffi, &puLen) &&
2985 (puLen > 0) )
2987 wsprintfW(tmp, szVersionFormat,
2988 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
2989 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS));
2990 if (lpVersionBuf) lstrcpynW(lpVersionBuf, tmp, *pcchVersionBuf);
2992 if (strlenW(tmp) >= *pcchVersionBuf)
2993 ret = ERROR_MORE_DATA;
2995 *pcchVersionBuf = lstrlenW(tmp);
2997 else
2999 if (lpVersionBuf) *lpVersionBuf = 0;
3000 *pcchVersionBuf = 0;
3004 if (pcchLangBuf)
3006 if (VerQueryValueW(lpVer, szLangResource, (LPVOID*)&lang, &puLen) &&
3007 (puLen > 0))
3009 wsprintfW(tmp, szLangFormat, *lang);
3010 if (lpLangBuf) lstrcpynW(lpLangBuf, tmp, *pcchLangBuf);
3012 if (strlenW(tmp) >= *pcchLangBuf)
3013 ret = ERROR_MORE_DATA;
3015 *pcchLangBuf = lstrlenW(tmp);
3017 else
3019 if (lpLangBuf) *lpLangBuf = 0;
3020 *pcchLangBuf = 0;
3024 end:
3025 msi_free(lpVer);
3026 return ret;
3029 /***********************************************************************
3030 * MsiGetFeatureUsageW [MSI.@]
3032 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
3033 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3035 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
3036 pdwUseCount, pwDateUsed);
3037 return ERROR_CALL_NOT_IMPLEMENTED;
3040 /***********************************************************************
3041 * MsiGetFeatureUsageA [MSI.@]
3043 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
3044 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3046 LPWSTR prod = NULL, feat = NULL;
3047 UINT ret = ERROR_OUTOFMEMORY;
3049 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
3050 pdwUseCount, pwDateUsed);
3052 prod = strdupAtoW( szProduct );
3053 if (szProduct && !prod)
3054 goto end;
3056 feat = strdupAtoW( szFeature );
3057 if (szFeature && !feat)
3058 goto end;
3060 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
3062 end:
3063 msi_free( prod );
3064 msi_free( feat );
3066 return ret;
3069 /***********************************************************************
3070 * MsiUseFeatureExW [MSI.@]
3072 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
3073 DWORD dwInstallMode, DWORD dwReserved )
3075 INSTALLSTATE state;
3077 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3078 dwInstallMode, dwReserved);
3080 state = MsiQueryFeatureStateW( szProduct, szFeature );
3082 if (dwReserved)
3083 return INSTALLSTATE_INVALIDARG;
3085 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
3087 FIXME("mark product %s feature %s as used\n",
3088 debugstr_w(szProduct), debugstr_w(szFeature) );
3091 return state;
3094 /***********************************************************************
3095 * MsiUseFeatureExA [MSI.@]
3097 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
3098 DWORD dwInstallMode, DWORD dwReserved )
3100 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
3101 LPWSTR prod = NULL, feat = NULL;
3103 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3104 dwInstallMode, dwReserved);
3106 prod = strdupAtoW( szProduct );
3107 if (szProduct && !prod)
3108 goto end;
3110 feat = strdupAtoW( szFeature );
3111 if (szFeature && !feat)
3112 goto end;
3114 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
3116 end:
3117 msi_free( prod );
3118 msi_free( feat );
3120 return ret;
3123 /***********************************************************************
3124 * MsiUseFeatureW [MSI.@]
3126 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
3128 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
3131 /***********************************************************************
3132 * MsiUseFeatureA [MSI.@]
3134 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
3136 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
3139 /***********************************************************************
3140 * MSI_ProvideQualifiedComponentEx [internal]
3142 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
3143 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3144 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
3145 LPDWORD pcchPathBuf)
3147 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
3148 feature[MAX_FEATURE_CHARS+1];
3149 LPWSTR info;
3150 HKEY hkey;
3151 DWORD sz;
3152 UINT rc;
3154 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent),
3155 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
3156 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3158 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
3159 if (rc != ERROR_SUCCESS)
3160 return ERROR_INDEX_ABSENT;
3162 info = msi_reg_get_val_str( hkey, szQualifier );
3163 RegCloseKey(hkey);
3165 if (!info)
3166 return ERROR_INDEX_ABSENT;
3168 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
3170 if (!szProduct)
3171 rc = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
3172 else
3173 rc = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
3175 msi_free( info );
3177 if (rc != INSTALLSTATE_LOCAL)
3178 return ERROR_FILE_NOT_FOUND;
3180 return ERROR_SUCCESS;
3183 /***********************************************************************
3184 * MsiProvideQualifiedComponentExW [MSI.@]
3186 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
3187 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3188 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
3189 LPDWORD pcchPathBuf)
3191 awstring path;
3193 path.unicode = TRUE;
3194 path.str.w = lpPathBuf;
3196 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
3197 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
3200 /***********************************************************************
3201 * MsiProvideQualifiedComponentExA [MSI.@]
3203 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
3204 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
3205 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
3206 LPDWORD pcchPathBuf)
3208 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
3209 UINT r = ERROR_OUTOFMEMORY;
3210 awstring path;
3212 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
3213 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
3214 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3216 szwComponent = strdupAtoW( szComponent );
3217 if (szComponent && !szwComponent)
3218 goto end;
3220 szwQualifier = strdupAtoW( szQualifier );
3221 if (szQualifier && !szwQualifier)
3222 goto end;
3224 szwProduct = strdupAtoW( szProduct );
3225 if (szProduct && !szwProduct)
3226 goto end;
3228 path.unicode = FALSE;
3229 path.str.a = lpPathBuf;
3231 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
3232 dwInstallMode, szwProduct, Unused1,
3233 Unused2, &path, pcchPathBuf);
3234 end:
3235 msi_free(szwProduct);
3236 msi_free(szwComponent);
3237 msi_free(szwQualifier);
3239 return r;
3242 /***********************************************************************
3243 * MsiProvideQualifiedComponentW [MSI.@]
3245 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
3246 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
3247 LPDWORD pcchPathBuf)
3249 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
3250 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3253 /***********************************************************************
3254 * MsiProvideQualifiedComponentA [MSI.@]
3256 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
3257 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
3258 LPDWORD pcchPathBuf)
3260 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
3261 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3264 /***********************************************************************
3265 * MSI_GetUserInfo [internal]
3267 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
3268 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
3269 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3270 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
3272 WCHAR squished_pc[SQUISH_GUID_SIZE];
3273 LPWSTR user, org, serial;
3274 USERINFOSTATE state;
3275 HKEY hkey, props;
3276 LPCWSTR orgptr;
3277 UINT r;
3279 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
3280 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
3281 pcchSerialBuf);
3283 if (!szProduct || !squash_guid(szProduct, squished_pc))
3284 return USERINFOSTATE_INVALIDARG;
3286 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
3287 &hkey, FALSE) != ERROR_SUCCESS &&
3288 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3289 &hkey, FALSE) != ERROR_SUCCESS &&
3290 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
3291 &hkey, FALSE) != ERROR_SUCCESS)
3293 return USERINFOSTATE_UNKNOWN;
3296 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
3297 NULL, &props, FALSE) != ERROR_SUCCESS &&
3298 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
3299 NULL, &props, FALSE) != ERROR_SUCCESS)
3301 RegCloseKey(hkey);
3302 return USERINFOSTATE_ABSENT;
3305 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3306 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3307 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3308 state = USERINFOSTATE_ABSENT;
3310 RegCloseKey(hkey);
3311 RegCloseKey(props);
3313 if (user && serial)
3314 state = USERINFOSTATE_PRESENT;
3316 if (pcchUserNameBuf)
3318 if (lpUserNameBuf && !user)
3320 (*pcchUserNameBuf)--;
3321 goto done;
3324 r = msi_strcpy_to_awstring(user, lpUserNameBuf, pcchUserNameBuf);
3325 if (r == ERROR_MORE_DATA)
3327 state = USERINFOSTATE_MOREDATA;
3328 goto done;
3332 if (pcchOrgNameBuf)
3334 orgptr = org;
3335 if (!orgptr) orgptr = szEmpty;
3337 r = msi_strcpy_to_awstring(orgptr, lpOrgNameBuf, pcchOrgNameBuf);
3338 if (r == ERROR_MORE_DATA)
3340 state = USERINFOSTATE_MOREDATA;
3341 goto done;
3345 if (pcchSerialBuf)
3347 if (!serial)
3349 (*pcchSerialBuf)--;
3350 goto done;
3353 r = msi_strcpy_to_awstring(serial, lpSerialBuf, pcchSerialBuf);
3354 if (r == ERROR_MORE_DATA)
3355 state = USERINFOSTATE_MOREDATA;
3358 done:
3359 msi_free(user);
3360 msi_free(org);
3361 msi_free(serial);
3363 return state;
3366 /***********************************************************************
3367 * MsiGetUserInfoW [MSI.@]
3369 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3370 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3371 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3372 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3374 awstring user, org, serial;
3376 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3377 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3378 (lpSerialBuf && !pcchSerialBuf))
3379 return USERINFOSTATE_INVALIDARG;
3381 user.unicode = TRUE;
3382 user.str.w = lpUserNameBuf;
3383 org.unicode = TRUE;
3384 org.str.w = lpOrgNameBuf;
3385 serial.unicode = TRUE;
3386 serial.str.w = lpSerialBuf;
3388 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3389 &org, pcchOrgNameBuf,
3390 &serial, pcchSerialBuf );
3393 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3394 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3395 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3396 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3398 awstring user, org, serial;
3399 LPWSTR prod;
3400 UINT r;
3402 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3403 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3404 (lpSerialBuf && !pcchSerialBuf))
3405 return USERINFOSTATE_INVALIDARG;
3407 prod = strdupAtoW( szProduct );
3408 if (szProduct && !prod)
3409 return ERROR_OUTOFMEMORY;
3411 user.unicode = FALSE;
3412 user.str.a = lpUserNameBuf;
3413 org.unicode = FALSE;
3414 org.str.a = lpOrgNameBuf;
3415 serial.unicode = FALSE;
3416 serial.str.a = lpSerialBuf;
3418 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3419 &org, pcchOrgNameBuf,
3420 &serial, pcchSerialBuf );
3422 msi_free( prod );
3424 return r;
3427 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3429 MSIHANDLE handle;
3430 UINT rc;
3431 MSIPACKAGE *package;
3432 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3434 TRACE("(%s)\n",debugstr_w(szProduct));
3436 rc = MsiOpenProductW(szProduct,&handle);
3437 if (rc != ERROR_SUCCESS)
3438 return ERROR_INVALID_PARAMETER;
3440 /* MsiCollectUserInfo cannot be called from a custom action. */
3441 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3442 if (!package)
3443 return ERROR_CALL_NOT_IMPLEMENTED;
3445 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3446 msiobj_release( &package->hdr );
3448 MsiCloseHandle(handle);
3450 return rc;
3453 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3455 MSIHANDLE handle;
3456 UINT rc;
3457 MSIPACKAGE *package;
3458 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3460 TRACE("(%s)\n",debugstr_a(szProduct));
3462 rc = MsiOpenProductA(szProduct,&handle);
3463 if (rc != ERROR_SUCCESS)
3464 return ERROR_INVALID_PARAMETER;
3466 /* MsiCollectUserInfo cannot be called from a custom action. */
3467 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3468 if (!package)
3469 return ERROR_CALL_NOT_IMPLEMENTED;
3471 rc = ACTION_PerformUIAction(package, szFirstRun, -1);
3472 msiobj_release( &package->hdr );
3474 MsiCloseHandle(handle);
3476 return rc;
3479 /***********************************************************************
3480 * MsiConfigureFeatureA [MSI.@]
3482 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3484 LPWSTR prod, feat = NULL;
3485 UINT r = ERROR_OUTOFMEMORY;
3487 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3489 prod = strdupAtoW( szProduct );
3490 if (szProduct && !prod)
3491 goto end;
3493 feat = strdupAtoW( szFeature );
3494 if (szFeature && !feat)
3495 goto end;
3497 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3499 end:
3500 msi_free(feat);
3501 msi_free(prod);
3503 return r;
3506 /***********************************************************************
3507 * MsiConfigureFeatureW [MSI.@]
3509 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3511 static const WCHAR szCostInit[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3512 MSIPACKAGE *package = NULL;
3513 UINT r;
3514 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3515 DWORD sz;
3517 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3519 if (!szProduct || !szFeature)
3520 return ERROR_INVALID_PARAMETER;
3522 switch (eInstallState)
3524 case INSTALLSTATE_DEFAULT:
3525 /* FIXME: how do we figure out the default location? */
3526 eInstallState = INSTALLSTATE_LOCAL;
3527 break;
3528 case INSTALLSTATE_LOCAL:
3529 case INSTALLSTATE_SOURCE:
3530 case INSTALLSTATE_ABSENT:
3531 case INSTALLSTATE_ADVERTISED:
3532 break;
3533 default:
3534 return ERROR_INVALID_PARAMETER;
3537 r = MSI_OpenProductW( szProduct, &package );
3538 if (r != ERROR_SUCCESS)
3539 return r;
3541 sz = sizeof(sourcepath);
3542 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3543 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3545 sz = sizeof(filename);
3546 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3547 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3549 lstrcatW( sourcepath, filename );
3551 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3553 r = ACTION_PerformUIAction( package, szCostInit, -1 );
3554 if (r != ERROR_SUCCESS)
3555 goto end;
3557 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3558 if (r != ERROR_SUCCESS)
3559 goto end;
3561 r = MSI_InstallPackage( package, sourcepath, NULL );
3563 end:
3564 msiobj_release( &package->hdr );
3566 return r;
3569 /***********************************************************************
3570 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3572 * Notes: undocumented
3574 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3576 WCHAR path[MAX_PATH];
3578 TRACE("%d\n", dwReserved);
3580 if (dwReserved)
3582 FIXME("dwReserved=%d\n", dwReserved);
3583 return ERROR_INVALID_PARAMETER;
3586 if (!GetWindowsDirectoryW(path, MAX_PATH))
3587 return ERROR_FUNCTION_FAILED;
3589 lstrcatW(path, installerW);
3591 if (!CreateDirectoryW(path, NULL))
3592 return ERROR_FUNCTION_FAILED;
3594 return ERROR_SUCCESS;
3597 /***********************************************************************
3598 * MsiGetShortcutTargetA [MSI.@]
3600 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3601 LPSTR szProductCode, LPSTR szFeatureId,
3602 LPSTR szComponentCode )
3604 LPWSTR target;
3605 const int len = MAX_FEATURE_CHARS+1;
3606 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3607 UINT r;
3609 target = strdupAtoW( szShortcutTarget );
3610 if (szShortcutTarget && !target )
3611 return ERROR_OUTOFMEMORY;
3612 product[0] = 0;
3613 feature[0] = 0;
3614 component[0] = 0;
3615 r = MsiGetShortcutTargetW( target, product, feature, component );
3616 msi_free( target );
3617 if (r == ERROR_SUCCESS)
3619 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3620 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3621 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3623 return r;
3626 /***********************************************************************
3627 * MsiGetShortcutTargetW [MSI.@]
3629 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3630 LPWSTR szProductCode, LPWSTR szFeatureId,
3631 LPWSTR szComponentCode )
3633 IShellLinkDataList *dl = NULL;
3634 IPersistFile *pf = NULL;
3635 LPEXP_DARWIN_LINK darwin = NULL;
3636 HRESULT r, init;
3638 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3639 szProductCode, szFeatureId, szComponentCode );
3641 init = CoInitialize(NULL);
3643 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3644 &IID_IPersistFile, (LPVOID*) &pf );
3645 if( SUCCEEDED( r ) )
3647 r = IPersistFile_Load( pf, szShortcutTarget,
3648 STGM_READ | STGM_SHARE_DENY_WRITE );
3649 if( SUCCEEDED( r ) )
3651 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3652 (LPVOID*) &dl );
3653 if( SUCCEEDED( r ) )
3655 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3656 (LPVOID) &darwin );
3657 IShellLinkDataList_Release( dl );
3660 IPersistFile_Release( pf );
3663 if (SUCCEEDED(init))
3664 CoUninitialize();
3666 TRACE("darwin = %p\n", darwin);
3668 if (darwin)
3670 DWORD sz;
3671 UINT ret;
3673 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3674 szProductCode, szFeatureId, szComponentCode, &sz );
3675 LocalFree( darwin );
3676 return ret;
3679 return ERROR_FUNCTION_FAILED;
3682 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature,
3683 DWORD dwReinstallMode )
3685 MSIPACKAGE* package = NULL;
3686 UINT r;
3687 WCHAR sourcepath[MAX_PATH];
3688 WCHAR filename[MAX_PATH];
3689 static const WCHAR szLogVerbose[] = {
3690 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3691 WCHAR reinstallmode[11];
3692 LPWSTR ptr;
3693 DWORD sz;
3695 FIXME("%s %s 0x%08x\n",
3696 debugstr_w(szProduct), debugstr_w(szFeature), dwReinstallMode);
3698 ptr = reinstallmode;
3700 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3701 *ptr++ = 'p';
3702 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3703 *ptr++ = 'o';
3704 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3705 *ptr++ = 'w';
3706 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3707 *ptr++ = 'd';
3708 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3709 *ptr++ = 'c';
3710 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3711 *ptr++ = 'a';
3712 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3713 *ptr++ = 'u';
3714 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3715 *ptr++ = 'm';
3716 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3717 *ptr++ = 's';
3718 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3719 *ptr++ = 'v';
3720 *ptr = 0;
3722 sz = sizeof(sourcepath);
3723 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3724 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3726 sz = sizeof(filename);
3727 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3728 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3730 lstrcatW( sourcepath, filename );
3732 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3733 r = MSI_OpenPackageW( sourcepath, &package );
3734 else
3735 r = MSI_OpenProductW( szProduct, &package );
3737 if (r != ERROR_SUCCESS)
3738 return r;
3740 msi_set_property( package->db, szReinstallMode, reinstallmode );
3741 msi_set_property( package->db, szInstalled, szOne );
3742 msi_set_property( package->db, szLogVerbose, szOne );
3743 msi_set_property( package->db, szReinstall, szFeature );
3745 r = MSI_InstallPackage( package, sourcepath, NULL );
3747 msiobj_release( &package->hdr );
3749 return r;
3752 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3753 DWORD dwReinstallMode )
3755 LPWSTR wszProduct;
3756 LPWSTR wszFeature;
3757 UINT rc;
3759 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3760 dwReinstallMode);
3762 wszProduct = strdupAtoW(szProduct);
3763 wszFeature = strdupAtoW(szFeature);
3765 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3767 msi_free(wszProduct);
3768 msi_free(wszFeature);
3769 return rc;
3772 typedef struct
3774 unsigned int i[2];
3775 unsigned int buf[4];
3776 unsigned char in[64];
3777 unsigned char digest[16];
3778 } MD5_CTX;
3780 extern VOID WINAPI MD5Init( MD5_CTX *);
3781 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
3782 extern VOID WINAPI MD5Final( MD5_CTX *);
3784 /***********************************************************************
3785 * MsiGetFileHashW [MSI.@]
3787 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
3788 PMSIFILEHASHINFO pHash )
3790 HANDLE handle, mapping;
3791 void *p;
3792 DWORD length;
3793 UINT r = ERROR_FUNCTION_FAILED;
3795 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
3797 if (!szFilePath)
3798 return ERROR_INVALID_PARAMETER;
3800 if (!*szFilePath)
3801 return ERROR_PATH_NOT_FOUND;
3803 if (dwOptions)
3804 return ERROR_INVALID_PARAMETER;
3805 if (!pHash)
3806 return ERROR_INVALID_PARAMETER;
3807 if (pHash->dwFileHashInfoSize < sizeof *pHash)
3808 return ERROR_INVALID_PARAMETER;
3810 handle = CreateFileW( szFilePath, GENERIC_READ,
3811 FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
3812 if (handle == INVALID_HANDLE_VALUE)
3814 WARN("can't open file %u\n", GetLastError());
3815 return ERROR_FILE_NOT_FOUND;
3817 length = GetFileSize( handle, NULL );
3819 mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL );
3820 if (mapping)
3822 p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length );
3823 if (p)
3825 MD5_CTX ctx;
3827 MD5Init( &ctx );
3828 MD5Update( &ctx, p, length );
3829 MD5Final( &ctx );
3830 UnmapViewOfFile( p );
3832 memcpy( pHash->dwData, ctx.digest, sizeof pHash->dwData );
3833 r = ERROR_SUCCESS;
3835 CloseHandle( mapping );
3837 CloseHandle( handle );
3839 return r;
3842 /***********************************************************************
3843 * MsiGetFileHashA [MSI.@]
3845 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
3846 PMSIFILEHASHINFO pHash )
3848 LPWSTR file;
3849 UINT r;
3851 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
3853 file = strdupAtoW( szFilePath );
3854 if (szFilePath && !file)
3855 return ERROR_OUTOFMEMORY;
3857 r = MsiGetFileHashW( file, dwOptions, pHash );
3858 msi_free( file );
3859 return r;
3862 /***********************************************************************
3863 * MsiAdvertiseScriptW [MSI.@]
3865 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
3866 PHKEY phRegData, BOOL fRemoveItems )
3868 FIXME("%s %08x %p %d\n",
3869 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3870 return ERROR_CALL_NOT_IMPLEMENTED;
3873 /***********************************************************************
3874 * MsiAdvertiseScriptA [MSI.@]
3876 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
3877 PHKEY phRegData, BOOL fRemoveItems )
3879 FIXME("%s %08x %p %d\n",
3880 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
3881 return ERROR_CALL_NOT_IMPLEMENTED;
3884 /***********************************************************************
3885 * MsiIsProductElevatedW [MSI.@]
3887 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
3889 FIXME("%s %p - stub\n",
3890 debugstr_w( szProduct ), pfElevated );
3891 *pfElevated = TRUE;
3892 return ERROR_SUCCESS;
3895 /***********************************************************************
3896 * MsiIsProductElevatedA [MSI.@]
3898 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
3900 FIXME("%s %p - stub\n",
3901 debugstr_a( szProduct ), pfElevated );
3902 *pfElevated = TRUE;
3903 return ERROR_SUCCESS;
3906 /***********************************************************************
3907 * MsiSetExternalUIRecord [MSI.@]
3909 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler,
3910 DWORD filter, LPVOID context,
3911 PINSTALLUI_HANDLER_RECORD prev )
3913 TRACE("%p %08x %p %p\n", handler, filter, context, prev);
3915 if (prev)
3916 *prev = gUIHandlerRecord;
3918 gUIHandlerRecord = handler;
3919 gUIFilter = filter;
3920 gUIContext = context;
3922 return ERROR_SUCCESS;
3925 /***********************************************************************
3926 * MsiInstallMissingComponentA [MSI.@]
3928 UINT WINAPI MsiInstallMissingComponentA( LPCSTR product, LPCSTR component, INSTALLSTATE state )
3930 UINT r;
3931 WCHAR *productW = NULL, *componentW = NULL;
3933 TRACE("%s, %s, %d\n", debugstr_a(product), debugstr_a(component), state);
3935 if (product && !(productW = strdupAtoW( product )))
3936 return ERROR_OUTOFMEMORY;
3938 if (component && !(componentW = strdupAtoW( component )))
3940 msi_free( productW );
3941 return ERROR_OUTOFMEMORY;
3944 r = MsiInstallMissingComponentW( productW, componentW, state );
3945 msi_free( productW );
3946 msi_free( componentW );
3947 return r;
3950 /***********************************************************************
3951 * MsiInstallMissingComponentW [MSI.@]
3953 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
3955 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
3956 return ERROR_SUCCESS;
3959 /***********************************************************************
3960 * MsiBeginTransactionA [MSI.@]
3962 UINT WINAPI MsiBeginTransactionA( LPCSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
3964 WCHAR *nameW;
3965 UINT r;
3967 FIXME("%s %u %p %p\n", debugstr_a(name), attrs, id, event);
3969 nameW = strdupAtoW( name );
3970 if (name && !nameW)
3971 return ERROR_OUTOFMEMORY;
3973 r = MsiBeginTransactionW( nameW, attrs, id, event );
3974 msi_free( nameW );
3975 return r;
3978 /***********************************************************************
3979 * MsiBeginTransactionW [MSI.@]
3981 UINT WINAPI MsiBeginTransactionW( LPCWSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
3983 FIXME("%s %u %p %p\n", debugstr_w(name), attrs, id, event);
3985 *id = (MSIHANDLE)0xdeadbeef;
3986 *event = (HANDLE)0xdeadbeef;
3988 return ERROR_SUCCESS;
3991 /***********************************************************************
3992 * MsiEndTransaction [MSI.@]
3994 UINT WINAPI MsiEndTransaction( DWORD state )
3996 FIXME("%u\n", state);
3997 return ERROR_SUCCESS;