include: Add IAuthenticateEx interface definition.
[wine.git] / dlls / msi / msi.c
blobc4c787da4e4638834353572ecf64ddd509ab4093
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 "wincrypt.h"
35 #include "winver.h"
36 #include "winuser.h"
37 #include "shlobj.h"
38 #include "shobjidl.h"
39 #include "objidl.h"
40 #include "wintrust.h"
41 #include "softpub.h"
43 #include "msipriv.h"
44 #include "winemsi.h"
46 #include "initguid.h"
47 #include "msxml2.h"
49 #include "wine/debug.h"
50 #include "wine/exception.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(msi);
54 BOOL is_wow64;
56 UINT msi_locate_product(LPCWSTR szProduct, MSIINSTALLCONTEXT *context)
58 HKEY hkey = NULL;
60 *context = MSIINSTALLCONTEXT_NONE;
61 if (!szProduct) return ERROR_UNKNOWN_PRODUCT;
63 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
64 &hkey, FALSE) == ERROR_SUCCESS)
65 *context = MSIINSTALLCONTEXT_USERMANAGED;
66 else if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
67 &hkey, FALSE) == ERROR_SUCCESS)
68 *context = MSIINSTALLCONTEXT_MACHINE;
69 else if (MSIREG_OpenProductKey(szProduct, NULL,
70 MSIINSTALLCONTEXT_USERUNMANAGED,
71 &hkey, FALSE) == ERROR_SUCCESS)
72 *context = MSIINSTALLCONTEXT_USERUNMANAGED;
74 RegCloseKey(hkey);
76 if (*context == MSIINSTALLCONTEXT_NONE)
77 return ERROR_UNKNOWN_PRODUCT;
79 return ERROR_SUCCESS;
82 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
84 UINT r;
85 LPWSTR szwProd = NULL;
87 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
89 if( szProduct )
91 szwProd = strdupAtoW( szProduct );
92 if( !szwProd )
93 return ERROR_OUTOFMEMORY;
96 r = MsiOpenProductW( szwProd, phProduct );
98 msi_free( szwProd );
100 return r;
103 static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
105 UINT r;
106 HKEY props;
107 LPWSTR path;
108 MSIINSTALLCONTEXT context;
110 TRACE("%s %p\n", debugstr_w(szProduct), package);
112 r = msi_locate_product(szProduct, &context);
113 if (r != ERROR_SUCCESS)
114 return r;
116 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &props, FALSE);
117 if (r != ERROR_SUCCESS)
118 return ERROR_UNKNOWN_PRODUCT;
120 if (context == MSIINSTALLCONTEXT_USERMANAGED)
121 path = msi_reg_get_val_str(props, L"ManagedLocalPackage");
122 else
123 path = msi_reg_get_val_str(props, L"LocalPackage");
125 r = ERROR_UNKNOWN_PRODUCT;
127 if (!path || GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
128 goto done;
130 if (PathIsRelativeW(path))
132 r = ERROR_INSTALL_PACKAGE_OPEN_FAILED;
133 goto done;
136 r = MSI_OpenPackageW(path, 0, package);
138 done:
139 RegCloseKey(props);
140 msi_free(path);
141 return r;
144 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
146 MSIPACKAGE *package = NULL;
147 WCHAR squashed_pc[SQUASHED_GUID_SIZE];
148 UINT r;
150 if (!szProduct || !squash_guid( szProduct, squashed_pc ))
151 return ERROR_INVALID_PARAMETER;
153 if (!phProduct)
154 return ERROR_INVALID_PARAMETER;
156 r = MSI_OpenProductW(szProduct, &package);
157 if (r != ERROR_SUCCESS)
158 return r;
160 *phProduct = alloc_msihandle(&package->hdr);
161 if (!*phProduct)
162 r = ERROR_NOT_ENOUGH_MEMORY;
164 msiobj_release(&package->hdr);
165 return r;
168 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
169 LPCSTR szTransforms, LANGID lgidLanguage)
171 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
172 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
173 return ERROR_CALL_NOT_IMPLEMENTED;
176 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
177 LPCWSTR szTransforms, LANGID lgidLanguage)
179 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
180 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
181 return ERROR_CALL_NOT_IMPLEMENTED;
184 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
185 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
187 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
188 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
189 lgidLanguage, dwPlatform, dwOptions);
190 return ERROR_CALL_NOT_IMPLEMENTED;
193 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
194 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
196 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
197 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
198 lgidLanguage, dwPlatform, dwOptions);
199 return ERROR_CALL_NOT_IMPLEMENTED;
202 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
204 LPWSTR szwPath = NULL, szwCommand = NULL;
205 UINT r = ERROR_OUTOFMEMORY;
207 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
209 if( szPackagePath )
211 szwPath = strdupAtoW( szPackagePath );
212 if( !szwPath )
213 goto end;
216 if( szCommandLine )
218 szwCommand = strdupAtoW( szCommandLine );
219 if( !szwCommand )
220 goto end;
223 r = MsiInstallProductW( szwPath, szwCommand );
225 end:
226 msi_free( szwPath );
227 msi_free( szwCommand );
229 return r;
232 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
234 MSIPACKAGE *package = NULL;
235 const WCHAR *reinstallmode;
236 DWORD options = 0;
237 UINT r, len;
239 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
241 if (!szPackagePath)
242 return ERROR_INVALID_PARAMETER;
244 if (!*szPackagePath)
245 return ERROR_PATH_NOT_FOUND;
247 reinstallmode = msi_get_command_line_option(szCommandLine, L"REINSTALLMODE", &len);
248 if (reinstallmode)
250 while (len > 0)
252 if (reinstallmode[--len] == 'v' || reinstallmode[len] == 'V')
254 options |= WINE_OPENPACKAGEFLAGS_RECACHE;
255 break;
260 r = MSI_OpenPackageW( szPackagePath, options, &package );
261 if (r == ERROR_SUCCESS)
263 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
264 msiobj_release( &package->hdr );
267 return r;
270 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
272 LPWSTR wszProduct;
273 UINT rc;
275 TRACE("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
277 wszProduct = strdupAtoW(szProduct);
279 rc = MsiReinstallProductW(wszProduct, dwReinstallMode);
281 msi_free(wszProduct);
282 return rc;
285 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
287 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
289 return MsiReinstallFeatureW(szProduct, L"ALL", dwReinstallMode);
292 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
293 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
295 LPWSTR patch_package = NULL;
296 LPWSTR install_package = NULL;
297 LPWSTR command_line = NULL;
298 UINT r = ERROR_OUTOFMEMORY;
300 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
301 eInstallType, debugstr_a(szCommandLine));
303 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
304 goto done;
306 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
307 goto done;
309 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
310 goto done;
312 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
314 done:
315 msi_free(patch_package);
316 msi_free(install_package);
317 msi_free(command_line);
319 return r;
322 static UINT get_patch_product_codes( LPCWSTR szPatchPackage, WCHAR ***product_codes )
324 MSIHANDLE patch, info = 0;
325 UINT r, type;
326 DWORD size;
327 static WCHAR empty[] = L"";
328 WCHAR *codes = NULL;
330 r = MsiOpenDatabaseW( szPatchPackage, MSIDBOPEN_READONLY, &patch );
331 if (r != ERROR_SUCCESS)
332 return r;
334 r = MsiGetSummaryInformationW( patch, NULL, 0, &info );
335 if (r != ERROR_SUCCESS)
336 goto done;
338 size = 0;
339 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, empty, &size );
340 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
342 ERR("Failed to read product codes from patch\n");
343 r = ERROR_FUNCTION_FAILED;
344 goto done;
347 codes = msi_alloc( ++size * sizeof(WCHAR) );
348 if (!codes)
350 r = ERROR_OUTOFMEMORY;
351 goto done;
354 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, codes, &size );
355 if (r == ERROR_SUCCESS)
356 *product_codes = msi_split_string( codes, ';' );
358 done:
359 MsiCloseHandle( info );
360 MsiCloseHandle( patch );
361 msi_free( codes );
362 return r;
365 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
367 UINT i, r = ERROR_FUNCTION_FAILED;
368 DWORD size;
369 LPCWSTR cmd_ptr = szCommandLine;
370 LPWSTR cmd, *codes = NULL;
371 BOOL succeeded = FALSE;
373 if (!szPatchPackage || !szPatchPackage[0])
374 return ERROR_INVALID_PARAMETER;
376 if (!szProductCode && (r = get_patch_product_codes( szPatchPackage, &codes )))
377 return r;
379 if (!szCommandLine)
380 cmd_ptr = L"";
382 size = lstrlenW(cmd_ptr) + lstrlenW(L"%s PATCH=\"%s\"") + lstrlenW(szPatchPackage) + 1;
383 cmd = msi_alloc(size * sizeof(WCHAR));
384 if (!cmd)
386 msi_free(codes);
387 return ERROR_OUTOFMEMORY;
389 swprintf(cmd, size, L"%s PATCH=\"%s\"", cmd_ptr, szPatchPackage);
391 if (szProductCode)
392 r = MsiConfigureProductExW(szProductCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
393 else
395 for (i = 0; codes[i]; i++)
397 r = MsiConfigureProductExW(codes[i], INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
398 if (r == ERROR_SUCCESS)
400 TRACE("patch applied\n");
401 succeeded = TRUE;
405 if (succeeded)
406 r = ERROR_SUCCESS;
409 msi_free(cmd);
410 msi_free(codes);
411 return r;
414 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
415 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
417 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
418 eInstallType, debugstr_w(szCommandLine));
420 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
421 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
423 FIXME("Only reading target products from patch\n");
424 return ERROR_CALL_NOT_IMPLEMENTED;
427 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
430 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
431 LPCSTR szProductCode, LPCSTR szPropertiesList)
433 LPWSTR patch_packages = NULL;
434 LPWSTR product_code = NULL;
435 LPWSTR properties_list = NULL;
436 UINT r = ERROR_OUTOFMEMORY;
438 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
439 debugstr_a(szPropertiesList));
441 if (!szPatchPackages || !szPatchPackages[0])
442 return ERROR_INVALID_PARAMETER;
444 if (!(patch_packages = strdupAtoW(szPatchPackages)))
445 return ERROR_OUTOFMEMORY;
447 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
448 goto done;
450 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
451 goto done;
453 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
455 done:
456 msi_free(patch_packages);
457 msi_free(product_code);
458 msi_free(properties_list);
460 return r;
463 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
464 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
466 UINT r = ERROR_SUCCESS;
467 LPCWSTR beg, end;
469 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
470 debugstr_w(szPropertiesList));
472 if (!szPatchPackages || !szPatchPackages[0])
473 return ERROR_INVALID_PARAMETER;
475 beg = end = szPatchPackages;
476 while (*beg)
478 DWORD len;
479 LPWSTR patch;
481 while (*beg == ' ') beg++;
482 while (*end && *end != ';') end++;
484 len = end - beg;
485 while (len && beg[len - 1] == ' ') len--;
487 if (!len) return ERROR_INVALID_NAME;
489 patch = msi_alloc((len + 1) * sizeof(WCHAR));
490 if (!patch)
491 return ERROR_OUTOFMEMORY;
493 memcpy(patch, beg, len * sizeof(WCHAR));
494 patch[len] = '\0';
496 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
497 msi_free(patch);
499 if (r != ERROR_SUCCESS || !*end)
500 break;
502 beg = ++end;
504 return r;
507 static void free_patchinfo( DWORD count, MSIPATCHSEQUENCEINFOW *info )
509 DWORD i;
510 for (i = 0; i < count; i++) msi_free( (WCHAR *)info[i].szPatchData );
511 msi_free( info );
514 static MSIPATCHSEQUENCEINFOW *patchinfoAtoW( DWORD count, const MSIPATCHSEQUENCEINFOA *info )
516 DWORD i;
517 MSIPATCHSEQUENCEINFOW *ret;
519 if (!(ret = msi_alloc( count * sizeof(MSIPATCHSEQUENCEINFOW) ))) return NULL;
520 for (i = 0; i < count; i++)
522 if (info[i].szPatchData && !(ret[i].szPatchData = strdupAtoW( info[i].szPatchData )))
524 free_patchinfo( i, ret );
525 return NULL;
527 ret[i].ePatchDataType = info[i].ePatchDataType;
528 ret[i].dwOrder = info[i].dwOrder;
529 ret[i].uStatus = info[i].uStatus;
531 return ret;
534 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
535 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
537 UINT i, r;
538 WCHAR *package_path = NULL;
539 MSIPATCHSEQUENCEINFOW *psi;
541 TRACE("%s, %u, %p\n", debugstr_a(szProductPackagePath), cPatchInfo, pPatchInfo);
543 if (szProductPackagePath && !(package_path = strdupAtoW( szProductPackagePath )))
544 return ERROR_OUTOFMEMORY;
546 if (!(psi = patchinfoAtoW( cPatchInfo, pPatchInfo )))
548 msi_free( package_path );
549 return ERROR_OUTOFMEMORY;
551 r = MsiDetermineApplicablePatchesW( package_path, cPatchInfo, psi );
552 if (r == ERROR_SUCCESS)
554 for (i = 0; i < cPatchInfo; i++)
556 pPatchInfo[i].dwOrder = psi[i].dwOrder;
557 pPatchInfo[i].uStatus = psi[i].uStatus;
560 msi_free( package_path );
561 free_patchinfo( cPatchInfo, psi );
562 return r;
565 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
567 MSISUMMARYINFO *si;
568 MSIDATABASE *patch_db;
569 UINT r;
571 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
572 if (r != ERROR_SUCCESS)
574 WARN("failed to open patch file %s\n", debugstr_w(patch));
575 return r;
578 r = msi_get_suminfo( patch_db->storage, 0, &si );
579 if (r != ERROR_SUCCESS)
581 msiobj_release( &patch_db->hdr );
582 return ERROR_FUNCTION_FAILED;
585 r = msi_check_patch_applicable( package, si );
586 if (r != ERROR_SUCCESS)
587 TRACE("patch not applicable\n");
589 msiobj_release( &patch_db->hdr );
590 msiobj_release( &si->hdr );
591 return r;
594 /* IXMLDOMDocument should be set to XPath mode already */
595 static UINT MSI_ApplicablePatchXML( MSIPACKAGE *package, IXMLDOMDocument *desc )
597 UINT r = ERROR_FUNCTION_FAILED;
598 IXMLDOMNodeList *list;
599 LPWSTR product_code;
600 IXMLDOMNode *node;
601 HRESULT hr;
602 BSTR s;
604 product_code = msi_dup_property( package->db, L"ProductCode" );
605 if (!product_code)
607 /* FIXME: the property ProductCode should be written into the DB somewhere */
608 ERR("no product code to check\n");
609 return ERROR_SUCCESS;
612 s = SysAllocString( L"MsiPatch/TargetProduct/TargetProductCode" );
613 hr = IXMLDOMDocument_selectNodes( desc, s, &list );
614 SysFreeString(s);
615 if (hr != S_OK)
616 return ERROR_INVALID_PATCH_XML;
618 while (IXMLDOMNodeList_nextNode( list, &node ) == S_OK && r != ERROR_SUCCESS)
620 hr = IXMLDOMNode_get_text( node, &s );
621 IXMLDOMNode_Release( node );
622 if (hr == S_OK)
624 if (!wcscmp( s, product_code )) r = ERROR_SUCCESS;
625 SysFreeString( s );
628 IXMLDOMNodeList_Release( list );
630 if (r != ERROR_SUCCESS)
631 TRACE("patch not applicable\n");
633 msi_free( product_code );
634 return r;
637 static UINT determine_patch_sequence( MSIPACKAGE *package, DWORD count, MSIPATCHSEQUENCEINFOW *info )
639 IXMLDOMDocument *desc = NULL;
640 DWORD i;
642 if (count > 1)
643 FIXME("patch ordering not supported\n");
645 for (i = 0; i < count; i++)
647 switch (info[i].ePatchDataType)
649 case MSIPATCH_DATATYPE_PATCHFILE:
651 if (MSI_ApplicablePatchW( package, info[i].szPatchData ) != ERROR_SUCCESS)
653 info[i].dwOrder = ~0u;
654 info[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
656 else
658 info[i].dwOrder = i;
659 info[i].uStatus = ERROR_SUCCESS;
661 break;
663 case MSIPATCH_DATATYPE_XMLPATH:
664 case MSIPATCH_DATATYPE_XMLBLOB:
666 VARIANT_BOOL b;
667 HRESULT hr;
668 BSTR s;
670 if (!desc)
672 hr = CoCreateInstance( &CLSID_DOMDocument30, NULL, CLSCTX_INPROC_SERVER,
673 &IID_IXMLDOMDocument, (void**)&desc );
674 if (hr != S_OK)
676 ERR("failed to create DOMDocument30 instance, 0x%08x\n", hr);
677 return ERROR_FUNCTION_FAILED;
681 s = SysAllocString( info[i].szPatchData );
682 if (info[i].ePatchDataType == MSIPATCH_DATATYPE_XMLPATH)
684 VARIANT src;
686 V_VT(&src) = VT_BSTR;
687 V_BSTR(&src) = s;
688 hr = IXMLDOMDocument_load( desc, src, &b );
690 else
691 hr = IXMLDOMDocument_loadXML( desc, s, &b );
692 SysFreeString( s );
693 if ( hr != S_OK )
695 ERR("failed to parse patch description\n");
696 IXMLDOMDocument_Release( desc );
697 break;
700 if (MSI_ApplicablePatchXML( package, desc ) != ERROR_SUCCESS)
702 info[i].dwOrder = ~0u;
703 info[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
705 else
707 info[i].dwOrder = i;
708 info[i].uStatus = ERROR_SUCCESS;
710 break;
712 default:
714 FIXME("unknown patch data type %u\n", info[i].ePatchDataType);
715 info[i].dwOrder = i;
716 info[i].uStatus = ERROR_SUCCESS;
717 break;
721 TRACE("szPatchData: %s\n", debugstr_w(info[i].szPatchData));
722 TRACE("ePatchDataType: %u\n", info[i].ePatchDataType);
723 TRACE("dwOrder: %u\n", info[i].dwOrder);
724 TRACE("uStatus: %u\n", info[i].uStatus);
727 if (desc) IXMLDOMDocument_Release( desc );
729 return ERROR_SUCCESS;
732 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
733 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
735 UINT r;
736 MSIPACKAGE *package;
738 TRACE("%s, %u, %p\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
740 r = MSI_OpenPackageW( szProductPackagePath, 0, &package );
741 if (r != ERROR_SUCCESS)
743 ERR("failed to open package %u\n", r);
744 return r;
746 r = determine_patch_sequence( package, cPatchInfo, pPatchInfo );
747 msiobj_release( &package->hdr );
748 return r;
751 UINT WINAPI MsiDeterminePatchSequenceA( LPCSTR product, LPCSTR usersid,
752 MSIINSTALLCONTEXT context, DWORD count, PMSIPATCHSEQUENCEINFOA patchinfo )
754 UINT i, r;
755 WCHAR *productW, *usersidW = NULL;
756 MSIPATCHSEQUENCEINFOW *patchinfoW;
758 TRACE("%s, %s, %d, %d, %p\n", debugstr_a(product), debugstr_a(usersid),
759 context, count, patchinfo);
761 if (!product) return ERROR_INVALID_PARAMETER;
762 if (!(productW = strdupAtoW( product ))) return ERROR_OUTOFMEMORY;
763 if (usersid && !(usersidW = strdupAtoW( usersid )))
765 msi_free( productW );
766 return ERROR_OUTOFMEMORY;
768 if (!(patchinfoW = patchinfoAtoW( count, patchinfo )))
770 msi_free( productW );
771 msi_free( usersidW );
772 return ERROR_OUTOFMEMORY;
774 r = MsiDeterminePatchSequenceW( productW, usersidW, context, count, patchinfoW );
775 if (r == ERROR_SUCCESS)
777 for (i = 0; i < count; i++)
779 patchinfo[i].dwOrder = patchinfoW[i].dwOrder;
780 patchinfo[i].uStatus = patchinfoW[i].uStatus;
783 msi_free( productW );
784 msi_free( usersidW );
785 free_patchinfo( count, patchinfoW );
786 return r;
789 static UINT open_package( const WCHAR *product, const WCHAR *usersid,
790 MSIINSTALLCONTEXT context, MSIPACKAGE **package )
792 UINT r;
793 HKEY props;
794 WCHAR *localpath, sourcepath[MAX_PATH], filename[MAX_PATH];
796 r = MSIREG_OpenInstallProps( product, context, usersid, &props, FALSE );
797 if (r != ERROR_SUCCESS) return ERROR_BAD_CONFIGURATION;
799 if ((localpath = msi_reg_get_val_str( props, L"LocalPackage" )))
801 lstrcpyW( sourcepath, localpath );
802 msi_free( localpath );
804 RegCloseKey( props );
805 if (!localpath || GetFileAttributesW( sourcepath ) == INVALID_FILE_ATTRIBUTES)
807 DWORD sz = sizeof(sourcepath);
808 MsiSourceListGetInfoW( product, usersid, context, MSICODE_PRODUCT,
809 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz );
810 sz = sizeof(filename);
811 MsiSourceListGetInfoW( product, usersid, context, MSICODE_PRODUCT,
812 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz );
813 lstrcatW( sourcepath, filename );
815 if (GetFileAttributesW( sourcepath ) == INVALID_FILE_ATTRIBUTES)
816 return ERROR_INSTALL_SOURCE_ABSENT;
818 return MSI_OpenPackageW( sourcepath, 0, package );
821 UINT WINAPI MsiDeterminePatchSequenceW( LPCWSTR product, LPCWSTR usersid,
822 MSIINSTALLCONTEXT context, DWORD count, PMSIPATCHSEQUENCEINFOW patchinfo )
824 UINT r;
825 MSIPACKAGE *package;
827 TRACE("%s, %s, %d, %d, %p\n", debugstr_w(product), debugstr_w(usersid),
828 context, count, patchinfo);
830 if (!product) return ERROR_INVALID_PARAMETER;
831 r = open_package( product, usersid, context, &package );
832 if (r != ERROR_SUCCESS) return r;
834 r = determine_patch_sequence( package, count, patchinfo );
835 msiobj_release( &package->hdr );
836 return r;
839 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
840 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
842 MSIPACKAGE* package = NULL;
843 MSIINSTALLCONTEXT context;
844 UINT r;
845 DWORD sz;
846 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
847 LPWSTR commandline;
849 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
850 debugstr_w(szCommandLine));
852 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
853 return ERROR_INVALID_PARAMETER;
855 if (eInstallState == INSTALLSTATE_ADVERTISED ||
856 eInstallState == INSTALLSTATE_SOURCE)
858 FIXME("State %d not implemented\n", eInstallState);
859 return ERROR_CALL_NOT_IMPLEMENTED;
862 r = msi_locate_product(szProduct, &context);
863 if (r != ERROR_SUCCESS)
864 return r;
866 r = open_package(szProduct, NULL, context, &package);
867 if (r != ERROR_SUCCESS)
868 return r;
870 sz = lstrlenW(L" Installed=1") + 1;
872 if (szCommandLine)
873 sz += lstrlenW(szCommandLine);
875 if (eInstallState != INSTALLSTATE_DEFAULT)
876 sz += lstrlenW(L" INSTALLLEVEL=32767");
878 if (eInstallState == INSTALLSTATE_ABSENT)
879 sz += lstrlenW(L" REMOVE=ALL");
881 if (context == MSIINSTALLCONTEXT_MACHINE)
882 sz += lstrlenW(L" ALLUSERS=1");
884 commandline = msi_alloc(sz * sizeof(WCHAR));
885 if (!commandline)
887 r = ERROR_OUTOFMEMORY;
888 goto end;
891 commandline[0] = 0;
892 if (szCommandLine)
893 lstrcpyW(commandline, szCommandLine);
895 if (eInstallState != INSTALLSTATE_DEFAULT)
896 lstrcatW(commandline, L" INSTALLLEVEL=32767");
898 if (eInstallState == INSTALLSTATE_ABSENT)
899 lstrcatW(commandline, L" REMOVE=ALL");
901 if (context == MSIINSTALLCONTEXT_MACHINE)
902 lstrcatW(commandline, L" ALLUSERS=1");
904 sz = sizeof(sourcepath);
905 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
906 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
908 sz = sizeof(filename);
909 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
910 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
912 lstrcatW(sourcepath, filename);
914 r = MSI_InstallPackage( package, sourcepath, commandline );
916 msi_free(commandline);
918 end:
919 msiobj_release( &package->hdr );
921 return r;
924 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
925 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
927 LPWSTR szwProduct = NULL;
928 LPWSTR szwCommandLine = NULL;
929 UINT r = ERROR_OUTOFMEMORY;
931 if( szProduct )
933 szwProduct = strdupAtoW( szProduct );
934 if( !szwProduct )
935 goto end;
938 if( szCommandLine)
940 szwCommandLine = strdupAtoW( szCommandLine );
941 if( !szwCommandLine)
942 goto end;
945 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
946 szwCommandLine );
947 end:
948 msi_free( szwProduct );
949 msi_free( szwCommandLine);
951 return r;
954 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
955 INSTALLSTATE eInstallState)
957 LPWSTR szwProduct = NULL;
958 UINT r;
960 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
962 if( szProduct )
964 szwProduct = strdupAtoW( szProduct );
965 if( !szwProduct )
966 return ERROR_OUTOFMEMORY;
969 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
970 msi_free( szwProduct );
972 return r;
975 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
976 INSTALLSTATE eInstallState)
978 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
981 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
983 LPWSTR szwComponent = NULL;
984 UINT r;
985 WCHAR szwBuffer[GUID_SIZE];
987 TRACE("%s %p\n", debugstr_a(szComponent), szBuffer);
989 if( szComponent )
991 szwComponent = strdupAtoW( szComponent );
992 if( !szwComponent )
993 return ERROR_OUTOFMEMORY;
996 *szwBuffer = '\0';
997 r = MsiGetProductCodeW( szwComponent, szwBuffer );
999 if(*szwBuffer)
1000 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
1002 msi_free( szwComponent );
1004 return r;
1007 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
1009 UINT rc, index;
1010 HKEY compkey, prodkey;
1011 WCHAR squashed_comp[SQUASHED_GUID_SIZE], squashed_prod[SQUASHED_GUID_SIZE];
1012 DWORD sz = ARRAY_SIZE(squashed_prod);
1014 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
1016 if (!szComponent || !*szComponent)
1017 return ERROR_INVALID_PARAMETER;
1019 if (!squash_guid( szComponent, squashed_comp ))
1020 return ERROR_INVALID_PARAMETER;
1022 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
1023 MSIREG_OpenUserDataComponentKey(szComponent, L"S-1-5-18", &compkey, FALSE) != ERROR_SUCCESS)
1025 return ERROR_UNKNOWN_COMPONENT;
1028 rc = RegEnumValueW( compkey, 0, squashed_prod, &sz, NULL, NULL, NULL, NULL );
1029 if (rc != ERROR_SUCCESS)
1031 RegCloseKey(compkey);
1032 return ERROR_UNKNOWN_COMPONENT;
1035 /* check simple case, only one product */
1036 rc = RegEnumValueW( compkey, 1, squashed_prod, &sz, NULL, NULL, NULL, NULL );
1037 if (rc == ERROR_NO_MORE_ITEMS)
1039 rc = ERROR_SUCCESS;
1040 goto done;
1043 index = 0;
1044 while ((rc = RegEnumValueW( compkey, index, squashed_prod, &sz, NULL, NULL, NULL, NULL )) !=
1045 ERROR_NO_MORE_ITEMS)
1047 index++;
1048 sz = GUID_SIZE;
1049 unsquash_guid( squashed_prod, szBuffer );
1051 if (MSIREG_OpenProductKey(szBuffer, NULL,
1052 MSIINSTALLCONTEXT_USERMANAGED,
1053 &prodkey, FALSE) == ERROR_SUCCESS ||
1054 MSIREG_OpenProductKey(szBuffer, NULL,
1055 MSIINSTALLCONTEXT_USERUNMANAGED,
1056 &prodkey, FALSE) == ERROR_SUCCESS ||
1057 MSIREG_OpenProductKey(szBuffer, NULL,
1058 MSIINSTALLCONTEXT_MACHINE,
1059 &prodkey, FALSE) == ERROR_SUCCESS)
1061 RegCloseKey(prodkey);
1062 rc = ERROR_SUCCESS;
1063 goto done;
1067 rc = ERROR_INSTALL_FAILURE;
1069 done:
1070 RegCloseKey(compkey);
1071 unsquash_guid( squashed_prod, szBuffer );
1072 return rc;
1075 static WCHAR *reg_get_value( HKEY hkey, const WCHAR *name, DWORD *type )
1077 LONG res;
1079 if ((res = RegQueryValueExW( hkey, name, NULL, type, NULL, NULL )) != ERROR_SUCCESS) return NULL;
1081 if (*type == REG_SZ) return msi_reg_get_val_str( hkey, name );
1082 if (*type == REG_DWORD)
1084 WCHAR temp[11];
1085 DWORD val;
1087 if (!msi_reg_get_val_dword( hkey, name, &val )) return NULL;
1088 swprintf( temp, ARRAY_SIZE(temp), L"%u", val );
1089 return strdupW( temp );
1092 ERR( "unhandled value type %u\n", *type );
1093 return NULL;
1096 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
1097 awstring *szValue, LPDWORD pcchValueBuf)
1099 static WCHAR empty[] = L"";
1100 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1101 UINT r = ERROR_UNKNOWN_PROPERTY;
1102 HKEY prodkey, userdata, source;
1103 WCHAR *val = NULL, squashed_pc[SQUASHED_GUID_SIZE], packagecode[GUID_SIZE];
1104 BOOL badconfig = FALSE;
1105 LONG res;
1106 DWORD type = REG_NONE;
1108 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1109 debugstr_w(szAttribute), szValue, pcchValueBuf);
1111 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
1112 return ERROR_INVALID_PARAMETER;
1114 if (!squash_guid( szProduct, squashed_pc ))
1115 return ERROR_INVALID_PARAMETER;
1117 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
1118 MSIINSTALLCONTEXT_USERMANAGED,
1119 &prodkey, FALSE)) != ERROR_SUCCESS &&
1120 (r = MSIREG_OpenProductKey(szProduct, NULL,
1121 MSIINSTALLCONTEXT_USERUNMANAGED,
1122 &prodkey, FALSE)) != ERROR_SUCCESS &&
1123 (r = MSIREG_OpenProductKey(szProduct, NULL,
1124 MSIINSTALLCONTEXT_MACHINE,
1125 &prodkey, FALSE)) == ERROR_SUCCESS)
1127 context = MSIINSTALLCONTEXT_MACHINE;
1130 if (!wcscmp( szAttribute, INSTALLPROPERTY_HELPLINKW ) ||
1131 !wcscmp( szAttribute, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1132 !wcscmp( szAttribute, INSTALLPROPERTY_INSTALLDATEW ) ||
1133 !wcscmp( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1134 !wcscmp( szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1135 !wcscmp( szAttribute, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1136 !wcscmp( szAttribute, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1137 !wcscmp( szAttribute, INSTALLPROPERTY_PUBLISHERW ) ||
1138 !wcscmp( szAttribute, INSTALLPROPERTY_URLINFOABOUTW ) ||
1139 !wcscmp( szAttribute, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1140 !wcscmp( szAttribute, INSTALLPROPERTY_VERSIONMINORW ) ||
1141 !wcscmp( szAttribute, INSTALLPROPERTY_VERSIONMAJORW ) ||
1142 !wcscmp( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1143 !wcscmp( szAttribute, INSTALLPROPERTY_PRODUCTIDW ) ||
1144 !wcscmp( szAttribute, INSTALLPROPERTY_REGCOMPANYW ) ||
1145 !wcscmp( szAttribute, INSTALLPROPERTY_REGOWNERW ))
1147 if (!prodkey)
1149 r = ERROR_UNKNOWN_PRODUCT;
1150 goto done;
1152 if (MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE))
1154 r = ERROR_UNKNOWN_PROPERTY;
1155 goto done;
1158 if (!wcscmp( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1159 szAttribute = L"DisplayName";
1160 else if (!wcscmp( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ))
1161 szAttribute = L"DisplayVersion";
1163 val = reg_get_value(userdata, szAttribute, &type);
1164 if (!val)
1165 val = empty;
1166 RegCloseKey(userdata);
1168 else if (!wcscmp( szAttribute, INSTALLPROPERTY_INSTANCETYPEW ) ||
1169 !wcscmp( szAttribute, INSTALLPROPERTY_TRANSFORMSW ) ||
1170 !wcscmp( szAttribute, INSTALLPROPERTY_LANGUAGEW ) ||
1171 !wcscmp( szAttribute, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1172 !wcscmp( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ) ||
1173 !wcscmp( szAttribute, INSTALLPROPERTY_PACKAGECODEW ) ||
1174 !wcscmp( szAttribute, INSTALLPROPERTY_VERSIONW ) ||
1175 !wcscmp( szAttribute, INSTALLPROPERTY_PRODUCTICONW ) ||
1176 !wcscmp( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ) ||
1177 !wcscmp( szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1179 if (!prodkey)
1181 r = ERROR_UNKNOWN_PRODUCT;
1182 goto done;
1185 if (!wcscmp( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1186 szAttribute = L"Assignment";
1188 if (!wcscmp( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ))
1190 res = RegOpenKeyW(prodkey, L"SourceList", &source);
1191 if (res != ERROR_SUCCESS)
1193 r = ERROR_UNKNOWN_PRODUCT;
1194 goto done;
1197 val = reg_get_value(source, szAttribute, &type);
1198 if (!val)
1199 val = empty;
1201 RegCloseKey(source);
1203 else
1205 val = reg_get_value(prodkey, szAttribute, &type);
1206 if (!val)
1207 val = empty;
1210 if (val != empty && type != REG_DWORD &&
1211 !wcscmp( szAttribute, INSTALLPROPERTY_PACKAGECODEW ))
1213 if (lstrlenW( val ) != SQUASHED_GUID_SIZE - 1)
1214 badconfig = TRUE;
1215 else
1217 unsquash_guid(val, packagecode);
1218 msi_free(val);
1219 val = strdupW(packagecode);
1224 if (!val)
1226 r = ERROR_UNKNOWN_PROPERTY;
1227 goto done;
1230 if (pcchValueBuf)
1232 int len = lstrlenW( val );
1234 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1235 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1236 * can't rely on its value.
1238 if (szValue->str.a || szValue->str.w)
1240 DWORD size = *pcchValueBuf;
1241 if (len < size)
1242 r = msi_strcpy_to_awstring( val, len, szValue, &size );
1243 else
1244 r = ERROR_MORE_DATA;
1247 if (!badconfig)
1248 *pcchValueBuf = len;
1251 if (badconfig)
1252 r = ERROR_BAD_CONFIGURATION;
1254 if (val != empty)
1255 msi_free(val);
1257 done:
1258 RegCloseKey(prodkey);
1259 return r;
1262 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1263 LPSTR szBuffer, LPDWORD pcchValueBuf)
1265 LPWSTR szwProduct, szwAttribute = NULL;
1266 UINT r = ERROR_OUTOFMEMORY;
1267 awstring buffer;
1269 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1270 szBuffer, pcchValueBuf);
1272 szwProduct = strdupAtoW( szProduct );
1273 if( szProduct && !szwProduct )
1274 goto end;
1276 szwAttribute = strdupAtoW( szAttribute );
1277 if( szAttribute && !szwAttribute )
1278 goto end;
1280 buffer.unicode = FALSE;
1281 buffer.str.a = szBuffer;
1283 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1284 &buffer, pcchValueBuf );
1286 end:
1287 msi_free( szwProduct );
1288 msi_free( szwAttribute );
1290 return r;
1293 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1294 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1296 awstring buffer;
1298 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1299 szBuffer, pcchValueBuf);
1301 buffer.unicode = TRUE;
1302 buffer.str.w = szBuffer;
1304 return MSI_GetProductInfo( szProduct, szAttribute,
1305 &buffer, pcchValueBuf );
1308 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1309 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1310 LPSTR szValue, LPDWORD pcchValue)
1312 LPWSTR product = NULL;
1313 LPWSTR usersid = NULL;
1314 LPWSTR property = NULL;
1315 LPWSTR value = NULL;
1316 DWORD len = 0;
1317 UINT r;
1319 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1320 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1321 szValue, pcchValue);
1323 if (szValue && !pcchValue)
1324 return ERROR_INVALID_PARAMETER;
1326 if (szProductCode) product = strdupAtoW(szProductCode);
1327 if (szUserSid) usersid = strdupAtoW(szUserSid);
1328 if (szProperty) property = strdupAtoW(szProperty);
1330 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1331 NULL, &len);
1332 if (r != ERROR_SUCCESS)
1333 goto done;
1335 value = msi_alloc(++len * sizeof(WCHAR));
1336 if (!value)
1338 r = ERROR_OUTOFMEMORY;
1339 goto done;
1342 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1343 value, &len);
1344 if (r != ERROR_SUCCESS)
1345 goto done;
1347 if (!pcchValue)
1348 goto done;
1350 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1351 if (*pcchValue >= len)
1352 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1353 else if (szValue)
1355 r = ERROR_MORE_DATA;
1356 if (*pcchValue > 0)
1357 *szValue = '\0';
1360 if (*pcchValue <= len || !szValue)
1361 len = len * sizeof(WCHAR) - 1;
1363 *pcchValue = len - 1;
1365 done:
1366 msi_free(product);
1367 msi_free(usersid);
1368 msi_free(property);
1369 msi_free(value);
1371 return r;
1374 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1376 UINT r = ERROR_SUCCESS;
1378 if (!val)
1379 return ERROR_UNKNOWN_PROPERTY;
1381 if (out)
1383 if (lstrlenW(val) >= *size)
1385 r = ERROR_MORE_DATA;
1386 if (*size > 0)
1387 *out = '\0';
1389 else
1390 lstrcpyW(out, val);
1393 if (size)
1394 *size = lstrlenW(val);
1396 return r;
1399 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1400 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1401 LPWSTR szValue, LPDWORD pcchValue)
1403 WCHAR *val = NULL, squashed_pc[SQUASHED_GUID_SIZE];
1404 LPCWSTR package = NULL;
1405 HKEY props = NULL, prod, classes = NULL, managed, hkey = NULL;
1406 DWORD type;
1407 UINT r = ERROR_UNKNOWN_PRODUCT;
1409 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1410 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1411 szValue, pcchValue);
1413 if (!szProductCode || !squash_guid( szProductCode, squashed_pc ))
1414 return ERROR_INVALID_PARAMETER;
1416 if (szValue && !pcchValue)
1417 return ERROR_INVALID_PARAMETER;
1419 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1420 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1421 dwContext != MSIINSTALLCONTEXT_MACHINE)
1422 return ERROR_INVALID_PARAMETER;
1424 if (!szProperty || !*szProperty)
1425 return ERROR_INVALID_PARAMETER;
1427 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1428 return ERROR_INVALID_PARAMETER;
1430 /* FIXME: dwContext is provided, no need to search for it */
1431 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1432 &managed, FALSE);
1433 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1434 &prod, FALSE);
1436 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1438 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1440 package = INSTALLPROPERTY_LOCALPACKAGEW;
1442 if (!props && !prod)
1443 goto done;
1445 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1447 package = L"ManagedLocalPackage";
1449 if (!props && !managed)
1450 goto done;
1452 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1454 package = INSTALLPROPERTY_LOCALPACKAGEW;
1455 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1457 if (!props && !classes)
1458 goto done;
1461 if (!wcscmp( szProperty, INSTALLPROPERTY_HELPLINKW ) ||
1462 !wcscmp( szProperty, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1463 !wcscmp( szProperty, INSTALLPROPERTY_INSTALLDATEW ) ||
1464 !wcscmp( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1465 !wcscmp( szProperty, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1466 !wcscmp( szProperty, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1467 !wcscmp( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1468 !wcscmp( szProperty, INSTALLPROPERTY_PUBLISHERW ) ||
1469 !wcscmp( szProperty, INSTALLPROPERTY_URLINFOABOUTW ) ||
1470 !wcscmp( szProperty, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1471 !wcscmp( szProperty, INSTALLPROPERTY_VERSIONMINORW ) ||
1472 !wcscmp( szProperty, INSTALLPROPERTY_VERSIONMAJORW ) ||
1473 !wcscmp( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1474 !wcscmp( szProperty, INSTALLPROPERTY_PRODUCTIDW ) ||
1475 !wcscmp( szProperty, INSTALLPROPERTY_REGCOMPANYW ) ||
1476 !wcscmp( szProperty, INSTALLPROPERTY_REGOWNERW ) ||
1477 !wcscmp( szProperty, INSTALLPROPERTY_INSTANCETYPEW ))
1479 val = reg_get_value(props, package, &type);
1480 if (!val)
1482 if (prod || classes)
1483 r = ERROR_UNKNOWN_PROPERTY;
1485 goto done;
1488 msi_free(val);
1490 if (!wcscmp( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1491 szProperty = L"DisplayName";
1492 else if (!wcscmp( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ))
1493 szProperty = L"DisplayVersion";
1495 val = reg_get_value(props, szProperty, &type);
1496 if (!val)
1497 val = strdupW(L"");
1499 r = msi_copy_outval(val, szValue, pcchValue);
1501 else if (!wcscmp( szProperty, INSTALLPROPERTY_TRANSFORMSW ) ||
1502 !wcscmp( szProperty, INSTALLPROPERTY_LANGUAGEW ) ||
1503 !wcscmp( szProperty, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1504 !wcscmp( szProperty, INSTALLPROPERTY_PACKAGECODEW ) ||
1505 !wcscmp( szProperty, INSTALLPROPERTY_VERSIONW ) ||
1506 !wcscmp( szProperty, INSTALLPROPERTY_PRODUCTICONW ) ||
1507 !wcscmp( szProperty, INSTALLPROPERTY_PACKAGENAMEW ) ||
1508 !wcscmp( szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1510 if (!prod && !classes)
1511 goto done;
1513 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1514 hkey = prod;
1515 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1516 hkey = managed;
1517 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1518 hkey = classes;
1520 val = reg_get_value(hkey, szProperty, &type);
1521 if (!val)
1522 val = strdupW(L"");
1524 r = msi_copy_outval(val, szValue, pcchValue);
1526 else if (!wcscmp( szProperty, INSTALLPROPERTY_PRODUCTSTATEW ))
1528 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1530 if (props)
1532 val = reg_get_value(props, package, &type);
1533 if (!val)
1534 goto done;
1536 msi_free(val);
1537 val = strdupW(L"5");
1539 else
1540 val = strdupW(L"1");
1542 r = msi_copy_outval(val, szValue, pcchValue);
1543 goto done;
1545 else if (props && (val = reg_get_value(props, package, &type)))
1547 msi_free(val);
1548 val = strdupW(L"5");
1549 r = msi_copy_outval(val, szValue, pcchValue);
1550 goto done;
1553 if (prod || managed)
1554 val = strdupW(L"1");
1555 else
1556 goto done;
1558 r = msi_copy_outval(val, szValue, pcchValue);
1560 else if (!wcscmp( szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1562 if (!prod && !classes)
1563 goto done;
1565 /* FIXME */
1566 val = strdupW(L"");
1567 r = msi_copy_outval(val, szValue, pcchValue);
1569 else
1570 r = ERROR_UNKNOWN_PROPERTY;
1572 done:
1573 RegCloseKey(props);
1574 RegCloseKey(prod);
1575 RegCloseKey(managed);
1576 RegCloseKey(classes);
1577 msi_free(val);
1579 return r;
1582 UINT WINAPI MsiGetPatchFileListA(LPCSTR szProductCode, LPCSTR szPatchList,
1583 LPDWORD pcFiles, MSIHANDLE **pphFileRecords)
1585 FIXME("(%s, %s, %p, %p) stub!\n", debugstr_a(szProductCode),
1586 debugstr_a(szPatchList), pcFiles, pphFileRecords);
1587 return ERROR_FUNCTION_FAILED;
1590 UINT WINAPI MsiGetPatchFileListW(LPCWSTR szProductCode, LPCWSTR szPatchList,
1591 LPDWORD pcFiles, MSIHANDLE **pphFileRecords)
1593 FIXME("(%s, %s, %p, %p) stub!\n", debugstr_w(szProductCode),
1594 debugstr_w(szPatchList), pcFiles, pphFileRecords);
1595 return ERROR_FUNCTION_FAILED;
1598 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1599 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1600 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1602 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1603 LPWSTR property = NULL, val = NULL;
1604 DWORD len;
1605 UINT r;
1607 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1608 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1609 debugstr_a(szProperty), lpValue, pcchValue);
1611 if (lpValue && !pcchValue)
1612 return ERROR_INVALID_PARAMETER;
1614 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1615 if (szProductCode) product = strdupAtoW(szProductCode);
1616 if (szUserSid) usersid = strdupAtoW(szUserSid);
1617 if (szProperty) property = strdupAtoW(szProperty);
1619 len = 0;
1620 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1621 NULL, &len);
1622 if (r != ERROR_SUCCESS)
1623 goto done;
1625 val = msi_alloc(++len * sizeof(WCHAR));
1626 if (!val)
1628 r = ERROR_OUTOFMEMORY;
1629 goto done;
1632 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1633 val, &len);
1634 if (r != ERROR_SUCCESS || !pcchValue)
1635 goto done;
1637 if (lpValue)
1638 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1639 *pcchValue - 1, NULL, NULL);
1641 len = lstrlenW(val);
1642 if ((*val && *pcchValue < len + 1) || !lpValue)
1644 if (lpValue)
1646 r = ERROR_MORE_DATA;
1647 lpValue[*pcchValue - 1] = '\0';
1650 *pcchValue = len * sizeof(WCHAR);
1652 else
1653 *pcchValue = len;
1655 done:
1656 msi_free(val);
1657 msi_free(patch);
1658 msi_free(product);
1659 msi_free(usersid);
1660 msi_free(property);
1662 return r;
1665 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1666 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1667 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1669 WCHAR *val = NULL, squashed_pc[SQUASHED_GUID_SIZE], squashed_patch[SQUASHED_GUID_SIZE];
1670 HKEY udprod = 0, prod = 0, props = 0;
1671 HKEY patch = 0, patches = 0;
1672 HKEY udpatch = 0, datakey = 0;
1673 HKEY prodpatches = 0;
1674 UINT r = ERROR_UNKNOWN_PRODUCT;
1675 DWORD len, type;
1676 LONG res;
1678 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1679 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1680 debugstr_w(szProperty), lpValue, pcchValue);
1682 if (!szProductCode || !squash_guid( szProductCode, squashed_pc ))
1683 return ERROR_INVALID_PARAMETER;
1685 if (!szPatchCode || !squash_guid( szPatchCode, squashed_patch ))
1686 return ERROR_INVALID_PARAMETER;
1688 if (!szProperty)
1689 return ERROR_INVALID_PARAMETER;
1691 if (lpValue && !pcchValue)
1692 return ERROR_INVALID_PARAMETER;
1694 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1695 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1696 dwContext != MSIINSTALLCONTEXT_MACHINE)
1697 return ERROR_INVALID_PARAMETER;
1699 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1700 return ERROR_INVALID_PARAMETER;
1702 if (szUserSid && !wcscmp( szUserSid, L"S-1-5-18" ))
1703 return ERROR_INVALID_PARAMETER;
1705 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1706 &udprod, FALSE) != ERROR_SUCCESS)
1707 goto done;
1709 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1710 &props, FALSE) != ERROR_SUCCESS)
1711 goto done;
1713 r = ERROR_UNKNOWN_PATCH;
1715 res = RegOpenKeyExW(udprod, L"Patches", 0, KEY_READ, &patches);
1716 if (res != ERROR_SUCCESS)
1717 goto done;
1719 res = RegOpenKeyExW( patches, squashed_patch, 0, KEY_READ, &patch );
1720 if (res != ERROR_SUCCESS)
1721 goto done;
1723 if (!wcscmp( szProperty, INSTALLPROPERTY_TRANSFORMSW ))
1725 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1726 &prod, FALSE) != ERROR_SUCCESS)
1727 goto done;
1729 res = RegOpenKeyExW(prod, L"Patches", 0, KEY_ALL_ACCESS, &prodpatches);
1730 if (res != ERROR_SUCCESS)
1731 goto done;
1733 datakey = prodpatches;
1734 szProperty = squashed_patch;
1736 else
1738 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1739 &udpatch, FALSE) != ERROR_SUCCESS)
1740 goto done;
1742 if (!wcscmp( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1744 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1745 szProperty = L"ManagedLocalPackage";
1746 datakey = udpatch;
1748 else if (!wcscmp( szProperty, INSTALLPROPERTY_INSTALLDATEW ))
1750 datakey = patch;
1751 szProperty = L"Installed";
1753 else if (!wcscmp( szProperty, INSTALLPROPERTY_UNINSTALLABLEW ) ||
1754 !wcscmp( szProperty, INSTALLPROPERTY_PATCHSTATEW ) ||
1755 !wcscmp( szProperty, INSTALLPROPERTY_DISPLAYNAMEW ) ||
1756 !wcscmp( szProperty, INSTALLPROPERTY_MOREINFOURLW ))
1758 datakey = patch;
1760 else
1762 r = ERROR_UNKNOWN_PROPERTY;
1763 goto done;
1767 val = reg_get_value(datakey, szProperty, &type);
1768 if (!val)
1769 val = strdupW(L"");
1771 r = ERROR_SUCCESS;
1773 if (!pcchValue)
1774 goto done;
1776 if (lpValue)
1777 lstrcpynW(lpValue, val, *pcchValue);
1779 len = lstrlenW(val);
1780 if ((*val && *pcchValue < len + 1) || !lpValue)
1782 if (lpValue)
1783 r = ERROR_MORE_DATA;
1785 *pcchValue = len * sizeof(WCHAR);
1788 *pcchValue = len;
1790 done:
1791 msi_free(val);
1792 RegCloseKey(prodpatches);
1793 RegCloseKey(prod);
1794 RegCloseKey(patch);
1795 RegCloseKey(patches);
1796 RegCloseKey(udpatch);
1797 RegCloseKey(props);
1798 RegCloseKey(udprod);
1800 return r;
1803 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1805 UINT r = ERROR_OUTOFMEMORY;
1806 DWORD size;
1807 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1809 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1811 if (!patch || !attr)
1812 return ERROR_INVALID_PARAMETER;
1814 if (!(patchW = strdupAtoW( patch )))
1815 goto done;
1817 if (!(attrW = strdupAtoW( attr )))
1818 goto done;
1820 size = 0;
1821 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1822 if (r != ERROR_SUCCESS)
1823 goto done;
1825 size++;
1826 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1828 r = ERROR_OUTOFMEMORY;
1829 goto done;
1832 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1833 if (r == ERROR_SUCCESS)
1835 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1836 if (len > *buflen)
1837 r = ERROR_MORE_DATA;
1838 else if (buffer)
1839 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1841 *buflen = len - 1;
1844 done:
1845 msi_free( patchW );
1846 msi_free( attrW );
1847 msi_free( bufferW );
1848 return r;
1851 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1853 UINT r;
1854 WCHAR product[GUID_SIZE];
1855 DWORD index;
1857 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1859 if (!patch || !attr)
1860 return ERROR_INVALID_PARAMETER;
1862 if (wcscmp( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1863 return ERROR_UNKNOWN_PROPERTY;
1865 index = 0;
1866 while (1)
1868 r = MsiEnumProductsW( index, product );
1869 if (r != ERROR_SUCCESS)
1870 break;
1872 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1873 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1874 return r;
1876 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1877 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1878 return r;
1880 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1881 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1882 return r;
1884 index++;
1887 return ERROR_UNKNOWN_PRODUCT;
1890 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1892 LPWSTR szwLogFile = NULL;
1893 UINT r;
1895 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1897 if( szLogFile )
1899 szwLogFile = strdupAtoW( szLogFile );
1900 if( !szwLogFile )
1901 return ERROR_OUTOFMEMORY;
1903 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1904 msi_free( szwLogFile );
1905 return r;
1908 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1910 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1912 msi_free(gszLogFile);
1913 gszLogFile = NULL;
1914 if (szLogFile)
1916 HANDLE file;
1918 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1919 DeleteFileW(szLogFile);
1920 file = CreateFileW(szLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
1921 FILE_ATTRIBUTE_NORMAL, NULL);
1922 if (file != INVALID_HANDLE_VALUE)
1924 gszLogFile = strdupW(szLogFile);
1925 CloseHandle(file);
1927 else
1928 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile), GetLastError());
1931 return ERROR_SUCCESS;
1934 UINT WINAPI MsiEnumComponentCostsA( MSIHANDLE handle, LPCSTR component, DWORD index,
1935 INSTALLSTATE state, LPSTR drive, DWORD *buflen,
1936 int *cost, int *temp )
1938 UINT r;
1939 DWORD len;
1940 WCHAR *driveW, *componentW = NULL;
1942 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_a(component), index,
1943 state, drive, buflen, cost, temp);
1945 if (!drive || !buflen) return ERROR_INVALID_PARAMETER;
1946 if (component && !(componentW = strdupAtoW( component ))) return ERROR_OUTOFMEMORY;
1948 len = *buflen;
1949 if (!(driveW = msi_alloc( len * sizeof(WCHAR) )))
1951 msi_free( componentW );
1952 return ERROR_OUTOFMEMORY;
1954 r = MsiEnumComponentCostsW( handle, componentW, index, state, driveW, buflen, cost, temp );
1955 if (!r)
1957 WideCharToMultiByte( CP_ACP, 0, driveW, -1, drive, len, NULL, NULL );
1959 msi_free( componentW );
1960 msi_free( driveW );
1961 return r;
1964 static UINT set_drive( WCHAR *buffer, WCHAR letter )
1966 buffer[0] = letter;
1967 buffer[1] = ':';
1968 buffer[2] = 0;
1969 return 2;
1972 UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, LPCWSTR component, DWORD index,
1973 INSTALLSTATE state, LPWSTR drive, DWORD *buflen,
1974 int *cost, int *temp )
1976 UINT r = ERROR_NO_MORE_ITEMS;
1977 MSICOMPONENT *comp = NULL;
1978 MSIPACKAGE *package;
1979 MSIFILE *file;
1980 STATSTG stat = {0};
1981 WCHAR path[MAX_PATH];
1983 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_w(component), index,
1984 state, drive, buflen, cost, temp);
1986 if (!drive || !buflen || !cost || !temp) return ERROR_INVALID_PARAMETER;
1987 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1989 WCHAR buffer[3];
1990 MSIHANDLE remote;
1992 if (!(remote = msi_get_remote(handle)))
1993 return ERROR_INVALID_HANDLE;
1995 __TRY
1997 r = remote_EnumComponentCosts(remote, component, index, state, buffer, cost, temp);
1999 __EXCEPT(rpc_filter)
2001 r = GetExceptionCode();
2003 __ENDTRY
2005 if (r == ERROR_SUCCESS)
2007 lstrcpynW(drive, buffer, *buflen);
2008 if (*buflen < 3)
2009 r = ERROR_MORE_DATA;
2010 *buflen = 2;
2012 return r;
2015 if (!msi_get_property_int( package->db, L"CostingComplete", 0 ))
2017 msiobj_release( &package->hdr );
2018 return ERROR_FUNCTION_NOT_CALLED;
2020 if (component && component[0] && !(comp = msi_get_loaded_component( package, component )))
2022 msiobj_release( &package->hdr );
2023 return ERROR_UNKNOWN_COMPONENT;
2025 if (*buflen < 3)
2027 *buflen = 2;
2028 msiobj_release( &package->hdr );
2029 return ERROR_MORE_DATA;
2031 if (index)
2033 msiobj_release( &package->hdr );
2034 return ERROR_NO_MORE_ITEMS;
2037 drive[0] = 0;
2038 *cost = *temp = 0;
2039 GetWindowsDirectoryW( path, MAX_PATH );
2040 if (component && component[0])
2042 if (msi_is_global_assembly( comp )) *temp = comp->Cost;
2043 if (!comp->Enabled || !comp->KeyPath)
2045 *cost = 0;
2046 *buflen = set_drive( drive, path[0] );
2047 r = ERROR_SUCCESS;
2049 else if ((file = msi_get_loaded_file( package, comp->KeyPath )))
2051 *cost = max( 8, comp->Cost / 512 );
2052 *buflen = set_drive( drive, file->TargetPath[0] );
2053 r = ERROR_SUCCESS;
2056 else if (IStorage_Stat( package->db->storage, &stat, STATFLAG_NONAME ) == S_OK)
2058 *temp = max( 8, stat.cbSize.QuadPart / 512 );
2059 *buflen = set_drive( drive, path[0] );
2060 r = ERROR_SUCCESS;
2062 msiobj_release( &package->hdr );
2063 return r;
2066 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
2067 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2068 LPCSTR szComponent, INSTALLSTATE *pdwState)
2070 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
2071 UINT r;
2073 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
2074 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
2076 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
2077 return ERROR_OUTOFMEMORY;
2079 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
2080 return ERROR_OUTOFMEMORY;
2082 if (szComponent && !(comp = strdupAtoW(szComponent)))
2083 return ERROR_OUTOFMEMORY;
2085 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
2087 msi_free(prodcode);
2088 msi_free(usersid);
2089 msi_free(comp);
2091 return r;
2094 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
2096 UINT r;
2097 HKEY hkey = NULL;
2099 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
2100 RegCloseKey(hkey);
2101 return (r == ERROR_SUCCESS);
2104 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
2106 LPCWSTR package;
2107 HKEY hkey;
2108 DWORD sz;
2109 LONG res;
2110 UINT r;
2112 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
2113 if (r != ERROR_SUCCESS)
2114 return FALSE;
2116 if (context == MSIINSTALLCONTEXT_USERMANAGED)
2117 package = L"ManagedLocalPackage";
2118 else
2119 package = L"LocalPackage";
2121 sz = 0;
2122 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
2123 RegCloseKey(hkey);
2125 return (res == ERROR_SUCCESS);
2128 static UINT msi_comp_find_prodcode(WCHAR *squashed_pc,
2129 MSIINSTALLCONTEXT context,
2130 LPCWSTR comp, LPWSTR val, DWORD *sz)
2132 HKEY hkey;
2133 LONG res;
2134 UINT r;
2136 if (context == MSIINSTALLCONTEXT_MACHINE)
2137 r = MSIREG_OpenUserDataComponentKey(comp, L"S-1-5-18", &hkey, FALSE);
2138 else
2139 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2141 if (r != ERROR_SUCCESS)
2142 return r;
2144 res = RegQueryValueExW( hkey, squashed_pc, NULL, NULL, (BYTE *)val, sz );
2145 if (res != ERROR_SUCCESS)
2146 return res;
2148 RegCloseKey(hkey);
2149 return res;
2152 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
2153 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2154 LPCWSTR szComponent, INSTALLSTATE *pdwState)
2156 WCHAR squashed_pc[SQUASHED_GUID_SIZE];
2157 BOOL found;
2158 DWORD sz;
2160 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
2161 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
2163 if (!pdwState || !szComponent)
2164 return ERROR_INVALID_PARAMETER;
2166 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
2167 return ERROR_INVALID_PARAMETER;
2169 if (!squash_guid( szProductCode, squashed_pc ))
2170 return ERROR_INVALID_PARAMETER;
2172 found = msi_comp_find_prod_key(szProductCode, dwContext);
2174 if (!msi_comp_find_package(szProductCode, dwContext))
2176 if (found)
2178 *pdwState = INSTALLSTATE_UNKNOWN;
2179 return ERROR_UNKNOWN_COMPONENT;
2182 return ERROR_UNKNOWN_PRODUCT;
2185 *pdwState = INSTALLSTATE_UNKNOWN;
2187 sz = 0;
2188 if (msi_comp_find_prodcode( squashed_pc, dwContext, szComponent, NULL, &sz ))
2189 return ERROR_UNKNOWN_COMPONENT;
2191 if (sz == 0)
2192 *pdwState = INSTALLSTATE_NOTUSED;
2193 else
2195 WCHAR *val;
2196 UINT r;
2198 if (!(val = msi_alloc( sz ))) return ERROR_OUTOFMEMORY;
2199 if ((r = msi_comp_find_prodcode( squashed_pc, dwContext, szComponent, val, &sz )))
2201 msi_free(val);
2202 return r;
2205 if (lstrlenW(val) > 2 &&
2206 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9' && val[2] != ':')
2208 *pdwState = INSTALLSTATE_SOURCE;
2210 else
2211 *pdwState = INSTALLSTATE_LOCAL;
2212 msi_free( val );
2215 TRACE("-> %d\n", *pdwState);
2216 return ERROR_SUCCESS;
2219 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
2221 LPWSTR szwProduct = NULL;
2222 INSTALLSTATE r;
2224 if( szProduct )
2226 szwProduct = strdupAtoW( szProduct );
2227 if( !szwProduct )
2228 return ERROR_OUTOFMEMORY;
2230 r = MsiQueryProductStateW( szwProduct );
2231 msi_free( szwProduct );
2232 return r;
2235 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
2237 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
2238 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
2239 HKEY prodkey = 0, userdata = 0;
2240 DWORD val;
2241 UINT r;
2243 TRACE("%s\n", debugstr_w(szProduct));
2245 if (!szProduct || !*szProduct)
2246 return INSTALLSTATE_INVALIDARG;
2248 if (lstrlenW(szProduct) != GUID_SIZE - 1)
2249 return INSTALLSTATE_INVALIDARG;
2251 if (szProduct[0] != '{' || szProduct[37] != '}')
2252 return INSTALLSTATE_UNKNOWN;
2254 SetLastError( ERROR_SUCCESS );
2256 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2257 &prodkey, FALSE) != ERROR_SUCCESS &&
2258 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2259 &prodkey, FALSE) != ERROR_SUCCESS &&
2260 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2261 &prodkey, FALSE) == ERROR_SUCCESS)
2263 context = MSIINSTALLCONTEXT_MACHINE;
2266 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
2267 if (r != ERROR_SUCCESS)
2268 goto done;
2270 if (!msi_reg_get_val_dword(userdata, L"WindowsInstaller", &val))
2271 goto done;
2273 if (val)
2274 state = INSTALLSTATE_DEFAULT;
2275 else
2276 state = INSTALLSTATE_UNKNOWN;
2278 done:
2279 if (!prodkey)
2281 state = INSTALLSTATE_UNKNOWN;
2283 if (userdata)
2284 state = INSTALLSTATE_ABSENT;
2287 RegCloseKey(prodkey);
2288 RegCloseKey(userdata);
2289 TRACE("-> %d\n", state);
2290 return state;
2293 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2295 INSTALLUILEVEL old = gUILevel;
2296 HWND oldwnd = gUIhwnd;
2298 TRACE("%08x %p\n", dwUILevel, phWnd);
2300 if (dwUILevel & ~(INSTALLUILEVEL_MASK|INSTALLUILEVEL_HIDECANCEL|INSTALLUILEVEL_PROGRESSONLY|
2301 INSTALLUILEVEL_ENDDIALOG|INSTALLUILEVEL_SOURCERESONLY))
2303 FIXME("Unrecognized flags %08x\n", dwUILevel);
2304 return INSTALLUILEVEL_NOCHANGE;
2307 if (dwUILevel != INSTALLUILEVEL_NOCHANGE)
2308 gUILevel = dwUILevel;
2310 if (phWnd)
2312 gUIhwnd = *phWnd;
2313 *phWnd = oldwnd;
2315 return old;
2318 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2319 DWORD dwMessageFilter, LPVOID pvContext)
2321 INSTALLUI_HANDLERA prev = gUIHandlerA;
2323 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2325 gUIHandlerA = puiHandler;
2326 gUIHandlerW = NULL;
2327 gUIFilter = dwMessageFilter;
2328 gUIContext = pvContext;
2330 return prev;
2333 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2334 DWORD dwMessageFilter, LPVOID pvContext)
2336 INSTALLUI_HANDLERW prev = gUIHandlerW;
2338 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2340 gUIHandlerA = NULL;
2341 gUIHandlerW = puiHandler;
2342 gUIFilter = dwMessageFilter;
2343 gUIContext = pvContext;
2345 return prev;
2348 /******************************************************************
2349 * MsiLoadStringW [MSI.@]
2351 * Loads a string from MSI's string resources.
2353 * PARAMS
2355 * handle [I] only -1 is handled currently
2356 * id [I] id of the string to be loaded
2357 * lpBuffer [O] buffer for the string to be written to
2358 * nBufferMax [I] maximum size of the buffer in characters
2359 * lang [I] the preferred language for the string
2361 * RETURNS
2363 * If successful, this function returns the language id of the string loaded
2364 * If the function fails, the function returns zero.
2366 * NOTES
2368 * The type of the first parameter is unknown. LoadString's prototype
2369 * suggests that it might be a module handle. I have made it an MSI handle
2370 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2371 * handle. Maybe strings can be stored in an MSI database somehow.
2373 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2374 int nBufferMax, LANGID lang )
2376 HRSRC hres;
2377 HGLOBAL hResData;
2378 LPWSTR p;
2379 DWORD i, len;
2381 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2383 if( handle != -1 )
2384 FIXME("don't know how to deal with handle = %08x\n", handle);
2386 if( !lang )
2387 lang = GetUserDefaultLangID();
2389 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2390 (LPWSTR)1, lang );
2391 if( !hres )
2392 return 0;
2393 hResData = LoadResource( msi_hInstance, hres );
2394 if( !hResData )
2395 return 0;
2396 p = LockResource( hResData );
2397 if( !p )
2398 return 0;
2400 for (i = 0; i < (id & 0xf); i++) p += *p + 1;
2401 len = *p;
2403 if( nBufferMax <= len )
2404 return 0;
2406 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2407 lpBuffer[ len ] = 0;
2409 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2410 return lang;
2413 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2414 int nBufferMax, LANGID lang )
2416 LPWSTR bufW;
2417 LANGID r;
2418 INT len;
2420 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2421 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2422 if( r )
2424 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2425 if( len <= nBufferMax )
2426 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2427 lpBuffer, nBufferMax, NULL, NULL );
2428 else
2429 r = 0;
2431 msi_free(bufW);
2432 return r;
2435 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2436 LPDWORD pcchBuf)
2438 char szProduct[GUID_SIZE];
2440 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2442 if (!szComponent || !pcchBuf)
2443 return INSTALLSTATE_INVALIDARG;
2445 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2446 return INSTALLSTATE_UNKNOWN;
2448 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2451 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2452 LPDWORD pcchBuf)
2454 WCHAR szProduct[GUID_SIZE];
2456 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2458 if (!szComponent || !pcchBuf)
2459 return INSTALLSTATE_INVALIDARG;
2461 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2462 return INSTALLSTATE_UNKNOWN;
2464 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2467 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2468 WORD wLanguageId, DWORD f)
2470 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2471 uType, wLanguageId, f);
2472 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2475 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2476 WORD wLanguageId, DWORD f)
2478 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2479 uType, wLanguageId, f);
2480 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2483 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2484 DWORD unknown, WORD wLanguageId, DWORD f)
2486 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2487 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2488 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2491 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2492 DWORD unknown, WORD wLanguageId, DWORD f)
2494 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2495 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2496 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2499 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2500 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2501 LPDWORD pcchPathBuf )
2503 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2504 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2505 pcchPathBuf);
2506 return ERROR_CALL_NOT_IMPLEMENTED;
2509 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2510 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2511 LPDWORD pcchPathBuf )
2513 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2514 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2515 pcchPathBuf);
2516 return ERROR_CALL_NOT_IMPLEMENTED;
2519 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2520 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2522 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2523 return ERROR_CALL_NOT_IMPLEMENTED;
2526 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2527 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2529 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2530 return ERROR_CALL_NOT_IMPLEMENTED;
2533 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2534 LPBYTE hash, LPDWORD hashlen )
2536 UINT r;
2537 WCHAR *pathW = NULL;
2539 TRACE("%s %08x %p %p %p\n", debugstr_a(path), flags, cert, hash, hashlen);
2541 if (path && !(pathW = strdupAtoW( path ))) return E_OUTOFMEMORY;
2542 r = MsiGetFileSignatureInformationW( pathW, flags, cert, hash, hashlen );
2543 msi_free( pathW );
2544 return r;
2547 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2548 LPBYTE hash, LPDWORD hashlen )
2550 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
2551 HRESULT hr;
2552 WINTRUST_DATA data;
2553 WINTRUST_FILE_INFO info;
2554 CRYPT_PROVIDER_SGNR *signer;
2555 CRYPT_PROVIDER_CERT *provider;
2557 TRACE("%s %08x %p %p %p\n", debugstr_w(path), flags, cert, hash, hashlen);
2559 if (!path || !cert) return E_INVALIDARG;
2561 info.cbStruct = sizeof(info);
2562 info.pcwszFilePath = path;
2563 info.hFile = NULL;
2564 info.pgKnownSubject = NULL;
2566 data.cbStruct = sizeof(data);
2567 data.pPolicyCallbackData = NULL;
2568 data.pSIPClientData = NULL;
2569 data.dwUIChoice = WTD_UI_NONE;
2570 data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
2571 data.dwUnionChoice = WTD_CHOICE_FILE;
2572 data.u.pFile = &info;
2573 data.dwStateAction = WTD_STATEACTION_VERIFY;
2574 data.hWVTStateData = NULL;
2575 data.pwszURLReference = NULL;
2576 data.dwProvFlags = 0;
2577 data.dwUIContext = WTD_UICONTEXT_INSTALL;
2578 hr = WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2579 *cert = NULL;
2580 if (FAILED(hr)) goto done;
2582 if (!(signer = WTHelperGetProvSignerFromChain( data.hWVTStateData, 0, FALSE, 0 )))
2584 hr = TRUST_E_NOSIGNATURE;
2585 goto done;
2587 if (hash)
2589 DWORD len = signer->psSigner->EncryptedHash.cbData;
2590 if (*hashlen < len)
2592 *hashlen = len;
2593 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
2594 goto done;
2596 memcpy( hash, signer->psSigner->EncryptedHash.pbData, len );
2597 *hashlen = len;
2599 if (!(provider = WTHelperGetProvCertFromChain( signer, 0 )))
2601 hr = TRUST_E_PROVIDER_UNKNOWN;
2602 goto done;
2604 *cert = CertDuplicateCertificateContext( provider->pCert );
2606 done:
2607 data.dwStateAction = WTD_STATEACTION_CLOSE;
2608 WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2609 return hr;
2612 /******************************************************************
2613 * MsiGetProductPropertyA [MSI.@]
2615 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2616 LPSTR szValue, LPDWORD pccbValue)
2618 LPWSTR prop = NULL, val = NULL;
2619 DWORD len;
2620 UINT r;
2622 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2623 szValue, pccbValue);
2625 if (szValue && !pccbValue)
2626 return ERROR_INVALID_PARAMETER;
2628 if (szProperty) prop = strdupAtoW(szProperty);
2630 len = 0;
2631 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2632 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2633 goto done;
2635 if (r == ERROR_SUCCESS)
2637 if (szValue) *szValue = '\0';
2638 if (pccbValue) *pccbValue = 0;
2639 goto done;
2642 val = msi_alloc(++len * sizeof(WCHAR));
2643 if (!val)
2645 r = ERROR_OUTOFMEMORY;
2646 goto done;
2649 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2650 if (r != ERROR_SUCCESS)
2651 goto done;
2653 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2655 if (szValue)
2656 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2657 *pccbValue, NULL, NULL);
2659 if (pccbValue)
2661 if (len > *pccbValue)
2662 r = ERROR_MORE_DATA;
2664 *pccbValue = len - 1;
2667 done:
2668 msi_free(prop);
2669 msi_free(val);
2671 return r;
2674 /******************************************************************
2675 * MsiGetProductPropertyW [MSI.@]
2677 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2678 LPWSTR szValue, LPDWORD pccbValue)
2680 MSIPACKAGE *package;
2681 MSIQUERY *view = NULL;
2682 MSIRECORD *rec = NULL;
2683 LPCWSTR val;
2684 UINT r;
2686 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2687 szValue, pccbValue);
2689 if (!szProperty)
2690 return ERROR_INVALID_PARAMETER;
2692 if (szValue && !pccbValue)
2693 return ERROR_INVALID_PARAMETER;
2695 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2696 if (!package)
2697 return ERROR_INVALID_HANDLE;
2699 r = MSI_OpenQuery(package->db, &view, L"SELECT * FROM `Property` WHERE `Property` = '%s'", szProperty);
2700 if (r != ERROR_SUCCESS)
2701 goto done;
2703 r = MSI_ViewExecute(view, 0);
2704 if (r != ERROR_SUCCESS)
2705 goto done;
2707 r = MSI_ViewFetch(view, &rec);
2708 if (r != ERROR_SUCCESS)
2709 goto done;
2711 val = MSI_RecordGetString(rec, 2);
2712 if (!val)
2713 goto done;
2715 if (lstrlenW(val) >= *pccbValue)
2717 if (szValue) lstrcpynW(szValue, val, *pccbValue);
2718 r = ERROR_MORE_DATA;
2720 else
2722 if (szValue) lstrcpyW(szValue, val);
2723 r = ERROR_SUCCESS;
2726 *pccbValue = lstrlenW(val);
2728 done:
2729 if (view)
2731 MSI_ViewClose(view);
2732 msiobj_release(&view->hdr);
2733 if (rec) msiobj_release(&rec->hdr);
2736 if (!rec)
2738 if (szValue) *szValue = '\0';
2739 if (pccbValue) *pccbValue = 0;
2740 r = ERROR_SUCCESS;
2743 msiobj_release(&package->hdr);
2744 return r;
2747 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2749 UINT r;
2750 LPWSTR szPack = NULL;
2752 TRACE("%s\n", debugstr_a(szPackage) );
2754 if( szPackage )
2756 szPack = strdupAtoW( szPackage );
2757 if( !szPack )
2758 return ERROR_OUTOFMEMORY;
2761 r = MsiVerifyPackageW( szPack );
2763 msi_free( szPack );
2765 return r;
2768 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2770 MSIHANDLE handle;
2771 UINT r;
2773 TRACE("%s\n", debugstr_w(szPackage) );
2775 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2776 MsiCloseHandle( handle );
2778 return r;
2781 static BOOL open_userdata_comp_key( const WCHAR *comp, const WCHAR *usersid, MSIINSTALLCONTEXT ctx,
2782 HKEY *hkey )
2784 if (ctx & MSIINSTALLCONTEXT_MACHINE)
2786 if (!MSIREG_OpenUserDataComponentKey( comp, L"S-1-5-18", hkey, FALSE )) return TRUE;
2788 if (ctx & (MSIINSTALLCONTEXT_USERMANAGED|MSIINSTALLCONTEXT_USERUNMANAGED))
2790 if (usersid && !wcsicmp( usersid, L"S-1-1-0" ))
2792 FIXME( "only looking at the current user\n" );
2793 usersid = NULL;
2795 if (!MSIREG_OpenUserDataComponentKey( comp, usersid, hkey, FALSE )) return TRUE;
2797 return FALSE;
2800 static INSTALLSTATE MSI_GetComponentPath( const WCHAR *szProduct, const WCHAR *szComponent,
2801 const WCHAR *szUserSid, MSIINSTALLCONTEXT ctx,
2802 awstring *lpPathBuf, DWORD *pcchBuf )
2804 WCHAR *path = NULL, squashed_pc[SQUASHED_GUID_SIZE], squashed_comp[SQUASHED_GUID_SIZE];
2805 HKEY hkey;
2806 INSTALLSTATE state;
2807 DWORD version;
2809 if (!szProduct || !szComponent)
2810 return INSTALLSTATE_INVALIDARG;
2812 if (lpPathBuf->str.w && !pcchBuf)
2813 return INSTALLSTATE_INVALIDARG;
2815 if (!squash_guid( szProduct, squashed_pc ) || !squash_guid( szComponent, squashed_comp ))
2816 return INSTALLSTATE_INVALIDARG;
2818 if (szUserSid && ctx == MSIINSTALLCONTEXT_MACHINE)
2819 return INSTALLSTATE_INVALIDARG;
2821 state = INSTALLSTATE_UNKNOWN;
2823 if (open_userdata_comp_key( szComponent, szUserSid, ctx, &hkey ))
2825 path = msi_reg_get_val_str( hkey, squashed_pc );
2826 RegCloseKey(hkey);
2828 state = INSTALLSTATE_ABSENT;
2830 if ((!MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL, &hkey, FALSE) ||
2831 !MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED, NULL, &hkey, FALSE)) &&
2832 msi_reg_get_val_dword(hkey, L"WindowsInstaller", &version) &&
2833 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2835 RegCloseKey(hkey);
2836 state = INSTALLSTATE_LOCAL;
2840 if (state != INSTALLSTATE_LOCAL &&
2841 (!MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, &hkey, FALSE) ||
2842 !MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE, &hkey, FALSE)))
2844 RegCloseKey(hkey);
2846 if (open_userdata_comp_key( szComponent, szUserSid, ctx, &hkey ))
2848 msi_free(path);
2849 path = msi_reg_get_val_str( hkey, squashed_pc );
2850 RegCloseKey(hkey);
2852 state = INSTALLSTATE_ABSENT;
2854 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2855 state = INSTALLSTATE_LOCAL;
2859 if (!path)
2860 return INSTALLSTATE_UNKNOWN;
2862 if (state == INSTALLSTATE_LOCAL && !*path)
2863 state = INSTALLSTATE_NOTUSED;
2865 if (msi_strcpy_to_awstring(path, -1, lpPathBuf, pcchBuf) == ERROR_MORE_DATA)
2866 state = INSTALLSTATE_MOREDATA;
2868 msi_free(path);
2869 return state;
2872 /******************************************************************
2873 * MsiGetComponentPathExW [MSI.@]
2875 INSTALLSTATE WINAPI MsiGetComponentPathExW( LPCWSTR product, LPCWSTR comp, LPCWSTR usersid,
2876 MSIINSTALLCONTEXT ctx, LPWSTR buf, LPDWORD buflen )
2878 awstring path;
2880 TRACE( "%s %s %s 0x%x %p %p\n", debugstr_w(product), debugstr_w(comp), debugstr_w(usersid),
2881 ctx, buf, buflen );
2883 path.unicode = TRUE;
2884 path.str.w = buf;
2886 return MSI_GetComponentPath( product, comp, usersid, ctx, &path, buflen );
2889 INSTALLSTATE WINAPI MsiGetComponentPathExA( LPCSTR product, LPCSTR comp, LPCSTR usersid,
2890 MSIINSTALLCONTEXT ctx, LPSTR buf, LPDWORD buflen )
2892 WCHAR *productW = NULL, *compW = NULL, *usersidW = NULL;
2893 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2894 awstring path;
2896 TRACE( "%s %s %s 0x%x %p %p\n", debugstr_a(product), debugstr_a(comp), debugstr_a(usersid),
2897 ctx, buf, buflen );
2899 if (product && !(productW = strdupAtoW( product ))) return INSTALLSTATE_UNKNOWN;
2900 if (comp && !(compW = strdupAtoW( comp ))) goto end;
2901 if (usersid && !(usersidW = strdupAtoW( usersid ))) goto end;
2903 path.unicode = FALSE;
2904 path.str.a = buf;
2906 r = MSI_GetComponentPath( productW, compW, usersidW, ctx, &path, buflen );
2908 end:
2909 msi_free( productW );
2910 msi_free( compW );
2911 msi_free( usersidW );
2913 return r;
2916 /******************************************************************
2917 * MsiGetComponentPathW [MSI.@]
2919 INSTALLSTATE WINAPI MsiGetComponentPathW( LPCWSTR product, LPCWSTR comp, LPWSTR buf, LPDWORD buflen )
2921 return MsiGetComponentPathExW( product, comp, L"S-1-1-0", MSIINSTALLCONTEXT_ALL, buf, buflen );
2924 /******************************************************************
2925 * MsiGetComponentPathA [MSI.@]
2927 INSTALLSTATE WINAPI MsiGetComponentPathA( LPCSTR product, LPCSTR comp, LPSTR buf, LPDWORD buflen )
2929 return MsiGetComponentPathExA( product, comp, "s-1-1-0", MSIINSTALLCONTEXT_ALL, buf, buflen );
2932 static UINT query_feature_state( const WCHAR *product, const WCHAR *squashed, const WCHAR *usersid,
2933 MSIINSTALLCONTEXT ctx, const WCHAR *feature, INSTALLSTATE *state )
2935 UINT r;
2936 HKEY hkey;
2937 WCHAR *parent, *components, *path;
2938 const WCHAR *p;
2939 BOOL missing = FALSE, source = FALSE;
2940 WCHAR comp[GUID_SIZE];
2941 GUID guid;
2943 if (ctx != MSIINSTALLCONTEXT_MACHINE) SetLastError( ERROR_SUCCESS );
2945 if (MSIREG_OpenFeaturesKey( product, usersid, ctx, &hkey, FALSE )) return ERROR_UNKNOWN_PRODUCT;
2947 parent = msi_reg_get_val_str( hkey, feature );
2948 RegCloseKey( hkey );
2949 if (!parent) return ERROR_UNKNOWN_FEATURE;
2951 *state = (parent[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2952 msi_free( parent );
2953 if (*state == INSTALLSTATE_ABSENT)
2954 return ERROR_SUCCESS;
2956 r = MSIREG_OpenUserDataFeaturesKey( product, usersid, ctx, &hkey, FALSE );
2957 if (r != ERROR_SUCCESS)
2959 *state = INSTALLSTATE_ADVERTISED;
2960 return ERROR_SUCCESS;
2962 components = msi_reg_get_val_str( hkey, feature );
2963 RegCloseKey( hkey );
2965 TRACE("buffer = %s\n", debugstr_w(components));
2967 if (!components)
2969 *state = INSTALLSTATE_ADVERTISED;
2970 return ERROR_SUCCESS;
2972 for (p = components; *p && *p != 2 ; p += 20)
2974 if (!decode_base85_guid( p, &guid ))
2976 if (p != components) break;
2977 msi_free( components );
2978 *state = INSTALLSTATE_BADCONFIG;
2979 return ERROR_BAD_CONFIGURATION;
2981 StringFromGUID2( &guid, comp, GUID_SIZE );
2982 if (ctx == MSIINSTALLCONTEXT_MACHINE)
2983 r = MSIREG_OpenUserDataComponentKey( comp, L"S-1-5-18", &hkey, FALSE );
2984 else
2985 r = MSIREG_OpenUserDataComponentKey( comp, usersid, &hkey, FALSE );
2987 if (r != ERROR_SUCCESS)
2989 msi_free( components );
2990 *state = INSTALLSTATE_ADVERTISED;
2991 return ERROR_SUCCESS;
2993 path = msi_reg_get_val_str( hkey, squashed );
2994 if (!path) missing = TRUE;
2995 else if (lstrlenW( path ) > 2 &&
2996 path[0] >= '0' && path[0] <= '9' &&
2997 path[1] >= '0' && path[1] <= '9')
2999 source = TRUE;
3001 msi_free( path );
3003 msi_free( components );
3005 if (missing)
3006 *state = INSTALLSTATE_ADVERTISED;
3007 else if (source)
3008 *state = INSTALLSTATE_SOURCE;
3009 else
3010 *state = INSTALLSTATE_LOCAL;
3012 TRACE("returning state %d\n", *state);
3013 return ERROR_SUCCESS;
3016 UINT WINAPI MsiQueryFeatureStateExA( LPCSTR product, LPCSTR usersid, MSIINSTALLCONTEXT ctx,
3017 LPCSTR feature, INSTALLSTATE *state )
3019 UINT r;
3020 WCHAR *productW = NULL, *usersidW = NULL, *featureW = NULL;
3022 if (product && !(productW = strdupAtoW( product ))) return ERROR_OUTOFMEMORY;
3023 if (usersid && !(usersidW = strdupAtoW( usersid )))
3025 msi_free( productW );
3026 return ERROR_OUTOFMEMORY;
3028 if (feature && !(featureW = strdupAtoW( feature )))
3030 msi_free( productW );
3031 msi_free( usersidW );
3032 return ERROR_OUTOFMEMORY;
3034 r = MsiQueryFeatureStateExW( productW, usersidW, ctx, featureW, state );
3035 msi_free( productW );
3036 msi_free( usersidW );
3037 msi_free( featureW );
3038 return r;
3041 UINT WINAPI MsiQueryFeatureStateExW( LPCWSTR product, LPCWSTR usersid, MSIINSTALLCONTEXT ctx,
3042 LPCWSTR feature, INSTALLSTATE *state )
3044 WCHAR squashed[33];
3045 if (!squash_guid( product, squashed )) return ERROR_INVALID_PARAMETER;
3046 return query_feature_state( product, squashed, usersid, ctx, feature, state );
3049 /******************************************************************
3050 * MsiQueryFeatureStateA [MSI.@]
3052 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
3054 LPWSTR szwProduct = NULL, szwFeature= NULL;
3055 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
3057 szwProduct = strdupAtoW( szProduct );
3058 if ( szProduct && !szwProduct )
3059 goto end;
3061 szwFeature = strdupAtoW( szFeature );
3062 if ( szFeature && !szwFeature )
3063 goto end;
3065 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
3067 end:
3068 msi_free( szwProduct);
3069 msi_free( szwFeature);
3071 return rc;
3074 /******************************************************************
3075 * MsiQueryFeatureStateW [MSI.@]
3077 * Checks the state of a feature
3079 * PARAMS
3080 * szProduct [I] Product's GUID string
3081 * szFeature [I] Feature's GUID string
3083 * RETURNS
3084 * INSTALLSTATE_LOCAL Feature is installed and usable
3085 * INSTALLSTATE_ABSENT Feature is absent
3086 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
3087 * INSTALLSTATE_UNKNOWN An error occurred
3088 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
3091 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
3093 UINT r;
3094 INSTALLSTATE state;
3095 WCHAR squashed[33];
3097 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
3099 if (!szProduct || !szFeature || !squash_guid( szProduct, squashed ))
3100 return INSTALLSTATE_INVALIDARG;
3102 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_USERMANAGED, szFeature, &state );
3103 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3105 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, szFeature, &state );
3106 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3108 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_MACHINE, szFeature, &state );
3109 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3111 return INSTALLSTATE_UNKNOWN;
3114 /******************************************************************
3115 * MsiGetFileVersionA [MSI.@]
3117 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
3118 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
3120 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
3121 UINT ret = ERROR_OUTOFMEMORY;
3123 if ((lpVersionBuf && !pcchVersionBuf) ||
3124 (lpLangBuf && !pcchLangBuf))
3125 return ERROR_INVALID_PARAMETER;
3127 if( szFilePath )
3129 szwFilePath = strdupAtoW( szFilePath );
3130 if( !szwFilePath )
3131 goto end;
3134 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
3136 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
3137 if( !lpwVersionBuff )
3138 goto end;
3141 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
3143 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
3144 if( !lpwLangBuff )
3145 goto end;
3148 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
3149 lpwLangBuff, pcchLangBuf);
3151 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
3152 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
3153 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
3154 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
3155 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
3156 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
3158 end:
3159 msi_free(szwFilePath);
3160 msi_free(lpwVersionBuff);
3161 msi_free(lpwLangBuff);
3163 return ret;
3166 static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
3167 WCHAR *langbuf, DWORD *langlen )
3169 UINT ret = ERROR_MORE_DATA;
3170 DWORD len, error;
3171 LPVOID version;
3172 VS_FIXEDFILEINFO *ffi;
3173 USHORT *lang;
3174 WCHAR tmp[32];
3176 if (!(len = GetFileVersionInfoSizeW( path, NULL )))
3178 error = GetLastError();
3179 if (error == ERROR_BAD_PATHNAME) return ERROR_FILE_NOT_FOUND;
3180 if (error == ERROR_RESOURCE_DATA_NOT_FOUND) return ERROR_FILE_INVALID;
3181 return error;
3183 if (!(version = msi_alloc( len ))) return ERROR_OUTOFMEMORY;
3184 if (!GetFileVersionInfoW( path, 0, len, version ))
3186 msi_free( version );
3187 return GetLastError();
3189 if (!verbuf && !verlen && !langbuf && !langlen)
3191 msi_free( version );
3192 return ERROR_SUCCESS;
3194 if (verlen)
3196 if (VerQueryValueW( version, L"\\", (LPVOID *)&ffi, &len ) && len > 0)
3198 swprintf( tmp, ARRAY_SIZE(tmp), L"%d.%d.%d.%d",
3199 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
3200 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS) );
3201 if (verbuf) lstrcpynW( verbuf, tmp, *verlen );
3202 len = lstrlenW( tmp );
3203 if (*verlen > len) ret = ERROR_SUCCESS;
3204 *verlen = len;
3206 else
3208 if (verbuf) *verbuf = 0;
3209 *verlen = 0;
3212 if (langlen)
3214 if (VerQueryValueW( version, L"\\VarFileInfo\\Translation", (LPVOID *)&lang, &len ) && len > 0)
3216 swprintf( tmp, ARRAY_SIZE(tmp), L"%d", *lang );
3217 if (langbuf) lstrcpynW( langbuf, tmp, *langlen );
3218 len = lstrlenW( tmp );
3219 if (*langlen > len) ret = ERROR_SUCCESS;
3220 *langlen = len;
3222 else
3224 if (langbuf) *langbuf = 0;
3225 *langlen = 0;
3228 msi_free( version );
3229 return ret;
3233 /******************************************************************
3234 * MsiGetFileVersionW [MSI.@]
3236 UINT WINAPI MsiGetFileVersionW( LPCWSTR path, LPWSTR verbuf, LPDWORD verlen,
3237 LPWSTR langbuf, LPDWORD langlen )
3239 UINT ret;
3241 TRACE("%s %p %u %p %u\n", debugstr_w(path), verbuf, verlen ? *verlen : 0,
3242 langbuf, langlen ? *langlen : 0);
3244 if ((verbuf && !verlen) || (langbuf && !langlen))
3245 return ERROR_INVALID_PARAMETER;
3247 ret = get_file_version( path, verbuf, verlen, langbuf, langlen );
3248 if (ret == ERROR_RESOURCE_DATA_NOT_FOUND && verlen)
3250 int len;
3251 WCHAR *version = msi_get_font_file_version( NULL, path );
3252 if (!version) return ERROR_FILE_INVALID;
3253 len = lstrlenW( version );
3254 if (len >= *verlen) ret = ERROR_MORE_DATA;
3255 else if (verbuf)
3257 lstrcpyW( verbuf, version );
3258 ret = ERROR_SUCCESS;
3260 *verlen = len;
3261 msi_free( version );
3263 return ret;
3266 /***********************************************************************
3267 * MsiGetFeatureUsageW [MSI.@]
3269 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
3270 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3272 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
3273 pdwUseCount, pwDateUsed);
3274 return ERROR_CALL_NOT_IMPLEMENTED;
3277 /***********************************************************************
3278 * MsiGetFeatureUsageA [MSI.@]
3280 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
3281 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3283 LPWSTR prod = NULL, feat = NULL;
3284 UINT ret = ERROR_OUTOFMEMORY;
3286 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
3287 pdwUseCount, pwDateUsed);
3289 prod = strdupAtoW( szProduct );
3290 if (szProduct && !prod)
3291 goto end;
3293 feat = strdupAtoW( szFeature );
3294 if (szFeature && !feat)
3295 goto end;
3297 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
3299 end:
3300 msi_free( prod );
3301 msi_free( feat );
3303 return ret;
3306 /***********************************************************************
3307 * MsiUseFeatureExW [MSI.@]
3309 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
3310 DWORD dwInstallMode, DWORD dwReserved )
3312 INSTALLSTATE state;
3314 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3315 dwInstallMode, dwReserved);
3317 state = MsiQueryFeatureStateW( szProduct, szFeature );
3319 if (dwReserved)
3320 return INSTALLSTATE_INVALIDARG;
3322 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
3324 FIXME("mark product %s feature %s as used\n",
3325 debugstr_w(szProduct), debugstr_w(szFeature) );
3328 return state;
3331 /***********************************************************************
3332 * MsiUseFeatureExA [MSI.@]
3334 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
3335 DWORD dwInstallMode, DWORD dwReserved )
3337 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
3338 LPWSTR prod = NULL, feat = NULL;
3340 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3341 dwInstallMode, dwReserved);
3343 prod = strdupAtoW( szProduct );
3344 if (szProduct && !prod)
3345 goto end;
3347 feat = strdupAtoW( szFeature );
3348 if (szFeature && !feat)
3349 goto end;
3351 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
3353 end:
3354 msi_free( prod );
3355 msi_free( feat );
3357 return ret;
3360 /***********************************************************************
3361 * MsiUseFeatureW [MSI.@]
3363 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
3365 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
3368 /***********************************************************************
3369 * MsiUseFeatureA [MSI.@]
3371 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
3373 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
3376 static WCHAR *reg_get_multisz( HKEY hkey, const WCHAR *name )
3378 WCHAR *ret;
3379 DWORD len, type;
3380 if (RegQueryValueExW( hkey, name, NULL, &type, NULL, &len ) || type != REG_MULTI_SZ) return NULL;
3381 if ((ret = msi_alloc( len ))) RegQueryValueExW( hkey, name, NULL, NULL, (BYTE *)ret, &len );
3382 return ret;
3385 static WCHAR *reg_get_sz( HKEY hkey, const WCHAR *name )
3387 WCHAR *ret;
3388 DWORD len, type;
3389 if (RegQueryValueExW( hkey, name, NULL, &type, NULL, &len ) || type != REG_SZ) return NULL;
3390 if ((ret = msi_alloc( len ))) RegQueryValueExW( hkey, name, NULL, NULL, (BYTE *)ret, &len );
3391 return ret;
3394 #define BASE85_SIZE 20
3396 /***********************************************************************
3397 * MSI_ProvideQualifiedComponentEx [internal]
3399 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
3400 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3401 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
3402 LPDWORD pcchPathBuf)
3404 WCHAR product[MAX_FEATURE_CHARS+1], comp[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1];
3405 WCHAR *desc;
3406 HKEY hkey;
3407 DWORD size;
3408 UINT ret;
3409 INSTALLSTATE state;
3411 if (MSIREG_OpenUserComponentsKey( szComponent, &hkey, FALSE )) return ERROR_UNKNOWN_COMPONENT;
3413 desc = reg_get_multisz( hkey, szQualifier );
3414 RegCloseKey(hkey);
3415 if (!desc) return ERROR_INDEX_ABSENT;
3417 /* FIXME: handle multiple descriptors */
3418 ret = MsiDecomposeDescriptorW( desc, product, feature, comp, &size );
3419 msi_free( desc );
3420 if (ret != ERROR_SUCCESS) return ret;
3422 if (!szProduct) szProduct = product;
3423 if (!comp[0])
3425 MSIINSTALLCONTEXT ctx;
3426 WCHAR *components;
3427 GUID guid;
3429 /* use the first component of the feature if the descriptor component is empty */
3430 if ((ret = msi_locate_product( szProduct, &ctx ))) return ret;
3431 if ((ret = MSIREG_OpenUserDataFeaturesKey( szProduct, NULL, ctx, &hkey, FALSE )))
3433 return ERROR_FILE_NOT_FOUND;
3435 components = reg_get_sz( hkey, feature );
3436 RegCloseKey( hkey );
3437 if (!components) return ERROR_FILE_NOT_FOUND;
3439 if (lstrlenW( components ) < BASE85_SIZE || !decode_base85_guid( components, &guid ))
3441 msi_free( components );
3442 return ERROR_FILE_NOT_FOUND;
3444 msi_free( components );
3445 StringFromGUID2( &guid, comp, ARRAY_SIZE( comp ));
3448 state = MSI_GetComponentPath( szProduct, comp, L"S-1-1-0", MSIINSTALLCONTEXT_ALL, lpPathBuf, pcchPathBuf );
3450 if (state == INSTALLSTATE_MOREDATA) return ERROR_MORE_DATA;
3451 if (state != INSTALLSTATE_LOCAL) return ERROR_FILE_NOT_FOUND;
3452 return ERROR_SUCCESS;
3455 /***********************************************************************
3456 * MsiProvideQualifiedComponentExW [MSI.@]
3458 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
3459 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3460 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
3461 LPDWORD pcchPathBuf)
3463 awstring path;
3465 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_w(szComponent),
3466 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
3467 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3469 path.unicode = TRUE;
3470 path.str.w = lpPathBuf;
3472 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
3473 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
3476 /***********************************************************************
3477 * MsiProvideQualifiedComponentExA [MSI.@]
3479 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
3480 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
3481 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
3482 LPDWORD pcchPathBuf)
3484 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
3485 UINT r = ERROR_OUTOFMEMORY;
3486 awstring path;
3488 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
3489 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
3490 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3492 szwComponent = strdupAtoW( szComponent );
3493 if (szComponent && !szwComponent)
3494 goto end;
3496 szwQualifier = strdupAtoW( szQualifier );
3497 if (szQualifier && !szwQualifier)
3498 goto end;
3500 szwProduct = strdupAtoW( szProduct );
3501 if (szProduct && !szwProduct)
3502 goto end;
3504 path.unicode = FALSE;
3505 path.str.a = lpPathBuf;
3507 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
3508 dwInstallMode, szwProduct, Unused1,
3509 Unused2, &path, pcchPathBuf);
3510 end:
3511 msi_free(szwProduct);
3512 msi_free(szwComponent);
3513 msi_free(szwQualifier);
3515 return r;
3518 /***********************************************************************
3519 * MsiProvideQualifiedComponentW [MSI.@]
3521 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
3522 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
3523 LPDWORD pcchPathBuf)
3525 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
3526 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3529 /***********************************************************************
3530 * MsiProvideQualifiedComponentA [MSI.@]
3532 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
3533 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
3534 LPDWORD pcchPathBuf)
3536 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
3537 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3540 /***********************************************************************
3541 * MSI_GetUserInfo [internal]
3543 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
3544 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
3545 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3546 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
3548 WCHAR *user, *org, *serial, squashed_pc[SQUASHED_GUID_SIZE];
3549 USERINFOSTATE state;
3550 HKEY hkey, props;
3551 LPCWSTR orgptr;
3552 UINT r;
3554 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
3555 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
3556 pcchSerialBuf);
3558 if (!szProduct || !squash_guid( szProduct, squashed_pc ))
3559 return USERINFOSTATE_INVALIDARG;
3561 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
3562 &hkey, FALSE) != ERROR_SUCCESS &&
3563 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3564 &hkey, FALSE) != ERROR_SUCCESS &&
3565 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
3566 &hkey, FALSE) != ERROR_SUCCESS)
3568 return USERINFOSTATE_UNKNOWN;
3571 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
3572 NULL, &props, FALSE) != ERROR_SUCCESS &&
3573 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
3574 NULL, &props, FALSE) != ERROR_SUCCESS)
3576 RegCloseKey(hkey);
3577 return USERINFOSTATE_ABSENT;
3580 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3581 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3582 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3583 state = USERINFOSTATE_ABSENT;
3585 RegCloseKey(hkey);
3586 RegCloseKey(props);
3588 if (user && serial)
3589 state = USERINFOSTATE_PRESENT;
3591 if (pcchUserNameBuf)
3593 if (lpUserNameBuf && !user)
3595 (*pcchUserNameBuf)--;
3596 goto done;
3599 r = msi_strcpy_to_awstring(user, -1, lpUserNameBuf, pcchUserNameBuf);
3600 if (r == ERROR_MORE_DATA)
3602 state = USERINFOSTATE_MOREDATA;
3603 goto done;
3607 if (pcchOrgNameBuf)
3609 orgptr = org;
3610 if (!orgptr) orgptr = L"";
3612 r = msi_strcpy_to_awstring(orgptr, -1, lpOrgNameBuf, pcchOrgNameBuf);
3613 if (r == ERROR_MORE_DATA)
3615 state = USERINFOSTATE_MOREDATA;
3616 goto done;
3620 if (pcchSerialBuf)
3622 if (!serial)
3624 (*pcchSerialBuf)--;
3625 goto done;
3628 r = msi_strcpy_to_awstring(serial, -1, lpSerialBuf, pcchSerialBuf);
3629 if (r == ERROR_MORE_DATA)
3630 state = USERINFOSTATE_MOREDATA;
3633 done:
3634 msi_free(user);
3635 msi_free(org);
3636 msi_free(serial);
3638 return state;
3641 /***********************************************************************
3642 * MsiGetUserInfoW [MSI.@]
3644 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3645 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3646 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3647 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3649 awstring user, org, serial;
3651 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3652 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3653 (lpSerialBuf && !pcchSerialBuf))
3654 return USERINFOSTATE_INVALIDARG;
3656 user.unicode = TRUE;
3657 user.str.w = lpUserNameBuf;
3658 org.unicode = TRUE;
3659 org.str.w = lpOrgNameBuf;
3660 serial.unicode = TRUE;
3661 serial.str.w = lpSerialBuf;
3663 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3664 &org, pcchOrgNameBuf,
3665 &serial, pcchSerialBuf );
3668 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3669 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3670 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3671 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3673 awstring user, org, serial;
3674 LPWSTR prod;
3675 UINT r;
3677 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3678 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3679 (lpSerialBuf && !pcchSerialBuf))
3680 return USERINFOSTATE_INVALIDARG;
3682 prod = strdupAtoW( szProduct );
3683 if (szProduct && !prod)
3684 return ERROR_OUTOFMEMORY;
3686 user.unicode = FALSE;
3687 user.str.a = lpUserNameBuf;
3688 org.unicode = FALSE;
3689 org.str.a = lpOrgNameBuf;
3690 serial.unicode = FALSE;
3691 serial.str.a = lpSerialBuf;
3693 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3694 &org, pcchOrgNameBuf,
3695 &serial, pcchSerialBuf );
3697 msi_free( prod );
3699 return r;
3702 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3704 MSIHANDLE handle;
3705 UINT rc;
3706 MSIPACKAGE *package;
3708 TRACE("(%s)\n",debugstr_w(szProduct));
3710 rc = MsiOpenProductW(szProduct,&handle);
3711 if (rc != ERROR_SUCCESS)
3712 return ERROR_INVALID_PARAMETER;
3714 /* MsiCollectUserInfo cannot be called from a custom action. */
3715 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3716 if (!package)
3717 return ERROR_CALL_NOT_IMPLEMENTED;
3719 rc = ACTION_PerformAction(package, L"FirstRun");
3720 msiobj_release( &package->hdr );
3722 MsiCloseHandle(handle);
3724 return rc;
3727 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3729 MSIHANDLE handle;
3730 UINT rc;
3731 MSIPACKAGE *package;
3733 TRACE("(%s)\n",debugstr_a(szProduct));
3735 rc = MsiOpenProductA(szProduct,&handle);
3736 if (rc != ERROR_SUCCESS)
3737 return ERROR_INVALID_PARAMETER;
3739 /* MsiCollectUserInfo cannot be called from a custom action. */
3740 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3741 if (!package)
3742 return ERROR_CALL_NOT_IMPLEMENTED;
3744 rc = ACTION_PerformAction(package, L"FirstRun");
3745 msiobj_release( &package->hdr );
3747 MsiCloseHandle(handle);
3749 return rc;
3752 /***********************************************************************
3753 * MsiConfigureFeatureA [MSI.@]
3755 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3757 LPWSTR prod, feat = NULL;
3758 UINT r = ERROR_OUTOFMEMORY;
3760 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3762 prod = strdupAtoW( szProduct );
3763 if (szProduct && !prod)
3764 goto end;
3766 feat = strdupAtoW( szFeature );
3767 if (szFeature && !feat)
3768 goto end;
3770 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3772 end:
3773 msi_free(feat);
3774 msi_free(prod);
3776 return r;
3779 /***********************************************************************
3780 * MsiConfigureFeatureW [MSI.@]
3782 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3784 MSIPACKAGE *package = NULL;
3785 UINT r;
3786 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3787 DWORD sz;
3789 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3791 if (!szProduct || !szFeature)
3792 return ERROR_INVALID_PARAMETER;
3794 switch (eInstallState)
3796 case INSTALLSTATE_DEFAULT:
3797 /* FIXME: how do we figure out the default location? */
3798 eInstallState = INSTALLSTATE_LOCAL;
3799 break;
3800 case INSTALLSTATE_LOCAL:
3801 case INSTALLSTATE_SOURCE:
3802 case INSTALLSTATE_ABSENT:
3803 case INSTALLSTATE_ADVERTISED:
3804 break;
3805 default:
3806 return ERROR_INVALID_PARAMETER;
3809 r = MSI_OpenProductW( szProduct, &package );
3810 if (r != ERROR_SUCCESS)
3811 return r;
3813 sz = sizeof(sourcepath);
3814 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3815 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3817 sz = sizeof(filename);
3818 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3819 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3821 lstrcatW( sourcepath, filename );
3823 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3825 r = ACTION_PerformAction(package, L"CostInitialize");
3826 if (r != ERROR_SUCCESS)
3827 goto end;
3829 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3830 if (r != ERROR_SUCCESS)
3831 goto end;
3833 r = MSI_InstallPackage( package, sourcepath, NULL );
3835 end:
3836 msiobj_release( &package->hdr );
3838 return r;
3841 /***********************************************************************
3842 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3844 * Notes: undocumented
3846 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3848 WCHAR path[MAX_PATH];
3850 TRACE("%d\n", dwReserved);
3852 if (dwReserved)
3854 FIXME("dwReserved=%d\n", dwReserved);
3855 return ERROR_INVALID_PARAMETER;
3858 if (!GetWindowsDirectoryW(path, MAX_PATH))
3859 return ERROR_FUNCTION_FAILED;
3861 lstrcatW(path, L"\\Installer");
3863 if (!CreateDirectoryW(path, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
3864 return ERROR_FUNCTION_FAILED;
3866 return ERROR_SUCCESS;
3869 /***********************************************************************
3870 * MsiGetShortcutTargetA [MSI.@]
3872 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3873 LPSTR szProductCode, LPSTR szFeatureId,
3874 LPSTR szComponentCode )
3876 LPWSTR target;
3877 const int len = MAX_FEATURE_CHARS+1;
3878 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3879 UINT r;
3881 target = strdupAtoW( szShortcutTarget );
3882 if (szShortcutTarget && !target )
3883 return ERROR_OUTOFMEMORY;
3884 product[0] = 0;
3885 feature[0] = 0;
3886 component[0] = 0;
3887 r = MsiGetShortcutTargetW( target, product, feature, component );
3888 msi_free( target );
3889 if (r == ERROR_SUCCESS)
3891 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3892 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3893 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3895 return r;
3898 /***********************************************************************
3899 * MsiGetShortcutTargetW [MSI.@]
3901 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3902 LPWSTR szProductCode, LPWSTR szFeatureId,
3903 LPWSTR szComponentCode )
3905 IShellLinkDataList *dl = NULL;
3906 IPersistFile *pf = NULL;
3907 LPEXP_DARWIN_LINK darwin = NULL;
3908 HRESULT r, init;
3910 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3911 szProductCode, szFeatureId, szComponentCode );
3913 init = CoInitialize(NULL);
3915 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3916 &IID_IPersistFile, (LPVOID*) &pf );
3917 if( SUCCEEDED( r ) )
3919 r = IPersistFile_Load( pf, szShortcutTarget,
3920 STGM_READ | STGM_SHARE_DENY_WRITE );
3921 if( SUCCEEDED( r ) )
3923 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3924 (LPVOID*) &dl );
3925 if( SUCCEEDED( r ) )
3927 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3928 (LPVOID) &darwin );
3929 IShellLinkDataList_Release( dl );
3932 IPersistFile_Release( pf );
3935 if (SUCCEEDED(init))
3936 CoUninitialize();
3938 TRACE("darwin = %p\n", darwin);
3940 if (darwin)
3942 DWORD sz;
3943 UINT ret;
3945 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3946 szProductCode, szFeatureId, szComponentCode, &sz );
3947 LocalFree( darwin );
3948 return ret;
3951 return ERROR_FUNCTION_FAILED;
3954 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature, DWORD dwReinstallMode )
3956 MSIPACKAGE *package;
3957 MSIINSTALLCONTEXT context;
3958 UINT r;
3959 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH], reinstallmode[11];
3960 WCHAR *ptr, *cmdline;
3961 DWORD sz;
3963 TRACE("%s, %s, 0x%08x\n", debugstr_w(szProduct), debugstr_w(szFeature), dwReinstallMode);
3965 r = msi_locate_product( szProduct, &context );
3966 if (r != ERROR_SUCCESS)
3967 return r;
3969 ptr = reinstallmode;
3971 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3972 *ptr++ = 'p';
3973 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3974 *ptr++ = 'o';
3975 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3976 *ptr++ = 'w';
3977 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3978 *ptr++ = 'd';
3979 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3980 *ptr++ = 'c';
3981 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3982 *ptr++ = 'a';
3983 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3984 *ptr++ = 'u';
3985 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3986 *ptr++ = 'm';
3987 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3988 *ptr++ = 's';
3989 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3990 *ptr++ = 'v';
3991 *ptr = 0;
3993 sz = sizeof(sourcepath);
3994 MsiSourceListGetInfoW( szProduct, NULL, context, MSICODE_PRODUCT,
3995 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz );
3996 sz = sizeof(filename);
3997 MsiSourceListGetInfoW( szProduct, NULL, context, MSICODE_PRODUCT,
3998 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz );
3999 lstrcatW( sourcepath, filename );
4001 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
4002 r = MSI_OpenPackageW( sourcepath, 0, &package );
4003 else
4004 r = MSI_OpenProductW( szProduct, &package );
4006 if (r != ERROR_SUCCESS)
4007 return r;
4009 sz = (lstrlenW( L"%s=%s %s=%s" ) + lstrlenW( L"REINSTALLMODE" ) + lstrlenW( reinstallmode )) * sizeof(WCHAR);
4010 sz += (lstrlenW( L"REINSTALL" ) + lstrlenW( szFeature )) * sizeof(WCHAR);
4011 if (!(cmdline = msi_alloc( sz )))
4013 msiobj_release( &package->hdr );
4014 return ERROR_OUTOFMEMORY;
4016 swprintf( cmdline, sz / sizeof(WCHAR), L"%s=%s %s=%s", L"REINSTALLMODE", reinstallmode, L"REINSTALL", szFeature );
4018 r = MSI_InstallPackage( package, sourcepath, cmdline );
4019 msiobj_release( &package->hdr );
4020 msi_free( cmdline );
4022 return r;
4025 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
4026 DWORD dwReinstallMode )
4028 LPWSTR wszProduct;
4029 LPWSTR wszFeature;
4030 UINT rc;
4032 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
4033 dwReinstallMode);
4035 wszProduct = strdupAtoW(szProduct);
4036 wszFeature = strdupAtoW(szFeature);
4038 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
4040 msi_free(wszProduct);
4041 msi_free(wszFeature);
4042 return rc;
4045 typedef struct
4047 unsigned int i[2];
4048 unsigned int buf[4];
4049 unsigned char in[64];
4050 unsigned char digest[16];
4051 } MD5_CTX;
4053 extern VOID WINAPI MD5Init( MD5_CTX *);
4054 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
4055 extern VOID WINAPI MD5Final( MD5_CTX *);
4057 UINT msi_get_filehash( MSIPACKAGE *package, const WCHAR *path, MSIFILEHASHINFO *hash )
4059 HANDLE handle, mapping;
4060 void *p;
4061 DWORD length;
4062 UINT r = ERROR_FUNCTION_FAILED;
4064 if (package)
4065 handle = msi_create_file( package, path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE, OPEN_EXISTING, 0 );
4066 else
4067 handle = CreateFileW( path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
4068 if (handle == INVALID_HANDLE_VALUE)
4070 WARN("can't open file %u\n", GetLastError());
4071 return ERROR_FILE_NOT_FOUND;
4073 if ((length = GetFileSize( handle, NULL )))
4075 if ((mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL )))
4077 if ((p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length )))
4079 MD5_CTX ctx;
4081 MD5Init( &ctx );
4082 MD5Update( &ctx, p, length );
4083 MD5Final( &ctx );
4084 UnmapViewOfFile( p );
4086 memcpy( hash->dwData, ctx.digest, sizeof(hash->dwData) );
4087 r = ERROR_SUCCESS;
4089 CloseHandle( mapping );
4092 else
4094 /* Empty file -> set hash to 0 */
4095 memset( hash->dwData, 0, sizeof(hash->dwData) );
4096 r = ERROR_SUCCESS;
4099 CloseHandle( handle );
4100 return r;
4103 /***********************************************************************
4104 * MsiGetFileHashW [MSI.@]
4106 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
4107 PMSIFILEHASHINFO pHash )
4109 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
4111 if (!szFilePath)
4112 return ERROR_INVALID_PARAMETER;
4114 if (!*szFilePath)
4115 return ERROR_PATH_NOT_FOUND;
4117 if (dwOptions)
4118 return ERROR_INVALID_PARAMETER;
4119 if (!pHash)
4120 return ERROR_INVALID_PARAMETER;
4121 if (pHash->dwFileHashInfoSize < sizeof *pHash)
4122 return ERROR_INVALID_PARAMETER;
4124 return msi_get_filehash( NULL, szFilePath, pHash );
4127 /***********************************************************************
4128 * MsiGetFileHashA [MSI.@]
4130 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
4131 PMSIFILEHASHINFO pHash )
4133 LPWSTR file;
4134 UINT r;
4136 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
4138 file = strdupAtoW( szFilePath );
4139 if (szFilePath && !file)
4140 return ERROR_OUTOFMEMORY;
4142 r = MsiGetFileHashW( file, dwOptions, pHash );
4143 msi_free( file );
4144 return r;
4147 /***********************************************************************
4148 * MsiAdvertiseScriptW [MSI.@]
4150 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
4151 PHKEY phRegData, BOOL fRemoveItems )
4153 FIXME("%s %08x %p %d\n",
4154 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
4155 return ERROR_CALL_NOT_IMPLEMENTED;
4158 /***********************************************************************
4159 * MsiAdvertiseScriptA [MSI.@]
4161 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
4162 PHKEY phRegData, BOOL fRemoveItems )
4164 FIXME("%s %08x %p %d\n",
4165 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
4166 return ERROR_CALL_NOT_IMPLEMENTED;
4169 /***********************************************************************
4170 * MsiIsProductElevatedW [MSI.@]
4172 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
4174 FIXME("%s %p - stub\n",
4175 debugstr_w( szProduct ), pfElevated );
4176 *pfElevated = TRUE;
4177 return ERROR_SUCCESS;
4180 /***********************************************************************
4181 * MsiIsProductElevatedA [MSI.@]
4183 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
4185 FIXME("%s %p - stub\n",
4186 debugstr_a( szProduct ), pfElevated );
4187 *pfElevated = TRUE;
4188 return ERROR_SUCCESS;
4191 /***********************************************************************
4192 * MsiSetExternalUIRecord [MSI.@]
4194 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler,
4195 DWORD filter, LPVOID context,
4196 PINSTALLUI_HANDLER_RECORD prev )
4198 TRACE("%p %08x %p %p\n", handler, filter, context, prev);
4200 if (prev)
4201 *prev = gUIHandlerRecord;
4203 gUIHandlerRecord = handler;
4204 gUIFilterRecord = filter;
4205 gUIContextRecord = context;
4207 return ERROR_SUCCESS;
4210 /***********************************************************************
4211 * MsiInstallMissingComponentA [MSI.@]
4213 UINT WINAPI MsiInstallMissingComponentA( LPCSTR product, LPCSTR component, INSTALLSTATE state )
4215 UINT r;
4216 WCHAR *productW = NULL, *componentW = NULL;
4218 TRACE("%s, %s, %d\n", debugstr_a(product), debugstr_a(component), state);
4220 if (product && !(productW = strdupAtoW( product )))
4221 return ERROR_OUTOFMEMORY;
4223 if (component && !(componentW = strdupAtoW( component )))
4225 msi_free( productW );
4226 return ERROR_OUTOFMEMORY;
4229 r = MsiInstallMissingComponentW( productW, componentW, state );
4230 msi_free( productW );
4231 msi_free( componentW );
4232 return r;
4235 /***********************************************************************
4236 * MsiInstallMissingComponentW [MSI.@]
4238 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
4240 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
4241 return ERROR_SUCCESS;
4244 UINT WINAPI MsiProvideComponentA( LPCSTR product, LPCSTR feature, LPCSTR component, DWORD mode, LPSTR buf, LPDWORD buflen )
4246 WCHAR *productW = NULL, *componentW = NULL, *featureW = NULL, *bufW = NULL;
4247 UINT r = ERROR_OUTOFMEMORY;
4248 DWORD lenW = 0;
4249 int len;
4251 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_a(product), debugstr_a(component), debugstr_a(feature), mode, buf, buflen);
4253 if (product && !(productW = strdupAtoW( product ))) goto done;
4254 if (feature && !(featureW = strdupAtoW( feature ))) goto done;
4255 if (component && !(componentW = strdupAtoW( component ))) goto done;
4257 r = MsiProvideComponentW( productW, featureW, componentW, mode, NULL, &lenW );
4258 if (r != ERROR_SUCCESS)
4259 goto done;
4261 if (!(bufW = msi_alloc( ++lenW * sizeof(WCHAR) )))
4263 r = ERROR_OUTOFMEMORY;
4264 goto done;
4267 r = MsiProvideComponentW( productW, featureW, componentW, mode, bufW, &lenW );
4268 if (r != ERROR_SUCCESS)
4269 goto done;
4271 len = WideCharToMultiByte( CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
4272 if (buf)
4274 if (len > *buflen)
4275 r = ERROR_MORE_DATA;
4276 else
4277 WideCharToMultiByte( CP_ACP, 0, bufW, -1, buf, *buflen, NULL, NULL );
4280 *buflen = len - 1;
4282 done:
4283 msi_free( productW );
4284 msi_free( featureW );
4285 msi_free( componentW );
4286 msi_free( bufW );
4287 return r;
4290 UINT WINAPI MsiProvideComponentW( LPCWSTR product, LPCWSTR feature, LPCWSTR component, DWORD mode, LPWSTR buf, LPDWORD buflen )
4292 INSTALLSTATE state;
4294 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_w(product), debugstr_w(component), debugstr_w(feature), mode, buf, buflen);
4296 state = MsiQueryFeatureStateW( product, feature );
4297 TRACE("feature state: %d\n", state);
4298 switch (mode)
4300 case INSTALLMODE_NODETECTION:
4301 break;
4303 default:
4304 FIXME("mode %x not implemented\n", mode);
4305 return ERROR_INSTALL_FAILURE;
4308 state = MsiGetComponentPathW( product, component, buf, buflen );
4309 TRACE("component state: %d\n", state);
4310 switch (state)
4312 case INSTALLSTATE_INVALIDARG:
4313 return ERROR_INVALID_PARAMETER;
4315 case INSTALLSTATE_MOREDATA:
4316 return ERROR_MORE_DATA;
4318 case INSTALLSTATE_ADVERTISED:
4319 case INSTALLSTATE_LOCAL:
4320 case INSTALLSTATE_SOURCE:
4321 MsiUseFeatureW( product, feature );
4322 return ERROR_SUCCESS;
4324 default:
4325 TRACE("MsiGetComponentPathW returned %d\n", state);
4326 return ERROR_INSTALL_FAILURE;
4330 /***********************************************************************
4331 * MsiBeginTransactionA [MSI.@]
4333 UINT WINAPI MsiBeginTransactionA( LPCSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4335 WCHAR *nameW;
4336 UINT r;
4338 FIXME("%s %u %p %p\n", debugstr_a(name), attrs, id, event);
4340 nameW = strdupAtoW( name );
4341 if (name && !nameW)
4342 return ERROR_OUTOFMEMORY;
4344 r = MsiBeginTransactionW( nameW, attrs, id, event );
4345 msi_free( nameW );
4346 return r;
4349 /***********************************************************************
4350 * MsiBeginTransactionW [MSI.@]
4352 UINT WINAPI MsiBeginTransactionW( LPCWSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4354 FIXME("%s %u %p %p\n", debugstr_w(name), attrs, id, event);
4356 *id = (MSIHANDLE)0xdeadbeef;
4357 *event = (HANDLE)0xdeadbeef;
4359 return ERROR_SUCCESS;
4362 /***********************************************************************
4363 * MsiJoinTransaction [MSI.@]
4365 UINT WINAPI MsiJoinTransaction( MSIHANDLE handle, DWORD attrs, HANDLE *event )
4367 FIXME("%u %08x %p\n", handle, attrs, event);
4369 *event = (HANDLE)0xdeadbeef;
4370 return ERROR_SUCCESS;
4373 /***********************************************************************
4374 * MsiEndTransaction [MSI.@]
4376 UINT WINAPI MsiEndTransaction( DWORD state )
4378 FIXME("%u\n", state);
4379 return ERROR_SUCCESS;
4382 UINT WINAPI Migrate10CachedPackagesW(void* a, void* b, void* c, DWORD d)
4384 FIXME("%p,%p,%p,%08x\n", a, b, c, d);
4385 return ERROR_SUCCESS;
4388 /***********************************************************************
4389 * MsiRemovePatchesA [MSI.@]
4391 UINT WINAPI MsiRemovePatchesA(LPCSTR patchlist, LPCSTR product, INSTALLTYPE type, LPCSTR propertylist)
4393 FIXME("(%s %s %d %s\n", debugstr_a(patchlist), debugstr_a(product), type, debugstr_a(propertylist));
4394 return ERROR_SUCCESS;
4397 /***********************************************************************
4398 * MsiRemovePatchesW [MSI.@]
4400 UINT WINAPI MsiRemovePatchesW(LPCWSTR patchlist, LPCWSTR product, INSTALLTYPE type, LPCWSTR propertylist)
4402 FIXME("(%s %s %d %s\n", debugstr_w(patchlist), debugstr_w(product), type, debugstr_w(propertylist));
4403 return ERROR_SUCCESS;