ws2_32/tests: Add tests for InetNtopW.
[wine.git] / dlls / msi / msi.c
blobecc3e94e3720e938db33788b8a0ad2ff7d8fb353
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "shlwapi.h"
31 #include "msi.h"
32 #include "msidefs.h"
33 #include "msiquery.h"
34 #include "msipriv.h"
35 #include "msiserver.h"
36 #include "wincrypt.h"
37 #include "winver.h"
38 #include "winuser.h"
39 #include "shlobj.h"
40 #include "shobjidl.h"
41 #include "objidl.h"
42 #include "wintrust.h"
43 #include "softpub.h"
45 #include "initguid.h"
46 #include "msxml2.h"
48 #include "wine/debug.h"
49 #include "wine/unicode.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(msi);
53 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};
55 UINT msi_locate_product(LPCWSTR szProduct, MSIINSTALLCONTEXT *context)
57 HKEY hkey = NULL;
59 *context = MSIINSTALLCONTEXT_NONE;
60 if (!szProduct) return ERROR_UNKNOWN_PRODUCT;
62 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
63 &hkey, FALSE) == ERROR_SUCCESS)
64 *context = MSIINSTALLCONTEXT_USERMANAGED;
65 else if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
66 &hkey, FALSE) == ERROR_SUCCESS)
67 *context = MSIINSTALLCONTEXT_MACHINE;
68 else if (MSIREG_OpenProductKey(szProduct, NULL,
69 MSIINSTALLCONTEXT_USERUNMANAGED,
70 &hkey, FALSE) == ERROR_SUCCESS)
71 *context = MSIINSTALLCONTEXT_USERUNMANAGED;
73 RegCloseKey(hkey);
75 if (*context == MSIINSTALLCONTEXT_NONE)
76 return ERROR_UNKNOWN_PRODUCT;
78 return ERROR_SUCCESS;
81 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
83 UINT r;
84 LPWSTR szwProd = NULL;
86 TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
88 if( szProduct )
90 szwProd = strdupAtoW( szProduct );
91 if( !szwProd )
92 return ERROR_OUTOFMEMORY;
95 r = MsiOpenProductW( szwProd, phProduct );
97 msi_free( szwProd );
99 return r;
102 static UINT MSI_OpenProductW(LPCWSTR szProduct, MSIPACKAGE **package)
104 UINT r;
105 HKEY props;
106 LPWSTR path;
107 MSIINSTALLCONTEXT context;
109 static const WCHAR managed[] = {
110 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
111 static const WCHAR local[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
113 TRACE("%s %p\n", debugstr_w(szProduct), package);
115 r = msi_locate_product(szProduct, &context);
116 if (r != ERROR_SUCCESS)
117 return r;
119 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &props, FALSE);
120 if (r != ERROR_SUCCESS)
121 return ERROR_UNKNOWN_PRODUCT;
123 if (context == MSIINSTALLCONTEXT_USERMANAGED)
124 path = msi_reg_get_val_str(props, managed);
125 else
126 path = msi_reg_get_val_str(props, local);
128 r = ERROR_UNKNOWN_PRODUCT;
130 if (!path || GetFileAttributesW(path) == INVALID_FILE_ATTRIBUTES)
131 goto done;
133 if (PathIsRelativeW(path))
135 r = ERROR_INSTALL_PACKAGE_OPEN_FAILED;
136 goto done;
139 r = MSI_OpenPackageW(path, package);
141 done:
142 RegCloseKey(props);
143 msi_free(path);
144 return r;
147 UINT WINAPI MsiOpenProductW(LPCWSTR szProduct, MSIHANDLE *phProduct)
149 MSIPACKAGE *package = NULL;
150 WCHAR squished_pc[GUID_SIZE];
151 UINT r;
153 if (!szProduct || !squash_guid(szProduct, squished_pc))
154 return ERROR_INVALID_PARAMETER;
156 if (!phProduct)
157 return ERROR_INVALID_PARAMETER;
159 r = MSI_OpenProductW(szProduct, &package);
160 if (r != ERROR_SUCCESS)
161 return r;
163 *phProduct = alloc_msihandle(&package->hdr);
164 if (!*phProduct)
165 r = ERROR_NOT_ENOUGH_MEMORY;
167 msiobj_release(&package->hdr);
168 return r;
171 UINT WINAPI MsiAdvertiseProductA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
172 LPCSTR szTransforms, LANGID lgidLanguage)
174 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath),
175 debugstr_a(szScriptfilePath), debugstr_a(szTransforms), lgidLanguage);
176 return ERROR_CALL_NOT_IMPLEMENTED;
179 UINT WINAPI MsiAdvertiseProductW(LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
180 LPCWSTR szTransforms, LANGID lgidLanguage)
182 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath),
183 debugstr_w(szScriptfilePath), debugstr_w(szTransforms), lgidLanguage);
184 return ERROR_CALL_NOT_IMPLEMENTED;
187 UINT WINAPI MsiAdvertiseProductExA(LPCSTR szPackagePath, LPCSTR szScriptfilePath,
188 LPCSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
190 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath),
191 debugstr_a(szScriptfilePath), debugstr_a(szTransforms),
192 lgidLanguage, dwPlatform, dwOptions);
193 return ERROR_CALL_NOT_IMPLEMENTED;
196 UINT WINAPI MsiAdvertiseProductExW( LPCWSTR szPackagePath, LPCWSTR szScriptfilePath,
197 LPCWSTR szTransforms, LANGID lgidLanguage, DWORD dwPlatform, DWORD dwOptions)
199 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath),
200 debugstr_w(szScriptfilePath), debugstr_w(szTransforms),
201 lgidLanguage, dwPlatform, dwOptions);
202 return ERROR_CALL_NOT_IMPLEMENTED;
205 UINT WINAPI MsiInstallProductA(LPCSTR szPackagePath, LPCSTR szCommandLine)
207 LPWSTR szwPath = NULL, szwCommand = NULL;
208 UINT r = ERROR_OUTOFMEMORY;
210 TRACE("%s %s\n",debugstr_a(szPackagePath), debugstr_a(szCommandLine));
212 if( szPackagePath )
214 szwPath = strdupAtoW( szPackagePath );
215 if( !szwPath )
216 goto end;
219 if( szCommandLine )
221 szwCommand = strdupAtoW( szCommandLine );
222 if( !szwCommand )
223 goto end;
226 r = MsiInstallProductW( szwPath, szwCommand );
228 end:
229 msi_free( szwPath );
230 msi_free( szwCommand );
232 return r;
235 UINT WINAPI MsiInstallProductW(LPCWSTR szPackagePath, LPCWSTR szCommandLine)
237 MSIPACKAGE *package = NULL;
238 UINT r;
240 TRACE("%s %s\n",debugstr_w(szPackagePath), debugstr_w(szCommandLine));
242 if (!szPackagePath)
243 return ERROR_INVALID_PARAMETER;
245 if (!*szPackagePath)
246 return ERROR_PATH_NOT_FOUND;
248 r = MSI_OpenPackageW( szPackagePath, &package );
249 if (r == ERROR_SUCCESS)
251 r = MSI_InstallPackage( package, szPackagePath, szCommandLine );
252 msiobj_release( &package->hdr );
255 return r;
258 UINT WINAPI MsiReinstallProductA(LPCSTR szProduct, DWORD dwReinstallMode)
260 LPWSTR wszProduct;
261 UINT rc;
263 TRACE("%s %08x\n", debugstr_a(szProduct), dwReinstallMode);
265 wszProduct = strdupAtoW(szProduct);
267 rc = MsiReinstallProductW(wszProduct, dwReinstallMode);
269 msi_free(wszProduct);
270 return rc;
273 UINT WINAPI MsiReinstallProductW(LPCWSTR szProduct, DWORD dwReinstallMode)
275 TRACE("%s %08x\n", debugstr_w(szProduct), dwReinstallMode);
277 return MsiReinstallFeatureW(szProduct, szAll, dwReinstallMode);
280 UINT WINAPI MsiApplyPatchA(LPCSTR szPatchPackage, LPCSTR szInstallPackage,
281 INSTALLTYPE eInstallType, LPCSTR szCommandLine)
283 LPWSTR patch_package = NULL;
284 LPWSTR install_package = NULL;
285 LPWSTR command_line = NULL;
286 UINT r = ERROR_OUTOFMEMORY;
288 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage), debugstr_a(szInstallPackage),
289 eInstallType, debugstr_a(szCommandLine));
291 if (szPatchPackage && !(patch_package = strdupAtoW(szPatchPackage)))
292 goto done;
294 if (szInstallPackage && !(install_package = strdupAtoW(szInstallPackage)))
295 goto done;
297 if (szCommandLine && !(command_line = strdupAtoW(szCommandLine)))
298 goto done;
300 r = MsiApplyPatchW(patch_package, install_package, eInstallType, command_line);
302 done:
303 msi_free(patch_package);
304 msi_free(install_package);
305 msi_free(command_line);
307 return r;
310 static UINT get_patch_product_codes( LPCWSTR szPatchPackage, WCHAR ***product_codes )
312 MSIHANDLE patch, info = 0;
313 UINT r, type;
314 DWORD size;
315 static WCHAR empty[] = {0};
316 WCHAR *codes = NULL;
318 r = MsiOpenDatabaseW( szPatchPackage, MSIDBOPEN_READONLY, &patch );
319 if (r != ERROR_SUCCESS)
320 return r;
322 r = MsiGetSummaryInformationW( patch, NULL, 0, &info );
323 if (r != ERROR_SUCCESS)
324 goto done;
326 size = 0;
327 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, empty, &size );
328 if (r != ERROR_MORE_DATA || !size || type != VT_LPSTR)
330 ERR("Failed to read product codes from patch\n");
331 r = ERROR_FUNCTION_FAILED;
332 goto done;
335 codes = msi_alloc( ++size * sizeof(WCHAR) );
336 if (!codes)
338 r = ERROR_OUTOFMEMORY;
339 goto done;
342 r = MsiSummaryInfoGetPropertyW( info, PID_TEMPLATE, &type, NULL, NULL, codes, &size );
343 if (r == ERROR_SUCCESS)
344 *product_codes = msi_split_string( codes, ';' );
346 done:
347 MsiCloseHandle( info );
348 MsiCloseHandle( patch );
349 msi_free( codes );
350 return r;
353 static UINT MSI_ApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szProductCode, LPCWSTR szCommandLine)
355 UINT i, r = ERROR_FUNCTION_FAILED;
356 DWORD size;
357 LPCWSTR cmd_ptr = szCommandLine;
358 LPWSTR cmd, *codes = NULL;
359 BOOL succeeded = FALSE;
361 static const WCHAR fmt[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
362 static const WCHAR empty[] = {0};
364 if (!szPatchPackage || !szPatchPackage[0])
365 return ERROR_INVALID_PARAMETER;
367 if (!szProductCode && (r = get_patch_product_codes( szPatchPackage, &codes )))
368 return r;
370 if (!szCommandLine)
371 cmd_ptr = empty;
373 size = strlenW(cmd_ptr) + strlenW(fmt) + strlenW(szPatchPackage) + 1;
374 cmd = msi_alloc(size * sizeof(WCHAR));
375 if (!cmd)
377 msi_free(codes);
378 return ERROR_OUTOFMEMORY;
380 sprintfW(cmd, fmt, cmd_ptr, szPatchPackage);
382 if (szProductCode)
383 r = MsiConfigureProductExW(szProductCode, INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
384 else
386 for (i = 0; codes[i]; i++)
388 r = MsiConfigureProductExW(codes[i], INSTALLLEVEL_DEFAULT, INSTALLSTATE_DEFAULT, cmd);
389 if (r == ERROR_SUCCESS)
391 TRACE("patch applied\n");
392 succeeded = TRUE;
396 if (succeeded)
397 r = ERROR_SUCCESS;
400 msi_free(cmd);
401 msi_free(codes);
402 return r;
405 UINT WINAPI MsiApplyPatchW(LPCWSTR szPatchPackage, LPCWSTR szInstallPackage,
406 INSTALLTYPE eInstallType, LPCWSTR szCommandLine)
408 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage), debugstr_w(szInstallPackage),
409 eInstallType, debugstr_w(szCommandLine));
411 if (szInstallPackage || eInstallType == INSTALLTYPE_NETWORK_IMAGE ||
412 eInstallType == INSTALLTYPE_SINGLE_INSTANCE)
414 FIXME("Only reading target products from patch\n");
415 return ERROR_CALL_NOT_IMPLEMENTED;
418 return MSI_ApplyPatchW(szPatchPackage, NULL, szCommandLine);
421 UINT WINAPI MsiApplyMultiplePatchesA(LPCSTR szPatchPackages,
422 LPCSTR szProductCode, LPCSTR szPropertiesList)
424 LPWSTR patch_packages = NULL;
425 LPWSTR product_code = NULL;
426 LPWSTR properties_list = NULL;
427 UINT r = ERROR_OUTOFMEMORY;
429 TRACE("%s %s %s\n", debugstr_a(szPatchPackages), debugstr_a(szProductCode),
430 debugstr_a(szPropertiesList));
432 if (!szPatchPackages || !szPatchPackages[0])
433 return ERROR_INVALID_PARAMETER;
435 if (!(patch_packages = strdupAtoW(szPatchPackages)))
436 return ERROR_OUTOFMEMORY;
438 if (szProductCode && !(product_code = strdupAtoW(szProductCode)))
439 goto done;
441 if (szPropertiesList && !(properties_list = strdupAtoW(szPropertiesList)))
442 goto done;
444 r = MsiApplyMultiplePatchesW(patch_packages, product_code, properties_list);
446 done:
447 msi_free(patch_packages);
448 msi_free(product_code);
449 msi_free(properties_list);
451 return r;
454 UINT WINAPI MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages,
455 LPCWSTR szProductCode, LPCWSTR szPropertiesList)
457 UINT r = ERROR_SUCCESS;
458 LPCWSTR beg, end;
460 TRACE("%s %s %s\n", debugstr_w(szPatchPackages), debugstr_w(szProductCode),
461 debugstr_w(szPropertiesList));
463 if (!szPatchPackages || !szPatchPackages[0])
464 return ERROR_INVALID_PARAMETER;
466 beg = end = szPatchPackages;
467 while (*beg)
469 DWORD len;
470 LPWSTR patch;
472 while (*beg == ' ') beg++;
473 while (*end && *end != ';') end++;
475 len = end - beg;
476 while (len && beg[len - 1] == ' ') len--;
478 if (!len) return ERROR_INVALID_NAME;
480 patch = msi_alloc((len + 1) * sizeof(WCHAR));
481 if (!patch)
482 return ERROR_OUTOFMEMORY;
484 memcpy(patch, beg, len * sizeof(WCHAR));
485 patch[len] = '\0';
487 r = MSI_ApplyPatchW(patch, szProductCode, szPropertiesList);
488 msi_free(patch);
490 if (r != ERROR_SUCCESS || !*end)
491 break;
493 beg = ++end;
495 return r;
498 static void free_patchinfo( DWORD count, MSIPATCHSEQUENCEINFOW *info )
500 DWORD i;
501 for (i = 0; i < count; i++) msi_free( (WCHAR *)info[i].szPatchData );
502 msi_free( info );
505 static MSIPATCHSEQUENCEINFOW *patchinfoAtoW( DWORD count, const MSIPATCHSEQUENCEINFOA *info )
507 DWORD i;
508 MSIPATCHSEQUENCEINFOW *ret;
510 if (!(ret = msi_alloc( count * sizeof(MSIPATCHSEQUENCEINFOW) ))) return NULL;
511 for (i = 0; i < count; i++)
513 if (info[i].szPatchData && !(ret[i].szPatchData = strdupAtoW( info[i].szPatchData )))
515 free_patchinfo( i, ret );
516 return NULL;
518 ret[i].ePatchDataType = info[i].ePatchDataType;
519 ret[i].dwOrder = info[i].dwOrder;
520 ret[i].uStatus = info[i].uStatus;
522 return ret;
525 UINT WINAPI MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath,
526 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOA pPatchInfo)
528 UINT i, r;
529 WCHAR *package_path = NULL;
530 MSIPATCHSEQUENCEINFOW *psi;
532 TRACE("%s, %u, %p\n", debugstr_a(szProductPackagePath), cPatchInfo, pPatchInfo);
534 if (szProductPackagePath && !(package_path = strdupAtoW( szProductPackagePath )))
535 return ERROR_OUTOFMEMORY;
537 if (!(psi = patchinfoAtoW( cPatchInfo, pPatchInfo )))
539 msi_free( package_path );
540 return ERROR_OUTOFMEMORY;
542 r = MsiDetermineApplicablePatchesW( package_path, cPatchInfo, psi );
543 if (r == ERROR_SUCCESS)
545 for (i = 0; i < cPatchInfo; i++)
547 pPatchInfo[i].dwOrder = psi[i].dwOrder;
548 pPatchInfo[i].uStatus = psi[i].uStatus;
551 msi_free( package_path );
552 free_patchinfo( cPatchInfo, psi );
553 return r;
556 static UINT MSI_ApplicablePatchW( MSIPACKAGE *package, LPCWSTR patch )
558 MSISUMMARYINFO *si;
559 MSIDATABASE *patch_db;
560 UINT r;
562 r = MSI_OpenDatabaseW( patch, MSIDBOPEN_READONLY, &patch_db );
563 if (r != ERROR_SUCCESS)
565 WARN("failed to open patch file %s\n", debugstr_w(patch));
566 return r;
569 r = msi_get_suminfo( patch_db->storage, 0, &si );
570 if (r != ERROR_SUCCESS)
572 msiobj_release( &patch_db->hdr );
573 return ERROR_FUNCTION_FAILED;
576 r = msi_check_patch_applicable( package, si );
577 if (r != ERROR_SUCCESS)
578 TRACE("patch not applicable\n");
580 msiobj_release( &patch_db->hdr );
581 msiobj_release( &si->hdr );
582 return r;
585 /* IXMLDOMDocument should be set to XPath mode already */
586 static UINT MSI_ApplicablePatchXML( MSIPACKAGE *package, IXMLDOMDocument *desc )
588 static const WCHAR queryW[] = {'M','s','i','P','a','t','c','h','/',
589 'T','a','r','g','e','t','P','r','o','d','u','c','t','/',
590 'T','a','r','g','e','t','P','r','o','d','u','c','t','C','o','d','e',0};
591 UINT r = ERROR_FUNCTION_FAILED;
592 IXMLDOMNodeList *list;
593 LPWSTR product_code;
594 IXMLDOMNode *node;
595 HRESULT hr;
596 BSTR s;
598 product_code = msi_dup_property( package->db, szProductCode );
599 if (!product_code)
601 /* FIXME: the property ProductCode should be written into the DB somewhere */
602 ERR("no product code to check\n");
603 return ERROR_SUCCESS;
606 s = SysAllocString(queryW);
607 hr = IXMLDOMDocument_selectNodes( desc, s, &list );
608 SysFreeString(s);
609 if (hr != S_OK)
610 return ERROR_INVALID_PATCH_XML;
612 while (IXMLDOMNodeList_nextNode( list, &node ) == S_OK && r != ERROR_SUCCESS)
614 hr = IXMLDOMNode_get_text( node, &s );
615 IXMLDOMNode_Release( node );
616 if (hr == S_OK)
618 if (!strcmpW( s, product_code )) r = ERROR_SUCCESS;
619 SysFreeString( s );
622 IXMLDOMNodeList_Release( list );
624 if (r != ERROR_SUCCESS)
625 TRACE("patch not applicable\n");
627 msi_free( product_code );
628 return r;
631 static UINT determine_patch_sequence( MSIPACKAGE *package, DWORD count, MSIPATCHSEQUENCEINFOW *info )
633 IXMLDOMDocument *desc = NULL;
634 DWORD i;
636 if (count > 1)
637 FIXME("patch ordering not supported\n");
639 for (i = 0; i < count; i++)
641 switch (info[i].ePatchDataType)
643 case MSIPATCH_DATATYPE_PATCHFILE:
645 if (MSI_ApplicablePatchW( package, info[i].szPatchData ) != ERROR_SUCCESS)
647 info[i].dwOrder = ~0u;
648 info[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
650 else
652 info[i].dwOrder = i;
653 info[i].uStatus = ERROR_SUCCESS;
655 break;
657 case MSIPATCH_DATATYPE_XMLPATH:
658 case MSIPATCH_DATATYPE_XMLBLOB:
660 VARIANT_BOOL b;
661 HRESULT hr;
662 BSTR s;
664 if (!desc)
666 hr = CoCreateInstance( &CLSID_DOMDocument30, NULL, CLSCTX_INPROC_SERVER,
667 &IID_IXMLDOMDocument, (void**)&desc );
668 if (hr != S_OK)
670 ERR("failed to create DOMDocument30 instance, 0x%08x\n", hr);
671 return ERROR_FUNCTION_FAILED;
675 s = SysAllocString( info[i].szPatchData );
676 if (info[i].ePatchDataType == MSIPATCH_DATATYPE_XMLPATH)
678 VARIANT src;
680 V_VT(&src) = VT_BSTR;
681 V_BSTR(&src) = s;
682 hr = IXMLDOMDocument_load( desc, src, &b );
684 else
685 hr = IXMLDOMDocument_loadXML( desc, s, &b );
686 SysFreeString( s );
687 if ( hr != S_OK )
689 ERR("failed to parse patch description\n");
690 IXMLDOMDocument_Release( desc );
691 break;
694 if (MSI_ApplicablePatchXML( package, desc ) != ERROR_SUCCESS)
696 info[i].dwOrder = ~0u;
697 info[i].uStatus = ERROR_PATCH_TARGET_NOT_FOUND;
699 else
701 info[i].dwOrder = i;
702 info[i].uStatus = ERROR_SUCCESS;
704 break;
706 default:
708 FIXME("unknown patch data type %u\n", info[i].ePatchDataType);
709 info[i].dwOrder = i;
710 info[i].uStatus = ERROR_SUCCESS;
711 break;
715 TRACE("szPatchData: %s\n", debugstr_w(info[i].szPatchData));
716 TRACE("ePatchDataType: %u\n", info[i].ePatchDataType);
717 TRACE("dwOrder: %u\n", info[i].dwOrder);
718 TRACE("uStatus: %u\n", info[i].uStatus);
721 if (desc) IXMLDOMDocument_Release( desc );
723 return ERROR_SUCCESS;
726 UINT WINAPI MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath,
727 DWORD cPatchInfo, PMSIPATCHSEQUENCEINFOW pPatchInfo)
729 UINT r;
730 MSIPACKAGE *package;
732 TRACE("%s, %u, %p\n", debugstr_w(szProductPackagePath), cPatchInfo, pPatchInfo);
734 r = MSI_OpenPackageW( szProductPackagePath, &package );
735 if (r != ERROR_SUCCESS)
737 ERR("failed to open package %u\n", r);
738 return r;
740 r = determine_patch_sequence( package, cPatchInfo, pPatchInfo );
741 msiobj_release( &package->hdr );
742 return r;
745 UINT WINAPI MsiDeterminePatchSequenceA( LPCSTR product, LPCSTR usersid,
746 MSIINSTALLCONTEXT context, DWORD count, PMSIPATCHSEQUENCEINFOA patchinfo )
748 UINT i, r;
749 WCHAR *productW, *usersidW = NULL;
750 MSIPATCHSEQUENCEINFOW *patchinfoW;
752 TRACE("%s, %s, %d, %d, %p\n", debugstr_a(product), debugstr_a(usersid),
753 context, count, patchinfo);
755 if (!product) return ERROR_INVALID_PARAMETER;
756 if (!(productW = strdupAtoW( product ))) return ERROR_OUTOFMEMORY;
757 if (usersid && !(usersidW = strdupAtoW( usersid )))
759 msi_free( productW );
760 return ERROR_OUTOFMEMORY;
762 if (!(patchinfoW = patchinfoAtoW( count, patchinfo )))
764 msi_free( productW );
765 msi_free( usersidW );
766 return ERROR_OUTOFMEMORY;
768 r = MsiDeterminePatchSequenceW( productW, usersidW, context, count, patchinfoW );
769 if (r == ERROR_SUCCESS)
771 for (i = 0; i < count; i++)
773 patchinfo[i].dwOrder = patchinfoW[i].dwOrder;
774 patchinfo[i].uStatus = patchinfoW[i].uStatus;
777 msi_free( productW );
778 msi_free( usersidW );
779 free_patchinfo( count, patchinfoW );
780 return r;
783 static UINT open_package( const WCHAR *product, const WCHAR *usersid,
784 MSIINSTALLCONTEXT context, MSIPACKAGE **package )
786 UINT r;
787 HKEY props;
788 WCHAR *localpath, sourcepath[MAX_PATH], filename[MAX_PATH];
790 r = MSIREG_OpenInstallProps( product, context, usersid, &props, FALSE );
791 if (r != ERROR_SUCCESS) return ERROR_BAD_CONFIGURATION;
793 if ((localpath = msi_reg_get_val_str( props, szLocalPackage )))
795 strcpyW( sourcepath, localpath );
796 msi_free( localpath );
798 RegCloseKey( props );
799 if (!localpath || GetFileAttributesW( sourcepath ) == INVALID_FILE_ATTRIBUTES)
801 DWORD sz = sizeof(sourcepath);
802 MsiSourceListGetInfoW( product, usersid, context, MSICODE_PRODUCT,
803 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz );
804 sz = sizeof(filename);
805 MsiSourceListGetInfoW( product, usersid, context, MSICODE_PRODUCT,
806 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz );
807 strcatW( sourcepath, filename );
809 if (GetFileAttributesW( sourcepath ) == INVALID_FILE_ATTRIBUTES)
810 return ERROR_INSTALL_SOURCE_ABSENT;
812 return MSI_OpenPackageW( sourcepath, package );
815 UINT WINAPI MsiDeterminePatchSequenceW( LPCWSTR product, LPCWSTR usersid,
816 MSIINSTALLCONTEXT context, DWORD count, PMSIPATCHSEQUENCEINFOW patchinfo )
818 UINT r;
819 MSIPACKAGE *package;
821 TRACE("%s, %s, %d, %d, %p\n", debugstr_w(product), debugstr_w(usersid),
822 context, count, patchinfo);
824 if (!product) return ERROR_INVALID_PARAMETER;
825 r = open_package( product, usersid, context, &package );
826 if (r != ERROR_SUCCESS) return r;
828 r = determine_patch_sequence( package, count, patchinfo );
829 msiobj_release( &package->hdr );
830 return r;
833 UINT WINAPI MsiConfigureProductExW(LPCWSTR szProduct, int iInstallLevel,
834 INSTALLSTATE eInstallState, LPCWSTR szCommandLine)
836 MSIPACKAGE* package = NULL;
837 MSIINSTALLCONTEXT context;
838 UINT r;
839 DWORD sz;
840 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
841 LPWSTR commandline;
843 static const WCHAR szInstalled[] = {
844 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
845 static const WCHAR szMaxInstallLevel[] = {
846 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
847 static const WCHAR szRemoveAll[] = {
848 ' ','R','E','M','O','V','E','=','A','L','L',0};
849 static const WCHAR szMachine[] = {
850 ' ','A','L','L','U','S','E','R','S','=','1',0};
852 TRACE("%s %d %d %s\n",debugstr_w(szProduct), iInstallLevel, eInstallState,
853 debugstr_w(szCommandLine));
855 if (!szProduct || lstrlenW(szProduct) != GUID_SIZE - 1)
856 return ERROR_INVALID_PARAMETER;
858 if (eInstallState == INSTALLSTATE_ADVERTISED ||
859 eInstallState == INSTALLSTATE_SOURCE)
861 FIXME("State %d not implemented\n", eInstallState);
862 return ERROR_CALL_NOT_IMPLEMENTED;
865 r = msi_locate_product(szProduct, &context);
866 if (r != ERROR_SUCCESS)
867 return r;
869 r = open_package(szProduct, NULL, context, &package);
870 if (r != ERROR_SUCCESS)
871 return r;
873 sz = lstrlenW(szInstalled) + 1;
875 if (szCommandLine)
876 sz += lstrlenW(szCommandLine);
878 if (eInstallState != INSTALLSTATE_DEFAULT)
879 sz += lstrlenW(szMaxInstallLevel);
881 if (eInstallState == INSTALLSTATE_ABSENT)
882 sz += lstrlenW(szRemoveAll);
884 if (context == MSIINSTALLCONTEXT_MACHINE)
885 sz += lstrlenW(szMachine);
887 commandline = msi_alloc(sz * sizeof(WCHAR));
888 if (!commandline)
890 r = ERROR_OUTOFMEMORY;
891 goto end;
894 commandline[0] = 0;
895 if (szCommandLine)
896 lstrcpyW(commandline,szCommandLine);
898 if (eInstallState != INSTALLSTATE_DEFAULT)
899 lstrcatW(commandline, szMaxInstallLevel);
901 if (eInstallState == INSTALLSTATE_ABSENT)
902 lstrcatW(commandline, szRemoveAll);
904 if (context == MSIINSTALLCONTEXT_MACHINE)
905 lstrcatW(commandline, szMachine);
907 sz = sizeof(sourcepath);
908 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
909 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
911 sz = sizeof(filename);
912 MsiSourceListGetInfoW(szProduct, NULL, context, MSICODE_PRODUCT,
913 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
915 strcatW(sourcepath, filename);
917 r = MSI_InstallPackage( package, sourcepath, commandline );
919 msi_free(commandline);
921 end:
922 msiobj_release( &package->hdr );
924 return r;
927 UINT WINAPI MsiConfigureProductExA(LPCSTR szProduct, int iInstallLevel,
928 INSTALLSTATE eInstallState, LPCSTR szCommandLine)
930 LPWSTR szwProduct = NULL;
931 LPWSTR szwCommandLine = NULL;
932 UINT r = ERROR_OUTOFMEMORY;
934 if( szProduct )
936 szwProduct = strdupAtoW( szProduct );
937 if( !szwProduct )
938 goto end;
941 if( szCommandLine)
943 szwCommandLine = strdupAtoW( szCommandLine );
944 if( !szwCommandLine)
945 goto end;
948 r = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
949 szwCommandLine );
950 end:
951 msi_free( szwProduct );
952 msi_free( szwCommandLine);
954 return r;
957 UINT WINAPI MsiConfigureProductA(LPCSTR szProduct, int iInstallLevel,
958 INSTALLSTATE eInstallState)
960 LPWSTR szwProduct = NULL;
961 UINT r;
963 TRACE("%s %d %d\n",debugstr_a(szProduct), iInstallLevel, eInstallState);
965 if( szProduct )
967 szwProduct = strdupAtoW( szProduct );
968 if( !szwProduct )
969 return ERROR_OUTOFMEMORY;
972 r = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
973 msi_free( szwProduct );
975 return r;
978 UINT WINAPI MsiConfigureProductW(LPCWSTR szProduct, int iInstallLevel,
979 INSTALLSTATE eInstallState)
981 return MsiConfigureProductExW(szProduct, iInstallLevel, eInstallState, NULL);
984 UINT WINAPI MsiGetProductCodeA(LPCSTR szComponent, LPSTR szBuffer)
986 LPWSTR szwComponent = NULL;
987 UINT r;
988 WCHAR szwBuffer[GUID_SIZE];
990 TRACE("%s %p\n", debugstr_a(szComponent), szBuffer);
992 if( szComponent )
994 szwComponent = strdupAtoW( szComponent );
995 if( !szwComponent )
996 return ERROR_OUTOFMEMORY;
999 *szwBuffer = '\0';
1000 r = MsiGetProductCodeW( szwComponent, szwBuffer );
1002 if(*szwBuffer)
1003 WideCharToMultiByte(CP_ACP, 0, szwBuffer, -1, szBuffer, GUID_SIZE, NULL, NULL);
1005 msi_free( szwComponent );
1007 return r;
1010 UINT WINAPI MsiGetProductCodeW(LPCWSTR szComponent, LPWSTR szBuffer)
1012 UINT rc, index;
1013 HKEY compkey, prodkey;
1014 WCHAR squished_comp[GUID_SIZE];
1015 WCHAR squished_prod[GUID_SIZE];
1016 DWORD sz = GUID_SIZE;
1018 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
1020 if (!szComponent || !*szComponent)
1021 return ERROR_INVALID_PARAMETER;
1023 if (!squash_guid(szComponent, squished_comp))
1024 return ERROR_INVALID_PARAMETER;
1026 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
1027 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
1029 return ERROR_UNKNOWN_COMPONENT;
1032 rc = RegEnumValueW(compkey, 0, squished_prod, &sz, NULL, NULL, NULL, NULL);
1033 if (rc != ERROR_SUCCESS)
1035 RegCloseKey(compkey);
1036 return ERROR_UNKNOWN_COMPONENT;
1039 /* check simple case, only one product */
1040 rc = RegEnumValueW(compkey, 1, squished_prod, &sz, NULL, NULL, NULL, NULL);
1041 if (rc == ERROR_NO_MORE_ITEMS)
1043 rc = ERROR_SUCCESS;
1044 goto done;
1047 index = 0;
1048 while ((rc = RegEnumValueW(compkey, index, squished_prod, &sz,
1049 NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
1051 index++;
1052 sz = GUID_SIZE;
1053 unsquash_guid(squished_prod, szBuffer);
1055 if (MSIREG_OpenProductKey(szBuffer, NULL,
1056 MSIINSTALLCONTEXT_USERMANAGED,
1057 &prodkey, FALSE) == ERROR_SUCCESS ||
1058 MSIREG_OpenProductKey(szBuffer, NULL,
1059 MSIINSTALLCONTEXT_USERUNMANAGED,
1060 &prodkey, FALSE) == ERROR_SUCCESS ||
1061 MSIREG_OpenProductKey(szBuffer, NULL,
1062 MSIINSTALLCONTEXT_MACHINE,
1063 &prodkey, FALSE) == ERROR_SUCCESS)
1065 RegCloseKey(prodkey);
1066 rc = ERROR_SUCCESS;
1067 goto done;
1071 rc = ERROR_INSTALL_FAILURE;
1073 done:
1074 RegCloseKey(compkey);
1075 unsquash_guid(squished_prod, szBuffer);
1076 return rc;
1079 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
1081 DWORD dval;
1082 LONG res;
1083 WCHAR temp[20];
1085 static const WCHAR format[] = {'%','d',0};
1087 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
1088 if (res != ERROR_SUCCESS)
1089 return NULL;
1091 if (*type == REG_SZ)
1092 return msi_reg_get_val_str(hkey, name);
1094 if (!msi_reg_get_val_dword(hkey, name, &dval))
1095 return NULL;
1097 sprintfW(temp, format, dval);
1098 return strdupW(temp);
1101 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
1102 awstring *szValue, LPDWORD pcchValueBuf)
1104 static WCHAR empty[] = {0};
1105 static const WCHAR sourcelist[] = {'S','o','u','r','c','e','L','i','s','t',0};
1106 static const WCHAR display_name[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
1107 static const WCHAR display_version[] = {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1108 static const WCHAR assignment[] = {'A','s','s','i','g','n','m','e','n','t',0};
1109 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1110 UINT r = ERROR_UNKNOWN_PROPERTY;
1111 HKEY prodkey, userdata, source;
1112 LPWSTR val = NULL;
1113 WCHAR squished_pc[GUID_SIZE];
1114 WCHAR packagecode[GUID_SIZE];
1115 BOOL badconfig = FALSE;
1116 LONG res;
1117 DWORD type = REG_NONE;
1119 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1120 debugstr_w(szAttribute), szValue, pcchValueBuf);
1122 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
1123 return ERROR_INVALID_PARAMETER;
1125 if (!squash_guid(szProduct, squished_pc))
1126 return ERROR_INVALID_PARAMETER;
1128 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
1129 MSIINSTALLCONTEXT_USERMANAGED,
1130 &prodkey, FALSE)) != ERROR_SUCCESS &&
1131 (r = MSIREG_OpenProductKey(szProduct, NULL,
1132 MSIINSTALLCONTEXT_USERUNMANAGED,
1133 &prodkey, FALSE)) != ERROR_SUCCESS &&
1134 (r = MSIREG_OpenProductKey(szProduct, NULL,
1135 MSIINSTALLCONTEXT_MACHINE,
1136 &prodkey, FALSE)) == ERROR_SUCCESS)
1138 context = MSIINSTALLCONTEXT_MACHINE;
1141 if (!strcmpW( szAttribute, INSTALLPROPERTY_HELPLINKW ) ||
1142 !strcmpW( szAttribute, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1143 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLDATEW ) ||
1144 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1145 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1146 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1147 !strcmpW( szAttribute, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1148 !strcmpW( szAttribute, INSTALLPROPERTY_PUBLISHERW ) ||
1149 !strcmpW( szAttribute, INSTALLPROPERTY_URLINFOABOUTW ) ||
1150 !strcmpW( szAttribute, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1151 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMINORW ) ||
1152 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMAJORW ) ||
1153 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1154 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTIDW ) ||
1155 !strcmpW( szAttribute, INSTALLPROPERTY_REGCOMPANYW ) ||
1156 !strcmpW( szAttribute, INSTALLPROPERTY_REGOWNERW ))
1158 if (!prodkey)
1160 r = ERROR_UNKNOWN_PRODUCT;
1161 goto done;
1163 if (MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE))
1165 r = ERROR_UNKNOWN_PROPERTY;
1166 goto done;
1169 if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1170 szAttribute = display_name;
1171 else if (!strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ))
1172 szAttribute = display_version;
1174 val = msi_reg_get_value(userdata, szAttribute, &type);
1175 if (!val)
1176 val = empty;
1177 RegCloseKey(userdata);
1179 else if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTANCETYPEW ) ||
1180 !strcmpW( szAttribute, INSTALLPROPERTY_TRANSFORMSW ) ||
1181 !strcmpW( szAttribute, INSTALLPROPERTY_LANGUAGEW ) ||
1182 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1183 !strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ) ||
1184 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ) ||
1185 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONW ) ||
1186 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTICONW ) ||
1187 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ) ||
1188 !strcmpW( szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1190 if (!prodkey)
1192 r = ERROR_UNKNOWN_PRODUCT;
1193 goto done;
1196 if (!strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1197 szAttribute = assignment;
1199 if (!strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ))
1201 res = RegOpenKeyW(prodkey, sourcelist, &source);
1202 if (res != ERROR_SUCCESS)
1204 r = ERROR_UNKNOWN_PRODUCT;
1205 goto done;
1208 val = msi_reg_get_value(source, szAttribute, &type);
1209 if (!val)
1210 val = empty;
1212 RegCloseKey(source);
1214 else
1216 val = msi_reg_get_value(prodkey, szAttribute, &type);
1217 if (!val)
1218 val = empty;
1221 if (val != empty && type != REG_DWORD &&
1222 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ))
1224 if (lstrlenW(val) != SQUISH_GUID_SIZE - 1)
1225 badconfig = TRUE;
1226 else
1228 unsquash_guid(val, packagecode);
1229 msi_free(val);
1230 val = strdupW(packagecode);
1235 if (!val)
1237 r = ERROR_UNKNOWN_PROPERTY;
1238 goto done;
1241 if (pcchValueBuf)
1243 int len = strlenW( val );
1245 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1246 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1247 * can't rely on its value.
1249 if (szValue->str.a || szValue->str.w)
1251 DWORD size = *pcchValueBuf;
1252 if (len < size)
1253 r = msi_strcpy_to_awstring( val, len, szValue, &size );
1254 else
1255 r = ERROR_MORE_DATA;
1258 if (!badconfig)
1259 *pcchValueBuf = len;
1262 if (badconfig)
1263 r = ERROR_BAD_CONFIGURATION;
1265 if (val != empty)
1266 msi_free(val);
1268 done:
1269 RegCloseKey(prodkey);
1270 return r;
1273 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1274 LPSTR szBuffer, LPDWORD pcchValueBuf)
1276 LPWSTR szwProduct, szwAttribute = NULL;
1277 UINT r = ERROR_OUTOFMEMORY;
1278 awstring buffer;
1280 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1281 szBuffer, pcchValueBuf);
1283 szwProduct = strdupAtoW( szProduct );
1284 if( szProduct && !szwProduct )
1285 goto end;
1287 szwAttribute = strdupAtoW( szAttribute );
1288 if( szAttribute && !szwAttribute )
1289 goto end;
1291 buffer.unicode = FALSE;
1292 buffer.str.a = szBuffer;
1294 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1295 &buffer, pcchValueBuf );
1297 end:
1298 msi_free( szwProduct );
1299 msi_free( szwAttribute );
1301 return r;
1304 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1305 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1307 awstring buffer;
1309 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1310 szBuffer, pcchValueBuf);
1312 buffer.unicode = TRUE;
1313 buffer.str.w = szBuffer;
1315 return MSI_GetProductInfo( szProduct, szAttribute,
1316 &buffer, pcchValueBuf );
1319 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1320 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1321 LPSTR szValue, LPDWORD pcchValue)
1323 LPWSTR product = NULL;
1324 LPWSTR usersid = NULL;
1325 LPWSTR property = NULL;
1326 LPWSTR value = NULL;
1327 DWORD len = 0;
1328 UINT r;
1330 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1331 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1332 szValue, pcchValue);
1334 if (szValue && !pcchValue)
1335 return ERROR_INVALID_PARAMETER;
1337 if (szProductCode) product = strdupAtoW(szProductCode);
1338 if (szUserSid) usersid = strdupAtoW(szUserSid);
1339 if (szProperty) property = strdupAtoW(szProperty);
1341 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1342 NULL, &len);
1343 if (r != ERROR_SUCCESS)
1344 goto done;
1346 value = msi_alloc(++len * sizeof(WCHAR));
1347 if (!value)
1349 r = ERROR_OUTOFMEMORY;
1350 goto done;
1353 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1354 value, &len);
1355 if (r != ERROR_SUCCESS)
1356 goto done;
1358 if (!pcchValue)
1359 goto done;
1361 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1362 if (*pcchValue >= len)
1363 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1364 else if (szValue)
1366 r = ERROR_MORE_DATA;
1367 if (*pcchValue > 0)
1368 *szValue = '\0';
1371 if (*pcchValue <= len || !szValue)
1372 len = len * sizeof(WCHAR) - 1;
1374 *pcchValue = len - 1;
1376 done:
1377 msi_free(product);
1378 msi_free(usersid);
1379 msi_free(property);
1380 msi_free(value);
1382 return r;
1385 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1387 UINT r = ERROR_SUCCESS;
1389 if (!val)
1390 return ERROR_UNKNOWN_PROPERTY;
1392 if (out)
1394 if (strlenW(val) >= *size)
1396 r = ERROR_MORE_DATA;
1397 if (*size > 0)
1398 *out = '\0';
1400 else
1401 lstrcpyW(out, val);
1404 if (size)
1405 *size = lstrlenW(val);
1407 return r;
1410 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1411 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1412 LPWSTR szValue, LPDWORD pcchValue)
1414 WCHAR squished_pc[GUID_SIZE];
1415 LPWSTR val = NULL;
1416 LPCWSTR package = NULL;
1417 HKEY props = NULL, prod;
1418 HKEY classes = NULL, managed;
1419 HKEY hkey = NULL;
1420 DWORD type;
1421 UINT r = ERROR_UNKNOWN_PRODUCT;
1423 static const WCHAR five[] = {'5',0};
1424 static const WCHAR displayname[] = {
1425 'D','i','s','p','l','a','y','N','a','m','e',0};
1426 static const WCHAR displayversion[] = {
1427 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1428 static const WCHAR managed_local_package[] = {
1429 'M','a','n','a','g','e','d','L','o','c','a','l',
1430 'P','a','c','k','a','g','e',0};
1432 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1433 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1434 szValue, pcchValue);
1436 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1437 return ERROR_INVALID_PARAMETER;
1439 if (szValue && !pcchValue)
1440 return ERROR_INVALID_PARAMETER;
1442 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1443 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1444 dwContext != MSIINSTALLCONTEXT_MACHINE)
1445 return ERROR_INVALID_PARAMETER;
1447 if (!szProperty || !*szProperty)
1448 return ERROR_INVALID_PARAMETER;
1450 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1451 return ERROR_INVALID_PARAMETER;
1453 /* FIXME: dwContext is provided, no need to search for it */
1454 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1455 &managed, FALSE);
1456 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1457 &prod, FALSE);
1459 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1461 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1463 package = INSTALLPROPERTY_LOCALPACKAGEW;
1465 if (!props && !prod)
1466 goto done;
1468 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1470 package = managed_local_package;
1472 if (!props && !managed)
1473 goto done;
1475 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1477 package = INSTALLPROPERTY_LOCALPACKAGEW;
1478 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1480 if (!props && !classes)
1481 goto done;
1484 if (!strcmpW( szProperty, INSTALLPROPERTY_HELPLINKW ) ||
1485 !strcmpW( szProperty, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1486 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ) ||
1487 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1488 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1489 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1490 !strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1491 !strcmpW( szProperty, INSTALLPROPERTY_PUBLISHERW ) ||
1492 !strcmpW( szProperty, INSTALLPROPERTY_URLINFOABOUTW ) ||
1493 !strcmpW( szProperty, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1494 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMINORW ) ||
1495 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMAJORW ) ||
1496 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1497 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTIDW ) ||
1498 !strcmpW( szProperty, INSTALLPROPERTY_REGCOMPANYW ) ||
1499 !strcmpW( szProperty, INSTALLPROPERTY_REGOWNERW ) ||
1500 !strcmpW( szProperty, INSTALLPROPERTY_INSTANCETYPEW ))
1502 val = msi_reg_get_value(props, package, &type);
1503 if (!val)
1505 if (prod || classes)
1506 r = ERROR_UNKNOWN_PROPERTY;
1508 goto done;
1511 msi_free(val);
1513 if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1514 szProperty = displayname;
1515 else if (!strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ))
1516 szProperty = displayversion;
1518 val = msi_reg_get_value(props, szProperty, &type);
1519 if (!val)
1520 val = strdupW(szEmpty);
1522 r = msi_copy_outval(val, szValue, pcchValue);
1524 else if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ) ||
1525 !strcmpW( szProperty, INSTALLPROPERTY_LANGUAGEW ) ||
1526 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1527 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGECODEW ) ||
1528 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONW ) ||
1529 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTICONW ) ||
1530 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ) ||
1531 !strcmpW( szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1533 if (!prod && !classes)
1534 goto done;
1536 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1537 hkey = prod;
1538 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1539 hkey = managed;
1540 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1541 hkey = classes;
1543 val = msi_reg_get_value(hkey, szProperty, &type);
1544 if (!val)
1545 val = strdupW(szEmpty);
1547 r = msi_copy_outval(val, szValue, pcchValue);
1549 else if (!strcmpW( szProperty, INSTALLPROPERTY_PRODUCTSTATEW ))
1551 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1553 if (props)
1555 val = msi_reg_get_value(props, package, &type);
1556 if (!val)
1557 goto done;
1559 msi_free(val);
1560 val = strdupW(five);
1562 else
1563 val = strdupW(szOne);
1565 r = msi_copy_outval(val, szValue, pcchValue);
1566 goto done;
1568 else if (props && (val = msi_reg_get_value(props, package, &type)))
1570 msi_free(val);
1571 val = strdupW(five);
1572 r = msi_copy_outval(val, szValue, pcchValue);
1573 goto done;
1576 if (prod || managed)
1577 val = strdupW(szOne);
1578 else
1579 goto done;
1581 r = msi_copy_outval(val, szValue, pcchValue);
1583 else if (!strcmpW( szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1585 if (!prod && !classes)
1586 goto done;
1588 /* FIXME */
1589 val = strdupW(szEmpty);
1590 r = msi_copy_outval(val, szValue, pcchValue);
1592 else
1593 r = ERROR_UNKNOWN_PROPERTY;
1595 done:
1596 RegCloseKey(props);
1597 RegCloseKey(prod);
1598 RegCloseKey(managed);
1599 RegCloseKey(classes);
1600 msi_free(val);
1602 return r;
1605 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1606 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1607 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1609 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1610 LPWSTR property = NULL, val = NULL;
1611 DWORD len;
1612 UINT r;
1614 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1615 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1616 debugstr_a(szProperty), lpValue, pcchValue);
1618 if (lpValue && !pcchValue)
1619 return ERROR_INVALID_PARAMETER;
1621 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1622 if (szProductCode) product = strdupAtoW(szProductCode);
1623 if (szUserSid) usersid = strdupAtoW(szUserSid);
1624 if (szProperty) property = strdupAtoW(szProperty);
1626 len = 0;
1627 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1628 NULL, &len);
1629 if (r != ERROR_SUCCESS)
1630 goto done;
1632 val = msi_alloc(++len * sizeof(WCHAR));
1633 if (!val)
1635 r = ERROR_OUTOFMEMORY;
1636 goto done;
1639 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1640 val, &len);
1641 if (r != ERROR_SUCCESS || !pcchValue)
1642 goto done;
1644 if (lpValue)
1645 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1646 *pcchValue - 1, NULL, NULL);
1648 len = lstrlenW(val);
1649 if ((*val && *pcchValue < len + 1) || !lpValue)
1651 if (lpValue)
1653 r = ERROR_MORE_DATA;
1654 lpValue[*pcchValue - 1] = '\0';
1657 *pcchValue = len * sizeof(WCHAR);
1659 else
1660 *pcchValue = len;
1662 done:
1663 msi_free(val);
1664 msi_free(patch);
1665 msi_free(product);
1666 msi_free(usersid);
1667 msi_free(property);
1669 return r;
1672 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1673 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1674 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1676 WCHAR squished_pc[GUID_SIZE];
1677 WCHAR squished_patch[GUID_SIZE];
1678 HKEY udprod = 0, prod = 0, props = 0;
1679 HKEY patch = 0, patches = 0;
1680 HKEY udpatch = 0, datakey = 0;
1681 HKEY prodpatches = 0;
1682 LPWSTR val = NULL;
1683 UINT r = ERROR_UNKNOWN_PRODUCT;
1684 DWORD len;
1685 LONG res;
1687 static const WCHAR szManagedPackage[] = {'M','a','n','a','g','e','d',
1688 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1690 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1691 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1692 debugstr_w(szProperty), lpValue, pcchValue);
1694 if (!szProductCode || !squash_guid(szProductCode, squished_pc))
1695 return ERROR_INVALID_PARAMETER;
1697 if (!szPatchCode || !squash_guid(szPatchCode, squished_patch))
1698 return ERROR_INVALID_PARAMETER;
1700 if (!szProperty)
1701 return ERROR_INVALID_PARAMETER;
1703 if (lpValue && !pcchValue)
1704 return ERROR_INVALID_PARAMETER;
1706 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1707 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1708 dwContext != MSIINSTALLCONTEXT_MACHINE)
1709 return ERROR_INVALID_PARAMETER;
1711 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1712 return ERROR_INVALID_PARAMETER;
1714 if (szUserSid && !strcmpW( szUserSid, szLocalSid ))
1715 return ERROR_INVALID_PARAMETER;
1717 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1718 &udprod, FALSE) != ERROR_SUCCESS)
1719 goto done;
1721 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1722 &props, FALSE) != ERROR_SUCCESS)
1723 goto done;
1725 r = ERROR_UNKNOWN_PATCH;
1727 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_WOW64_64KEY|KEY_READ, &patches);
1728 if (res != ERROR_SUCCESS)
1729 goto done;
1731 res = RegOpenKeyExW(patches, squished_patch, 0, KEY_WOW64_64KEY|KEY_READ, &patch);
1732 if (res != ERROR_SUCCESS)
1733 goto done;
1735 if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ))
1737 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1738 &prod, FALSE) != ERROR_SUCCESS)
1739 goto done;
1741 res = RegOpenKeyExW(prod, szPatches, 0, KEY_WOW64_64KEY|KEY_ALL_ACCESS, &prodpatches);
1742 if (res != ERROR_SUCCESS)
1743 goto done;
1745 datakey = prodpatches;
1746 szProperty = squished_patch;
1748 else
1750 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1751 &udpatch, FALSE) != ERROR_SUCCESS)
1752 goto done;
1754 if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1756 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1757 szProperty = szManagedPackage;
1758 datakey = udpatch;
1760 else if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ))
1762 datakey = patch;
1763 szProperty = szInstalled;
1765 else if (!strcmpW( szProperty, INSTALLPROPERTY_UNINSTALLABLEW ) ||
1766 !strcmpW( szProperty, INSTALLPROPERTY_PATCHSTATEW ) ||
1767 !strcmpW( szProperty, INSTALLPROPERTY_DISPLAYNAMEW ) ||
1768 !strcmpW( szProperty, INSTALLPROPERTY_MOREINFOURLW ))
1770 datakey = patch;
1772 else
1774 r = ERROR_UNKNOWN_PROPERTY;
1775 goto done;
1779 val = msi_reg_get_val_str(datakey, szProperty);
1780 if (!val)
1781 val = strdupW(szEmpty);
1783 r = ERROR_SUCCESS;
1785 if (!pcchValue)
1786 goto done;
1788 if (lpValue)
1789 lstrcpynW(lpValue, val, *pcchValue);
1791 len = lstrlenW(val);
1792 if ((*val && *pcchValue < len + 1) || !lpValue)
1794 if (lpValue)
1795 r = ERROR_MORE_DATA;
1797 *pcchValue = len * sizeof(WCHAR);
1800 *pcchValue = len;
1802 done:
1803 msi_free(val);
1804 RegCloseKey(prodpatches);
1805 RegCloseKey(prod);
1806 RegCloseKey(patch);
1807 RegCloseKey(patches);
1808 RegCloseKey(udpatch);
1809 RegCloseKey(props);
1810 RegCloseKey(udprod);
1812 return r;
1815 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1817 UINT r = ERROR_OUTOFMEMORY;
1818 DWORD size;
1819 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1821 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1823 if (!patch || !attr)
1824 return ERROR_INVALID_PARAMETER;
1826 if (!(patchW = strdupAtoW( patch )))
1827 goto done;
1829 if (!(attrW = strdupAtoW( attr )))
1830 goto done;
1832 size = 0;
1833 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1834 if (r != ERROR_SUCCESS)
1835 goto done;
1837 size++;
1838 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1840 r = ERROR_OUTOFMEMORY;
1841 goto done;
1844 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1845 if (r == ERROR_SUCCESS)
1847 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1848 if (len > *buflen)
1849 r = ERROR_MORE_DATA;
1850 else if (buffer)
1851 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1853 *buflen = len - 1;
1856 done:
1857 msi_free( patchW );
1858 msi_free( attrW );
1859 msi_free( bufferW );
1860 return r;
1863 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1865 UINT r;
1866 WCHAR product[GUID_SIZE];
1867 DWORD index;
1869 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1871 if (!patch || !attr)
1872 return ERROR_INVALID_PARAMETER;
1874 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1875 return ERROR_UNKNOWN_PROPERTY;
1877 index = 0;
1878 while (1)
1880 r = MsiEnumProductsW( index, product );
1881 if (r != ERROR_SUCCESS)
1882 break;
1884 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1885 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1886 return r;
1888 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1889 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1890 return r;
1892 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1893 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1894 return r;
1896 index++;
1899 return ERROR_UNKNOWN_PRODUCT;
1902 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1904 LPWSTR szwLogFile = NULL;
1905 UINT r;
1907 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1909 if( szLogFile )
1911 szwLogFile = strdupAtoW( szLogFile );
1912 if( !szwLogFile )
1913 return ERROR_OUTOFMEMORY;
1915 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1916 msi_free( szwLogFile );
1917 return r;
1920 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1922 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1924 msi_free(gszLogFile);
1925 gszLogFile = NULL;
1926 if (szLogFile)
1928 HANDLE file;
1930 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1931 DeleteFileW(szLogFile);
1932 file = CreateFileW(szLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
1933 FILE_ATTRIBUTE_NORMAL, NULL);
1934 if (file != INVALID_HANDLE_VALUE)
1936 gszLogFile = strdupW(szLogFile);
1937 CloseHandle(file);
1939 else
1940 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile), GetLastError());
1943 return ERROR_SUCCESS;
1946 UINT WINAPI MsiEnumComponentCostsA( MSIHANDLE handle, LPCSTR component, DWORD index,
1947 INSTALLSTATE state, LPSTR drive, DWORD *buflen,
1948 int *cost, int *temp )
1950 UINT r;
1951 DWORD len;
1952 WCHAR *driveW, *componentW = NULL;
1954 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_a(component), index,
1955 state, drive, buflen, cost, temp);
1957 if (!drive || !buflen) return ERROR_INVALID_PARAMETER;
1958 if (component && !(componentW = strdupAtoW( component ))) return ERROR_OUTOFMEMORY;
1960 len = *buflen;
1961 if (!(driveW = msi_alloc( len * sizeof(WCHAR) )))
1963 msi_free( componentW );
1964 return ERROR_OUTOFMEMORY;
1966 r = MsiEnumComponentCostsW( handle, componentW, index, state, driveW, buflen, cost, temp );
1967 if (!r)
1969 WideCharToMultiByte( CP_ACP, 0, driveW, -1, drive, len, NULL, NULL );
1971 msi_free( componentW );
1972 msi_free( driveW );
1973 return r;
1976 static UINT set_drive( WCHAR *buffer, WCHAR letter )
1978 buffer[0] = letter;
1979 buffer[1] = ':';
1980 buffer[2] = 0;
1981 return 2;
1984 UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, LPCWSTR component, DWORD index,
1985 INSTALLSTATE state, LPWSTR drive, DWORD *buflen,
1986 int *cost, int *temp )
1988 UINT r = ERROR_NO_MORE_ITEMS;
1989 MSICOMPONENT *comp = NULL;
1990 MSIPACKAGE *package;
1991 MSIFILE *file;
1992 STATSTG stat = {0};
1993 WCHAR path[MAX_PATH];
1995 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_w(component), index,
1996 state, drive, buflen, cost, temp);
1998 if (!drive || !buflen || !cost || !temp) return ERROR_INVALID_PARAMETER;
1999 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
2001 HRESULT hr;
2002 IWineMsiRemotePackage *remote_package;
2003 BSTR bname = NULL;
2005 if (!(remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle )))
2006 return ERROR_INVALID_HANDLE;
2008 if (component && !(bname = SysAllocString( component )))
2010 IWineMsiRemotePackage_Release( remote_package );
2011 return ERROR_OUTOFMEMORY;
2013 hr = IWineMsiRemotePackage_EnumComponentCosts( remote_package, bname, index, state, drive, buflen, cost, temp );
2014 IWineMsiRemotePackage_Release( remote_package );
2015 SysFreeString( bname );
2016 if (FAILED(hr))
2018 if (HRESULT_FACILITY(hr) == FACILITY_WIN32) return HRESULT_CODE(hr);
2019 return ERROR_FUNCTION_FAILED;
2021 return ERROR_SUCCESS;
2024 if (!msi_get_property_int( package->db, szCostingComplete, 0 ))
2026 msiobj_release( &package->hdr );
2027 return ERROR_FUNCTION_NOT_CALLED;
2029 if (component && component[0] && !(comp = msi_get_loaded_component( package, component )))
2031 msiobj_release( &package->hdr );
2032 return ERROR_UNKNOWN_COMPONENT;
2034 if (*buflen < 3)
2036 *buflen = 2;
2037 msiobj_release( &package->hdr );
2038 return ERROR_MORE_DATA;
2040 if (index)
2042 msiobj_release( &package->hdr );
2043 return ERROR_NO_MORE_ITEMS;
2046 drive[0] = 0;
2047 *cost = *temp = 0;
2048 GetWindowsDirectoryW( path, MAX_PATH );
2049 if (component && component[0])
2051 if (msi_is_global_assembly( comp )) *temp = comp->Cost;
2052 if (!comp->Enabled || !comp->KeyPath)
2054 *cost = 0;
2055 *buflen = set_drive( drive, path[0] );
2056 r = ERROR_SUCCESS;
2058 else if ((file = msi_get_loaded_file( package, comp->KeyPath )))
2060 *cost = max( 8, comp->Cost / 512 );
2061 *buflen = set_drive( drive, file->TargetPath[0] );
2062 r = ERROR_SUCCESS;
2065 else if (IStorage_Stat( package->db->storage, &stat, STATFLAG_NONAME ) == S_OK)
2067 *temp = max( 8, stat.cbSize.QuadPart / 512 );
2068 *buflen = set_drive( drive, path[0] );
2069 r = ERROR_SUCCESS;
2071 msiobj_release( &package->hdr );
2072 return r;
2075 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
2076 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2077 LPCSTR szComponent, INSTALLSTATE *pdwState)
2079 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
2080 UINT r;
2082 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
2083 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
2085 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
2086 return ERROR_OUTOFMEMORY;
2088 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
2089 return ERROR_OUTOFMEMORY;
2091 if (szComponent && !(comp = strdupAtoW(szComponent)))
2092 return ERROR_OUTOFMEMORY;
2094 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
2096 msi_free(prodcode);
2097 msi_free(usersid);
2098 msi_free(comp);
2100 return r;
2103 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
2105 UINT r;
2106 HKEY hkey = NULL;
2108 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
2109 RegCloseKey(hkey);
2110 return (r == ERROR_SUCCESS);
2113 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
2115 LPCWSTR package;
2116 HKEY hkey;
2117 DWORD sz;
2118 LONG res;
2119 UINT r;
2121 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
2122 static const WCHAR managed_local_package[] = {
2123 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
2126 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
2127 if (r != ERROR_SUCCESS)
2128 return FALSE;
2130 if (context == MSIINSTALLCONTEXT_USERMANAGED)
2131 package = managed_local_package;
2132 else
2133 package = local_package;
2135 sz = 0;
2136 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
2137 RegCloseKey(hkey);
2139 return (res == ERROR_SUCCESS);
2142 static UINT msi_comp_find_prodcode(LPWSTR squished_pc,
2143 MSIINSTALLCONTEXT context,
2144 LPCWSTR comp, LPWSTR val, DWORD *sz)
2146 HKEY hkey;
2147 LONG res;
2148 UINT r;
2150 if (context == MSIINSTALLCONTEXT_MACHINE)
2151 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2152 else
2153 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2155 if (r != ERROR_SUCCESS)
2156 return r;
2158 res = RegQueryValueExW(hkey, squished_pc, NULL, NULL, (BYTE *)val, sz);
2159 if (res != ERROR_SUCCESS)
2160 return res;
2162 RegCloseKey(hkey);
2163 return res;
2166 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
2167 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2168 LPCWSTR szComponent, INSTALLSTATE *pdwState)
2170 WCHAR squished_pc[GUID_SIZE];
2171 BOOL found;
2172 DWORD sz;
2174 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
2175 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
2177 if (!pdwState || !szComponent)
2178 return ERROR_INVALID_PARAMETER;
2180 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
2181 return ERROR_INVALID_PARAMETER;
2183 if (!squash_guid(szProductCode, squished_pc))
2184 return ERROR_INVALID_PARAMETER;
2186 found = msi_comp_find_prod_key(szProductCode, dwContext);
2188 if (!msi_comp_find_package(szProductCode, dwContext))
2190 if (found)
2192 *pdwState = INSTALLSTATE_UNKNOWN;
2193 return ERROR_UNKNOWN_COMPONENT;
2196 return ERROR_UNKNOWN_PRODUCT;
2199 *pdwState = INSTALLSTATE_UNKNOWN;
2201 sz = 0;
2202 if (msi_comp_find_prodcode(squished_pc, dwContext, szComponent, NULL, &sz))
2203 return ERROR_UNKNOWN_COMPONENT;
2205 if (sz == 0)
2206 *pdwState = INSTALLSTATE_NOTUSED;
2207 else
2209 WCHAR *val;
2210 UINT r;
2212 if (!(val = msi_alloc( sz ))) return ERROR_OUTOFMEMORY;
2213 if ((r = msi_comp_find_prodcode(squished_pc, dwContext, szComponent, val, &sz)))
2215 msi_free(val);
2216 return r;
2219 if (lstrlenW(val) > 2 &&
2220 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9' && val[2] != ':')
2222 *pdwState = INSTALLSTATE_SOURCE;
2224 else
2225 *pdwState = INSTALLSTATE_LOCAL;
2226 msi_free( val );
2229 TRACE("-> %d\n", *pdwState);
2230 return ERROR_SUCCESS;
2233 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
2235 LPWSTR szwProduct = NULL;
2236 INSTALLSTATE r;
2238 if( szProduct )
2240 szwProduct = strdupAtoW( szProduct );
2241 if( !szwProduct )
2242 return ERROR_OUTOFMEMORY;
2244 r = MsiQueryProductStateW( szwProduct );
2245 msi_free( szwProduct );
2246 return r;
2249 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
2251 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
2252 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
2253 HKEY prodkey = 0, userdata = 0;
2254 DWORD val;
2255 UINT r;
2257 TRACE("%s\n", debugstr_w(szProduct));
2259 if (!szProduct || !*szProduct)
2260 return INSTALLSTATE_INVALIDARG;
2262 if (lstrlenW(szProduct) != GUID_SIZE - 1)
2263 return INSTALLSTATE_INVALIDARG;
2265 if (szProduct[0] != '{' || szProduct[37] != '}')
2266 return INSTALLSTATE_UNKNOWN;
2268 SetLastError( ERROR_SUCCESS );
2270 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2271 &prodkey, FALSE) != ERROR_SUCCESS &&
2272 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2273 &prodkey, FALSE) != ERROR_SUCCESS &&
2274 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2275 &prodkey, FALSE) == ERROR_SUCCESS)
2277 context = MSIINSTALLCONTEXT_MACHINE;
2280 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
2281 if (r != ERROR_SUCCESS)
2282 goto done;
2284 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
2285 goto done;
2287 if (val)
2288 state = INSTALLSTATE_DEFAULT;
2289 else
2290 state = INSTALLSTATE_UNKNOWN;
2292 done:
2293 if (!prodkey)
2295 state = INSTALLSTATE_UNKNOWN;
2297 if (userdata)
2298 state = INSTALLSTATE_ABSENT;
2301 RegCloseKey(prodkey);
2302 RegCloseKey(userdata);
2303 TRACE("-> %d\n", state);
2304 return state;
2307 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2309 INSTALLUILEVEL old = gUILevel;
2310 HWND oldwnd = gUIhwnd;
2312 TRACE("%08x %p\n", dwUILevel, phWnd);
2314 gUILevel = dwUILevel;
2315 if (phWnd)
2317 gUIhwnd = *phWnd;
2318 *phWnd = oldwnd;
2320 return old;
2323 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2324 DWORD dwMessageFilter, LPVOID pvContext)
2326 INSTALLUI_HANDLERA prev = gUIHandlerA;
2328 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2330 gUIHandlerA = puiHandler;
2331 gUIHandlerW = NULL;
2332 gUIFilter = dwMessageFilter;
2333 gUIContext = pvContext;
2335 return prev;
2338 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2339 DWORD dwMessageFilter, LPVOID pvContext)
2341 INSTALLUI_HANDLERW prev = gUIHandlerW;
2343 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2345 gUIHandlerA = NULL;
2346 gUIHandlerW = puiHandler;
2347 gUIFilter = dwMessageFilter;
2348 gUIContext = pvContext;
2350 return prev;
2353 /******************************************************************
2354 * MsiLoadStringW [MSI.@]
2356 * Loads a string from MSI's string resources.
2358 * PARAMS
2360 * handle [I] only -1 is handled currently
2361 * id [I] id of the string to be loaded
2362 * lpBuffer [O] buffer for the string to be written to
2363 * nBufferMax [I] maximum size of the buffer in characters
2364 * lang [I] the preferred language for the string
2366 * RETURNS
2368 * If successful, this function returns the language id of the string loaded
2369 * If the function fails, the function returns zero.
2371 * NOTES
2373 * The type of the first parameter is unknown. LoadString's prototype
2374 * suggests that it might be a module handle. I have made it an MSI handle
2375 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2376 * handle. Maybe strings can be stored in an MSI database somehow.
2378 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2379 int nBufferMax, LANGID lang )
2381 HRSRC hres;
2382 HGLOBAL hResData;
2383 LPWSTR p;
2384 DWORD i, len;
2386 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2388 if( handle != -1 )
2389 FIXME("don't know how to deal with handle = %08x\n", handle);
2391 if( !lang )
2392 lang = GetUserDefaultLangID();
2394 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2395 (LPWSTR)1, lang );
2396 if( !hres )
2397 return 0;
2398 hResData = LoadResource( msi_hInstance, hres );
2399 if( !hResData )
2400 return 0;
2401 p = LockResource( hResData );
2402 if( !p )
2403 return 0;
2405 for (i = 0; i < (id & 0xf); i++) p += *p + 1;
2406 len = *p;
2408 if( nBufferMax <= len )
2409 return 0;
2411 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2412 lpBuffer[ len ] = 0;
2414 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2415 return lang;
2418 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2419 int nBufferMax, LANGID lang )
2421 LPWSTR bufW;
2422 LANGID r;
2423 INT len;
2425 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2426 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2427 if( r )
2429 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2430 if( len <= nBufferMax )
2431 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2432 lpBuffer, nBufferMax, NULL, NULL );
2433 else
2434 r = 0;
2436 msi_free(bufW);
2437 return r;
2440 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2441 LPDWORD pcchBuf)
2443 char szProduct[GUID_SIZE];
2445 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2447 if (!szComponent || !pcchBuf)
2448 return INSTALLSTATE_INVALIDARG;
2450 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2451 return INSTALLSTATE_UNKNOWN;
2453 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2456 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2457 LPDWORD pcchBuf)
2459 WCHAR szProduct[GUID_SIZE];
2461 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2463 if (!szComponent || !pcchBuf)
2464 return INSTALLSTATE_INVALIDARG;
2466 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2467 return INSTALLSTATE_UNKNOWN;
2469 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2472 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2473 WORD wLanguageId, DWORD f)
2475 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2476 uType, wLanguageId, f);
2477 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2480 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2481 WORD wLanguageId, DWORD f)
2483 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2484 uType, wLanguageId, f);
2485 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2488 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2489 DWORD unknown, WORD wLanguageId, DWORD f)
2491 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2492 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2493 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2496 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2497 DWORD unknown, WORD wLanguageId, DWORD f)
2499 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2500 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2501 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2504 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2505 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2506 LPDWORD pcchPathBuf )
2508 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2509 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2510 pcchPathBuf);
2511 return ERROR_CALL_NOT_IMPLEMENTED;
2514 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2515 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2516 LPDWORD pcchPathBuf )
2518 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2519 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2520 pcchPathBuf);
2521 return ERROR_CALL_NOT_IMPLEMENTED;
2524 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2525 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2527 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2528 return ERROR_CALL_NOT_IMPLEMENTED;
2531 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2532 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2534 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2535 return ERROR_CALL_NOT_IMPLEMENTED;
2538 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2539 LPBYTE hash, LPDWORD hashlen )
2541 UINT r;
2542 WCHAR *pathW = NULL;
2544 TRACE("%s %08x %p %p %p\n", debugstr_a(path), flags, cert, hash, hashlen);
2546 if (path && !(pathW = strdupAtoW( path ))) return ERROR_OUTOFMEMORY;
2547 r = MsiGetFileSignatureInformationW( pathW, flags, cert, hash, hashlen );
2548 msi_free( pathW );
2549 return r;
2552 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2553 LPBYTE hash, LPDWORD hashlen )
2555 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
2556 HRESULT hr;
2557 WINTRUST_DATA data;
2558 WINTRUST_FILE_INFO info;
2559 CRYPT_PROVIDER_SGNR *signer;
2560 CRYPT_PROVIDER_CERT *provider;
2562 TRACE("%s %08x %p %p %p\n", debugstr_w(path), flags, cert, hash, hashlen);
2564 if (!path || !cert) return E_INVALIDARG;
2566 info.cbStruct = sizeof(info);
2567 info.pcwszFilePath = path;
2568 info.hFile = NULL;
2569 info.pgKnownSubject = NULL;
2571 data.cbStruct = sizeof(data);
2572 data.pPolicyCallbackData = NULL;
2573 data.pSIPClientData = NULL;
2574 data.dwUIChoice = WTD_UI_NONE;
2575 data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
2576 data.dwUnionChoice = WTD_CHOICE_FILE;
2577 data.u.pFile = &info;
2578 data.dwStateAction = WTD_STATEACTION_VERIFY;
2579 data.hWVTStateData = NULL;
2580 data.pwszURLReference = NULL;
2581 data.dwProvFlags = 0;
2582 data.dwUIContext = WTD_UICONTEXT_INSTALL;
2583 hr = WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2584 *cert = NULL;
2585 if (FAILED(hr)) goto done;
2587 if (!(signer = WTHelperGetProvSignerFromChain( data.hWVTStateData, 0, FALSE, 0 )))
2589 hr = TRUST_E_NOSIGNATURE;
2590 goto done;
2592 if (hash)
2594 DWORD len = signer->psSigner->EncryptedHash.cbData;
2595 if (*hashlen < len)
2597 *hashlen = len;
2598 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
2599 goto done;
2601 memcpy( hash, signer->psSigner->EncryptedHash.pbData, len );
2602 *hashlen = len;
2604 if (!(provider = WTHelperGetProvCertFromChain( signer, 0 )))
2606 hr = TRUST_E_PROVIDER_UNKNOWN;
2607 goto done;
2609 *cert = CertDuplicateCertificateContext( provider->pCert );
2611 done:
2612 data.dwStateAction = WTD_STATEACTION_CLOSE;
2613 WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2614 return hr;
2617 /******************************************************************
2618 * MsiGetProductPropertyA [MSI.@]
2620 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2621 LPSTR szValue, LPDWORD pccbValue)
2623 LPWSTR prop = NULL, val = NULL;
2624 DWORD len;
2625 UINT r;
2627 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2628 szValue, pccbValue);
2630 if (szValue && !pccbValue)
2631 return ERROR_INVALID_PARAMETER;
2633 if (szProperty) prop = strdupAtoW(szProperty);
2635 len = 0;
2636 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2637 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2638 goto done;
2640 if (r == ERROR_SUCCESS)
2642 if (szValue) *szValue = '\0';
2643 if (pccbValue) *pccbValue = 0;
2644 goto done;
2647 val = msi_alloc(++len * sizeof(WCHAR));
2648 if (!val)
2650 r = ERROR_OUTOFMEMORY;
2651 goto done;
2654 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2655 if (r != ERROR_SUCCESS)
2656 goto done;
2658 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2660 if (szValue)
2661 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2662 *pccbValue, NULL, NULL);
2664 if (pccbValue)
2666 if (len > *pccbValue)
2667 r = ERROR_MORE_DATA;
2669 *pccbValue = len - 1;
2672 done:
2673 msi_free(prop);
2674 msi_free(val);
2676 return r;
2679 /******************************************************************
2680 * MsiGetProductPropertyW [MSI.@]
2682 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2683 LPWSTR szValue, LPDWORD pccbValue)
2685 MSIPACKAGE *package;
2686 MSIQUERY *view = NULL;
2687 MSIRECORD *rec = NULL;
2688 LPCWSTR val;
2689 UINT r;
2691 static const WCHAR query[] = {
2692 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2693 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2694 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2696 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2697 szValue, pccbValue);
2699 if (!szProperty)
2700 return ERROR_INVALID_PARAMETER;
2702 if (szValue && !pccbValue)
2703 return ERROR_INVALID_PARAMETER;
2705 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2706 if (!package)
2707 return ERROR_INVALID_HANDLE;
2709 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2710 if (r != ERROR_SUCCESS)
2711 goto done;
2713 r = MSI_ViewExecute(view, 0);
2714 if (r != ERROR_SUCCESS)
2715 goto done;
2717 r = MSI_ViewFetch(view, &rec);
2718 if (r != ERROR_SUCCESS)
2719 goto done;
2721 val = MSI_RecordGetString(rec, 2);
2722 if (!val)
2723 goto done;
2725 if (lstrlenW(val) >= *pccbValue)
2727 lstrcpynW(szValue, val, *pccbValue);
2728 *pccbValue = lstrlenW(val);
2729 r = ERROR_MORE_DATA;
2731 else
2733 lstrcpyW(szValue, val);
2734 *pccbValue = lstrlenW(val);
2735 r = ERROR_SUCCESS;
2738 done:
2739 if (view)
2741 MSI_ViewClose(view);
2742 msiobj_release(&view->hdr);
2743 if (rec) msiobj_release(&rec->hdr);
2746 if (!rec)
2748 if (szValue) *szValue = '\0';
2749 if (pccbValue) *pccbValue = 0;
2750 r = ERROR_SUCCESS;
2753 msiobj_release(&package->hdr);
2754 return r;
2757 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2759 UINT r;
2760 LPWSTR szPack = NULL;
2762 TRACE("%s\n", debugstr_a(szPackage) );
2764 if( szPackage )
2766 szPack = strdupAtoW( szPackage );
2767 if( !szPack )
2768 return ERROR_OUTOFMEMORY;
2771 r = MsiVerifyPackageW( szPack );
2773 msi_free( szPack );
2775 return r;
2778 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2780 MSIHANDLE handle;
2781 UINT r;
2783 TRACE("%s\n", debugstr_w(szPackage) );
2785 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2786 MsiCloseHandle( handle );
2788 return r;
2791 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2792 awstring* lpPathBuf, LPDWORD pcchBuf)
2794 static const WCHAR wininstaller[] =
2795 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2796 WCHAR squished_pc[GUID_SIZE];
2797 WCHAR squished_comp[GUID_SIZE];
2798 HKEY hkey;
2799 LPWSTR path = NULL;
2800 INSTALLSTATE state;
2801 DWORD version;
2803 if (!szProduct || !szComponent)
2804 return INSTALLSTATE_INVALIDARG;
2806 if (lpPathBuf->str.w && !pcchBuf)
2807 return INSTALLSTATE_INVALIDARG;
2809 if (!squash_guid(szProduct, squished_pc) ||
2810 !squash_guid(szComponent, squished_comp))
2811 return INSTALLSTATE_INVALIDARG;
2813 state = INSTALLSTATE_UNKNOWN;
2815 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2816 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2818 path = msi_reg_get_val_str(hkey, squished_pc);
2819 RegCloseKey(hkey);
2821 state = INSTALLSTATE_ABSENT;
2823 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2824 &hkey, FALSE) == ERROR_SUCCESS ||
2825 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2826 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2827 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2828 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2830 RegCloseKey(hkey);
2831 state = INSTALLSTATE_LOCAL;
2835 if (state != INSTALLSTATE_LOCAL &&
2836 (MSIREG_OpenProductKey(szProduct, NULL,
2837 MSIINSTALLCONTEXT_USERUNMANAGED,
2838 &hkey, FALSE) == ERROR_SUCCESS ||
2839 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2840 &hkey, FALSE) == ERROR_SUCCESS))
2842 RegCloseKey(hkey);
2844 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2845 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2847 msi_free(path);
2848 path = msi_reg_get_val_str(hkey, squished_pc);
2849 RegCloseKey(hkey);
2851 state = INSTALLSTATE_ABSENT;
2853 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2854 state = INSTALLSTATE_LOCAL;
2858 if (!path)
2859 return INSTALLSTATE_UNKNOWN;
2861 if (state == INSTALLSTATE_LOCAL && !*path)
2862 state = INSTALLSTATE_NOTUSED;
2864 if (msi_strcpy_to_awstring(path, -1, lpPathBuf, pcchBuf) == ERROR_MORE_DATA)
2865 state = INSTALLSTATE_MOREDATA;
2867 msi_free(path);
2868 return state;
2871 /******************************************************************
2872 * MsiGetComponentPathW [MSI.@]
2874 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2875 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2877 awstring path;
2879 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szComponent), lpPathBuf, pcchBuf);
2881 path.unicode = TRUE;
2882 path.str.w = lpPathBuf;
2884 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2887 /******************************************************************
2888 * MsiGetComponentPathA [MSI.@]
2890 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2891 LPSTR lpPathBuf, LPDWORD pcchBuf)
2893 LPWSTR szwProduct, szwComponent = NULL;
2894 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2895 awstring path;
2897 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szComponent), lpPathBuf, pcchBuf);
2899 szwProduct = strdupAtoW( szProduct );
2900 if( szProduct && !szwProduct)
2901 goto end;
2903 szwComponent = strdupAtoW( szComponent );
2904 if( szComponent && !szwComponent )
2905 goto end;
2907 path.unicode = FALSE;
2908 path.str.a = lpPathBuf;
2910 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2912 end:
2913 msi_free( szwProduct );
2914 msi_free( szwComponent );
2916 return r;
2919 static UINT query_feature_state( const WCHAR *product, const WCHAR *squashed, const WCHAR *usersid,
2920 MSIINSTALLCONTEXT ctx, const WCHAR *feature, INSTALLSTATE *state )
2922 UINT r;
2923 HKEY hkey;
2924 WCHAR *parent, *components, *path;
2925 const WCHAR *p;
2926 BOOL missing = FALSE, source = FALSE;
2927 WCHAR comp[GUID_SIZE];
2928 GUID guid;
2930 if (ctx != MSIINSTALLCONTEXT_MACHINE) SetLastError( ERROR_SUCCESS );
2932 if (MSIREG_OpenFeaturesKey( product, usersid, ctx, &hkey, FALSE )) return ERROR_UNKNOWN_PRODUCT;
2934 parent = msi_reg_get_val_str( hkey, feature );
2935 RegCloseKey( hkey );
2936 if (!parent) return ERROR_UNKNOWN_FEATURE;
2938 *state = (parent[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2939 msi_free( parent );
2940 if (*state == INSTALLSTATE_ABSENT)
2941 return ERROR_SUCCESS;
2943 r = MSIREG_OpenUserDataFeaturesKey( product, usersid, ctx, &hkey, FALSE );
2944 if (r != ERROR_SUCCESS)
2946 *state = INSTALLSTATE_ADVERTISED;
2947 return ERROR_SUCCESS;
2949 components = msi_reg_get_val_str( hkey, feature );
2950 RegCloseKey( hkey );
2952 TRACE("buffer = %s\n", debugstr_w(components));
2954 if (!components)
2956 *state = INSTALLSTATE_ADVERTISED;
2957 return ERROR_SUCCESS;
2959 for (p = components; *p && *p != 2 ; p += 20)
2961 if (!decode_base85_guid( p, &guid ))
2963 if (p != components) break;
2964 msi_free( components );
2965 *state = INSTALLSTATE_BADCONFIG;
2966 return ERROR_BAD_CONFIGURATION;
2968 StringFromGUID2( &guid, comp, GUID_SIZE );
2969 if (ctx == MSIINSTALLCONTEXT_MACHINE)
2970 r = MSIREG_OpenUserDataComponentKey( comp, szLocalSid, &hkey, FALSE );
2971 else
2972 r = MSIREG_OpenUserDataComponentKey( comp, usersid, &hkey, FALSE );
2974 if (r != ERROR_SUCCESS)
2976 msi_free( components );
2977 *state = INSTALLSTATE_ADVERTISED;
2978 return ERROR_SUCCESS;
2980 path = msi_reg_get_val_str( hkey, squashed );
2981 if (!path) missing = TRUE;
2982 else if (strlenW( path ) > 2 &&
2983 path[0] >= '0' && path[0] <= '9' &&
2984 path[1] >= '0' && path[1] <= '9')
2986 source = TRUE;
2988 msi_free( path );
2990 msi_free( components );
2992 if (missing)
2993 *state = INSTALLSTATE_ADVERTISED;
2994 else if (source)
2995 *state = INSTALLSTATE_SOURCE;
2996 else
2997 *state = INSTALLSTATE_LOCAL;
2999 TRACE("returning state %d\n", *state);
3000 return ERROR_SUCCESS;
3003 UINT WINAPI MsiQueryFeatureStateExA( LPCSTR product, LPCSTR usersid, MSIINSTALLCONTEXT ctx,
3004 LPCSTR feature, INSTALLSTATE *state )
3006 UINT r;
3007 WCHAR *productW = NULL, *usersidW = NULL, *featureW = NULL;
3009 if (product && !(productW = strdupAtoW( product ))) return ERROR_OUTOFMEMORY;
3010 if (usersid && !(usersidW = strdupAtoW( usersid )))
3012 msi_free( productW );
3013 return ERROR_OUTOFMEMORY;
3015 if (feature && !(featureW = strdupAtoW( feature )))
3017 msi_free( productW );
3018 msi_free( usersidW );
3019 return ERROR_OUTOFMEMORY;
3021 r = MsiQueryFeatureStateExW( productW, usersidW, ctx, featureW, state );
3022 msi_free( productW );
3023 msi_free( usersidW );
3024 msi_free( featureW );
3025 return r;
3028 UINT WINAPI MsiQueryFeatureStateExW( LPCWSTR product, LPCWSTR usersid, MSIINSTALLCONTEXT ctx,
3029 LPCWSTR feature, INSTALLSTATE *state )
3031 WCHAR squashed[33];
3032 if (!squash_guid( product, squashed )) return ERROR_INVALID_PARAMETER;
3033 return query_feature_state( product, squashed, usersid, ctx, feature, state );
3036 /******************************************************************
3037 * MsiQueryFeatureStateA [MSI.@]
3039 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
3041 LPWSTR szwProduct = NULL, szwFeature= NULL;
3042 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
3044 szwProduct = strdupAtoW( szProduct );
3045 if ( szProduct && !szwProduct )
3046 goto end;
3048 szwFeature = strdupAtoW( szFeature );
3049 if ( szFeature && !szwFeature )
3050 goto end;
3052 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
3054 end:
3055 msi_free( szwProduct);
3056 msi_free( szwFeature);
3058 return rc;
3061 /******************************************************************
3062 * MsiQueryFeatureStateW [MSI.@]
3064 * Checks the state of a feature
3066 * PARAMS
3067 * szProduct [I] Product's GUID string
3068 * szFeature [I] Feature's GUID string
3070 * RETURNS
3071 * INSTALLSTATE_LOCAL Feature is installed and usable
3072 * INSTALLSTATE_ABSENT Feature is absent
3073 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
3074 * INSTALLSTATE_UNKNOWN An error occurred
3075 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
3078 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
3080 UINT r;
3081 INSTALLSTATE state;
3082 WCHAR squashed[33];
3084 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
3086 if (!szProduct || !szFeature || !squash_guid( szProduct, squashed ))
3087 return INSTALLSTATE_INVALIDARG;
3089 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_USERMANAGED, szFeature, &state );
3090 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3092 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, szFeature, &state );
3093 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3095 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_MACHINE, szFeature, &state );
3096 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3098 return INSTALLSTATE_UNKNOWN;
3101 /******************************************************************
3102 * MsiGetFileVersionA [MSI.@]
3104 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
3105 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
3107 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
3108 UINT ret = ERROR_OUTOFMEMORY;
3110 if ((lpVersionBuf && !pcchVersionBuf) ||
3111 (lpLangBuf && !pcchLangBuf))
3112 return ERROR_INVALID_PARAMETER;
3114 if( szFilePath )
3116 szwFilePath = strdupAtoW( szFilePath );
3117 if( !szwFilePath )
3118 goto end;
3121 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
3123 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
3124 if( !lpwVersionBuff )
3125 goto end;
3128 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
3130 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
3131 if( !lpwLangBuff )
3132 goto end;
3135 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
3136 lpwLangBuff, pcchLangBuf);
3138 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
3139 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
3140 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
3141 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
3142 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
3143 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
3145 end:
3146 msi_free(szwFilePath);
3147 msi_free(lpwVersionBuff);
3148 msi_free(lpwLangBuff);
3150 return ret;
3153 static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
3154 WCHAR *langbuf, DWORD *langlen )
3156 static const WCHAR szVersionResource[] = {'\\',0};
3157 static const WCHAR szVersionFormat[] = {'%','d','.','%','d','.','%','d','.','%','d',0};
3158 static const WCHAR szLangFormat[] = {'%','d',0};
3159 UINT ret = ERROR_MORE_DATA;
3160 DWORD len, error;
3161 LPVOID version;
3162 VS_FIXEDFILEINFO *ffi;
3163 USHORT *lang;
3164 WCHAR tmp[32];
3166 if (!(len = GetFileVersionInfoSizeW( path, NULL )))
3168 error = GetLastError();
3169 if (error == ERROR_BAD_PATHNAME) return ERROR_FILE_NOT_FOUND;
3170 if (error == ERROR_RESOURCE_DATA_NOT_FOUND) return ERROR_FILE_INVALID;
3171 return error;
3173 if (!(version = msi_alloc( len ))) return ERROR_OUTOFMEMORY;
3174 if (!GetFileVersionInfoW( path, 0, len, version ))
3176 msi_free( version );
3177 return GetLastError();
3179 if (!verbuf && !verlen && !langbuf && !langlen)
3181 msi_free( version );
3182 return ERROR_SUCCESS;
3184 if (verlen)
3186 if (VerQueryValueW( version, szVersionResource, (LPVOID *)&ffi, &len ) && len > 0)
3188 sprintfW( tmp, szVersionFormat,
3189 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
3190 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS) );
3191 if (verbuf) lstrcpynW( verbuf, tmp, *verlen );
3192 len = strlenW( tmp );
3193 if (*verlen > len) ret = ERROR_SUCCESS;
3194 *verlen = len;
3196 else
3198 if (verbuf) *verbuf = 0;
3199 *verlen = 0;
3202 if (langlen)
3204 if (VerQueryValueW( version, szLangResource, (LPVOID *)&lang, &len ) && len > 0)
3206 sprintfW( tmp, szLangFormat, *lang );
3207 if (langbuf) lstrcpynW( langbuf, tmp, *langlen );
3208 len = strlenW( tmp );
3209 if (*langlen > len) ret = ERROR_SUCCESS;
3210 *langlen = len;
3212 else
3214 if (langbuf) *langbuf = 0;
3215 *langlen = 0;
3218 msi_free( version );
3219 return ret;
3223 /******************************************************************
3224 * MsiGetFileVersionW [MSI.@]
3226 UINT WINAPI MsiGetFileVersionW( LPCWSTR path, LPWSTR verbuf, LPDWORD verlen,
3227 LPWSTR langbuf, LPDWORD langlen )
3229 UINT ret;
3231 TRACE("%s %p %u %p %u\n", debugstr_w(path), verbuf, verlen ? *verlen : 0,
3232 langbuf, langlen ? *langlen : 0);
3234 if ((verbuf && !verlen) || (langbuf && !langlen))
3235 return ERROR_INVALID_PARAMETER;
3237 ret = get_file_version( path, verbuf, verlen, langbuf, langlen );
3238 if (ret == ERROR_RESOURCE_DATA_NOT_FOUND && verlen)
3240 int len;
3241 WCHAR *version = msi_font_version_from_file( path );
3242 if (!version) return ERROR_FILE_INVALID;
3243 len = strlenW( version );
3244 if (len >= *verlen) ret = ERROR_MORE_DATA;
3245 else if (verbuf)
3247 strcpyW( verbuf, version );
3248 ret = ERROR_SUCCESS;
3250 *verlen = len;
3251 msi_free( version );
3253 return ret;
3256 /***********************************************************************
3257 * MsiGetFeatureUsageW [MSI.@]
3259 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
3260 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3262 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
3263 pdwUseCount, pwDateUsed);
3264 return ERROR_CALL_NOT_IMPLEMENTED;
3267 /***********************************************************************
3268 * MsiGetFeatureUsageA [MSI.@]
3270 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
3271 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3273 LPWSTR prod = NULL, feat = NULL;
3274 UINT ret = ERROR_OUTOFMEMORY;
3276 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
3277 pdwUseCount, pwDateUsed);
3279 prod = strdupAtoW( szProduct );
3280 if (szProduct && !prod)
3281 goto end;
3283 feat = strdupAtoW( szFeature );
3284 if (szFeature && !feat)
3285 goto end;
3287 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
3289 end:
3290 msi_free( prod );
3291 msi_free( feat );
3293 return ret;
3296 /***********************************************************************
3297 * MsiUseFeatureExW [MSI.@]
3299 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
3300 DWORD dwInstallMode, DWORD dwReserved )
3302 INSTALLSTATE state;
3304 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3305 dwInstallMode, dwReserved);
3307 state = MsiQueryFeatureStateW( szProduct, szFeature );
3309 if (dwReserved)
3310 return INSTALLSTATE_INVALIDARG;
3312 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
3314 FIXME("mark product %s feature %s as used\n",
3315 debugstr_w(szProduct), debugstr_w(szFeature) );
3318 return state;
3321 /***********************************************************************
3322 * MsiUseFeatureExA [MSI.@]
3324 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
3325 DWORD dwInstallMode, DWORD dwReserved )
3327 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
3328 LPWSTR prod = NULL, feat = NULL;
3330 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3331 dwInstallMode, dwReserved);
3333 prod = strdupAtoW( szProduct );
3334 if (szProduct && !prod)
3335 goto end;
3337 feat = strdupAtoW( szFeature );
3338 if (szFeature && !feat)
3339 goto end;
3341 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
3343 end:
3344 msi_free( prod );
3345 msi_free( feat );
3347 return ret;
3350 /***********************************************************************
3351 * MsiUseFeatureW [MSI.@]
3353 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
3355 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
3358 /***********************************************************************
3359 * MsiUseFeatureA [MSI.@]
3361 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
3363 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
3366 /***********************************************************************
3367 * MSI_ProvideQualifiedComponentEx [internal]
3369 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
3370 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3371 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
3372 LPDWORD pcchPathBuf)
3374 WCHAR product[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1],
3375 feature[MAX_FEATURE_CHARS+1];
3376 LPWSTR info;
3377 HKEY hkey;
3378 DWORD sz;
3379 UINT rc;
3380 INSTALLSTATE state;
3382 rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
3383 if (rc != ERROR_SUCCESS)
3384 return ERROR_INDEX_ABSENT;
3386 info = msi_reg_get_val_str( hkey, szQualifier );
3387 RegCloseKey(hkey);
3389 if (!info)
3390 return ERROR_INDEX_ABSENT;
3392 MsiDecomposeDescriptorW(info, product, feature, component, &sz);
3394 if (!szProduct)
3395 state = MSI_GetComponentPath(product, component, lpPathBuf, pcchPathBuf);
3396 else
3397 state = MSI_GetComponentPath(szProduct, component, lpPathBuf, pcchPathBuf);
3399 msi_free( info );
3401 if (state == INSTALLSTATE_MOREDATA)
3402 return ERROR_MORE_DATA;
3404 if (state != INSTALLSTATE_LOCAL)
3405 return ERROR_FILE_NOT_FOUND;
3407 return ERROR_SUCCESS;
3410 /***********************************************************************
3411 * MsiProvideQualifiedComponentExW [MSI.@]
3413 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
3414 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3415 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
3416 LPDWORD pcchPathBuf)
3418 awstring path;
3420 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_w(szComponent),
3421 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
3422 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3424 path.unicode = TRUE;
3425 path.str.w = lpPathBuf;
3427 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
3428 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
3431 /***********************************************************************
3432 * MsiProvideQualifiedComponentExA [MSI.@]
3434 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
3435 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
3436 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
3437 LPDWORD pcchPathBuf)
3439 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
3440 UINT r = ERROR_OUTOFMEMORY;
3441 awstring path;
3443 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
3444 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
3445 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3447 szwComponent = strdupAtoW( szComponent );
3448 if (szComponent && !szwComponent)
3449 goto end;
3451 szwQualifier = strdupAtoW( szQualifier );
3452 if (szQualifier && !szwQualifier)
3453 goto end;
3455 szwProduct = strdupAtoW( szProduct );
3456 if (szProduct && !szwProduct)
3457 goto end;
3459 path.unicode = FALSE;
3460 path.str.a = lpPathBuf;
3462 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
3463 dwInstallMode, szwProduct, Unused1,
3464 Unused2, &path, pcchPathBuf);
3465 end:
3466 msi_free(szwProduct);
3467 msi_free(szwComponent);
3468 msi_free(szwQualifier);
3470 return r;
3473 /***********************************************************************
3474 * MsiProvideQualifiedComponentW [MSI.@]
3476 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
3477 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
3478 LPDWORD pcchPathBuf)
3480 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
3481 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3484 /***********************************************************************
3485 * MsiProvideQualifiedComponentA [MSI.@]
3487 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
3488 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
3489 LPDWORD pcchPathBuf)
3491 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
3492 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3495 /***********************************************************************
3496 * MSI_GetUserInfo [internal]
3498 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
3499 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
3500 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3501 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
3503 WCHAR squished_pc[SQUISH_GUID_SIZE];
3504 LPWSTR user, org, serial;
3505 USERINFOSTATE state;
3506 HKEY hkey, props;
3507 LPCWSTR orgptr;
3508 UINT r;
3510 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
3511 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
3512 pcchSerialBuf);
3514 if (!szProduct || !squash_guid(szProduct, squished_pc))
3515 return USERINFOSTATE_INVALIDARG;
3517 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
3518 &hkey, FALSE) != ERROR_SUCCESS &&
3519 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3520 &hkey, FALSE) != ERROR_SUCCESS &&
3521 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
3522 &hkey, FALSE) != ERROR_SUCCESS)
3524 return USERINFOSTATE_UNKNOWN;
3527 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
3528 NULL, &props, FALSE) != ERROR_SUCCESS &&
3529 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
3530 NULL, &props, FALSE) != ERROR_SUCCESS)
3532 RegCloseKey(hkey);
3533 return USERINFOSTATE_ABSENT;
3536 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3537 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3538 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3539 state = USERINFOSTATE_ABSENT;
3541 RegCloseKey(hkey);
3542 RegCloseKey(props);
3544 if (user && serial)
3545 state = USERINFOSTATE_PRESENT;
3547 if (pcchUserNameBuf)
3549 if (lpUserNameBuf && !user)
3551 (*pcchUserNameBuf)--;
3552 goto done;
3555 r = msi_strcpy_to_awstring(user, -1, lpUserNameBuf, pcchUserNameBuf);
3556 if (r == ERROR_MORE_DATA)
3558 state = USERINFOSTATE_MOREDATA;
3559 goto done;
3563 if (pcchOrgNameBuf)
3565 orgptr = org;
3566 if (!orgptr) orgptr = szEmpty;
3568 r = msi_strcpy_to_awstring(orgptr, -1, lpOrgNameBuf, pcchOrgNameBuf);
3569 if (r == ERROR_MORE_DATA)
3571 state = USERINFOSTATE_MOREDATA;
3572 goto done;
3576 if (pcchSerialBuf)
3578 if (!serial)
3580 (*pcchSerialBuf)--;
3581 goto done;
3584 r = msi_strcpy_to_awstring(serial, -1, lpSerialBuf, pcchSerialBuf);
3585 if (r == ERROR_MORE_DATA)
3586 state = USERINFOSTATE_MOREDATA;
3589 done:
3590 msi_free(user);
3591 msi_free(org);
3592 msi_free(serial);
3594 return state;
3597 /***********************************************************************
3598 * MsiGetUserInfoW [MSI.@]
3600 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3601 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3602 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3603 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3605 awstring user, org, serial;
3607 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3608 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3609 (lpSerialBuf && !pcchSerialBuf))
3610 return USERINFOSTATE_INVALIDARG;
3612 user.unicode = TRUE;
3613 user.str.w = lpUserNameBuf;
3614 org.unicode = TRUE;
3615 org.str.w = lpOrgNameBuf;
3616 serial.unicode = TRUE;
3617 serial.str.w = lpSerialBuf;
3619 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3620 &org, pcchOrgNameBuf,
3621 &serial, pcchSerialBuf );
3624 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3625 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3626 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3627 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3629 awstring user, org, serial;
3630 LPWSTR prod;
3631 UINT r;
3633 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3634 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3635 (lpSerialBuf && !pcchSerialBuf))
3636 return USERINFOSTATE_INVALIDARG;
3638 prod = strdupAtoW( szProduct );
3639 if (szProduct && !prod)
3640 return ERROR_OUTOFMEMORY;
3642 user.unicode = FALSE;
3643 user.str.a = lpUserNameBuf;
3644 org.unicode = FALSE;
3645 org.str.a = lpOrgNameBuf;
3646 serial.unicode = FALSE;
3647 serial.str.a = lpSerialBuf;
3649 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3650 &org, pcchOrgNameBuf,
3651 &serial, pcchSerialBuf );
3653 msi_free( prod );
3655 return r;
3658 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3660 MSIHANDLE handle;
3661 UINT rc;
3662 MSIPACKAGE *package;
3663 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3665 TRACE("(%s)\n",debugstr_w(szProduct));
3667 rc = MsiOpenProductW(szProduct,&handle);
3668 if (rc != ERROR_SUCCESS)
3669 return ERROR_INVALID_PARAMETER;
3671 /* MsiCollectUserInfo cannot be called from a custom action. */
3672 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3673 if (!package)
3674 return ERROR_CALL_NOT_IMPLEMENTED;
3676 rc = ACTION_PerformUIAction(package, szFirstRun, SCRIPT_NONE);
3677 msiobj_release( &package->hdr );
3679 MsiCloseHandle(handle);
3681 return rc;
3684 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3686 MSIHANDLE handle;
3687 UINT rc;
3688 MSIPACKAGE *package;
3689 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3691 TRACE("(%s)\n",debugstr_a(szProduct));
3693 rc = MsiOpenProductA(szProduct,&handle);
3694 if (rc != ERROR_SUCCESS)
3695 return ERROR_INVALID_PARAMETER;
3697 /* MsiCollectUserInfo cannot be called from a custom action. */
3698 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3699 if (!package)
3700 return ERROR_CALL_NOT_IMPLEMENTED;
3702 rc = ACTION_PerformUIAction(package, szFirstRun, SCRIPT_NONE);
3703 msiobj_release( &package->hdr );
3705 MsiCloseHandle(handle);
3707 return rc;
3710 /***********************************************************************
3711 * MsiConfigureFeatureA [MSI.@]
3713 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3715 LPWSTR prod, feat = NULL;
3716 UINT r = ERROR_OUTOFMEMORY;
3718 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3720 prod = strdupAtoW( szProduct );
3721 if (szProduct && !prod)
3722 goto end;
3724 feat = strdupAtoW( szFeature );
3725 if (szFeature && !feat)
3726 goto end;
3728 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3730 end:
3731 msi_free(feat);
3732 msi_free(prod);
3734 return r;
3737 /***********************************************************************
3738 * MsiConfigureFeatureW [MSI.@]
3740 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3742 MSIPACKAGE *package = NULL;
3743 UINT r;
3744 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3745 DWORD sz;
3747 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3749 if (!szProduct || !szFeature)
3750 return ERROR_INVALID_PARAMETER;
3752 switch (eInstallState)
3754 case INSTALLSTATE_DEFAULT:
3755 /* FIXME: how do we figure out the default location? */
3756 eInstallState = INSTALLSTATE_LOCAL;
3757 break;
3758 case INSTALLSTATE_LOCAL:
3759 case INSTALLSTATE_SOURCE:
3760 case INSTALLSTATE_ABSENT:
3761 case INSTALLSTATE_ADVERTISED:
3762 break;
3763 default:
3764 return ERROR_INVALID_PARAMETER;
3767 r = MSI_OpenProductW( szProduct, &package );
3768 if (r != ERROR_SUCCESS)
3769 return r;
3771 sz = sizeof(sourcepath);
3772 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3773 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3775 sz = sizeof(filename);
3776 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3777 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3779 lstrcatW( sourcepath, filename );
3781 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3783 r = ACTION_PerformUIAction( package, szCostInitialize, SCRIPT_NONE );
3784 if (r != ERROR_SUCCESS)
3785 goto end;
3787 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3788 if (r != ERROR_SUCCESS)
3789 goto end;
3791 r = MSI_InstallPackage( package, sourcepath, NULL );
3793 end:
3794 msiobj_release( &package->hdr );
3796 return r;
3799 /***********************************************************************
3800 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3802 * Notes: undocumented
3804 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3806 WCHAR path[MAX_PATH];
3808 TRACE("%d\n", dwReserved);
3810 if (dwReserved)
3812 FIXME("dwReserved=%d\n", dwReserved);
3813 return ERROR_INVALID_PARAMETER;
3816 if (!GetWindowsDirectoryW(path, MAX_PATH))
3817 return ERROR_FUNCTION_FAILED;
3819 lstrcatW(path, installerW);
3821 if (!CreateDirectoryW(path, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
3822 return ERROR_FUNCTION_FAILED;
3824 return ERROR_SUCCESS;
3827 /***********************************************************************
3828 * MsiGetShortcutTargetA [MSI.@]
3830 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3831 LPSTR szProductCode, LPSTR szFeatureId,
3832 LPSTR szComponentCode )
3834 LPWSTR target;
3835 const int len = MAX_FEATURE_CHARS+1;
3836 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3837 UINT r;
3839 target = strdupAtoW( szShortcutTarget );
3840 if (szShortcutTarget && !target )
3841 return ERROR_OUTOFMEMORY;
3842 product[0] = 0;
3843 feature[0] = 0;
3844 component[0] = 0;
3845 r = MsiGetShortcutTargetW( target, product, feature, component );
3846 msi_free( target );
3847 if (r == ERROR_SUCCESS)
3849 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3850 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3851 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3853 return r;
3856 /***********************************************************************
3857 * MsiGetShortcutTargetW [MSI.@]
3859 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3860 LPWSTR szProductCode, LPWSTR szFeatureId,
3861 LPWSTR szComponentCode )
3863 IShellLinkDataList *dl = NULL;
3864 IPersistFile *pf = NULL;
3865 LPEXP_DARWIN_LINK darwin = NULL;
3866 HRESULT r, init;
3868 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3869 szProductCode, szFeatureId, szComponentCode );
3871 init = CoInitialize(NULL);
3873 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3874 &IID_IPersistFile, (LPVOID*) &pf );
3875 if( SUCCEEDED( r ) )
3877 r = IPersistFile_Load( pf, szShortcutTarget,
3878 STGM_READ | STGM_SHARE_DENY_WRITE );
3879 if( SUCCEEDED( r ) )
3881 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3882 (LPVOID*) &dl );
3883 if( SUCCEEDED( r ) )
3885 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3886 (LPVOID) &darwin );
3887 IShellLinkDataList_Release( dl );
3890 IPersistFile_Release( pf );
3893 if (SUCCEEDED(init))
3894 CoUninitialize();
3896 TRACE("darwin = %p\n", darwin);
3898 if (darwin)
3900 DWORD sz;
3901 UINT ret;
3903 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3904 szProductCode, szFeatureId, szComponentCode, &sz );
3905 LocalFree( darwin );
3906 return ret;
3909 return ERROR_FUNCTION_FAILED;
3912 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature, DWORD dwReinstallMode )
3914 static const WCHAR fmtW[] = {'%','s','=','%','s',' ','%','s','=','%','s',0};
3915 MSIPACKAGE *package;
3916 MSIINSTALLCONTEXT context;
3917 UINT r;
3918 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH], reinstallmode[11];
3919 WCHAR *ptr, *cmdline;
3920 DWORD sz;
3922 TRACE("%s, %s, 0x%08x\n", debugstr_w(szProduct), debugstr_w(szFeature), dwReinstallMode);
3924 r = msi_locate_product( szProduct, &context );
3925 if (r != ERROR_SUCCESS)
3926 return r;
3928 ptr = reinstallmode;
3930 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3931 *ptr++ = 'p';
3932 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3933 *ptr++ = 'o';
3934 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3935 *ptr++ = 'w';
3936 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3937 *ptr++ = 'd';
3938 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3939 *ptr++ = 'c';
3940 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3941 *ptr++ = 'a';
3942 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3943 *ptr++ = 'u';
3944 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3945 *ptr++ = 'm';
3946 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3947 *ptr++ = 's';
3948 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3949 *ptr++ = 'v';
3950 *ptr = 0;
3952 sz = sizeof(sourcepath);
3953 MsiSourceListGetInfoW( szProduct, NULL, context, MSICODE_PRODUCT,
3954 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz );
3955 sz = sizeof(filename);
3956 MsiSourceListGetInfoW( szProduct, NULL, context, MSICODE_PRODUCT,
3957 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz );
3958 strcatW( sourcepath, filename );
3960 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3961 r = MSI_OpenPackageW( sourcepath, &package );
3962 else
3963 r = MSI_OpenProductW( szProduct, &package );
3965 if (r != ERROR_SUCCESS)
3966 return r;
3968 sz = (strlenW( fmtW ) + strlenW( szReinstallMode ) + strlenW( reinstallmode )) * sizeof(WCHAR);
3969 sz += (strlenW( szReinstall ) + strlenW( szFeature )) * sizeof(WCHAR);
3970 if (!(cmdline = msi_alloc( sz )))
3972 msiobj_release( &package->hdr );
3973 return ERROR_OUTOFMEMORY;
3975 sprintfW( cmdline, fmtW, szReinstallMode, reinstallmode, szReinstall, szFeature );
3977 r = MSI_InstallPackage( package, sourcepath, cmdline );
3978 msiobj_release( &package->hdr );
3979 msi_free( cmdline );
3981 return r;
3984 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
3985 DWORD dwReinstallMode )
3987 LPWSTR wszProduct;
3988 LPWSTR wszFeature;
3989 UINT rc;
3991 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3992 dwReinstallMode);
3994 wszProduct = strdupAtoW(szProduct);
3995 wszFeature = strdupAtoW(szFeature);
3997 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
3999 msi_free(wszProduct);
4000 msi_free(wszFeature);
4001 return rc;
4004 typedef struct
4006 unsigned int i[2];
4007 unsigned int buf[4];
4008 unsigned char in[64];
4009 unsigned char digest[16];
4010 } MD5_CTX;
4012 extern VOID WINAPI MD5Init( MD5_CTX *);
4013 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
4014 extern VOID WINAPI MD5Final( MD5_CTX *);
4016 UINT msi_get_filehash( const WCHAR *path, MSIFILEHASHINFO *hash )
4018 HANDLE handle, mapping;
4019 void *p;
4020 DWORD length;
4021 UINT r = ERROR_FUNCTION_FAILED;
4023 handle = CreateFileW( path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
4024 if (handle == INVALID_HANDLE_VALUE)
4026 WARN("can't open file %u\n", GetLastError());
4027 return ERROR_FILE_NOT_FOUND;
4029 if ((length = GetFileSize( handle, NULL )))
4031 if ((mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL )))
4033 if ((p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length )))
4035 MD5_CTX ctx;
4037 MD5Init( &ctx );
4038 MD5Update( &ctx, p, length );
4039 MD5Final( &ctx );
4040 UnmapViewOfFile( p );
4042 memcpy( hash->dwData, ctx.digest, sizeof(hash->dwData) );
4043 r = ERROR_SUCCESS;
4045 CloseHandle( mapping );
4048 else
4050 /* Empty file -> set hash to 0 */
4051 memset( hash->dwData, 0, sizeof(hash->dwData) );
4052 r = ERROR_SUCCESS;
4055 CloseHandle( handle );
4056 return r;
4059 /***********************************************************************
4060 * MsiGetFileHashW [MSI.@]
4062 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
4063 PMSIFILEHASHINFO pHash )
4065 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
4067 if (!szFilePath)
4068 return ERROR_INVALID_PARAMETER;
4070 if (!*szFilePath)
4071 return ERROR_PATH_NOT_FOUND;
4073 if (dwOptions)
4074 return ERROR_INVALID_PARAMETER;
4075 if (!pHash)
4076 return ERROR_INVALID_PARAMETER;
4077 if (pHash->dwFileHashInfoSize < sizeof *pHash)
4078 return ERROR_INVALID_PARAMETER;
4080 return msi_get_filehash( szFilePath, pHash );
4083 /***********************************************************************
4084 * MsiGetFileHashA [MSI.@]
4086 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
4087 PMSIFILEHASHINFO pHash )
4089 LPWSTR file;
4090 UINT r;
4092 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
4094 file = strdupAtoW( szFilePath );
4095 if (szFilePath && !file)
4096 return ERROR_OUTOFMEMORY;
4098 r = MsiGetFileHashW( file, dwOptions, pHash );
4099 msi_free( file );
4100 return r;
4103 /***********************************************************************
4104 * MsiAdvertiseScriptW [MSI.@]
4106 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
4107 PHKEY phRegData, BOOL fRemoveItems )
4109 FIXME("%s %08x %p %d\n",
4110 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
4111 return ERROR_CALL_NOT_IMPLEMENTED;
4114 /***********************************************************************
4115 * MsiAdvertiseScriptA [MSI.@]
4117 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
4118 PHKEY phRegData, BOOL fRemoveItems )
4120 FIXME("%s %08x %p %d\n",
4121 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
4122 return ERROR_CALL_NOT_IMPLEMENTED;
4125 /***********************************************************************
4126 * MsiIsProductElevatedW [MSI.@]
4128 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
4130 FIXME("%s %p - stub\n",
4131 debugstr_w( szProduct ), pfElevated );
4132 *pfElevated = TRUE;
4133 return ERROR_SUCCESS;
4136 /***********************************************************************
4137 * MsiIsProductElevatedA [MSI.@]
4139 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
4141 FIXME("%s %p - stub\n",
4142 debugstr_a( szProduct ), pfElevated );
4143 *pfElevated = TRUE;
4144 return ERROR_SUCCESS;
4147 /***********************************************************************
4148 * MsiSetExternalUIRecord [MSI.@]
4150 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler,
4151 DWORD filter, LPVOID context,
4152 PINSTALLUI_HANDLER_RECORD prev )
4154 TRACE("%p %08x %p %p\n", handler, filter, context, prev);
4156 if (prev)
4157 *prev = gUIHandlerRecord;
4159 gUIHandlerRecord = handler;
4160 gUIFilter = filter;
4161 gUIContext = context;
4163 return ERROR_SUCCESS;
4166 /***********************************************************************
4167 * MsiInstallMissingComponentA [MSI.@]
4169 UINT WINAPI MsiInstallMissingComponentA( LPCSTR product, LPCSTR component, INSTALLSTATE state )
4171 UINT r;
4172 WCHAR *productW = NULL, *componentW = NULL;
4174 TRACE("%s, %s, %d\n", debugstr_a(product), debugstr_a(component), state);
4176 if (product && !(productW = strdupAtoW( product )))
4177 return ERROR_OUTOFMEMORY;
4179 if (component && !(componentW = strdupAtoW( component )))
4181 msi_free( productW );
4182 return ERROR_OUTOFMEMORY;
4185 r = MsiInstallMissingComponentW( productW, componentW, state );
4186 msi_free( productW );
4187 msi_free( componentW );
4188 return r;
4191 /***********************************************************************
4192 * MsiInstallMissingComponentW [MSI.@]
4194 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
4196 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
4197 return ERROR_SUCCESS;
4200 UINT WINAPI MsiProvideComponentA( LPCSTR product, LPCSTR feature, LPCSTR component, DWORD mode, LPSTR buf, LPDWORD buflen )
4202 WCHAR *productW = NULL, *componentW = NULL, *featureW = NULL, *bufW = NULL;
4203 UINT r = ERROR_OUTOFMEMORY;
4204 DWORD lenW = 0;
4205 int len;
4207 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_a(product), debugstr_a(component), debugstr_a(feature), mode, buf, buflen);
4209 if (product && !(productW = strdupAtoW( product ))) goto done;
4210 if (feature && !(featureW = strdupAtoW( feature ))) goto done;
4211 if (component && !(componentW = strdupAtoW( component ))) goto done;
4213 r = MsiProvideComponentW( productW, featureW, componentW, mode, NULL, &lenW );
4214 if (r != ERROR_SUCCESS)
4215 goto done;
4217 if (!(bufW = msi_alloc( ++lenW * sizeof(WCHAR) )))
4219 r = ERROR_OUTOFMEMORY;
4220 goto done;
4223 r = MsiProvideComponentW( productW, featureW, componentW, mode, bufW, &lenW );
4224 if (r != ERROR_SUCCESS)
4225 goto done;
4227 len = WideCharToMultiByte( CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
4228 if (buf)
4230 if (len > *buflen)
4231 r = ERROR_MORE_DATA;
4232 else
4233 WideCharToMultiByte( CP_ACP, 0, bufW, -1, buf, *buflen, NULL, NULL );
4236 *buflen = len - 1;
4238 done:
4239 msi_free( productW );
4240 msi_free( featureW );
4241 msi_free( componentW );
4242 msi_free( bufW );
4243 return r;
4246 UINT WINAPI MsiProvideComponentW( LPCWSTR product, LPCWSTR feature, LPCWSTR component, DWORD mode, LPWSTR buf, LPDWORD buflen )
4248 INSTALLSTATE state;
4250 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_w(product), debugstr_w(component), debugstr_w(feature), mode, buf, buflen);
4252 state = MsiQueryFeatureStateW( product, feature );
4253 TRACE("feature state: %d\n", state);
4254 switch (mode)
4256 case INSTALLMODE_NODETECTION:
4257 break;
4259 default:
4260 FIXME("mode %x not implemented\n", mode);
4261 return ERROR_INSTALL_FAILURE;
4264 state = MsiGetComponentPathW( product, component, buf, buflen );
4265 TRACE("component state: %d\n", state);
4266 switch (state)
4268 case INSTALLSTATE_INVALIDARG:
4269 return ERROR_INVALID_PARAMETER;
4271 case INSTALLSTATE_MOREDATA:
4272 return ERROR_MORE_DATA;
4274 case INSTALLSTATE_ADVERTISED:
4275 case INSTALLSTATE_LOCAL:
4276 case INSTALLSTATE_SOURCE:
4277 MsiUseFeatureW( product, feature );
4278 return ERROR_SUCCESS;
4280 default:
4281 TRACE("MsiGetComponentPathW returned %d\n", state);
4282 return ERROR_INSTALL_FAILURE;
4286 /***********************************************************************
4287 * MsiBeginTransactionA [MSI.@]
4289 UINT WINAPI MsiBeginTransactionA( LPCSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4291 WCHAR *nameW;
4292 UINT r;
4294 FIXME("%s %u %p %p\n", debugstr_a(name), attrs, id, event);
4296 nameW = strdupAtoW( name );
4297 if (name && !nameW)
4298 return ERROR_OUTOFMEMORY;
4300 r = MsiBeginTransactionW( nameW, attrs, id, event );
4301 msi_free( nameW );
4302 return r;
4305 /***********************************************************************
4306 * MsiBeginTransactionW [MSI.@]
4308 UINT WINAPI MsiBeginTransactionW( LPCWSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4310 FIXME("%s %u %p %p\n", debugstr_w(name), attrs, id, event);
4312 *id = (MSIHANDLE)0xdeadbeef;
4313 *event = (HANDLE)0xdeadbeef;
4315 return ERROR_SUCCESS;
4318 /***********************************************************************
4319 * MsiJoinTransaction [MSI.@]
4321 UINT WINAPI MsiJoinTransaction( MSIHANDLE handle, DWORD attrs, HANDLE *event )
4323 FIXME("%u %08x %p\n", handle, attrs, event);
4325 *event = (HANDLE)0xdeadbeef;
4326 return ERROR_SUCCESS;
4329 /***********************************************************************
4330 * MsiEndTransaction [MSI.@]
4332 UINT WINAPI MsiEndTransaction( DWORD state )
4334 FIXME("%u\n", state);
4335 return ERROR_SUCCESS;
4338 UINT WINAPI Migrate10CachedPackagesW(void* a, void* b, void* c, DWORD d)
4340 FIXME("%p,%p,%p,%08x\n", a, b, c, d);
4341 return ERROR_SUCCESS;
4344 /***********************************************************************
4345 * MsiRemovePatchesA [MSI.@]
4347 UINT WINAPI MsiRemovePatchesA(LPCSTR patchlist, LPCSTR product, INSTALLTYPE type, LPCSTR propertylist)
4349 FIXME("(%s %s %d %s\n", debugstr_a(patchlist), debugstr_a(product), type, debugstr_a(propertylist));
4350 return ERROR_SUCCESS;
4353 /***********************************************************************
4354 * MsiRemovePatchesW [MSI.@]
4356 UINT WINAPI MsiRemovePatchesW(LPCWSTR patchlist, LPCWSTR product, INSTALLTYPE type, LPCWSTR propertylist)
4358 FIXME("(%s %s %d %s\n", debugstr_w(patchlist), debugstr_w(product), type, debugstr_w(propertylist));
4359 return ERROR_SUCCESS;