ddraw/tests: Validate the "surface" pointer is unmodified after CreateSurface() witho...
[wine.git] / dlls / msi / msi.c
blob1687a28a394001bfebde7022d3601131c9c39498
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 squashed_pc[SQUASHED_GUID_SIZE];
151 UINT r;
153 if (!szProduct || !squash_guid( szProduct, squashed_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 squashed_comp[SQUASHED_GUID_SIZE], squashed_prod[SQUASHED_GUID_SIZE];
1015 DWORD sz = sizeof(squashed_prod)/sizeof(squashed_prod[0]);
1017 TRACE("%s %p\n", debugstr_w(szComponent), szBuffer);
1019 if (!szComponent || !*szComponent)
1020 return ERROR_INVALID_PARAMETER;
1022 if (!squash_guid( szComponent, squashed_comp ))
1023 return ERROR_INVALID_PARAMETER;
1025 if (MSIREG_OpenUserDataComponentKey(szComponent, NULL, &compkey, FALSE) != ERROR_SUCCESS &&
1026 MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &compkey, FALSE) != ERROR_SUCCESS)
1028 return ERROR_UNKNOWN_COMPONENT;
1031 rc = RegEnumValueW( compkey, 0, squashed_prod, &sz, NULL, NULL, NULL, NULL );
1032 if (rc != ERROR_SUCCESS)
1034 RegCloseKey(compkey);
1035 return ERROR_UNKNOWN_COMPONENT;
1038 /* check simple case, only one product */
1039 rc = RegEnumValueW( compkey, 1, squashed_prod, &sz, NULL, NULL, NULL, NULL );
1040 if (rc == ERROR_NO_MORE_ITEMS)
1042 rc = ERROR_SUCCESS;
1043 goto done;
1046 index = 0;
1047 while ((rc = RegEnumValueW( compkey, index, squashed_prod, &sz, NULL, NULL, NULL, NULL )) !=
1048 ERROR_NO_MORE_ITEMS)
1050 index++;
1051 sz = GUID_SIZE;
1052 unsquash_guid( squashed_prod, szBuffer );
1054 if (MSIREG_OpenProductKey(szBuffer, NULL,
1055 MSIINSTALLCONTEXT_USERMANAGED,
1056 &prodkey, FALSE) == ERROR_SUCCESS ||
1057 MSIREG_OpenProductKey(szBuffer, NULL,
1058 MSIINSTALLCONTEXT_USERUNMANAGED,
1059 &prodkey, FALSE) == ERROR_SUCCESS ||
1060 MSIREG_OpenProductKey(szBuffer, NULL,
1061 MSIINSTALLCONTEXT_MACHINE,
1062 &prodkey, FALSE) == ERROR_SUCCESS)
1064 RegCloseKey(prodkey);
1065 rc = ERROR_SUCCESS;
1066 goto done;
1070 rc = ERROR_INSTALL_FAILURE;
1072 done:
1073 RegCloseKey(compkey);
1074 unsquash_guid( squashed_prod, szBuffer );
1075 return rc;
1078 static LPWSTR msi_reg_get_value(HKEY hkey, LPCWSTR name, DWORD *type)
1080 DWORD dval;
1081 LONG res;
1082 WCHAR temp[20];
1084 static const WCHAR format[] = {'%','d',0};
1086 res = RegQueryValueExW(hkey, name, NULL, type, NULL, NULL);
1087 if (res != ERROR_SUCCESS)
1088 return NULL;
1090 if (*type == REG_SZ)
1091 return msi_reg_get_val_str(hkey, name);
1093 if (!msi_reg_get_val_dword(hkey, name, &dval))
1094 return NULL;
1096 sprintfW(temp, format, dval);
1097 return strdupW(temp);
1100 static UINT MSI_GetProductInfo(LPCWSTR szProduct, LPCWSTR szAttribute,
1101 awstring *szValue, LPDWORD pcchValueBuf)
1103 static WCHAR empty[] = {0};
1104 static const WCHAR sourcelist[] = {'S','o','u','r','c','e','L','i','s','t',0};
1105 static const WCHAR display_name[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
1106 static const WCHAR display_version[] = {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1107 static const WCHAR assignment[] = {'A','s','s','i','g','n','m','e','n','t',0};
1108 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
1109 UINT r = ERROR_UNKNOWN_PROPERTY;
1110 HKEY prodkey, userdata, source;
1111 WCHAR *val = NULL, squashed_pc[SQUASHED_GUID_SIZE], packagecode[GUID_SIZE];
1112 BOOL badconfig = FALSE;
1113 LONG res;
1114 DWORD type = REG_NONE;
1116 TRACE("%s %s %p %p\n", debugstr_w(szProduct),
1117 debugstr_w(szAttribute), szValue, pcchValueBuf);
1119 if ((szValue->str.w && !pcchValueBuf) || !szProduct || !szAttribute)
1120 return ERROR_INVALID_PARAMETER;
1122 if (!squash_guid( szProduct, squashed_pc ))
1123 return ERROR_INVALID_PARAMETER;
1125 if ((r = MSIREG_OpenProductKey(szProduct, NULL,
1126 MSIINSTALLCONTEXT_USERMANAGED,
1127 &prodkey, FALSE)) != ERROR_SUCCESS &&
1128 (r = MSIREG_OpenProductKey(szProduct, NULL,
1129 MSIINSTALLCONTEXT_USERUNMANAGED,
1130 &prodkey, FALSE)) != ERROR_SUCCESS &&
1131 (r = MSIREG_OpenProductKey(szProduct, NULL,
1132 MSIINSTALLCONTEXT_MACHINE,
1133 &prodkey, FALSE)) == ERROR_SUCCESS)
1135 context = MSIINSTALLCONTEXT_MACHINE;
1138 if (!strcmpW( szAttribute, INSTALLPROPERTY_HELPLINKW ) ||
1139 !strcmpW( szAttribute, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1140 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLDATEW ) ||
1141 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1142 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1143 !strcmpW( szAttribute, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1144 !strcmpW( szAttribute, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1145 !strcmpW( szAttribute, INSTALLPROPERTY_PUBLISHERW ) ||
1146 !strcmpW( szAttribute, INSTALLPROPERTY_URLINFOABOUTW ) ||
1147 !strcmpW( szAttribute, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1148 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMINORW ) ||
1149 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONMAJORW ) ||
1150 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1151 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTIDW ) ||
1152 !strcmpW( szAttribute, INSTALLPROPERTY_REGCOMPANYW ) ||
1153 !strcmpW( szAttribute, INSTALLPROPERTY_REGOWNERW ))
1155 if (!prodkey)
1157 r = ERROR_UNKNOWN_PRODUCT;
1158 goto done;
1160 if (MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE))
1162 r = ERROR_UNKNOWN_PROPERTY;
1163 goto done;
1166 if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1167 szAttribute = display_name;
1168 else if (!strcmpW( szAttribute, INSTALLPROPERTY_VERSIONSTRINGW ))
1169 szAttribute = display_version;
1171 val = msi_reg_get_value(userdata, szAttribute, &type);
1172 if (!val)
1173 val = empty;
1174 RegCloseKey(userdata);
1176 else if (!strcmpW( szAttribute, INSTALLPROPERTY_INSTANCETYPEW ) ||
1177 !strcmpW( szAttribute, INSTALLPROPERTY_TRANSFORMSW ) ||
1178 !strcmpW( szAttribute, INSTALLPROPERTY_LANGUAGEW ) ||
1179 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1180 !strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ) ||
1181 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ) ||
1182 !strcmpW( szAttribute, INSTALLPROPERTY_VERSIONW ) ||
1183 !strcmpW( szAttribute, INSTALLPROPERTY_PRODUCTICONW ) ||
1184 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ) ||
1185 !strcmpW( szAttribute, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1187 if (!prodkey)
1189 r = ERROR_UNKNOWN_PRODUCT;
1190 goto done;
1193 if (!strcmpW( szAttribute, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1194 szAttribute = assignment;
1196 if (!strcmpW( szAttribute, INSTALLPROPERTY_PACKAGENAMEW ))
1198 res = RegOpenKeyW(prodkey, sourcelist, &source);
1199 if (res != ERROR_SUCCESS)
1201 r = ERROR_UNKNOWN_PRODUCT;
1202 goto done;
1205 val = msi_reg_get_value(source, szAttribute, &type);
1206 if (!val)
1207 val = empty;
1209 RegCloseKey(source);
1211 else
1213 val = msi_reg_get_value(prodkey, szAttribute, &type);
1214 if (!val)
1215 val = empty;
1218 if (val != empty && type != REG_DWORD &&
1219 !strcmpW( szAttribute, INSTALLPROPERTY_PACKAGECODEW ))
1221 if (lstrlenW( val ) != SQUASHED_GUID_SIZE - 1)
1222 badconfig = TRUE;
1223 else
1225 unsquash_guid(val, packagecode);
1226 msi_free(val);
1227 val = strdupW(packagecode);
1232 if (!val)
1234 r = ERROR_UNKNOWN_PROPERTY;
1235 goto done;
1238 if (pcchValueBuf)
1240 int len = strlenW( val );
1242 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1243 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1244 * can't rely on its value.
1246 if (szValue->str.a || szValue->str.w)
1248 DWORD size = *pcchValueBuf;
1249 if (len < size)
1250 r = msi_strcpy_to_awstring( val, len, szValue, &size );
1251 else
1252 r = ERROR_MORE_DATA;
1255 if (!badconfig)
1256 *pcchValueBuf = len;
1259 if (badconfig)
1260 r = ERROR_BAD_CONFIGURATION;
1262 if (val != empty)
1263 msi_free(val);
1265 done:
1266 RegCloseKey(prodkey);
1267 return r;
1270 UINT WINAPI MsiGetProductInfoA(LPCSTR szProduct, LPCSTR szAttribute,
1271 LPSTR szBuffer, LPDWORD pcchValueBuf)
1273 LPWSTR szwProduct, szwAttribute = NULL;
1274 UINT r = ERROR_OUTOFMEMORY;
1275 awstring buffer;
1277 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szAttribute),
1278 szBuffer, pcchValueBuf);
1280 szwProduct = strdupAtoW( szProduct );
1281 if( szProduct && !szwProduct )
1282 goto end;
1284 szwAttribute = strdupAtoW( szAttribute );
1285 if( szAttribute && !szwAttribute )
1286 goto end;
1288 buffer.unicode = FALSE;
1289 buffer.str.a = szBuffer;
1291 r = MSI_GetProductInfo( szwProduct, szwAttribute,
1292 &buffer, pcchValueBuf );
1294 end:
1295 msi_free( szwProduct );
1296 msi_free( szwAttribute );
1298 return r;
1301 UINT WINAPI MsiGetProductInfoW(LPCWSTR szProduct, LPCWSTR szAttribute,
1302 LPWSTR szBuffer, LPDWORD pcchValueBuf)
1304 awstring buffer;
1306 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szAttribute),
1307 szBuffer, pcchValueBuf);
1309 buffer.unicode = TRUE;
1310 buffer.str.w = szBuffer;
1312 return MSI_GetProductInfo( szProduct, szAttribute,
1313 &buffer, pcchValueBuf );
1316 UINT WINAPI MsiGetProductInfoExA(LPCSTR szProductCode, LPCSTR szUserSid,
1317 MSIINSTALLCONTEXT dwContext, LPCSTR szProperty,
1318 LPSTR szValue, LPDWORD pcchValue)
1320 LPWSTR product = NULL;
1321 LPWSTR usersid = NULL;
1322 LPWSTR property = NULL;
1323 LPWSTR value = NULL;
1324 DWORD len = 0;
1325 UINT r;
1327 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode),
1328 debugstr_a(szUserSid), dwContext, debugstr_a(szProperty),
1329 szValue, pcchValue);
1331 if (szValue && !pcchValue)
1332 return ERROR_INVALID_PARAMETER;
1334 if (szProductCode) product = strdupAtoW(szProductCode);
1335 if (szUserSid) usersid = strdupAtoW(szUserSid);
1336 if (szProperty) property = strdupAtoW(szProperty);
1338 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1339 NULL, &len);
1340 if (r != ERROR_SUCCESS)
1341 goto done;
1343 value = msi_alloc(++len * sizeof(WCHAR));
1344 if (!value)
1346 r = ERROR_OUTOFMEMORY;
1347 goto done;
1350 r = MsiGetProductInfoExW(product, usersid, dwContext, property,
1351 value, &len);
1352 if (r != ERROR_SUCCESS)
1353 goto done;
1355 if (!pcchValue)
1356 goto done;
1358 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
1359 if (*pcchValue >= len)
1360 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
1361 else if (szValue)
1363 r = ERROR_MORE_DATA;
1364 if (*pcchValue > 0)
1365 *szValue = '\0';
1368 if (*pcchValue <= len || !szValue)
1369 len = len * sizeof(WCHAR) - 1;
1371 *pcchValue = len - 1;
1373 done:
1374 msi_free(product);
1375 msi_free(usersid);
1376 msi_free(property);
1377 msi_free(value);
1379 return r;
1382 static UINT msi_copy_outval(LPWSTR val, LPWSTR out, LPDWORD size)
1384 UINT r = ERROR_SUCCESS;
1386 if (!val)
1387 return ERROR_UNKNOWN_PROPERTY;
1389 if (out)
1391 if (strlenW(val) >= *size)
1393 r = ERROR_MORE_DATA;
1394 if (*size > 0)
1395 *out = '\0';
1397 else
1398 lstrcpyW(out, val);
1401 if (size)
1402 *size = lstrlenW(val);
1404 return r;
1407 UINT WINAPI MsiGetProductInfoExW(LPCWSTR szProductCode, LPCWSTR szUserSid,
1408 MSIINSTALLCONTEXT dwContext, LPCWSTR szProperty,
1409 LPWSTR szValue, LPDWORD pcchValue)
1411 static const WCHAR five[] = {'5',0};
1412 static const WCHAR displayname[] = {
1413 'D','i','s','p','l','a','y','N','a','m','e',0};
1414 static const WCHAR displayversion[] = {
1415 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1416 static const WCHAR managed_local_package[] = {
1417 'M','a','n','a','g','e','d','L','o','c','a','l',
1418 'P','a','c','k','a','g','e',0};
1419 WCHAR *val = NULL, squashed_pc[SQUASHED_GUID_SIZE];
1420 LPCWSTR package = NULL;
1421 HKEY props = NULL, prod, classes = NULL, managed, hkey = NULL;
1422 DWORD type;
1423 UINT r = ERROR_UNKNOWN_PRODUCT;
1425 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode),
1426 debugstr_w(szUserSid), dwContext, debugstr_w(szProperty),
1427 szValue, pcchValue);
1429 if (!szProductCode || !squash_guid( szProductCode, squashed_pc ))
1430 return ERROR_INVALID_PARAMETER;
1432 if (szValue && !pcchValue)
1433 return ERROR_INVALID_PARAMETER;
1435 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1436 dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1437 dwContext != MSIINSTALLCONTEXT_MACHINE)
1438 return ERROR_INVALID_PARAMETER;
1440 if (!szProperty || !*szProperty)
1441 return ERROR_INVALID_PARAMETER;
1443 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1444 return ERROR_INVALID_PARAMETER;
1446 /* FIXME: dwContext is provided, no need to search for it */
1447 MSIREG_OpenProductKey(szProductCode, NULL,MSIINSTALLCONTEXT_USERMANAGED,
1448 &managed, FALSE);
1449 MSIREG_OpenProductKey(szProductCode, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
1450 &prod, FALSE);
1452 MSIREG_OpenInstallProps(szProductCode, dwContext, NULL, &props, FALSE);
1454 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1456 package = INSTALLPROPERTY_LOCALPACKAGEW;
1458 if (!props && !prod)
1459 goto done;
1461 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1463 package = managed_local_package;
1465 if (!props && !managed)
1466 goto done;
1468 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1470 package = INSTALLPROPERTY_LOCALPACKAGEW;
1471 MSIREG_OpenProductKey(szProductCode, NULL, dwContext, &classes, FALSE);
1473 if (!props && !classes)
1474 goto done;
1477 if (!strcmpW( szProperty, INSTALLPROPERTY_HELPLINKW ) ||
1478 !strcmpW( szProperty, INSTALLPROPERTY_HELPTELEPHONEW ) ||
1479 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ) ||
1480 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ) ||
1481 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLLOCATIONW ) ||
1482 !strcmpW( szProperty, INSTALLPROPERTY_INSTALLSOURCEW ) ||
1483 !strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ) ||
1484 !strcmpW( szProperty, INSTALLPROPERTY_PUBLISHERW ) ||
1485 !strcmpW( szProperty, INSTALLPROPERTY_URLINFOABOUTW ) ||
1486 !strcmpW( szProperty, INSTALLPROPERTY_URLUPDATEINFOW ) ||
1487 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMINORW ) ||
1488 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONMAJORW ) ||
1489 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ) ||
1490 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTIDW ) ||
1491 !strcmpW( szProperty, INSTALLPROPERTY_REGCOMPANYW ) ||
1492 !strcmpW( szProperty, INSTALLPROPERTY_REGOWNERW ) ||
1493 !strcmpW( szProperty, INSTALLPROPERTY_INSTANCETYPEW ))
1495 val = msi_reg_get_value(props, package, &type);
1496 if (!val)
1498 if (prod || classes)
1499 r = ERROR_UNKNOWN_PROPERTY;
1501 goto done;
1504 msi_free(val);
1506 if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW ))
1507 szProperty = displayname;
1508 else if (!strcmpW( szProperty, INSTALLPROPERTY_VERSIONSTRINGW ))
1509 szProperty = displayversion;
1511 val = msi_reg_get_value(props, szProperty, &type);
1512 if (!val)
1513 val = strdupW(szEmpty);
1515 r = msi_copy_outval(val, szValue, pcchValue);
1517 else if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ) ||
1518 !strcmpW( szProperty, INSTALLPROPERTY_LANGUAGEW ) ||
1519 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTNAMEW ) ||
1520 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGECODEW ) ||
1521 !strcmpW( szProperty, INSTALLPROPERTY_VERSIONW ) ||
1522 !strcmpW( szProperty, INSTALLPROPERTY_PRODUCTICONW ) ||
1523 !strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ) ||
1524 !strcmpW( szProperty, INSTALLPROPERTY_AUTHORIZED_LUA_APPW ))
1526 if (!prod && !classes)
1527 goto done;
1529 if (dwContext == MSIINSTALLCONTEXT_USERUNMANAGED)
1530 hkey = prod;
1531 else if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1532 hkey = managed;
1533 else if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1534 hkey = classes;
1536 val = msi_reg_get_value(hkey, szProperty, &type);
1537 if (!val)
1538 val = strdupW(szEmpty);
1540 r = msi_copy_outval(val, szValue, pcchValue);
1542 else if (!strcmpW( szProperty, INSTALLPROPERTY_PRODUCTSTATEW ))
1544 if (dwContext == MSIINSTALLCONTEXT_MACHINE)
1546 if (props)
1548 val = msi_reg_get_value(props, package, &type);
1549 if (!val)
1550 goto done;
1552 msi_free(val);
1553 val = strdupW(five);
1555 else
1556 val = strdupW(szOne);
1558 r = msi_copy_outval(val, szValue, pcchValue);
1559 goto done;
1561 else if (props && (val = msi_reg_get_value(props, package, &type)))
1563 msi_free(val);
1564 val = strdupW(five);
1565 r = msi_copy_outval(val, szValue, pcchValue);
1566 goto done;
1569 if (prod || managed)
1570 val = strdupW(szOne);
1571 else
1572 goto done;
1574 r = msi_copy_outval(val, szValue, pcchValue);
1576 else if (!strcmpW( szProperty, INSTALLPROPERTY_ASSIGNMENTTYPEW ))
1578 if (!prod && !classes)
1579 goto done;
1581 /* FIXME */
1582 val = strdupW(szEmpty);
1583 r = msi_copy_outval(val, szValue, pcchValue);
1585 else
1586 r = ERROR_UNKNOWN_PROPERTY;
1588 done:
1589 RegCloseKey(props);
1590 RegCloseKey(prod);
1591 RegCloseKey(managed);
1592 RegCloseKey(classes);
1593 msi_free(val);
1595 return r;
1598 UINT WINAPI MsiGetPatchInfoExA(LPCSTR szPatchCode, LPCSTR szProductCode,
1599 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1600 LPCSTR szProperty, LPSTR lpValue, DWORD *pcchValue)
1602 LPWSTR patch = NULL, product = NULL, usersid = NULL;
1603 LPWSTR property = NULL, val = NULL;
1604 DWORD len;
1605 UINT r;
1607 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode),
1608 debugstr_a(szProductCode), debugstr_a(szUserSid), dwContext,
1609 debugstr_a(szProperty), lpValue, pcchValue);
1611 if (lpValue && !pcchValue)
1612 return ERROR_INVALID_PARAMETER;
1614 if (szPatchCode) patch = strdupAtoW(szPatchCode);
1615 if (szProductCode) product = strdupAtoW(szProductCode);
1616 if (szUserSid) usersid = strdupAtoW(szUserSid);
1617 if (szProperty) property = strdupAtoW(szProperty);
1619 len = 0;
1620 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1621 NULL, &len);
1622 if (r != ERROR_SUCCESS)
1623 goto done;
1625 val = msi_alloc(++len * sizeof(WCHAR));
1626 if (!val)
1628 r = ERROR_OUTOFMEMORY;
1629 goto done;
1632 r = MsiGetPatchInfoExW(patch, product, usersid, dwContext, property,
1633 val, &len);
1634 if (r != ERROR_SUCCESS || !pcchValue)
1635 goto done;
1637 if (lpValue)
1638 WideCharToMultiByte(CP_ACP, 0, val, -1, lpValue,
1639 *pcchValue - 1, NULL, NULL);
1641 len = lstrlenW(val);
1642 if ((*val && *pcchValue < len + 1) || !lpValue)
1644 if (lpValue)
1646 r = ERROR_MORE_DATA;
1647 lpValue[*pcchValue - 1] = '\0';
1650 *pcchValue = len * sizeof(WCHAR);
1652 else
1653 *pcchValue = len;
1655 done:
1656 msi_free(val);
1657 msi_free(patch);
1658 msi_free(product);
1659 msi_free(usersid);
1660 msi_free(property);
1662 return r;
1665 UINT WINAPI MsiGetPatchInfoExW(LPCWSTR szPatchCode, LPCWSTR szProductCode,
1666 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
1667 LPCWSTR szProperty, LPWSTR lpValue, DWORD *pcchValue)
1669 static const WCHAR szManagedPackage[] =
1670 {'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
1671 WCHAR *val = NULL, squashed_pc[SQUASHED_GUID_SIZE], squashed_patch[SQUASHED_GUID_SIZE];
1672 HKEY udprod = 0, prod = 0, props = 0;
1673 HKEY patch = 0, patches = 0;
1674 HKEY udpatch = 0, datakey = 0;
1675 HKEY prodpatches = 0;
1676 UINT r = ERROR_UNKNOWN_PRODUCT;
1677 DWORD len;
1678 LONG res;
1680 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode),
1681 debugstr_w(szProductCode), debugstr_w(szUserSid), dwContext,
1682 debugstr_w(szProperty), lpValue, pcchValue);
1684 if (!szProductCode || !squash_guid( szProductCode, squashed_pc ))
1685 return ERROR_INVALID_PARAMETER;
1687 if (!szPatchCode || !squash_guid( szPatchCode, squashed_patch ))
1688 return ERROR_INVALID_PARAMETER;
1690 if (!szProperty)
1691 return ERROR_INVALID_PARAMETER;
1693 if (lpValue && !pcchValue)
1694 return ERROR_INVALID_PARAMETER;
1696 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
1697 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
1698 dwContext != MSIINSTALLCONTEXT_MACHINE)
1699 return ERROR_INVALID_PARAMETER;
1701 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
1702 return ERROR_INVALID_PARAMETER;
1704 if (szUserSid && !strcmpW( szUserSid, szLocalSid ))
1705 return ERROR_INVALID_PARAMETER;
1707 if (MSIREG_OpenUserDataProductKey(szProductCode, dwContext, NULL,
1708 &udprod, FALSE) != ERROR_SUCCESS)
1709 goto done;
1711 if (MSIREG_OpenInstallProps(szProductCode, dwContext, NULL,
1712 &props, FALSE) != ERROR_SUCCESS)
1713 goto done;
1715 r = ERROR_UNKNOWN_PATCH;
1717 res = RegOpenKeyExW(udprod, szPatches, 0, KEY_WOW64_64KEY|KEY_READ, &patches);
1718 if (res != ERROR_SUCCESS)
1719 goto done;
1721 res = RegOpenKeyExW( patches, squashed_patch, 0, KEY_WOW64_64KEY|KEY_READ, &patch );
1722 if (res != ERROR_SUCCESS)
1723 goto done;
1725 if (!strcmpW( szProperty, INSTALLPROPERTY_TRANSFORMSW ))
1727 if (MSIREG_OpenProductKey(szProductCode, NULL, dwContext,
1728 &prod, FALSE) != ERROR_SUCCESS)
1729 goto done;
1731 res = RegOpenKeyExW(prod, szPatches, 0, KEY_WOW64_64KEY|KEY_ALL_ACCESS, &prodpatches);
1732 if (res != ERROR_SUCCESS)
1733 goto done;
1735 datakey = prodpatches;
1736 szProperty = squashed_patch;
1738 else
1740 if (MSIREG_OpenUserDataPatchKey(szPatchCode, dwContext,
1741 &udpatch, FALSE) != ERROR_SUCCESS)
1742 goto done;
1744 if (!strcmpW( szProperty, INSTALLPROPERTY_LOCALPACKAGEW ))
1746 if (dwContext == MSIINSTALLCONTEXT_USERMANAGED)
1747 szProperty = szManagedPackage;
1748 datakey = udpatch;
1750 else if (!strcmpW( szProperty, INSTALLPROPERTY_INSTALLDATEW ))
1752 datakey = patch;
1753 szProperty = szInstalled;
1755 else if (!strcmpW( szProperty, INSTALLPROPERTY_UNINSTALLABLEW ) ||
1756 !strcmpW( szProperty, INSTALLPROPERTY_PATCHSTATEW ) ||
1757 !strcmpW( szProperty, INSTALLPROPERTY_DISPLAYNAMEW ) ||
1758 !strcmpW( szProperty, INSTALLPROPERTY_MOREINFOURLW ))
1760 datakey = patch;
1762 else
1764 r = ERROR_UNKNOWN_PROPERTY;
1765 goto done;
1769 val = msi_reg_get_val_str(datakey, szProperty);
1770 if (!val)
1771 val = strdupW(szEmpty);
1773 r = ERROR_SUCCESS;
1775 if (!pcchValue)
1776 goto done;
1778 if (lpValue)
1779 lstrcpynW(lpValue, val, *pcchValue);
1781 len = lstrlenW(val);
1782 if ((*val && *pcchValue < len + 1) || !lpValue)
1784 if (lpValue)
1785 r = ERROR_MORE_DATA;
1787 *pcchValue = len * sizeof(WCHAR);
1790 *pcchValue = len;
1792 done:
1793 msi_free(val);
1794 RegCloseKey(prodpatches);
1795 RegCloseKey(prod);
1796 RegCloseKey(patch);
1797 RegCloseKey(patches);
1798 RegCloseKey(udpatch);
1799 RegCloseKey(props);
1800 RegCloseKey(udprod);
1802 return r;
1805 UINT WINAPI MsiGetPatchInfoA( LPCSTR patch, LPCSTR attr, LPSTR buffer, LPDWORD buflen )
1807 UINT r = ERROR_OUTOFMEMORY;
1808 DWORD size;
1809 LPWSTR patchW = NULL, attrW = NULL, bufferW = NULL;
1811 TRACE("%s %s %p %p\n", debugstr_a(patch), debugstr_a(attr), buffer, buflen);
1813 if (!patch || !attr)
1814 return ERROR_INVALID_PARAMETER;
1816 if (!(patchW = strdupAtoW( patch )))
1817 goto done;
1819 if (!(attrW = strdupAtoW( attr )))
1820 goto done;
1822 size = 0;
1823 r = MsiGetPatchInfoW( patchW, attrW, NULL, &size );
1824 if (r != ERROR_SUCCESS)
1825 goto done;
1827 size++;
1828 if (!(bufferW = msi_alloc( size * sizeof(WCHAR) )))
1830 r = ERROR_OUTOFMEMORY;
1831 goto done;
1834 r = MsiGetPatchInfoW( patchW, attrW, bufferW, &size );
1835 if (r == ERROR_SUCCESS)
1837 int len = WideCharToMultiByte( CP_ACP, 0, bufferW, -1, NULL, 0, NULL, NULL );
1838 if (len > *buflen)
1839 r = ERROR_MORE_DATA;
1840 else if (buffer)
1841 WideCharToMultiByte( CP_ACP, 0, bufferW, -1, buffer, *buflen, NULL, NULL );
1843 *buflen = len - 1;
1846 done:
1847 msi_free( patchW );
1848 msi_free( attrW );
1849 msi_free( bufferW );
1850 return r;
1853 UINT WINAPI MsiGetPatchInfoW( LPCWSTR patch, LPCWSTR attr, LPWSTR buffer, LPDWORD buflen )
1855 UINT r;
1856 WCHAR product[GUID_SIZE];
1857 DWORD index;
1859 TRACE("%s %s %p %p\n", debugstr_w(patch), debugstr_w(attr), buffer, buflen);
1861 if (!patch || !attr)
1862 return ERROR_INVALID_PARAMETER;
1864 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW, attr ))
1865 return ERROR_UNKNOWN_PROPERTY;
1867 index = 0;
1868 while (1)
1870 r = MsiEnumProductsW( index, product );
1871 if (r != ERROR_SUCCESS)
1872 break;
1874 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERMANAGED, attr, buffer, buflen );
1875 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1876 return r;
1878 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, attr, buffer, buflen );
1879 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1880 return r;
1882 r = MsiGetPatchInfoExW( patch, product, NULL, MSIINSTALLCONTEXT_MACHINE, attr, buffer, buflen );
1883 if (r == ERROR_SUCCESS || r == ERROR_MORE_DATA)
1884 return r;
1886 index++;
1889 return ERROR_UNKNOWN_PRODUCT;
1892 UINT WINAPI MsiEnableLogA(DWORD dwLogMode, LPCSTR szLogFile, DWORD attributes)
1894 LPWSTR szwLogFile = NULL;
1895 UINT r;
1897 TRACE("%08x %s %08x\n", dwLogMode, debugstr_a(szLogFile), attributes);
1899 if( szLogFile )
1901 szwLogFile = strdupAtoW( szLogFile );
1902 if( !szwLogFile )
1903 return ERROR_OUTOFMEMORY;
1905 r = MsiEnableLogW( dwLogMode, szwLogFile, attributes );
1906 msi_free( szwLogFile );
1907 return r;
1910 UINT WINAPI MsiEnableLogW(DWORD dwLogMode, LPCWSTR szLogFile, DWORD attributes)
1912 TRACE("%08x %s %08x\n", dwLogMode, debugstr_w(szLogFile), attributes);
1914 msi_free(gszLogFile);
1915 gszLogFile = NULL;
1916 if (szLogFile)
1918 HANDLE file;
1920 if (!(attributes & INSTALLLOGATTRIBUTES_APPEND))
1921 DeleteFileW(szLogFile);
1922 file = CreateFileW(szLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
1923 FILE_ATTRIBUTE_NORMAL, NULL);
1924 if (file != INVALID_HANDLE_VALUE)
1926 gszLogFile = strdupW(szLogFile);
1927 CloseHandle(file);
1929 else
1930 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile), GetLastError());
1933 return ERROR_SUCCESS;
1936 UINT WINAPI MsiEnumComponentCostsA( MSIHANDLE handle, LPCSTR component, DWORD index,
1937 INSTALLSTATE state, LPSTR drive, DWORD *buflen,
1938 int *cost, int *temp )
1940 UINT r;
1941 DWORD len;
1942 WCHAR *driveW, *componentW = NULL;
1944 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_a(component), index,
1945 state, drive, buflen, cost, temp);
1947 if (!drive || !buflen) return ERROR_INVALID_PARAMETER;
1948 if (component && !(componentW = strdupAtoW( component ))) return ERROR_OUTOFMEMORY;
1950 len = *buflen;
1951 if (!(driveW = msi_alloc( len * sizeof(WCHAR) )))
1953 msi_free( componentW );
1954 return ERROR_OUTOFMEMORY;
1956 r = MsiEnumComponentCostsW( handle, componentW, index, state, driveW, buflen, cost, temp );
1957 if (!r)
1959 WideCharToMultiByte( CP_ACP, 0, driveW, -1, drive, len, NULL, NULL );
1961 msi_free( componentW );
1962 msi_free( driveW );
1963 return r;
1966 static UINT set_drive( WCHAR *buffer, WCHAR letter )
1968 buffer[0] = letter;
1969 buffer[1] = ':';
1970 buffer[2] = 0;
1971 return 2;
1974 UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, LPCWSTR component, DWORD index,
1975 INSTALLSTATE state, LPWSTR drive, DWORD *buflen,
1976 int *cost, int *temp )
1978 UINT r = ERROR_NO_MORE_ITEMS;
1979 MSICOMPONENT *comp = NULL;
1980 MSIPACKAGE *package;
1981 MSIFILE *file;
1982 STATSTG stat = {0};
1983 WCHAR path[MAX_PATH];
1985 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle, debugstr_w(component), index,
1986 state, drive, buflen, cost, temp);
1988 if (!drive || !buflen || !cost || !temp) return ERROR_INVALID_PARAMETER;
1989 if (!(package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE )))
1991 HRESULT hr;
1992 IWineMsiRemotePackage *remote_package;
1993 BSTR bname = NULL;
1995 if (!(remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle )))
1996 return ERROR_INVALID_HANDLE;
1998 if (component && !(bname = SysAllocString( component )))
2000 IWineMsiRemotePackage_Release( remote_package );
2001 return ERROR_OUTOFMEMORY;
2003 hr = IWineMsiRemotePackage_EnumComponentCosts( remote_package, bname, index, state, drive, buflen, cost, temp );
2004 IWineMsiRemotePackage_Release( remote_package );
2005 SysFreeString( bname );
2006 if (FAILED(hr))
2008 if (HRESULT_FACILITY(hr) == FACILITY_WIN32) return HRESULT_CODE(hr);
2009 return ERROR_FUNCTION_FAILED;
2011 return ERROR_SUCCESS;
2014 if (!msi_get_property_int( package->db, szCostingComplete, 0 ))
2016 msiobj_release( &package->hdr );
2017 return ERROR_FUNCTION_NOT_CALLED;
2019 if (component && component[0] && !(comp = msi_get_loaded_component( package, component )))
2021 msiobj_release( &package->hdr );
2022 return ERROR_UNKNOWN_COMPONENT;
2024 if (*buflen < 3)
2026 *buflen = 2;
2027 msiobj_release( &package->hdr );
2028 return ERROR_MORE_DATA;
2030 if (index)
2032 msiobj_release( &package->hdr );
2033 return ERROR_NO_MORE_ITEMS;
2036 drive[0] = 0;
2037 *cost = *temp = 0;
2038 GetWindowsDirectoryW( path, MAX_PATH );
2039 if (component && component[0])
2041 if (msi_is_global_assembly( comp )) *temp = comp->Cost;
2042 if (!comp->Enabled || !comp->KeyPath)
2044 *cost = 0;
2045 *buflen = set_drive( drive, path[0] );
2046 r = ERROR_SUCCESS;
2048 else if ((file = msi_get_loaded_file( package, comp->KeyPath )))
2050 *cost = max( 8, comp->Cost / 512 );
2051 *buflen = set_drive( drive, file->TargetPath[0] );
2052 r = ERROR_SUCCESS;
2055 else if (IStorage_Stat( package->db->storage, &stat, STATFLAG_NONAME ) == S_OK)
2057 *temp = max( 8, stat.cbSize.QuadPart / 512 );
2058 *buflen = set_drive( drive, path[0] );
2059 r = ERROR_SUCCESS;
2061 msiobj_release( &package->hdr );
2062 return r;
2065 UINT WINAPI MsiQueryComponentStateA(LPCSTR szProductCode,
2066 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2067 LPCSTR szComponent, INSTALLSTATE *pdwState)
2069 LPWSTR prodcode = NULL, usersid = NULL, comp = NULL;
2070 UINT r;
2072 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode),
2073 debugstr_a(szUserSid), dwContext, debugstr_a(szComponent), pdwState);
2075 if (szProductCode && !(prodcode = strdupAtoW(szProductCode)))
2076 return ERROR_OUTOFMEMORY;
2078 if (szUserSid && !(usersid = strdupAtoW(szUserSid)))
2079 return ERROR_OUTOFMEMORY;
2081 if (szComponent && !(comp = strdupAtoW(szComponent)))
2082 return ERROR_OUTOFMEMORY;
2084 r = MsiQueryComponentStateW(prodcode, usersid, dwContext, comp, pdwState);
2086 msi_free(prodcode);
2087 msi_free(usersid);
2088 msi_free(comp);
2090 return r;
2093 static BOOL msi_comp_find_prod_key(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
2095 UINT r;
2096 HKEY hkey = NULL;
2098 r = MSIREG_OpenProductKey(prodcode, NULL, context, &hkey, FALSE);
2099 RegCloseKey(hkey);
2100 return (r == ERROR_SUCCESS);
2103 static BOOL msi_comp_find_package(LPCWSTR prodcode, MSIINSTALLCONTEXT context)
2105 LPCWSTR package;
2106 HKEY hkey;
2107 DWORD sz;
2108 LONG res;
2109 UINT r;
2111 static const WCHAR local_package[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
2112 static const WCHAR managed_local_package[] = {
2113 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
2116 r = MSIREG_OpenInstallProps(prodcode, context, NULL, &hkey, FALSE);
2117 if (r != ERROR_SUCCESS)
2118 return FALSE;
2120 if (context == MSIINSTALLCONTEXT_USERMANAGED)
2121 package = managed_local_package;
2122 else
2123 package = local_package;
2125 sz = 0;
2126 res = RegQueryValueExW(hkey, package, NULL, NULL, NULL, &sz);
2127 RegCloseKey(hkey);
2129 return (res == ERROR_SUCCESS);
2132 static UINT msi_comp_find_prodcode(WCHAR *squashed_pc,
2133 MSIINSTALLCONTEXT context,
2134 LPCWSTR comp, LPWSTR val, DWORD *sz)
2136 HKEY hkey;
2137 LONG res;
2138 UINT r;
2140 if (context == MSIINSTALLCONTEXT_MACHINE)
2141 r = MSIREG_OpenUserDataComponentKey(comp, szLocalSid, &hkey, FALSE);
2142 else
2143 r = MSIREG_OpenUserDataComponentKey(comp, NULL, &hkey, FALSE);
2145 if (r != ERROR_SUCCESS)
2146 return r;
2148 res = RegQueryValueExW( hkey, squashed_pc, NULL, NULL, (BYTE *)val, sz );
2149 if (res != ERROR_SUCCESS)
2150 return res;
2152 RegCloseKey(hkey);
2153 return res;
2156 UINT WINAPI MsiQueryComponentStateW(LPCWSTR szProductCode,
2157 LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
2158 LPCWSTR szComponent, INSTALLSTATE *pdwState)
2160 WCHAR squashed_pc[SQUASHED_GUID_SIZE];
2161 BOOL found;
2162 DWORD sz;
2164 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode),
2165 debugstr_w(szUserSid), dwContext, debugstr_w(szComponent), pdwState);
2167 if (!pdwState || !szComponent)
2168 return ERROR_INVALID_PARAMETER;
2170 if (!szProductCode || !*szProductCode || lstrlenW(szProductCode) != GUID_SIZE - 1)
2171 return ERROR_INVALID_PARAMETER;
2173 if (!squash_guid( szProductCode, squashed_pc ))
2174 return ERROR_INVALID_PARAMETER;
2176 found = msi_comp_find_prod_key(szProductCode, dwContext);
2178 if (!msi_comp_find_package(szProductCode, dwContext))
2180 if (found)
2182 *pdwState = INSTALLSTATE_UNKNOWN;
2183 return ERROR_UNKNOWN_COMPONENT;
2186 return ERROR_UNKNOWN_PRODUCT;
2189 *pdwState = INSTALLSTATE_UNKNOWN;
2191 sz = 0;
2192 if (msi_comp_find_prodcode( squashed_pc, dwContext, szComponent, NULL, &sz ))
2193 return ERROR_UNKNOWN_COMPONENT;
2195 if (sz == 0)
2196 *pdwState = INSTALLSTATE_NOTUSED;
2197 else
2199 WCHAR *val;
2200 UINT r;
2202 if (!(val = msi_alloc( sz ))) return ERROR_OUTOFMEMORY;
2203 if ((r = msi_comp_find_prodcode( squashed_pc, dwContext, szComponent, val, &sz )))
2205 msi_free(val);
2206 return r;
2209 if (lstrlenW(val) > 2 &&
2210 val[0] >= '0' && val[0] <= '9' && val[1] >= '0' && val[1] <= '9' && val[2] != ':')
2212 *pdwState = INSTALLSTATE_SOURCE;
2214 else
2215 *pdwState = INSTALLSTATE_LOCAL;
2216 msi_free( val );
2219 TRACE("-> %d\n", *pdwState);
2220 return ERROR_SUCCESS;
2223 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
2225 LPWSTR szwProduct = NULL;
2226 INSTALLSTATE r;
2228 if( szProduct )
2230 szwProduct = strdupAtoW( szProduct );
2231 if( !szwProduct )
2232 return ERROR_OUTOFMEMORY;
2234 r = MsiQueryProductStateW( szwProduct );
2235 msi_free( szwProduct );
2236 return r;
2239 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
2241 MSIINSTALLCONTEXT context = MSIINSTALLCONTEXT_USERUNMANAGED;
2242 INSTALLSTATE state = INSTALLSTATE_ADVERTISED;
2243 HKEY prodkey = 0, userdata = 0;
2244 DWORD val;
2245 UINT r;
2247 TRACE("%s\n", debugstr_w(szProduct));
2249 if (!szProduct || !*szProduct)
2250 return INSTALLSTATE_INVALIDARG;
2252 if (lstrlenW(szProduct) != GUID_SIZE - 1)
2253 return INSTALLSTATE_INVALIDARG;
2255 if (szProduct[0] != '{' || szProduct[37] != '}')
2256 return INSTALLSTATE_UNKNOWN;
2258 SetLastError( ERROR_SUCCESS );
2260 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
2261 &prodkey, FALSE) != ERROR_SUCCESS &&
2262 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
2263 &prodkey, FALSE) != ERROR_SUCCESS &&
2264 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2265 &prodkey, FALSE) == ERROR_SUCCESS)
2267 context = MSIINSTALLCONTEXT_MACHINE;
2270 r = MSIREG_OpenInstallProps(szProduct, context, NULL, &userdata, FALSE);
2271 if (r != ERROR_SUCCESS)
2272 goto done;
2274 if (!msi_reg_get_val_dword(userdata, szWindowsInstaller, &val))
2275 goto done;
2277 if (val)
2278 state = INSTALLSTATE_DEFAULT;
2279 else
2280 state = INSTALLSTATE_UNKNOWN;
2282 done:
2283 if (!prodkey)
2285 state = INSTALLSTATE_UNKNOWN;
2287 if (userdata)
2288 state = INSTALLSTATE_ABSENT;
2291 RegCloseKey(prodkey);
2292 RegCloseKey(userdata);
2293 TRACE("-> %d\n", state);
2294 return state;
2297 INSTALLUILEVEL WINAPI MsiSetInternalUI(INSTALLUILEVEL dwUILevel, HWND *phWnd)
2299 INSTALLUILEVEL old = gUILevel;
2300 HWND oldwnd = gUIhwnd;
2302 TRACE("%08x %p\n", dwUILevel, phWnd);
2304 gUILevel = dwUILevel;
2305 if (phWnd)
2307 gUIhwnd = *phWnd;
2308 *phWnd = oldwnd;
2310 return old;
2313 INSTALLUI_HANDLERA WINAPI MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler,
2314 DWORD dwMessageFilter, LPVOID pvContext)
2316 INSTALLUI_HANDLERA prev = gUIHandlerA;
2318 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2320 gUIHandlerA = puiHandler;
2321 gUIHandlerW = NULL;
2322 gUIFilter = dwMessageFilter;
2323 gUIContext = pvContext;
2325 return prev;
2328 INSTALLUI_HANDLERW WINAPI MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler,
2329 DWORD dwMessageFilter, LPVOID pvContext)
2331 INSTALLUI_HANDLERW prev = gUIHandlerW;
2333 TRACE("%p %08x %p\n", puiHandler, dwMessageFilter, pvContext);
2335 gUIHandlerA = NULL;
2336 gUIHandlerW = puiHandler;
2337 gUIFilter = dwMessageFilter;
2338 gUIContext = pvContext;
2340 return prev;
2343 /******************************************************************
2344 * MsiLoadStringW [MSI.@]
2346 * Loads a string from MSI's string resources.
2348 * PARAMS
2350 * handle [I] only -1 is handled currently
2351 * id [I] id of the string to be loaded
2352 * lpBuffer [O] buffer for the string to be written to
2353 * nBufferMax [I] maximum size of the buffer in characters
2354 * lang [I] the preferred language for the string
2356 * RETURNS
2358 * If successful, this function returns the language id of the string loaded
2359 * If the function fails, the function returns zero.
2361 * NOTES
2363 * The type of the first parameter is unknown. LoadString's prototype
2364 * suggests that it might be a module handle. I have made it an MSI handle
2365 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2366 * handle. Maybe strings can be stored in an MSI database somehow.
2368 LANGID WINAPI MsiLoadStringW( MSIHANDLE handle, UINT id, LPWSTR lpBuffer,
2369 int nBufferMax, LANGID lang )
2371 HRSRC hres;
2372 HGLOBAL hResData;
2373 LPWSTR p;
2374 DWORD i, len;
2376 TRACE("%d %u %p %d %d\n", handle, id, lpBuffer, nBufferMax, lang);
2378 if( handle != -1 )
2379 FIXME("don't know how to deal with handle = %08x\n", handle);
2381 if( !lang )
2382 lang = GetUserDefaultLangID();
2384 hres = FindResourceExW( msi_hInstance, (LPCWSTR) RT_STRING,
2385 (LPWSTR)1, lang );
2386 if( !hres )
2387 return 0;
2388 hResData = LoadResource( msi_hInstance, hres );
2389 if( !hResData )
2390 return 0;
2391 p = LockResource( hResData );
2392 if( !p )
2393 return 0;
2395 for (i = 0; i < (id & 0xf); i++) p += *p + 1;
2396 len = *p;
2398 if( nBufferMax <= len )
2399 return 0;
2401 memcpy( lpBuffer, p+1, len * sizeof(WCHAR));
2402 lpBuffer[ len ] = 0;
2404 TRACE("found -> %s\n", debugstr_w(lpBuffer));
2405 return lang;
2408 LANGID WINAPI MsiLoadStringA( MSIHANDLE handle, UINT id, LPSTR lpBuffer,
2409 int nBufferMax, LANGID lang )
2411 LPWSTR bufW;
2412 LANGID r;
2413 INT len;
2415 bufW = msi_alloc(nBufferMax*sizeof(WCHAR));
2416 r = MsiLoadStringW(handle, id, bufW, nBufferMax, lang);
2417 if( r )
2419 len = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
2420 if( len <= nBufferMax )
2421 WideCharToMultiByte( CP_ACP, 0, bufW, -1,
2422 lpBuffer, nBufferMax, NULL, NULL );
2423 else
2424 r = 0;
2426 msi_free(bufW);
2427 return r;
2430 INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf,
2431 LPDWORD pcchBuf)
2433 char szProduct[GUID_SIZE];
2435 TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf);
2437 if (!szComponent || !pcchBuf)
2438 return INSTALLSTATE_INVALIDARG;
2440 if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS)
2441 return INSTALLSTATE_UNKNOWN;
2443 return MsiGetComponentPathA( szProduct, szComponent, lpPathBuf, pcchBuf );
2446 INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf,
2447 LPDWORD pcchBuf)
2449 WCHAR szProduct[GUID_SIZE];
2451 TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf);
2453 if (!szComponent || !pcchBuf)
2454 return INSTALLSTATE_INVALIDARG;
2456 if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS)
2457 return INSTALLSTATE_UNKNOWN;
2459 return MsiGetComponentPathW( szProduct, szComponent, lpPathBuf, pcchBuf );
2462 UINT WINAPI MsiMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2463 WORD wLanguageId, DWORD f)
2465 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_a(lpText), debugstr_a(lpCaption),
2466 uType, wLanguageId, f);
2467 return MessageBoxExA(hWnd,lpText,lpCaption,uType,wLanguageId);
2470 UINT WINAPI MsiMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2471 WORD wLanguageId, DWORD f)
2473 FIXME("%p %s %s %u %08x %08x\n", hWnd, debugstr_w(lpText), debugstr_w(lpCaption),
2474 uType, wLanguageId, f);
2475 return MessageBoxExW(hWnd,lpText,lpCaption,uType,wLanguageId);
2478 UINT WINAPI MsiMessageBoxExA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType,
2479 DWORD unknown, WORD wLanguageId, DWORD f)
2481 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_a(lpText),
2482 debugstr_a(lpCaption), uType, unknown, wLanguageId, f);
2483 return MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId);
2486 UINT WINAPI MsiMessageBoxExW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType,
2487 DWORD unknown, WORD wLanguageId, DWORD f)
2489 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd, debugstr_w(lpText),
2490 debugstr_w(lpCaption), uType, unknown, wLanguageId, f);
2491 return MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId);
2494 UINT WINAPI MsiProvideAssemblyA( LPCSTR szAssemblyName, LPCSTR szAppContext,
2495 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPSTR lpPathBuf,
2496 LPDWORD pcchPathBuf )
2498 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName),
2499 debugstr_a(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2500 pcchPathBuf);
2501 return ERROR_CALL_NOT_IMPLEMENTED;
2504 UINT WINAPI MsiProvideAssemblyW( LPCWSTR szAssemblyName, LPCWSTR szAppContext,
2505 DWORD dwInstallMode, DWORD dwAssemblyInfo, LPWSTR lpPathBuf,
2506 LPDWORD pcchPathBuf )
2508 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName),
2509 debugstr_w(szAppContext), dwInstallMode, dwAssemblyInfo, lpPathBuf,
2510 pcchPathBuf);
2511 return ERROR_CALL_NOT_IMPLEMENTED;
2514 UINT WINAPI MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor,
2515 LPSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2517 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor), szPath, pcchPath, pcchArgs );
2518 return ERROR_CALL_NOT_IMPLEMENTED;
2521 UINT WINAPI MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor,
2522 LPWSTR szPath, LPDWORD pcchPath, LPDWORD pcchArgs )
2524 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor), szPath, pcchPath, pcchArgs );
2525 return ERROR_CALL_NOT_IMPLEMENTED;
2528 HRESULT WINAPI MsiGetFileSignatureInformationA( LPCSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2529 LPBYTE hash, LPDWORD hashlen )
2531 UINT r;
2532 WCHAR *pathW = NULL;
2534 TRACE("%s %08x %p %p %p\n", debugstr_a(path), flags, cert, hash, hashlen);
2536 if (path && !(pathW = strdupAtoW( path ))) return E_OUTOFMEMORY;
2537 r = MsiGetFileSignatureInformationW( pathW, flags, cert, hash, hashlen );
2538 msi_free( pathW );
2539 return r;
2542 HRESULT WINAPI MsiGetFileSignatureInformationW( LPCWSTR path, DWORD flags, PCCERT_CONTEXT *cert,
2543 LPBYTE hash, LPDWORD hashlen )
2545 static GUID generic_verify_v2 = WINTRUST_ACTION_GENERIC_VERIFY_V2;
2546 HRESULT hr;
2547 WINTRUST_DATA data;
2548 WINTRUST_FILE_INFO info;
2549 CRYPT_PROVIDER_SGNR *signer;
2550 CRYPT_PROVIDER_CERT *provider;
2552 TRACE("%s %08x %p %p %p\n", debugstr_w(path), flags, cert, hash, hashlen);
2554 if (!path || !cert) return E_INVALIDARG;
2556 info.cbStruct = sizeof(info);
2557 info.pcwszFilePath = path;
2558 info.hFile = NULL;
2559 info.pgKnownSubject = NULL;
2561 data.cbStruct = sizeof(data);
2562 data.pPolicyCallbackData = NULL;
2563 data.pSIPClientData = NULL;
2564 data.dwUIChoice = WTD_UI_NONE;
2565 data.fdwRevocationChecks = WTD_REVOKE_WHOLECHAIN;
2566 data.dwUnionChoice = WTD_CHOICE_FILE;
2567 data.u.pFile = &info;
2568 data.dwStateAction = WTD_STATEACTION_VERIFY;
2569 data.hWVTStateData = NULL;
2570 data.pwszURLReference = NULL;
2571 data.dwProvFlags = 0;
2572 data.dwUIContext = WTD_UICONTEXT_INSTALL;
2573 hr = WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2574 *cert = NULL;
2575 if (FAILED(hr)) goto done;
2577 if (!(signer = WTHelperGetProvSignerFromChain( data.hWVTStateData, 0, FALSE, 0 )))
2579 hr = TRUST_E_NOSIGNATURE;
2580 goto done;
2582 if (hash)
2584 DWORD len = signer->psSigner->EncryptedHash.cbData;
2585 if (*hashlen < len)
2587 *hashlen = len;
2588 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
2589 goto done;
2591 memcpy( hash, signer->psSigner->EncryptedHash.pbData, len );
2592 *hashlen = len;
2594 if (!(provider = WTHelperGetProvCertFromChain( signer, 0 )))
2596 hr = TRUST_E_PROVIDER_UNKNOWN;
2597 goto done;
2599 *cert = CertDuplicateCertificateContext( provider->pCert );
2601 done:
2602 data.dwStateAction = WTD_STATEACTION_CLOSE;
2603 WinVerifyTrustEx( INVALID_HANDLE_VALUE, &generic_verify_v2, &data );
2604 return hr;
2607 /******************************************************************
2608 * MsiGetProductPropertyA [MSI.@]
2610 UINT WINAPI MsiGetProductPropertyA(MSIHANDLE hProduct, LPCSTR szProperty,
2611 LPSTR szValue, LPDWORD pccbValue)
2613 LPWSTR prop = NULL, val = NULL;
2614 DWORD len;
2615 UINT r;
2617 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_a(szProperty),
2618 szValue, pccbValue);
2620 if (szValue && !pccbValue)
2621 return ERROR_INVALID_PARAMETER;
2623 if (szProperty) prop = strdupAtoW(szProperty);
2625 len = 0;
2626 r = MsiGetProductPropertyW(hProduct, prop, NULL, &len);
2627 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2628 goto done;
2630 if (r == ERROR_SUCCESS)
2632 if (szValue) *szValue = '\0';
2633 if (pccbValue) *pccbValue = 0;
2634 goto done;
2637 val = msi_alloc(++len * sizeof(WCHAR));
2638 if (!val)
2640 r = ERROR_OUTOFMEMORY;
2641 goto done;
2644 r = MsiGetProductPropertyW(hProduct, prop, val, &len);
2645 if (r != ERROR_SUCCESS)
2646 goto done;
2648 len = WideCharToMultiByte(CP_ACP, 0, val, -1, NULL, 0, NULL, NULL);
2650 if (szValue)
2651 WideCharToMultiByte(CP_ACP, 0, val, -1, szValue,
2652 *pccbValue, NULL, NULL);
2654 if (pccbValue)
2656 if (len > *pccbValue)
2657 r = ERROR_MORE_DATA;
2659 *pccbValue = len - 1;
2662 done:
2663 msi_free(prop);
2664 msi_free(val);
2666 return r;
2669 /******************************************************************
2670 * MsiGetProductPropertyW [MSI.@]
2672 UINT WINAPI MsiGetProductPropertyW(MSIHANDLE hProduct, LPCWSTR szProperty,
2673 LPWSTR szValue, LPDWORD pccbValue)
2675 MSIPACKAGE *package;
2676 MSIQUERY *view = NULL;
2677 MSIRECORD *rec = NULL;
2678 LPCWSTR val;
2679 UINT r;
2681 static const WCHAR query[] = {
2682 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2683 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2684 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2686 TRACE("(%d, %s, %p, %p)\n", hProduct, debugstr_w(szProperty),
2687 szValue, pccbValue);
2689 if (!szProperty)
2690 return ERROR_INVALID_PARAMETER;
2692 if (szValue && !pccbValue)
2693 return ERROR_INVALID_PARAMETER;
2695 package = msihandle2msiinfo(hProduct, MSIHANDLETYPE_PACKAGE);
2696 if (!package)
2697 return ERROR_INVALID_HANDLE;
2699 r = MSI_OpenQuery(package->db, &view, query, szProperty);
2700 if (r != ERROR_SUCCESS)
2701 goto done;
2703 r = MSI_ViewExecute(view, 0);
2704 if (r != ERROR_SUCCESS)
2705 goto done;
2707 r = MSI_ViewFetch(view, &rec);
2708 if (r != ERROR_SUCCESS)
2709 goto done;
2711 val = MSI_RecordGetString(rec, 2);
2712 if (!val)
2713 goto done;
2715 if (lstrlenW(val) >= *pccbValue)
2717 if (szValue) lstrcpynW(szValue, val, *pccbValue);
2718 r = ERROR_MORE_DATA;
2720 else
2722 if (szValue) lstrcpyW(szValue, val);
2723 r = ERROR_SUCCESS;
2726 *pccbValue = lstrlenW(val);
2728 done:
2729 if (view)
2731 MSI_ViewClose(view);
2732 msiobj_release(&view->hdr);
2733 if (rec) msiobj_release(&rec->hdr);
2736 if (!rec)
2738 if (szValue) *szValue = '\0';
2739 if (pccbValue) *pccbValue = 0;
2740 r = ERROR_SUCCESS;
2743 msiobj_release(&package->hdr);
2744 return r;
2747 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
2749 UINT r;
2750 LPWSTR szPack = NULL;
2752 TRACE("%s\n", debugstr_a(szPackage) );
2754 if( szPackage )
2756 szPack = strdupAtoW( szPackage );
2757 if( !szPack )
2758 return ERROR_OUTOFMEMORY;
2761 r = MsiVerifyPackageW( szPack );
2763 msi_free( szPack );
2765 return r;
2768 UINT WINAPI MsiVerifyPackageW( LPCWSTR szPackage )
2770 MSIHANDLE handle;
2771 UINT r;
2773 TRACE("%s\n", debugstr_w(szPackage) );
2775 r = MsiOpenDatabaseW( szPackage, MSIDBOPEN_READONLY, &handle );
2776 MsiCloseHandle( handle );
2778 return r;
2781 static INSTALLSTATE MSI_GetComponentPath(LPCWSTR szProduct, LPCWSTR szComponent,
2782 awstring* lpPathBuf, LPDWORD pcchBuf)
2784 static const WCHAR wininstaller[] =
2785 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2786 WCHAR *path = NULL, squashed_pc[SQUASHED_GUID_SIZE], squashed_comp[SQUASHED_GUID_SIZE];
2787 HKEY hkey;
2788 INSTALLSTATE state;
2789 DWORD version;
2791 if (!szProduct || !szComponent)
2792 return INSTALLSTATE_INVALIDARG;
2794 if (lpPathBuf->str.w && !pcchBuf)
2795 return INSTALLSTATE_INVALIDARG;
2797 if (!squash_guid( szProduct, squashed_pc ) || !squash_guid( szComponent, squashed_comp ))
2798 return INSTALLSTATE_INVALIDARG;
2800 state = INSTALLSTATE_UNKNOWN;
2802 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2803 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2805 path = msi_reg_get_val_str( hkey, squashed_pc );
2806 RegCloseKey(hkey);
2808 state = INSTALLSTATE_ABSENT;
2810 if ((MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE, NULL,
2811 &hkey, FALSE) == ERROR_SUCCESS ||
2812 MSIREG_OpenUserDataProductKey(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
2813 NULL, &hkey, FALSE) == ERROR_SUCCESS) &&
2814 msi_reg_get_val_dword(hkey, wininstaller, &version) &&
2815 GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2817 RegCloseKey(hkey);
2818 state = INSTALLSTATE_LOCAL;
2822 if (state != INSTALLSTATE_LOCAL &&
2823 (MSIREG_OpenProductKey(szProduct, NULL,
2824 MSIINSTALLCONTEXT_USERUNMANAGED,
2825 &hkey, FALSE) == ERROR_SUCCESS ||
2826 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
2827 &hkey, FALSE) == ERROR_SUCCESS))
2829 RegCloseKey(hkey);
2831 if (MSIREG_OpenUserDataComponentKey(szComponent, szLocalSid, &hkey, FALSE) == ERROR_SUCCESS ||
2832 MSIREG_OpenUserDataComponentKey(szComponent, NULL, &hkey, FALSE) == ERROR_SUCCESS)
2834 msi_free(path);
2835 path = msi_reg_get_val_str( hkey, squashed_pc );
2836 RegCloseKey(hkey);
2838 state = INSTALLSTATE_ABSENT;
2840 if (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES)
2841 state = INSTALLSTATE_LOCAL;
2845 if (!path)
2846 return INSTALLSTATE_UNKNOWN;
2848 if (state == INSTALLSTATE_LOCAL && !*path)
2849 state = INSTALLSTATE_NOTUSED;
2851 if (msi_strcpy_to_awstring(path, -1, lpPathBuf, pcchBuf) == ERROR_MORE_DATA)
2852 state = INSTALLSTATE_MOREDATA;
2854 msi_free(path);
2855 return state;
2858 /******************************************************************
2859 * MsiGetComponentPathW [MSI.@]
2861 INSTALLSTATE WINAPI MsiGetComponentPathW(LPCWSTR szProduct, LPCWSTR szComponent,
2862 LPWSTR lpPathBuf, LPDWORD pcchBuf)
2864 awstring path;
2866 TRACE("%s %s %p %p\n", debugstr_w(szProduct), debugstr_w(szComponent), lpPathBuf, pcchBuf);
2868 path.unicode = TRUE;
2869 path.str.w = lpPathBuf;
2871 return MSI_GetComponentPath( szProduct, szComponent, &path, pcchBuf );
2874 /******************************************************************
2875 * MsiGetComponentPathA [MSI.@]
2877 INSTALLSTATE WINAPI MsiGetComponentPathA(LPCSTR szProduct, LPCSTR szComponent,
2878 LPSTR lpPathBuf, LPDWORD pcchBuf)
2880 LPWSTR szwProduct, szwComponent = NULL;
2881 INSTALLSTATE r = INSTALLSTATE_UNKNOWN;
2882 awstring path;
2884 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szComponent), lpPathBuf, pcchBuf);
2886 szwProduct = strdupAtoW( szProduct );
2887 if( szProduct && !szwProduct)
2888 goto end;
2890 szwComponent = strdupAtoW( szComponent );
2891 if( szComponent && !szwComponent )
2892 goto end;
2894 path.unicode = FALSE;
2895 path.str.a = lpPathBuf;
2897 r = MSI_GetComponentPath( szwProduct, szwComponent, &path, pcchBuf );
2899 end:
2900 msi_free( szwProduct );
2901 msi_free( szwComponent );
2903 return r;
2906 static UINT query_feature_state( const WCHAR *product, const WCHAR *squashed, const WCHAR *usersid,
2907 MSIINSTALLCONTEXT ctx, const WCHAR *feature, INSTALLSTATE *state )
2909 UINT r;
2910 HKEY hkey;
2911 WCHAR *parent, *components, *path;
2912 const WCHAR *p;
2913 BOOL missing = FALSE, source = FALSE;
2914 WCHAR comp[GUID_SIZE];
2915 GUID guid;
2917 if (ctx != MSIINSTALLCONTEXT_MACHINE) SetLastError( ERROR_SUCCESS );
2919 if (MSIREG_OpenFeaturesKey( product, usersid, ctx, &hkey, FALSE )) return ERROR_UNKNOWN_PRODUCT;
2921 parent = msi_reg_get_val_str( hkey, feature );
2922 RegCloseKey( hkey );
2923 if (!parent) return ERROR_UNKNOWN_FEATURE;
2925 *state = (parent[0] == 6) ? INSTALLSTATE_ABSENT : INSTALLSTATE_LOCAL;
2926 msi_free( parent );
2927 if (*state == INSTALLSTATE_ABSENT)
2928 return ERROR_SUCCESS;
2930 r = MSIREG_OpenUserDataFeaturesKey( product, usersid, ctx, &hkey, FALSE );
2931 if (r != ERROR_SUCCESS)
2933 *state = INSTALLSTATE_ADVERTISED;
2934 return ERROR_SUCCESS;
2936 components = msi_reg_get_val_str( hkey, feature );
2937 RegCloseKey( hkey );
2939 TRACE("buffer = %s\n", debugstr_w(components));
2941 if (!components)
2943 *state = INSTALLSTATE_ADVERTISED;
2944 return ERROR_SUCCESS;
2946 for (p = components; *p && *p != 2 ; p += 20)
2948 if (!decode_base85_guid( p, &guid ))
2950 if (p != components) break;
2951 msi_free( components );
2952 *state = INSTALLSTATE_BADCONFIG;
2953 return ERROR_BAD_CONFIGURATION;
2955 StringFromGUID2( &guid, comp, GUID_SIZE );
2956 if (ctx == MSIINSTALLCONTEXT_MACHINE)
2957 r = MSIREG_OpenUserDataComponentKey( comp, szLocalSid, &hkey, FALSE );
2958 else
2959 r = MSIREG_OpenUserDataComponentKey( comp, usersid, &hkey, FALSE );
2961 if (r != ERROR_SUCCESS)
2963 msi_free( components );
2964 *state = INSTALLSTATE_ADVERTISED;
2965 return ERROR_SUCCESS;
2967 path = msi_reg_get_val_str( hkey, squashed );
2968 if (!path) missing = TRUE;
2969 else if (strlenW( path ) > 2 &&
2970 path[0] >= '0' && path[0] <= '9' &&
2971 path[1] >= '0' && path[1] <= '9')
2973 source = TRUE;
2975 msi_free( path );
2977 msi_free( components );
2979 if (missing)
2980 *state = INSTALLSTATE_ADVERTISED;
2981 else if (source)
2982 *state = INSTALLSTATE_SOURCE;
2983 else
2984 *state = INSTALLSTATE_LOCAL;
2986 TRACE("returning state %d\n", *state);
2987 return ERROR_SUCCESS;
2990 UINT WINAPI MsiQueryFeatureStateExA( LPCSTR product, LPCSTR usersid, MSIINSTALLCONTEXT ctx,
2991 LPCSTR feature, INSTALLSTATE *state )
2993 UINT r;
2994 WCHAR *productW = NULL, *usersidW = NULL, *featureW = NULL;
2996 if (product && !(productW = strdupAtoW( product ))) return ERROR_OUTOFMEMORY;
2997 if (usersid && !(usersidW = strdupAtoW( usersid )))
2999 msi_free( productW );
3000 return ERROR_OUTOFMEMORY;
3002 if (feature && !(featureW = strdupAtoW( feature )))
3004 msi_free( productW );
3005 msi_free( usersidW );
3006 return ERROR_OUTOFMEMORY;
3008 r = MsiQueryFeatureStateExW( productW, usersidW, ctx, featureW, state );
3009 msi_free( productW );
3010 msi_free( usersidW );
3011 msi_free( featureW );
3012 return r;
3015 UINT WINAPI MsiQueryFeatureStateExW( LPCWSTR product, LPCWSTR usersid, MSIINSTALLCONTEXT ctx,
3016 LPCWSTR feature, INSTALLSTATE *state )
3018 WCHAR squashed[33];
3019 if (!squash_guid( product, squashed )) return ERROR_INVALID_PARAMETER;
3020 return query_feature_state( product, squashed, usersid, ctx, feature, state );
3023 /******************************************************************
3024 * MsiQueryFeatureStateA [MSI.@]
3026 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
3028 LPWSTR szwProduct = NULL, szwFeature= NULL;
3029 INSTALLSTATE rc = INSTALLSTATE_UNKNOWN;
3031 szwProduct = strdupAtoW( szProduct );
3032 if ( szProduct && !szwProduct )
3033 goto end;
3035 szwFeature = strdupAtoW( szFeature );
3036 if ( szFeature && !szwFeature )
3037 goto end;
3039 rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
3041 end:
3042 msi_free( szwProduct);
3043 msi_free( szwFeature);
3045 return rc;
3048 /******************************************************************
3049 * MsiQueryFeatureStateW [MSI.@]
3051 * Checks the state of a feature
3053 * PARAMS
3054 * szProduct [I] Product's GUID string
3055 * szFeature [I] Feature's GUID string
3057 * RETURNS
3058 * INSTALLSTATE_LOCAL Feature is installed and usable
3059 * INSTALLSTATE_ABSENT Feature is absent
3060 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
3061 * INSTALLSTATE_UNKNOWN An error occurred
3062 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
3065 INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature)
3067 UINT r;
3068 INSTALLSTATE state;
3069 WCHAR squashed[33];
3071 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature));
3073 if (!szProduct || !szFeature || !squash_guid( szProduct, squashed ))
3074 return INSTALLSTATE_INVALIDARG;
3076 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_USERMANAGED, szFeature, &state );
3077 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3079 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_USERUNMANAGED, szFeature, &state );
3080 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3082 r = query_feature_state( szProduct, squashed, NULL, MSIINSTALLCONTEXT_MACHINE, szFeature, &state );
3083 if (r == ERROR_SUCCESS || r == ERROR_BAD_CONFIGURATION) return state;
3085 return INSTALLSTATE_UNKNOWN;
3088 /******************************************************************
3089 * MsiGetFileVersionA [MSI.@]
3091 UINT WINAPI MsiGetFileVersionA(LPCSTR szFilePath, LPSTR lpVersionBuf,
3092 LPDWORD pcchVersionBuf, LPSTR lpLangBuf, LPDWORD pcchLangBuf)
3094 LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
3095 UINT ret = ERROR_OUTOFMEMORY;
3097 if ((lpVersionBuf && !pcchVersionBuf) ||
3098 (lpLangBuf && !pcchLangBuf))
3099 return ERROR_INVALID_PARAMETER;
3101 if( szFilePath )
3103 szwFilePath = strdupAtoW( szFilePath );
3104 if( !szwFilePath )
3105 goto end;
3108 if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
3110 lpwVersionBuff = msi_alloc(*pcchVersionBuf*sizeof(WCHAR));
3111 if( !lpwVersionBuff )
3112 goto end;
3115 if( lpLangBuf && pcchLangBuf && *pcchLangBuf )
3117 lpwLangBuff = msi_alloc(*pcchLangBuf*sizeof(WCHAR));
3118 if( !lpwLangBuff )
3119 goto end;
3122 ret = MsiGetFileVersionW(szwFilePath, lpwVersionBuff, pcchVersionBuf,
3123 lpwLangBuff, pcchLangBuf);
3125 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwVersionBuff )
3126 WideCharToMultiByte(CP_ACP, 0, lpwVersionBuff, -1,
3127 lpVersionBuf, *pcchVersionBuf + 1, NULL, NULL);
3128 if( (ret == ERROR_SUCCESS || ret == ERROR_MORE_DATA) && lpwLangBuff )
3129 WideCharToMultiByte(CP_ACP, 0, lpwLangBuff, -1,
3130 lpLangBuf, *pcchLangBuf + 1, NULL, NULL);
3132 end:
3133 msi_free(szwFilePath);
3134 msi_free(lpwVersionBuff);
3135 msi_free(lpwLangBuff);
3137 return ret;
3140 static UINT get_file_version( const WCHAR *path, WCHAR *verbuf, DWORD *verlen,
3141 WCHAR *langbuf, DWORD *langlen )
3143 static const WCHAR szVersionResource[] = {'\\',0};
3144 static const WCHAR szVersionFormat[] = {'%','d','.','%','d','.','%','d','.','%','d',0};
3145 static const WCHAR szLangFormat[] = {'%','d',0};
3146 UINT ret = ERROR_MORE_DATA;
3147 DWORD len, error;
3148 LPVOID version;
3149 VS_FIXEDFILEINFO *ffi;
3150 USHORT *lang;
3151 WCHAR tmp[32];
3153 if (!(len = GetFileVersionInfoSizeW( path, NULL )))
3155 error = GetLastError();
3156 if (error == ERROR_BAD_PATHNAME) return ERROR_FILE_NOT_FOUND;
3157 if (error == ERROR_RESOURCE_DATA_NOT_FOUND) return ERROR_FILE_INVALID;
3158 return error;
3160 if (!(version = msi_alloc( len ))) return ERROR_OUTOFMEMORY;
3161 if (!GetFileVersionInfoW( path, 0, len, version ))
3163 msi_free( version );
3164 return GetLastError();
3166 if (!verbuf && !verlen && !langbuf && !langlen)
3168 msi_free( version );
3169 return ERROR_SUCCESS;
3171 if (verlen)
3173 if (VerQueryValueW( version, szVersionResource, (LPVOID *)&ffi, &len ) && len > 0)
3175 sprintfW( tmp, szVersionFormat,
3176 HIWORD(ffi->dwFileVersionMS), LOWORD(ffi->dwFileVersionMS),
3177 HIWORD(ffi->dwFileVersionLS), LOWORD(ffi->dwFileVersionLS) );
3178 if (verbuf) lstrcpynW( verbuf, tmp, *verlen );
3179 len = strlenW( tmp );
3180 if (*verlen > len) ret = ERROR_SUCCESS;
3181 *verlen = len;
3183 else
3185 if (verbuf) *verbuf = 0;
3186 *verlen = 0;
3189 if (langlen)
3191 if (VerQueryValueW( version, szLangResource, (LPVOID *)&lang, &len ) && len > 0)
3193 sprintfW( tmp, szLangFormat, *lang );
3194 if (langbuf) lstrcpynW( langbuf, tmp, *langlen );
3195 len = strlenW( tmp );
3196 if (*langlen > len) ret = ERROR_SUCCESS;
3197 *langlen = len;
3199 else
3201 if (langbuf) *langbuf = 0;
3202 *langlen = 0;
3205 msi_free( version );
3206 return ret;
3210 /******************************************************************
3211 * MsiGetFileVersionW [MSI.@]
3213 UINT WINAPI MsiGetFileVersionW( LPCWSTR path, LPWSTR verbuf, LPDWORD verlen,
3214 LPWSTR langbuf, LPDWORD langlen )
3216 UINT ret;
3218 TRACE("%s %p %u %p %u\n", debugstr_w(path), verbuf, verlen ? *verlen : 0,
3219 langbuf, langlen ? *langlen : 0);
3221 if ((verbuf && !verlen) || (langbuf && !langlen))
3222 return ERROR_INVALID_PARAMETER;
3224 ret = get_file_version( path, verbuf, verlen, langbuf, langlen );
3225 if (ret == ERROR_RESOURCE_DATA_NOT_FOUND && verlen)
3227 int len;
3228 WCHAR *version = msi_font_version_from_file( path );
3229 if (!version) return ERROR_FILE_INVALID;
3230 len = strlenW( version );
3231 if (len >= *verlen) ret = ERROR_MORE_DATA;
3232 else if (verbuf)
3234 strcpyW( verbuf, version );
3235 ret = ERROR_SUCCESS;
3237 *verlen = len;
3238 msi_free( version );
3240 return ret;
3243 /***********************************************************************
3244 * MsiGetFeatureUsageW [MSI.@]
3246 UINT WINAPI MsiGetFeatureUsageW( LPCWSTR szProduct, LPCWSTR szFeature,
3247 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3249 FIXME("%s %s %p %p\n",debugstr_w(szProduct), debugstr_w(szFeature),
3250 pdwUseCount, pwDateUsed);
3251 return ERROR_CALL_NOT_IMPLEMENTED;
3254 /***********************************************************************
3255 * MsiGetFeatureUsageA [MSI.@]
3257 UINT WINAPI MsiGetFeatureUsageA( LPCSTR szProduct, LPCSTR szFeature,
3258 LPDWORD pdwUseCount, LPWORD pwDateUsed )
3260 LPWSTR prod = NULL, feat = NULL;
3261 UINT ret = ERROR_OUTOFMEMORY;
3263 TRACE("%s %s %p %p\n", debugstr_a(szProduct), debugstr_a(szFeature),
3264 pdwUseCount, pwDateUsed);
3266 prod = strdupAtoW( szProduct );
3267 if (szProduct && !prod)
3268 goto end;
3270 feat = strdupAtoW( szFeature );
3271 if (szFeature && !feat)
3272 goto end;
3274 ret = MsiGetFeatureUsageW( prod, feat, pdwUseCount, pwDateUsed );
3276 end:
3277 msi_free( prod );
3278 msi_free( feat );
3280 return ret;
3283 /***********************************************************************
3284 * MsiUseFeatureExW [MSI.@]
3286 INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature,
3287 DWORD dwInstallMode, DWORD dwReserved )
3289 INSTALLSTATE state;
3291 TRACE("%s %s %i %i\n", debugstr_w(szProduct), debugstr_w(szFeature),
3292 dwInstallMode, dwReserved);
3294 state = MsiQueryFeatureStateW( szProduct, szFeature );
3296 if (dwReserved)
3297 return INSTALLSTATE_INVALIDARG;
3299 if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION)
3301 FIXME("mark product %s feature %s as used\n",
3302 debugstr_w(szProduct), debugstr_w(szFeature) );
3305 return state;
3308 /***********************************************************************
3309 * MsiUseFeatureExA [MSI.@]
3311 INSTALLSTATE WINAPI MsiUseFeatureExA( LPCSTR szProduct, LPCSTR szFeature,
3312 DWORD dwInstallMode, DWORD dwReserved )
3314 INSTALLSTATE ret = INSTALLSTATE_UNKNOWN;
3315 LPWSTR prod = NULL, feat = NULL;
3317 TRACE("%s %s %i %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
3318 dwInstallMode, dwReserved);
3320 prod = strdupAtoW( szProduct );
3321 if (szProduct && !prod)
3322 goto end;
3324 feat = strdupAtoW( szFeature );
3325 if (szFeature && !feat)
3326 goto end;
3328 ret = MsiUseFeatureExW( prod, feat, dwInstallMode, dwReserved );
3330 end:
3331 msi_free( prod );
3332 msi_free( feat );
3334 return ret;
3337 /***********************************************************************
3338 * MsiUseFeatureW [MSI.@]
3340 INSTALLSTATE WINAPI MsiUseFeatureW( LPCWSTR szProduct, LPCWSTR szFeature )
3342 return MsiUseFeatureExW(szProduct, szFeature, 0, 0);
3345 /***********************************************************************
3346 * MsiUseFeatureA [MSI.@]
3348 INSTALLSTATE WINAPI MsiUseFeatureA( LPCSTR szProduct, LPCSTR szFeature )
3350 return MsiUseFeatureExA(szProduct, szFeature, 0, 0);
3353 static WCHAR *reg_get_multisz( HKEY hkey, const WCHAR *name )
3355 WCHAR *ret;
3356 DWORD len, type;
3357 if (RegQueryValueExW( hkey, name, NULL, &type, NULL, &len ) || type != REG_MULTI_SZ) return NULL;
3358 if ((ret = msi_alloc( len ))) RegQueryValueExW( hkey, name, NULL, NULL, (BYTE *)ret, &len );
3359 return ret;
3362 static WCHAR *reg_get_sz( HKEY hkey, const WCHAR *name )
3364 WCHAR *ret;
3365 DWORD len, type;
3366 if (RegQueryValueExW( hkey, name, NULL, &type, NULL, &len ) || type != REG_SZ) return NULL;
3367 if ((ret = msi_alloc( len ))) RegQueryValueExW( hkey, name, NULL, NULL, (BYTE *)ret, &len );
3368 return ret;
3371 #define BASE85_SIZE 20
3373 /***********************************************************************
3374 * MSI_ProvideQualifiedComponentEx [internal]
3376 static UINT MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent,
3377 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3378 DWORD Unused1, DWORD Unused2, awstring *lpPathBuf,
3379 LPDWORD pcchPathBuf)
3381 WCHAR product[MAX_FEATURE_CHARS+1], comp[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1];
3382 WCHAR *desc;
3383 HKEY hkey;
3384 DWORD size;
3385 UINT ret;
3386 INSTALLSTATE state;
3388 if (MSIREG_OpenUserComponentsKey( szComponent, &hkey, FALSE )) return ERROR_UNKNOWN_COMPONENT;
3390 desc = reg_get_multisz( hkey, szQualifier );
3391 RegCloseKey(hkey);
3392 if (!desc) return ERROR_INDEX_ABSENT;
3394 /* FIXME: handle multiple descriptors */
3395 ret = MsiDecomposeDescriptorW( desc, product, feature, comp, &size );
3396 msi_free( desc );
3397 if (ret != ERROR_SUCCESS) return ret;
3399 if (!szProduct) szProduct = product;
3400 if (!comp[0])
3402 MSIINSTALLCONTEXT ctx;
3403 WCHAR *components;
3404 GUID guid;
3406 /* use the first component of the feature if the descriptor component is empty */
3407 if ((ret = msi_locate_product( szProduct, &ctx ))) return ret;
3408 if ((ret = MSIREG_OpenUserDataFeaturesKey( szProduct, NULL, ctx, &hkey, FALSE )))
3410 return ERROR_FILE_NOT_FOUND;
3412 components = reg_get_sz( hkey, feature );
3413 RegCloseKey( hkey );
3414 if (!components) return ERROR_FILE_NOT_FOUND;
3416 if (strlenW( components ) < BASE85_SIZE || !decode_base85_guid( components, &guid ))
3418 msi_free( components );
3419 return ERROR_FILE_NOT_FOUND;
3421 msi_free( components );
3422 StringFromGUID2( &guid, comp, sizeof(comp)/sizeof(comp[0]) );
3425 state = MSI_GetComponentPath( szProduct, comp, lpPathBuf, pcchPathBuf );
3427 if (state == INSTALLSTATE_MOREDATA) return ERROR_MORE_DATA;
3428 if (state != INSTALLSTATE_LOCAL) return ERROR_FILE_NOT_FOUND;
3429 return ERROR_SUCCESS;
3432 /***********************************************************************
3433 * MsiProvideQualifiedComponentExW [MSI.@]
3435 UINT WINAPI MsiProvideQualifiedComponentExW(LPCWSTR szComponent,
3436 LPCWSTR szQualifier, DWORD dwInstallMode, LPCWSTR szProduct,
3437 DWORD Unused1, DWORD Unused2, LPWSTR lpPathBuf,
3438 LPDWORD pcchPathBuf)
3440 awstring path;
3442 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_w(szComponent),
3443 debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
3444 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3446 path.unicode = TRUE;
3447 path.str.w = lpPathBuf;
3449 return MSI_ProvideQualifiedComponentEx(szComponent, szQualifier,
3450 dwInstallMode, szProduct, Unused1, Unused2, &path, pcchPathBuf);
3453 /***********************************************************************
3454 * MsiProvideQualifiedComponentExA [MSI.@]
3456 UINT WINAPI MsiProvideQualifiedComponentExA(LPCSTR szComponent,
3457 LPCSTR szQualifier, DWORD dwInstallMode, LPCSTR szProduct,
3458 DWORD Unused1, DWORD Unused2, LPSTR lpPathBuf,
3459 LPDWORD pcchPathBuf)
3461 LPWSTR szwComponent, szwQualifier = NULL, szwProduct = NULL;
3462 UINT r = ERROR_OUTOFMEMORY;
3463 awstring path;
3465 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent),
3466 debugstr_a(szQualifier), dwInstallMode, debugstr_a(szProduct),
3467 Unused1, Unused2, lpPathBuf, pcchPathBuf);
3469 szwComponent = strdupAtoW( szComponent );
3470 if (szComponent && !szwComponent)
3471 goto end;
3473 szwQualifier = strdupAtoW( szQualifier );
3474 if (szQualifier && !szwQualifier)
3475 goto end;
3477 szwProduct = strdupAtoW( szProduct );
3478 if (szProduct && !szwProduct)
3479 goto end;
3481 path.unicode = FALSE;
3482 path.str.a = lpPathBuf;
3484 r = MSI_ProvideQualifiedComponentEx(szwComponent, szwQualifier,
3485 dwInstallMode, szwProduct, Unused1,
3486 Unused2, &path, pcchPathBuf);
3487 end:
3488 msi_free(szwProduct);
3489 msi_free(szwComponent);
3490 msi_free(szwQualifier);
3492 return r;
3495 /***********************************************************************
3496 * MsiProvideQualifiedComponentW [MSI.@]
3498 UINT WINAPI MsiProvideQualifiedComponentW( LPCWSTR szComponent,
3499 LPCWSTR szQualifier, DWORD dwInstallMode, LPWSTR lpPathBuf,
3500 LPDWORD pcchPathBuf)
3502 return MsiProvideQualifiedComponentExW(szComponent, szQualifier,
3503 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3506 /***********************************************************************
3507 * MsiProvideQualifiedComponentA [MSI.@]
3509 UINT WINAPI MsiProvideQualifiedComponentA( LPCSTR szComponent,
3510 LPCSTR szQualifier, DWORD dwInstallMode, LPSTR lpPathBuf,
3511 LPDWORD pcchPathBuf)
3513 return MsiProvideQualifiedComponentExA(szComponent, szQualifier,
3514 dwInstallMode, NULL, 0, 0, lpPathBuf, pcchPathBuf);
3517 /***********************************************************************
3518 * MSI_GetUserInfo [internal]
3520 static USERINFOSTATE MSI_GetUserInfo(LPCWSTR szProduct,
3521 awstring *lpUserNameBuf, LPDWORD pcchUserNameBuf,
3522 awstring *lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3523 awstring *lpSerialBuf, LPDWORD pcchSerialBuf)
3525 WCHAR *user, *org, *serial, squashed_pc[SQUASHED_GUID_SIZE];
3526 USERINFOSTATE state;
3527 HKEY hkey, props;
3528 LPCWSTR orgptr;
3529 UINT r;
3531 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct), lpUserNameBuf,
3532 pcchUserNameBuf, lpOrgNameBuf, pcchOrgNameBuf, lpSerialBuf,
3533 pcchSerialBuf);
3535 if (!szProduct || !squash_guid( szProduct, squashed_pc ))
3536 return USERINFOSTATE_INVALIDARG;
3538 if (MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
3539 &hkey, FALSE) != ERROR_SUCCESS &&
3540 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3541 &hkey, FALSE) != ERROR_SUCCESS &&
3542 MSIREG_OpenProductKey(szProduct, NULL, MSIINSTALLCONTEXT_MACHINE,
3543 &hkey, FALSE) != ERROR_SUCCESS)
3545 return USERINFOSTATE_UNKNOWN;
3548 if (MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_USERUNMANAGED,
3549 NULL, &props, FALSE) != ERROR_SUCCESS &&
3550 MSIREG_OpenInstallProps(szProduct, MSIINSTALLCONTEXT_MACHINE,
3551 NULL, &props, FALSE) != ERROR_SUCCESS)
3553 RegCloseKey(hkey);
3554 return USERINFOSTATE_ABSENT;
3557 user = msi_reg_get_val_str(props, INSTALLPROPERTY_REGOWNERW);
3558 org = msi_reg_get_val_str(props, INSTALLPROPERTY_REGCOMPANYW);
3559 serial = msi_reg_get_val_str(props, INSTALLPROPERTY_PRODUCTIDW);
3560 state = USERINFOSTATE_ABSENT;
3562 RegCloseKey(hkey);
3563 RegCloseKey(props);
3565 if (user && serial)
3566 state = USERINFOSTATE_PRESENT;
3568 if (pcchUserNameBuf)
3570 if (lpUserNameBuf && !user)
3572 (*pcchUserNameBuf)--;
3573 goto done;
3576 r = msi_strcpy_to_awstring(user, -1, lpUserNameBuf, pcchUserNameBuf);
3577 if (r == ERROR_MORE_DATA)
3579 state = USERINFOSTATE_MOREDATA;
3580 goto done;
3584 if (pcchOrgNameBuf)
3586 orgptr = org;
3587 if (!orgptr) orgptr = szEmpty;
3589 r = msi_strcpy_to_awstring(orgptr, -1, lpOrgNameBuf, pcchOrgNameBuf);
3590 if (r == ERROR_MORE_DATA)
3592 state = USERINFOSTATE_MOREDATA;
3593 goto done;
3597 if (pcchSerialBuf)
3599 if (!serial)
3601 (*pcchSerialBuf)--;
3602 goto done;
3605 r = msi_strcpy_to_awstring(serial, -1, lpSerialBuf, pcchSerialBuf);
3606 if (r == ERROR_MORE_DATA)
3607 state = USERINFOSTATE_MOREDATA;
3610 done:
3611 msi_free(user);
3612 msi_free(org);
3613 msi_free(serial);
3615 return state;
3618 /***********************************************************************
3619 * MsiGetUserInfoW [MSI.@]
3621 USERINFOSTATE WINAPI MsiGetUserInfoW(LPCWSTR szProduct,
3622 LPWSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3623 LPWSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3624 LPWSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3626 awstring user, org, serial;
3628 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3629 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3630 (lpSerialBuf && !pcchSerialBuf))
3631 return USERINFOSTATE_INVALIDARG;
3633 user.unicode = TRUE;
3634 user.str.w = lpUserNameBuf;
3635 org.unicode = TRUE;
3636 org.str.w = lpOrgNameBuf;
3637 serial.unicode = TRUE;
3638 serial.str.w = lpSerialBuf;
3640 return MSI_GetUserInfo( szProduct, &user, pcchUserNameBuf,
3641 &org, pcchOrgNameBuf,
3642 &serial, pcchSerialBuf );
3645 USERINFOSTATE WINAPI MsiGetUserInfoA(LPCSTR szProduct,
3646 LPSTR lpUserNameBuf, LPDWORD pcchUserNameBuf,
3647 LPSTR lpOrgNameBuf, LPDWORD pcchOrgNameBuf,
3648 LPSTR lpSerialBuf, LPDWORD pcchSerialBuf)
3650 awstring user, org, serial;
3651 LPWSTR prod;
3652 UINT r;
3654 if ((lpUserNameBuf && !pcchUserNameBuf) ||
3655 (lpOrgNameBuf && !pcchOrgNameBuf) ||
3656 (lpSerialBuf && !pcchSerialBuf))
3657 return USERINFOSTATE_INVALIDARG;
3659 prod = strdupAtoW( szProduct );
3660 if (szProduct && !prod)
3661 return ERROR_OUTOFMEMORY;
3663 user.unicode = FALSE;
3664 user.str.a = lpUserNameBuf;
3665 org.unicode = FALSE;
3666 org.str.a = lpOrgNameBuf;
3667 serial.unicode = FALSE;
3668 serial.str.a = lpSerialBuf;
3670 r = MSI_GetUserInfo( prod, &user, pcchUserNameBuf,
3671 &org, pcchOrgNameBuf,
3672 &serial, pcchSerialBuf );
3674 msi_free( prod );
3676 return r;
3679 UINT WINAPI MsiCollectUserInfoW(LPCWSTR szProduct)
3681 MSIHANDLE handle;
3682 UINT rc;
3683 MSIPACKAGE *package;
3684 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3686 TRACE("(%s)\n",debugstr_w(szProduct));
3688 rc = MsiOpenProductW(szProduct,&handle);
3689 if (rc != ERROR_SUCCESS)
3690 return ERROR_INVALID_PARAMETER;
3692 /* MsiCollectUserInfo cannot be called from a custom action. */
3693 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3694 if (!package)
3695 return ERROR_CALL_NOT_IMPLEMENTED;
3697 rc = ACTION_PerformUIAction(package, szFirstRun, SCRIPT_NONE);
3698 msiobj_release( &package->hdr );
3700 MsiCloseHandle(handle);
3702 return rc;
3705 UINT WINAPI MsiCollectUserInfoA(LPCSTR szProduct)
3707 MSIHANDLE handle;
3708 UINT rc;
3709 MSIPACKAGE *package;
3710 static const WCHAR szFirstRun[] = {'F','i','r','s','t','R','u','n',0};
3712 TRACE("(%s)\n",debugstr_a(szProduct));
3714 rc = MsiOpenProductA(szProduct,&handle);
3715 if (rc != ERROR_SUCCESS)
3716 return ERROR_INVALID_PARAMETER;
3718 /* MsiCollectUserInfo cannot be called from a custom action. */
3719 package = msihandle2msiinfo(handle, MSIHANDLETYPE_PACKAGE);
3720 if (!package)
3721 return ERROR_CALL_NOT_IMPLEMENTED;
3723 rc = ACTION_PerformUIAction(package, szFirstRun, SCRIPT_NONE);
3724 msiobj_release( &package->hdr );
3726 MsiCloseHandle(handle);
3728 return rc;
3731 /***********************************************************************
3732 * MsiConfigureFeatureA [MSI.@]
3734 UINT WINAPI MsiConfigureFeatureA(LPCSTR szProduct, LPCSTR szFeature, INSTALLSTATE eInstallState)
3736 LPWSTR prod, feat = NULL;
3737 UINT r = ERROR_OUTOFMEMORY;
3739 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature), eInstallState);
3741 prod = strdupAtoW( szProduct );
3742 if (szProduct && !prod)
3743 goto end;
3745 feat = strdupAtoW( szFeature );
3746 if (szFeature && !feat)
3747 goto end;
3749 r = MsiConfigureFeatureW(prod, feat, eInstallState);
3751 end:
3752 msi_free(feat);
3753 msi_free(prod);
3755 return r;
3758 /***********************************************************************
3759 * MsiConfigureFeatureW [MSI.@]
3761 UINT WINAPI MsiConfigureFeatureW(LPCWSTR szProduct, LPCWSTR szFeature, INSTALLSTATE eInstallState)
3763 MSIPACKAGE *package = NULL;
3764 UINT r;
3765 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH];
3766 DWORD sz;
3768 TRACE("%s %s %i\n", debugstr_w(szProduct), debugstr_w(szFeature), eInstallState);
3770 if (!szProduct || !szFeature)
3771 return ERROR_INVALID_PARAMETER;
3773 switch (eInstallState)
3775 case INSTALLSTATE_DEFAULT:
3776 /* FIXME: how do we figure out the default location? */
3777 eInstallState = INSTALLSTATE_LOCAL;
3778 break;
3779 case INSTALLSTATE_LOCAL:
3780 case INSTALLSTATE_SOURCE:
3781 case INSTALLSTATE_ABSENT:
3782 case INSTALLSTATE_ADVERTISED:
3783 break;
3784 default:
3785 return ERROR_INVALID_PARAMETER;
3788 r = MSI_OpenProductW( szProduct, &package );
3789 if (r != ERROR_SUCCESS)
3790 return r;
3792 sz = sizeof(sourcepath);
3793 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3794 MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz);
3796 sz = sizeof(filename);
3797 MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERUNMANAGED,
3798 MSICODE_PRODUCT, INSTALLPROPERTY_PACKAGENAMEW, filename, &sz);
3800 lstrcatW( sourcepath, filename );
3802 MsiSetInternalUI( INSTALLUILEVEL_BASIC, NULL );
3804 r = ACTION_PerformUIAction( package, szCostInitialize, SCRIPT_NONE );
3805 if (r != ERROR_SUCCESS)
3806 goto end;
3808 r = MSI_SetFeatureStateW( package, szFeature, eInstallState);
3809 if (r != ERROR_SUCCESS)
3810 goto end;
3812 r = MSI_InstallPackage( package, sourcepath, NULL );
3814 end:
3815 msiobj_release( &package->hdr );
3817 return r;
3820 /***********************************************************************
3821 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3823 * Notes: undocumented
3825 UINT WINAPI MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved)
3827 WCHAR path[MAX_PATH];
3829 TRACE("%d\n", dwReserved);
3831 if (dwReserved)
3833 FIXME("dwReserved=%d\n", dwReserved);
3834 return ERROR_INVALID_PARAMETER;
3837 if (!GetWindowsDirectoryW(path, MAX_PATH))
3838 return ERROR_FUNCTION_FAILED;
3840 lstrcatW(path, installerW);
3842 if (!CreateDirectoryW(path, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
3843 return ERROR_FUNCTION_FAILED;
3845 return ERROR_SUCCESS;
3848 /***********************************************************************
3849 * MsiGetShortcutTargetA [MSI.@]
3851 UINT WINAPI MsiGetShortcutTargetA( LPCSTR szShortcutTarget,
3852 LPSTR szProductCode, LPSTR szFeatureId,
3853 LPSTR szComponentCode )
3855 LPWSTR target;
3856 const int len = MAX_FEATURE_CHARS+1;
3857 WCHAR product[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1], component[MAX_FEATURE_CHARS+1];
3858 UINT r;
3860 target = strdupAtoW( szShortcutTarget );
3861 if (szShortcutTarget && !target )
3862 return ERROR_OUTOFMEMORY;
3863 product[0] = 0;
3864 feature[0] = 0;
3865 component[0] = 0;
3866 r = MsiGetShortcutTargetW( target, product, feature, component );
3867 msi_free( target );
3868 if (r == ERROR_SUCCESS)
3870 WideCharToMultiByte( CP_ACP, 0, product, -1, szProductCode, len, NULL, NULL );
3871 WideCharToMultiByte( CP_ACP, 0, feature, -1, szFeatureId, len, NULL, NULL );
3872 WideCharToMultiByte( CP_ACP, 0, component, -1, szComponentCode, len, NULL, NULL );
3874 return r;
3877 /***********************************************************************
3878 * MsiGetShortcutTargetW [MSI.@]
3880 UINT WINAPI MsiGetShortcutTargetW( LPCWSTR szShortcutTarget,
3881 LPWSTR szProductCode, LPWSTR szFeatureId,
3882 LPWSTR szComponentCode )
3884 IShellLinkDataList *dl = NULL;
3885 IPersistFile *pf = NULL;
3886 LPEXP_DARWIN_LINK darwin = NULL;
3887 HRESULT r, init;
3889 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget),
3890 szProductCode, szFeatureId, szComponentCode );
3892 init = CoInitialize(NULL);
3894 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
3895 &IID_IPersistFile, (LPVOID*) &pf );
3896 if( SUCCEEDED( r ) )
3898 r = IPersistFile_Load( pf, szShortcutTarget,
3899 STGM_READ | STGM_SHARE_DENY_WRITE );
3900 if( SUCCEEDED( r ) )
3902 r = IPersistFile_QueryInterface( pf, &IID_IShellLinkDataList,
3903 (LPVOID*) &dl );
3904 if( SUCCEEDED( r ) )
3906 IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG,
3907 (LPVOID) &darwin );
3908 IShellLinkDataList_Release( dl );
3911 IPersistFile_Release( pf );
3914 if (SUCCEEDED(init))
3915 CoUninitialize();
3917 TRACE("darwin = %p\n", darwin);
3919 if (darwin)
3921 DWORD sz;
3922 UINT ret;
3924 ret = MsiDecomposeDescriptorW( darwin->szwDarwinID,
3925 szProductCode, szFeatureId, szComponentCode, &sz );
3926 LocalFree( darwin );
3927 return ret;
3930 return ERROR_FUNCTION_FAILED;
3933 UINT WINAPI MsiReinstallFeatureW( LPCWSTR szProduct, LPCWSTR szFeature, DWORD dwReinstallMode )
3935 static const WCHAR fmtW[] = {'%','s','=','%','s',' ','%','s','=','%','s',0};
3936 MSIPACKAGE *package;
3937 MSIINSTALLCONTEXT context;
3938 UINT r;
3939 WCHAR sourcepath[MAX_PATH], filename[MAX_PATH], reinstallmode[11];
3940 WCHAR *ptr, *cmdline;
3941 DWORD sz;
3943 TRACE("%s, %s, 0x%08x\n", debugstr_w(szProduct), debugstr_w(szFeature), dwReinstallMode);
3945 r = msi_locate_product( szProduct, &context );
3946 if (r != ERROR_SUCCESS)
3947 return r;
3949 ptr = reinstallmode;
3951 if (dwReinstallMode & REINSTALLMODE_FILEMISSING)
3952 *ptr++ = 'p';
3953 if (dwReinstallMode & REINSTALLMODE_FILEOLDERVERSION)
3954 *ptr++ = 'o';
3955 if (dwReinstallMode & REINSTALLMODE_FILEEQUALVERSION)
3956 *ptr++ = 'w';
3957 if (dwReinstallMode & REINSTALLMODE_FILEEXACT)
3958 *ptr++ = 'd';
3959 if (dwReinstallMode & REINSTALLMODE_FILEVERIFY)
3960 *ptr++ = 'c';
3961 if (dwReinstallMode & REINSTALLMODE_FILEREPLACE)
3962 *ptr++ = 'a';
3963 if (dwReinstallMode & REINSTALLMODE_USERDATA)
3964 *ptr++ = 'u';
3965 if (dwReinstallMode & REINSTALLMODE_MACHINEDATA)
3966 *ptr++ = 'm';
3967 if (dwReinstallMode & REINSTALLMODE_SHORTCUT)
3968 *ptr++ = 's';
3969 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3970 *ptr++ = 'v';
3971 *ptr = 0;
3973 sz = sizeof(sourcepath);
3974 MsiSourceListGetInfoW( szProduct, NULL, context, MSICODE_PRODUCT,
3975 INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath, &sz );
3976 sz = sizeof(filename);
3977 MsiSourceListGetInfoW( szProduct, NULL, context, MSICODE_PRODUCT,
3978 INSTALLPROPERTY_PACKAGENAMEW, filename, &sz );
3979 strcatW( sourcepath, filename );
3981 if (dwReinstallMode & REINSTALLMODE_PACKAGE)
3982 r = MSI_OpenPackageW( sourcepath, &package );
3983 else
3984 r = MSI_OpenProductW( szProduct, &package );
3986 if (r != ERROR_SUCCESS)
3987 return r;
3989 sz = (strlenW( fmtW ) + strlenW( szReinstallMode ) + strlenW( reinstallmode )) * sizeof(WCHAR);
3990 sz += (strlenW( szReinstall ) + strlenW( szFeature )) * sizeof(WCHAR);
3991 if (!(cmdline = msi_alloc( sz )))
3993 msiobj_release( &package->hdr );
3994 return ERROR_OUTOFMEMORY;
3996 sprintfW( cmdline, fmtW, szReinstallMode, reinstallmode, szReinstall, szFeature );
3998 r = MSI_InstallPackage( package, sourcepath, cmdline );
3999 msiobj_release( &package->hdr );
4000 msi_free( cmdline );
4002 return r;
4005 UINT WINAPI MsiReinstallFeatureA( LPCSTR szProduct, LPCSTR szFeature,
4006 DWORD dwReinstallMode )
4008 LPWSTR wszProduct;
4009 LPWSTR wszFeature;
4010 UINT rc;
4012 TRACE("%s %s %i\n", debugstr_a(szProduct), debugstr_a(szFeature),
4013 dwReinstallMode);
4015 wszProduct = strdupAtoW(szProduct);
4016 wszFeature = strdupAtoW(szFeature);
4018 rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
4020 msi_free(wszProduct);
4021 msi_free(wszFeature);
4022 return rc;
4025 typedef struct
4027 unsigned int i[2];
4028 unsigned int buf[4];
4029 unsigned char in[64];
4030 unsigned char digest[16];
4031 } MD5_CTX;
4033 extern VOID WINAPI MD5Init( MD5_CTX *);
4034 extern VOID WINAPI MD5Update( MD5_CTX *, const unsigned char *, unsigned int );
4035 extern VOID WINAPI MD5Final( MD5_CTX *);
4037 UINT msi_get_filehash( const WCHAR *path, MSIFILEHASHINFO *hash )
4039 HANDLE handle, mapping;
4040 void *p;
4041 DWORD length;
4042 UINT r = ERROR_FUNCTION_FAILED;
4044 handle = CreateFileW( path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL );
4045 if (handle == INVALID_HANDLE_VALUE)
4047 WARN("can't open file %u\n", GetLastError());
4048 return ERROR_FILE_NOT_FOUND;
4050 if ((length = GetFileSize( handle, NULL )))
4052 if ((mapping = CreateFileMappingW( handle, NULL, PAGE_READONLY, 0, 0, NULL )))
4054 if ((p = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, length )))
4056 MD5_CTX ctx;
4058 MD5Init( &ctx );
4059 MD5Update( &ctx, p, length );
4060 MD5Final( &ctx );
4061 UnmapViewOfFile( p );
4063 memcpy( hash->dwData, ctx.digest, sizeof(hash->dwData) );
4064 r = ERROR_SUCCESS;
4066 CloseHandle( mapping );
4069 else
4071 /* Empty file -> set hash to 0 */
4072 memset( hash->dwData, 0, sizeof(hash->dwData) );
4073 r = ERROR_SUCCESS;
4076 CloseHandle( handle );
4077 return r;
4080 /***********************************************************************
4081 * MsiGetFileHashW [MSI.@]
4083 UINT WINAPI MsiGetFileHashW( LPCWSTR szFilePath, DWORD dwOptions,
4084 PMSIFILEHASHINFO pHash )
4086 TRACE("%s %08x %p\n", debugstr_w(szFilePath), dwOptions, pHash );
4088 if (!szFilePath)
4089 return ERROR_INVALID_PARAMETER;
4091 if (!*szFilePath)
4092 return ERROR_PATH_NOT_FOUND;
4094 if (dwOptions)
4095 return ERROR_INVALID_PARAMETER;
4096 if (!pHash)
4097 return ERROR_INVALID_PARAMETER;
4098 if (pHash->dwFileHashInfoSize < sizeof *pHash)
4099 return ERROR_INVALID_PARAMETER;
4101 return msi_get_filehash( szFilePath, pHash );
4104 /***********************************************************************
4105 * MsiGetFileHashA [MSI.@]
4107 UINT WINAPI MsiGetFileHashA( LPCSTR szFilePath, DWORD dwOptions,
4108 PMSIFILEHASHINFO pHash )
4110 LPWSTR file;
4111 UINT r;
4113 TRACE("%s %08x %p\n", debugstr_a(szFilePath), dwOptions, pHash );
4115 file = strdupAtoW( szFilePath );
4116 if (szFilePath && !file)
4117 return ERROR_OUTOFMEMORY;
4119 r = MsiGetFileHashW( file, dwOptions, pHash );
4120 msi_free( file );
4121 return r;
4124 /***********************************************************************
4125 * MsiAdvertiseScriptW [MSI.@]
4127 UINT WINAPI MsiAdvertiseScriptW( LPCWSTR szScriptFile, DWORD dwFlags,
4128 PHKEY phRegData, BOOL fRemoveItems )
4130 FIXME("%s %08x %p %d\n",
4131 debugstr_w( szScriptFile ), dwFlags, phRegData, fRemoveItems );
4132 return ERROR_CALL_NOT_IMPLEMENTED;
4135 /***********************************************************************
4136 * MsiAdvertiseScriptA [MSI.@]
4138 UINT WINAPI MsiAdvertiseScriptA( LPCSTR szScriptFile, DWORD dwFlags,
4139 PHKEY phRegData, BOOL fRemoveItems )
4141 FIXME("%s %08x %p %d\n",
4142 debugstr_a( szScriptFile ), dwFlags, phRegData, fRemoveItems );
4143 return ERROR_CALL_NOT_IMPLEMENTED;
4146 /***********************************************************************
4147 * MsiIsProductElevatedW [MSI.@]
4149 UINT WINAPI MsiIsProductElevatedW( LPCWSTR szProduct, BOOL *pfElevated )
4151 FIXME("%s %p - stub\n",
4152 debugstr_w( szProduct ), pfElevated );
4153 *pfElevated = TRUE;
4154 return ERROR_SUCCESS;
4157 /***********************************************************************
4158 * MsiIsProductElevatedA [MSI.@]
4160 UINT WINAPI MsiIsProductElevatedA( LPCSTR szProduct, BOOL *pfElevated )
4162 FIXME("%s %p - stub\n",
4163 debugstr_a( szProduct ), pfElevated );
4164 *pfElevated = TRUE;
4165 return ERROR_SUCCESS;
4168 /***********************************************************************
4169 * MsiSetExternalUIRecord [MSI.@]
4171 UINT WINAPI MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler,
4172 DWORD filter, LPVOID context,
4173 PINSTALLUI_HANDLER_RECORD prev )
4175 TRACE("%p %08x %p %p\n", handler, filter, context, prev);
4177 if (prev)
4178 *prev = gUIHandlerRecord;
4180 gUIHandlerRecord = handler;
4181 gUIFilter = filter;
4182 gUIContext = context;
4184 return ERROR_SUCCESS;
4187 /***********************************************************************
4188 * MsiInstallMissingComponentA [MSI.@]
4190 UINT WINAPI MsiInstallMissingComponentA( LPCSTR product, LPCSTR component, INSTALLSTATE state )
4192 UINT r;
4193 WCHAR *productW = NULL, *componentW = NULL;
4195 TRACE("%s, %s, %d\n", debugstr_a(product), debugstr_a(component), state);
4197 if (product && !(productW = strdupAtoW( product )))
4198 return ERROR_OUTOFMEMORY;
4200 if (component && !(componentW = strdupAtoW( component )))
4202 msi_free( productW );
4203 return ERROR_OUTOFMEMORY;
4206 r = MsiInstallMissingComponentW( productW, componentW, state );
4207 msi_free( productW );
4208 msi_free( componentW );
4209 return r;
4212 /***********************************************************************
4213 * MsiInstallMissingComponentW [MSI.@]
4215 UINT WINAPI MsiInstallMissingComponentW(LPCWSTR szProduct, LPCWSTR szComponent, INSTALLSTATE eInstallState)
4217 FIXME("(%s %s %d\n", debugstr_w(szProduct), debugstr_w(szComponent), eInstallState);
4218 return ERROR_SUCCESS;
4221 UINT WINAPI MsiProvideComponentA( LPCSTR product, LPCSTR feature, LPCSTR component, DWORD mode, LPSTR buf, LPDWORD buflen )
4223 WCHAR *productW = NULL, *componentW = NULL, *featureW = NULL, *bufW = NULL;
4224 UINT r = ERROR_OUTOFMEMORY;
4225 DWORD lenW = 0;
4226 int len;
4228 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_a(product), debugstr_a(component), debugstr_a(feature), mode, buf, buflen);
4230 if (product && !(productW = strdupAtoW( product ))) goto done;
4231 if (feature && !(featureW = strdupAtoW( feature ))) goto done;
4232 if (component && !(componentW = strdupAtoW( component ))) goto done;
4234 r = MsiProvideComponentW( productW, featureW, componentW, mode, NULL, &lenW );
4235 if (r != ERROR_SUCCESS)
4236 goto done;
4238 if (!(bufW = msi_alloc( ++lenW * sizeof(WCHAR) )))
4240 r = ERROR_OUTOFMEMORY;
4241 goto done;
4244 r = MsiProvideComponentW( productW, featureW, componentW, mode, bufW, &lenW );
4245 if (r != ERROR_SUCCESS)
4246 goto done;
4248 len = WideCharToMultiByte( CP_ACP, 0, bufW, -1, NULL, 0, NULL, NULL );
4249 if (buf)
4251 if (len > *buflen)
4252 r = ERROR_MORE_DATA;
4253 else
4254 WideCharToMultiByte( CP_ACP, 0, bufW, -1, buf, *buflen, NULL, NULL );
4257 *buflen = len - 1;
4259 done:
4260 msi_free( productW );
4261 msi_free( featureW );
4262 msi_free( componentW );
4263 msi_free( bufW );
4264 return r;
4267 UINT WINAPI MsiProvideComponentW( LPCWSTR product, LPCWSTR feature, LPCWSTR component, DWORD mode, LPWSTR buf, LPDWORD buflen )
4269 INSTALLSTATE state;
4271 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_w(product), debugstr_w(component), debugstr_w(feature), mode, buf, buflen);
4273 state = MsiQueryFeatureStateW( product, feature );
4274 TRACE("feature state: %d\n", state);
4275 switch (mode)
4277 case INSTALLMODE_NODETECTION:
4278 break;
4280 default:
4281 FIXME("mode %x not implemented\n", mode);
4282 return ERROR_INSTALL_FAILURE;
4285 state = MsiGetComponentPathW( product, component, buf, buflen );
4286 TRACE("component state: %d\n", state);
4287 switch (state)
4289 case INSTALLSTATE_INVALIDARG:
4290 return ERROR_INVALID_PARAMETER;
4292 case INSTALLSTATE_MOREDATA:
4293 return ERROR_MORE_DATA;
4295 case INSTALLSTATE_ADVERTISED:
4296 case INSTALLSTATE_LOCAL:
4297 case INSTALLSTATE_SOURCE:
4298 MsiUseFeatureW( product, feature );
4299 return ERROR_SUCCESS;
4301 default:
4302 TRACE("MsiGetComponentPathW returned %d\n", state);
4303 return ERROR_INSTALL_FAILURE;
4307 /***********************************************************************
4308 * MsiBeginTransactionA [MSI.@]
4310 UINT WINAPI MsiBeginTransactionA( LPCSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4312 WCHAR *nameW;
4313 UINT r;
4315 FIXME("%s %u %p %p\n", debugstr_a(name), attrs, id, event);
4317 nameW = strdupAtoW( name );
4318 if (name && !nameW)
4319 return ERROR_OUTOFMEMORY;
4321 r = MsiBeginTransactionW( nameW, attrs, id, event );
4322 msi_free( nameW );
4323 return r;
4326 /***********************************************************************
4327 * MsiBeginTransactionW [MSI.@]
4329 UINT WINAPI MsiBeginTransactionW( LPCWSTR name, DWORD attrs, MSIHANDLE *id, HANDLE *event )
4331 FIXME("%s %u %p %p\n", debugstr_w(name), attrs, id, event);
4333 *id = (MSIHANDLE)0xdeadbeef;
4334 *event = (HANDLE)0xdeadbeef;
4336 return ERROR_SUCCESS;
4339 /***********************************************************************
4340 * MsiJoinTransaction [MSI.@]
4342 UINT WINAPI MsiJoinTransaction( MSIHANDLE handle, DWORD attrs, HANDLE *event )
4344 FIXME("%u %08x %p\n", handle, attrs, event);
4346 *event = (HANDLE)0xdeadbeef;
4347 return ERROR_SUCCESS;
4350 /***********************************************************************
4351 * MsiEndTransaction [MSI.@]
4353 UINT WINAPI MsiEndTransaction( DWORD state )
4355 FIXME("%u\n", state);
4356 return ERROR_SUCCESS;
4359 UINT WINAPI Migrate10CachedPackagesW(void* a, void* b, void* c, DWORD d)
4361 FIXME("%p,%p,%p,%08x\n", a, b, c, d);
4362 return ERROR_SUCCESS;
4365 /***********************************************************************
4366 * MsiRemovePatchesA [MSI.@]
4368 UINT WINAPI MsiRemovePatchesA(LPCSTR patchlist, LPCSTR product, INSTALLTYPE type, LPCSTR propertylist)
4370 FIXME("(%s %s %d %s\n", debugstr_a(patchlist), debugstr_a(product), type, debugstr_a(propertylist));
4371 return ERROR_SUCCESS;
4374 /***********************************************************************
4375 * MsiRemovePatchesW [MSI.@]
4377 UINT WINAPI MsiRemovePatchesW(LPCWSTR patchlist, LPCWSTR product, INSTALLTYPE type, LPCWSTR propertylist)
4379 FIXME("(%s %s %d %s\n", debugstr_w(patchlist), debugstr_w(product), type, debugstr_w(propertylist));
4380 return ERROR_SUCCESS;