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
24 #define NONAMELESSUNION
35 #include "msiserver.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
)
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
;
75 if (*context
== MSIINSTALLCONTEXT_NONE
)
76 return ERROR_UNKNOWN_PRODUCT
;
81 UINT WINAPI
MsiOpenProductA(LPCSTR szProduct
, MSIHANDLE
*phProduct
)
84 LPWSTR szwProd
= NULL
;
86 TRACE("%s %p\n",debugstr_a(szProduct
), phProduct
);
90 szwProd
= strdupAtoW( szProduct
);
92 return ERROR_OUTOFMEMORY
;
95 r
= MsiOpenProductW( szwProd
, phProduct
);
102 static UINT
MSI_OpenProductW(LPCWSTR szProduct
, MSIPACKAGE
**package
)
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
)
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
);
126 path
= msi_reg_get_val_str(props
, local
);
128 r
= ERROR_UNKNOWN_PRODUCT
;
130 if (!path
|| GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
133 if (PathIsRelativeW(path
))
135 r
= ERROR_INSTALL_PACKAGE_OPEN_FAILED
;
139 r
= MSI_OpenPackageW(path
, package
);
147 UINT WINAPI
MsiOpenProductW(LPCWSTR szProduct
, MSIHANDLE
*phProduct
)
149 MSIPACKAGE
*package
= NULL
;
150 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
153 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
154 return ERROR_INVALID_PARAMETER
;
157 return ERROR_INVALID_PARAMETER
;
159 r
= MSI_OpenProductW(szProduct
, &package
);
160 if (r
!= ERROR_SUCCESS
)
163 *phProduct
= alloc_msihandle(&package
->hdr
);
165 r
= ERROR_NOT_ENOUGH_MEMORY
;
167 msiobj_release(&package
->hdr
);
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
));
214 szwPath
= strdupAtoW( szPackagePath
);
221 szwCommand
= strdupAtoW( szCommandLine
);
226 r
= MsiInstallProductW( szwPath
, szwCommand
);
230 msi_free( szwCommand
);
235 UINT WINAPI
MsiInstallProductW(LPCWSTR szPackagePath
, LPCWSTR szCommandLine
)
237 MSIPACKAGE
*package
= NULL
;
240 TRACE("%s %s\n",debugstr_w(szPackagePath
), debugstr_w(szCommandLine
));
243 return ERROR_INVALID_PARAMETER
;
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
);
258 UINT WINAPI
MsiReinstallProductA(LPCSTR szProduct
, DWORD dwReinstallMode
)
263 TRACE("%s %08x\n", debugstr_a(szProduct
), dwReinstallMode
);
265 wszProduct
= strdupAtoW(szProduct
);
267 rc
= MsiReinstallProductW(wszProduct
, dwReinstallMode
);
269 msi_free(wszProduct
);
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
)))
294 if (szInstallPackage
&& !(install_package
= strdupAtoW(szInstallPackage
)))
297 if (szCommandLine
&& !(command_line
= strdupAtoW(szCommandLine
)))
300 r
= MsiApplyPatchW(patch_package
, install_package
, eInstallType
, command_line
);
303 msi_free(patch_package
);
304 msi_free(install_package
);
305 msi_free(command_line
);
310 static UINT
get_patch_product_codes( LPCWSTR szPatchPackage
, WCHAR
***product_codes
)
312 MSIHANDLE patch
, info
= 0;
315 static WCHAR empty
[] = {0};
318 r
= MsiOpenDatabaseW( szPatchPackage
, MSIDBOPEN_READONLY
, &patch
);
319 if (r
!= ERROR_SUCCESS
)
322 r
= MsiGetSummaryInformationW( patch
, NULL
, 0, &info
);
323 if (r
!= ERROR_SUCCESS
)
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
;
335 codes
= msi_alloc( ++size
* sizeof(WCHAR
) );
338 r
= ERROR_OUTOFMEMORY
;
342 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, codes
, &size
);
343 if (r
== ERROR_SUCCESS
)
344 *product_codes
= msi_split_string( codes
, ';' );
347 MsiCloseHandle( info
);
348 MsiCloseHandle( patch
);
353 static UINT
MSI_ApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szProductCode
, LPCWSTR szCommandLine
)
355 UINT i
, r
= ERROR_FUNCTION_FAILED
;
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
)))
373 size
= strlenW(cmd_ptr
) + strlenW(fmt
) + strlenW(szPatchPackage
) + 1;
374 cmd
= msi_alloc(size
* sizeof(WCHAR
));
378 return ERROR_OUTOFMEMORY
;
380 sprintfW(cmd
, fmt
, cmd_ptr
, szPatchPackage
);
383 r
= MsiConfigureProductExW(szProductCode
, INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
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");
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
)))
441 if (szPropertiesList
&& !(properties_list
= strdupAtoW(szPropertiesList
)))
444 r
= MsiApplyMultiplePatchesW(patch_packages
, product_code
, properties_list
);
447 msi_free(patch_packages
);
448 msi_free(product_code
);
449 msi_free(properties_list
);
454 UINT WINAPI
MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages
,
455 LPCWSTR szProductCode
, LPCWSTR szPropertiesList
)
457 UINT r
= ERROR_SUCCESS
;
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
;
472 while (*beg
== ' ') beg
++;
473 while (*end
&& *end
!= ';') end
++;
476 while (len
&& beg
[len
- 1] == ' ') len
--;
478 if (!len
) return ERROR_INVALID_NAME
;
480 patch
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
482 return ERROR_OUTOFMEMORY
;
484 memcpy(patch
, beg
, len
* sizeof(WCHAR
));
487 r
= MSI_ApplyPatchW(patch
, szProductCode
, szPropertiesList
);
490 if (r
!= ERROR_SUCCESS
|| !*end
)
498 static void free_patchinfo( DWORD count
, MSIPATCHSEQUENCEINFOW
*info
)
501 for (i
= 0; i
< count
; i
++) msi_free( (WCHAR
*)info
[i
].szPatchData
);
505 static MSIPATCHSEQUENCEINFOW
*patchinfoAtoW( DWORD count
, const MSIPATCHSEQUENCEINFOA
*info
)
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
);
518 ret
[i
].ePatchDataType
= info
[i
].ePatchDataType
;
519 ret
[i
].dwOrder
= info
[i
].dwOrder
;
520 ret
[i
].uStatus
= info
[i
].uStatus
;
525 UINT WINAPI
MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath
,
526 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
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
);
556 static UINT
MSI_ApplicablePatchW( MSIPACKAGE
*package
, LPCWSTR patch
)
559 MSIDATABASE
*patch_db
;
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
));
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
);
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
;
598 product_code
= msi_dup_property( package
->db
, szProductCode
);
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
);
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
);
618 if (!strcmpW( s
, product_code
)) r
= ERROR_SUCCESS
;
622 IXMLDOMNodeList_Release( list
);
624 if (r
!= ERROR_SUCCESS
)
625 TRACE("patch not applicable\n");
627 msi_free( product_code
);
631 static UINT
determine_patch_sequence( MSIPACKAGE
*package
, DWORD count
, MSIPATCHSEQUENCEINFOW
*info
)
633 IXMLDOMDocument
*desc
= NULL
;
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
;
653 info
[i
].uStatus
= ERROR_SUCCESS
;
657 case MSIPATCH_DATATYPE_XMLPATH
:
658 case MSIPATCH_DATATYPE_XMLBLOB
:
666 hr
= CoCreateInstance( &CLSID_DOMDocument30
, NULL
, CLSCTX_INPROC_SERVER
,
667 &IID_IXMLDOMDocument
, (void**)&desc
);
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
)
680 V_VT(&src
) = VT_BSTR
;
682 hr
= IXMLDOMDocument_load( desc
, src
, &b
);
685 hr
= IXMLDOMDocument_loadXML( desc
, s
, &b
);
689 ERR("failed to parse patch description\n");
690 IXMLDOMDocument_Release( desc
);
694 if (MSI_ApplicablePatchXML( package
, desc
) != ERROR_SUCCESS
)
696 info
[i
].dwOrder
= ~0u;
697 info
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
702 info
[i
].uStatus
= ERROR_SUCCESS
;
708 FIXME("unknown patch data type %u\n", info
[i
].ePatchDataType
);
710 info
[i
].uStatus
= ERROR_SUCCESS
;
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
)
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
);
740 r
= determine_patch_sequence( package
, cPatchInfo
, pPatchInfo
);
741 msiobj_release( &package
->hdr
);
745 UINT WINAPI
MsiDeterminePatchSequenceA( LPCSTR product
, LPCSTR usersid
,
746 MSIINSTALLCONTEXT context
, DWORD count
, PMSIPATCHSEQUENCEINFOA patchinfo
)
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
);
783 static UINT
open_package( const WCHAR
*product
, const WCHAR
*usersid
,
784 MSIINSTALLCONTEXT context
, MSIPACKAGE
**package
)
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
)
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
);
833 UINT WINAPI
MsiConfigureProductExW(LPCWSTR szProduct
, int iInstallLevel
,
834 INSTALLSTATE eInstallState
, LPCWSTR szCommandLine
)
836 MSIPACKAGE
* package
= NULL
;
837 MSIINSTALLCONTEXT context
;
840 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
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
)
869 r
= open_package(szProduct
, NULL
, context
, &package
);
870 if (r
!= ERROR_SUCCESS
)
873 sz
= lstrlenW(szInstalled
) + 1;
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
));
890 r
= ERROR_OUTOFMEMORY
;
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
);
922 msiobj_release( &package
->hdr
);
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
;
936 szwProduct
= strdupAtoW( szProduct
);
943 szwCommandLine
= strdupAtoW( szCommandLine
);
948 r
= MsiConfigureProductExW( szwProduct
, iInstallLevel
, eInstallState
,
951 msi_free( szwProduct
);
952 msi_free( szwCommandLine
);
957 UINT WINAPI
MsiConfigureProductA(LPCSTR szProduct
, int iInstallLevel
,
958 INSTALLSTATE eInstallState
)
960 LPWSTR szwProduct
= NULL
;
963 TRACE("%s %d %d\n",debugstr_a(szProduct
), iInstallLevel
, eInstallState
);
967 szwProduct
= strdupAtoW( szProduct
);
969 return ERROR_OUTOFMEMORY
;
972 r
= MsiConfigureProductW( szwProduct
, iInstallLevel
, eInstallState
);
973 msi_free( szwProduct
);
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
;
988 WCHAR szwBuffer
[GUID_SIZE
];
990 TRACE("%s %p\n", debugstr_a(szComponent
), szBuffer
);
994 szwComponent
= strdupAtoW( szComponent
);
996 return ERROR_OUTOFMEMORY
;
1000 r
= MsiGetProductCodeW( szwComponent
, szwBuffer
);
1003 WideCharToMultiByte(CP_ACP
, 0, szwBuffer
, -1, szBuffer
, GUID_SIZE
, NULL
, NULL
);
1005 msi_free( szwComponent
);
1010 UINT WINAPI
MsiGetProductCodeW(LPCWSTR szComponent
, LPWSTR szBuffer
)
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
)
1047 while ((rc
= RegEnumValueW( compkey
, index
, squashed_prod
, &sz
, NULL
, NULL
, NULL
, NULL
)) !=
1048 ERROR_NO_MORE_ITEMS
)
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
);
1070 rc
= ERROR_INSTALL_FAILURE
;
1073 RegCloseKey(compkey
);
1074 unsquash_guid( squashed_prod
, szBuffer
);
1078 static LPWSTR
msi_reg_get_value(HKEY hkey
, LPCWSTR name
, DWORD
*type
)
1084 static const WCHAR format
[] = {'%','d',0};
1086 res
= RegQueryValueExW(hkey
, name
, NULL
, type
, NULL
, NULL
);
1087 if (res
!= ERROR_SUCCESS
)
1090 if (*type
== REG_SZ
)
1091 return msi_reg_get_val_str(hkey
, name
);
1093 if (!msi_reg_get_val_dword(hkey
, name
, &dval
))
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
;
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
))
1157 r
= ERROR_UNKNOWN_PRODUCT
;
1160 if (MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
))
1162 r
= ERROR_UNKNOWN_PROPERTY
;
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
);
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
))
1189 r
= ERROR_UNKNOWN_PRODUCT
;
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
;
1205 val
= msi_reg_get_value(source
, szAttribute
, &type
);
1209 RegCloseKey(source
);
1213 val
= msi_reg_get_value(prodkey
, szAttribute
, &type
);
1218 if (val
!= empty
&& type
!= REG_DWORD
&&
1219 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
))
1221 if (lstrlenW( val
) != SQUASHED_GUID_SIZE
- 1)
1225 unsquash_guid(val
, packagecode
);
1227 val
= strdupW(packagecode
);
1234 r
= ERROR_UNKNOWN_PROPERTY
;
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
;
1250 r
= msi_strcpy_to_awstring( val
, len
, szValue
, &size
);
1252 r
= ERROR_MORE_DATA
;
1256 *pcchValueBuf
= len
;
1260 r
= ERROR_BAD_CONFIGURATION
;
1266 RegCloseKey(prodkey
);
1270 UINT WINAPI
MsiGetProductInfoA(LPCSTR szProduct
, LPCSTR szAttribute
,
1271 LPSTR szBuffer
, LPDWORD pcchValueBuf
)
1273 LPWSTR szwProduct
, szwAttribute
= NULL
;
1274 UINT r
= ERROR_OUTOFMEMORY
;
1277 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szAttribute
),
1278 szBuffer
, pcchValueBuf
);
1280 szwProduct
= strdupAtoW( szProduct
);
1281 if( szProduct
&& !szwProduct
)
1284 szwAttribute
= strdupAtoW( szAttribute
);
1285 if( szAttribute
&& !szwAttribute
)
1288 buffer
.unicode
= FALSE
;
1289 buffer
.str
.a
= szBuffer
;
1291 r
= MSI_GetProductInfo( szwProduct
, szwAttribute
,
1292 &buffer
, pcchValueBuf
);
1295 msi_free( szwProduct
);
1296 msi_free( szwAttribute
);
1301 UINT WINAPI
MsiGetProductInfoW(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1302 LPWSTR szBuffer
, LPDWORD pcchValueBuf
)
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
;
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
,
1340 if (r
!= ERROR_SUCCESS
)
1343 value
= msi_alloc(++len
* sizeof(WCHAR
));
1346 r
= ERROR_OUTOFMEMORY
;
1350 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1352 if (r
!= ERROR_SUCCESS
)
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
);
1363 r
= ERROR_MORE_DATA
;
1368 if (*pcchValue
<= len
|| !szValue
)
1369 len
= len
* sizeof(WCHAR
) - 1;
1371 *pcchValue
= len
- 1;
1382 static UINT
msi_copy_outval(LPWSTR val
, LPWSTR out
, LPDWORD size
)
1384 UINT r
= ERROR_SUCCESS
;
1387 return ERROR_UNKNOWN_PROPERTY
;
1391 if (strlenW(val
) >= *size
)
1393 r
= ERROR_MORE_DATA
;
1402 *size
= lstrlenW(val
);
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
;
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
,
1449 MSIREG_OpenProductKey(szProductCode
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1452 MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
, &props
, FALSE
);
1454 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1456 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1458 if (!props
&& !prod
)
1461 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1463 package
= managed_local_package
;
1465 if (!props
&& !managed
)
1468 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1470 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1471 MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
, &classes
, FALSE
);
1473 if (!props
&& !classes
)
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
);
1498 if (prod
|| classes
)
1499 r
= ERROR_UNKNOWN_PROPERTY
;
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
);
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
)
1529 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1531 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1533 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1536 val
= msi_reg_get_value(hkey
, szProperty
, &type
);
1538 val
= strdupW(szEmpty
);
1540 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1542 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTSTATEW
))
1544 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1548 val
= msi_reg_get_value(props
, package
, &type
);
1553 val
= strdupW(five
);
1556 val
= strdupW(szOne
);
1558 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1561 else if (props
&& (val
= msi_reg_get_value(props
, package
, &type
)))
1564 val
= strdupW(five
);
1565 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1569 if (prod
|| managed
)
1570 val
= strdupW(szOne
);
1574 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1576 else if (!strcmpW( szProperty
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1578 if (!prod
&& !classes
)
1582 val
= strdupW(szEmpty
);
1583 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1586 r
= ERROR_UNKNOWN_PROPERTY
;
1591 RegCloseKey(managed
);
1592 RegCloseKey(classes
);
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
;
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
);
1620 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1622 if (r
!= ERROR_SUCCESS
)
1625 val
= msi_alloc(++len
* sizeof(WCHAR
));
1628 r
= ERROR_OUTOFMEMORY
;
1632 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1634 if (r
!= ERROR_SUCCESS
|| !pcchValue
)
1638 WideCharToMultiByte(CP_ACP
, 0, val
, -1, lpValue
,
1639 *pcchValue
- 1, NULL
, NULL
);
1641 len
= lstrlenW(val
);
1642 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1646 r
= ERROR_MORE_DATA
;
1647 lpValue
[*pcchValue
- 1] = '\0';
1650 *pcchValue
= len
* sizeof(WCHAR
);
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
;
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
;
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
)
1711 if (MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
,
1712 &props
, FALSE
) != ERROR_SUCCESS
)
1715 r
= ERROR_UNKNOWN_PATCH
;
1717 res
= RegOpenKeyExW(udprod
, szPatches
, 0, KEY_WOW64_64KEY
|KEY_READ
, &patches
);
1718 if (res
!= ERROR_SUCCESS
)
1721 res
= RegOpenKeyExW( patches
, squashed_patch
, 0, KEY_WOW64_64KEY
|KEY_READ
, &patch
);
1722 if (res
!= ERROR_SUCCESS
)
1725 if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
))
1727 if (MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
,
1728 &prod
, FALSE
) != ERROR_SUCCESS
)
1731 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_WOW64_64KEY
|KEY_ALL_ACCESS
, &prodpatches
);
1732 if (res
!= ERROR_SUCCESS
)
1735 datakey
= prodpatches
;
1736 szProperty
= squashed_patch
;
1740 if (MSIREG_OpenUserDataPatchKey(szPatchCode
, dwContext
,
1741 &udpatch
, FALSE
) != ERROR_SUCCESS
)
1744 if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1746 if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1747 szProperty
= szManagedPackage
;
1750 else if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
))
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
))
1764 r
= ERROR_UNKNOWN_PROPERTY
;
1769 val
= msi_reg_get_val_str(datakey
, szProperty
);
1771 val
= strdupW(szEmpty
);
1779 lstrcpynW(lpValue
, val
, *pcchValue
);
1781 len
= lstrlenW(val
);
1782 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1785 r
= ERROR_MORE_DATA
;
1787 *pcchValue
= len
* sizeof(WCHAR
);
1794 RegCloseKey(prodpatches
);
1797 RegCloseKey(patches
);
1798 RegCloseKey(udpatch
);
1800 RegCloseKey(udprod
);
1805 UINT WINAPI
MsiGetPatchInfoA( LPCSTR patch
, LPCSTR attr
, LPSTR buffer
, LPDWORD buflen
)
1807 UINT r
= ERROR_OUTOFMEMORY
;
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
)))
1819 if (!(attrW
= strdupAtoW( attr
)))
1823 r
= MsiGetPatchInfoW( patchW
, attrW
, NULL
, &size
);
1824 if (r
!= ERROR_SUCCESS
)
1828 if (!(bufferW
= msi_alloc( size
* sizeof(WCHAR
) )))
1830 r
= ERROR_OUTOFMEMORY
;
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
);
1839 r
= ERROR_MORE_DATA
;
1841 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *buflen
, NULL
, NULL
);
1849 msi_free( bufferW
);
1853 UINT WINAPI
MsiGetPatchInfoW( LPCWSTR patch
, LPCWSTR attr
, LPWSTR buffer
, LPDWORD buflen
)
1856 WCHAR product
[GUID_SIZE
];
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
;
1870 r
= MsiEnumProductsW( index
, product
);
1871 if (r
!= ERROR_SUCCESS
)
1874 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, attr
, buffer
, buflen
);
1875 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1878 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, attr
, buffer
, buflen
);
1879 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1882 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_MACHINE
, attr
, buffer
, buflen
);
1883 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1889 return ERROR_UNKNOWN_PRODUCT
;
1892 UINT WINAPI
MsiEnableLogA(DWORD dwLogMode
, LPCSTR szLogFile
, DWORD attributes
)
1894 LPWSTR szwLogFile
= NULL
;
1897 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_a(szLogFile
), attributes
);
1901 szwLogFile
= strdupAtoW( szLogFile
);
1903 return ERROR_OUTOFMEMORY
;
1905 r
= MsiEnableLogW( dwLogMode
, szwLogFile
, attributes
);
1906 msi_free( szwLogFile
);
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
);
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
);
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
)
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
;
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
);
1959 WideCharToMultiByte( CP_ACP
, 0, driveW
, -1, drive
, len
, NULL
, NULL
);
1961 msi_free( componentW
);
1966 static UINT
set_drive( WCHAR
*buffer
, WCHAR letter
)
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
;
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
)))
1992 IWineMsiRemotePackage
*remote_package
;
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
);
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
;
2027 msiobj_release( &package
->hdr
);
2028 return ERROR_MORE_DATA
;
2032 msiobj_release( &package
->hdr
);
2033 return ERROR_NO_MORE_ITEMS
;
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
)
2045 *buflen
= set_drive( drive
, path
[0] );
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] );
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] );
2061 msiobj_release( &package
->hdr
);
2065 UINT WINAPI
MsiQueryComponentStateA(LPCSTR szProductCode
,
2066 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
2067 LPCSTR szComponent
, INSTALLSTATE
*pdwState
)
2069 LPWSTR prodcode
= NULL
, usersid
= NULL
, comp
= NULL
;
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
);
2093 static BOOL
msi_comp_find_prod_key(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
2098 r
= MSIREG_OpenProductKey(prodcode
, NULL
, context
, &hkey
, FALSE
);
2100 return (r
== ERROR_SUCCESS
);
2103 static BOOL
msi_comp_find_package(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
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
)
2120 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
2121 package
= managed_local_package
;
2123 package
= local_package
;
2126 res
= RegQueryValueExW(hkey
, package
, NULL
, NULL
, NULL
, &sz
);
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
)
2140 if (context
== MSIINSTALLCONTEXT_MACHINE
)
2141 r
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2143 r
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2145 if (r
!= ERROR_SUCCESS
)
2148 res
= RegQueryValueExW( hkey
, squashed_pc
, NULL
, NULL
, (BYTE
*)val
, sz
);
2149 if (res
!= ERROR_SUCCESS
)
2156 UINT WINAPI
MsiQueryComponentStateW(LPCWSTR szProductCode
,
2157 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
2158 LPCWSTR szComponent
, INSTALLSTATE
*pdwState
)
2160 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
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
))
2182 *pdwState
= INSTALLSTATE_UNKNOWN
;
2183 return ERROR_UNKNOWN_COMPONENT
;
2186 return ERROR_UNKNOWN_PRODUCT
;
2189 *pdwState
= INSTALLSTATE_UNKNOWN
;
2192 if (msi_comp_find_prodcode( squashed_pc
, dwContext
, szComponent
, NULL
, &sz
))
2193 return ERROR_UNKNOWN_COMPONENT
;
2196 *pdwState
= INSTALLSTATE_NOTUSED
;
2202 if (!(val
= msi_alloc( sz
))) return ERROR_OUTOFMEMORY
;
2203 if ((r
= msi_comp_find_prodcode( squashed_pc
, dwContext
, szComponent
, val
, &sz
)))
2209 if (lstrlenW(val
) > 2 &&
2210 val
[0] >= '0' && val
[0] <= '9' && val
[1] >= '0' && val
[1] <= '9' && val
[2] != ':')
2212 *pdwState
= INSTALLSTATE_SOURCE
;
2215 *pdwState
= INSTALLSTATE_LOCAL
;
2219 TRACE("-> %d\n", *pdwState
);
2220 return ERROR_SUCCESS
;
2223 INSTALLSTATE WINAPI
MsiQueryProductStateA(LPCSTR szProduct
)
2225 LPWSTR szwProduct
= NULL
;
2230 szwProduct
= strdupAtoW( szProduct
);
2232 return ERROR_OUTOFMEMORY
;
2234 r
= MsiQueryProductStateW( szwProduct
);
2235 msi_free( szwProduct
);
2239 INSTALLSTATE WINAPI
MsiQueryProductStateW(LPCWSTR szProduct
)
2241 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
2242 INSTALLSTATE state
= INSTALLSTATE_ADVERTISED
;
2243 HKEY prodkey
= 0, userdata
= 0;
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
)
2274 if (!msi_reg_get_val_dword(userdata
, szWindowsInstaller
, &val
))
2278 state
= INSTALLSTATE_DEFAULT
;
2280 state
= INSTALLSTATE_UNKNOWN
;
2285 state
= INSTALLSTATE_UNKNOWN
;
2288 state
= INSTALLSTATE_ABSENT
;
2291 RegCloseKey(prodkey
);
2292 RegCloseKey(userdata
);
2293 TRACE("-> %d\n", 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
;
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
;
2322 gUIFilter
= dwMessageFilter
;
2323 gUIContext
= pvContext
;
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
);
2336 gUIHandlerW
= puiHandler
;
2337 gUIFilter
= dwMessageFilter
;
2338 gUIContext
= pvContext
;
2343 /******************************************************************
2344 * MsiLoadStringW [MSI.@]
2346 * Loads a string from MSI's string resources.
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
2358 * If successful, this function returns the language id of the string loaded
2359 * If the function fails, the function returns zero.
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
)
2376 TRACE("%d %u %p %d %d\n", handle
, id
, lpBuffer
, nBufferMax
, lang
);
2379 FIXME("don't know how to deal with handle = %08x\n", handle
);
2382 lang
= GetUserDefaultLangID();
2384 hres
= FindResourceExW( msi_hInstance
, (LPCWSTR
) RT_STRING
,
2388 hResData
= LoadResource( msi_hInstance
, hres
);
2391 p
= LockResource( hResData
);
2395 for (i
= 0; i
< (id
& 0xf); i
++) p
+= *p
+ 1;
2398 if( nBufferMax
<= len
)
2401 memcpy( lpBuffer
, p
+1, len
* sizeof(WCHAR
));
2402 lpBuffer
[ len
] = 0;
2404 TRACE("found -> %s\n", debugstr_w(lpBuffer
));
2408 LANGID WINAPI
MsiLoadStringA( MSIHANDLE handle
, UINT id
, LPSTR lpBuffer
,
2409 int nBufferMax
, LANGID lang
)
2415 bufW
= msi_alloc(nBufferMax
*sizeof(WCHAR
));
2416 r
= MsiLoadStringW(handle
, id
, bufW
, nBufferMax
, lang
);
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
);
2430 INSTALLSTATE WINAPI
MsiLocateComponentA(LPCSTR szComponent
, LPSTR lpPathBuf
,
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
,
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
,
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
,
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
)
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
);
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
;
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
;
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
);
2575 if (FAILED(hr
)) goto done
;
2577 if (!(signer
= WTHelperGetProvSignerFromChain( data
.hWVTStateData
, 0, FALSE
, 0 )))
2579 hr
= TRUST_E_NOSIGNATURE
;
2584 DWORD len
= signer
->psSigner
->EncryptedHash
.cbData
;
2588 hr
= HRESULT_FROM_WIN32(ERROR_MORE_DATA
);
2591 memcpy( hash
, signer
->psSigner
->EncryptedHash
.pbData
, len
);
2594 if (!(provider
= WTHelperGetProvCertFromChain( signer
, 0 )))
2596 hr
= TRUST_E_PROVIDER_UNKNOWN
;
2599 *cert
= CertDuplicateCertificateContext( provider
->pCert
);
2602 data
.dwStateAction
= WTD_STATEACTION_CLOSE
;
2603 WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2607 /******************************************************************
2608 * MsiGetProductPropertyA [MSI.@]
2610 UINT WINAPI
MsiGetProductPropertyA(MSIHANDLE hProduct
, LPCSTR szProperty
,
2611 LPSTR szValue
, LPDWORD pccbValue
)
2613 LPWSTR prop
= NULL
, val
= NULL
;
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
);
2626 r
= MsiGetProductPropertyW(hProduct
, prop
, NULL
, &len
);
2627 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2630 if (r
== ERROR_SUCCESS
)
2632 if (szValue
) *szValue
= '\0';
2633 if (pccbValue
) *pccbValue
= 0;
2637 val
= msi_alloc(++len
* sizeof(WCHAR
));
2640 r
= ERROR_OUTOFMEMORY
;
2644 r
= MsiGetProductPropertyW(hProduct
, prop
, val
, &len
);
2645 if (r
!= ERROR_SUCCESS
)
2648 len
= WideCharToMultiByte(CP_ACP
, 0, val
, -1, NULL
, 0, NULL
, NULL
);
2651 WideCharToMultiByte(CP_ACP
, 0, val
, -1, szValue
,
2652 *pccbValue
, NULL
, NULL
);
2656 if (len
> *pccbValue
)
2657 r
= ERROR_MORE_DATA
;
2659 *pccbValue
= len
- 1;
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
;
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
);
2690 return ERROR_INVALID_PARAMETER
;
2692 if (szValue
&& !pccbValue
)
2693 return ERROR_INVALID_PARAMETER
;
2695 package
= msihandle2msiinfo(hProduct
, MSIHANDLETYPE_PACKAGE
);
2697 return ERROR_INVALID_HANDLE
;
2699 r
= MSI_OpenQuery(package
->db
, &view
, query
, szProperty
);
2700 if (r
!= ERROR_SUCCESS
)
2703 r
= MSI_ViewExecute(view
, 0);
2704 if (r
!= ERROR_SUCCESS
)
2707 r
= MSI_ViewFetch(view
, &rec
);
2708 if (r
!= ERROR_SUCCESS
)
2711 val
= MSI_RecordGetString(rec
, 2);
2715 if (lstrlenW(val
) >= *pccbValue
)
2717 if (szValue
) lstrcpynW(szValue
, val
, *pccbValue
);
2718 r
= ERROR_MORE_DATA
;
2722 if (szValue
) lstrcpyW(szValue
, val
);
2726 *pccbValue
= lstrlenW(val
);
2731 MSI_ViewClose(view
);
2732 msiobj_release(&view
->hdr
);
2733 if (rec
) msiobj_release(&rec
->hdr
);
2738 if (szValue
) *szValue
= '\0';
2739 if (pccbValue
) *pccbValue
= 0;
2743 msiobj_release(&package
->hdr
);
2747 UINT WINAPI
MsiVerifyPackageA( LPCSTR szPackage
)
2750 LPWSTR szPack
= NULL
;
2752 TRACE("%s\n", debugstr_a(szPackage
) );
2756 szPack
= strdupAtoW( szPackage
);
2758 return ERROR_OUTOFMEMORY
;
2761 r
= MsiVerifyPackageW( szPack
);
2768 UINT WINAPI
MsiVerifyPackageW( LPCWSTR szPackage
)
2773 TRACE("%s\n", debugstr_w(szPackage
) );
2775 r
= MsiOpenDatabaseW( szPackage
, MSIDBOPEN_READONLY
, &handle
);
2776 MsiCloseHandle( handle
);
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
];
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
);
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
)
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
))
2831 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2832 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2835 path
= msi_reg_get_val_str( hkey
, squashed_pc
);
2838 state
= INSTALLSTATE_ABSENT
;
2840 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2841 state
= INSTALLSTATE_LOCAL
;
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
;
2858 /******************************************************************
2859 * MsiGetComponentPathW [MSI.@]
2861 INSTALLSTATE WINAPI
MsiGetComponentPathW(LPCWSTR szProduct
, LPCWSTR szComponent
,
2862 LPWSTR lpPathBuf
, LPDWORD pcchBuf
)
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
;
2884 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2886 szwProduct
= strdupAtoW( szProduct
);
2887 if( szProduct
&& !szwProduct
)
2890 szwComponent
= strdupAtoW( szComponent
);
2891 if( szComponent
&& !szwComponent
)
2894 path
.unicode
= FALSE
;
2895 path
.str
.a
= lpPathBuf
;
2897 r
= MSI_GetComponentPath( szwProduct
, szwComponent
, &path
, pcchBuf
);
2900 msi_free( szwProduct
);
2901 msi_free( szwComponent
);
2906 static UINT
query_feature_state( const WCHAR
*product
, const WCHAR
*squashed
, const WCHAR
*usersid
,
2907 MSIINSTALLCONTEXT ctx
, const WCHAR
*feature
, INSTALLSTATE
*state
)
2911 WCHAR
*parent
, *components
, *path
;
2913 BOOL missing
= FALSE
, source
= FALSE
;
2914 WCHAR comp
[GUID_SIZE
];
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
;
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
));
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
);
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')
2977 msi_free( components
);
2980 *state
= INSTALLSTATE_ADVERTISED
;
2982 *state
= INSTALLSTATE_SOURCE
;
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
)
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
);
3015 UINT WINAPI
MsiQueryFeatureStateExW( LPCWSTR product
, LPCWSTR usersid
, MSIINSTALLCONTEXT ctx
,
3016 LPCWSTR feature
, INSTALLSTATE
*state
)
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
)
3035 szwFeature
= strdupAtoW( szFeature
);
3036 if ( szFeature
&& !szwFeature
)
3039 rc
= MsiQueryFeatureStateW(szwProduct
, szwFeature
);
3042 msi_free( szwProduct
);
3043 msi_free( szwFeature
);
3048 /******************************************************************
3049 * MsiQueryFeatureStateW [MSI.@]
3051 * Checks the state of a feature
3054 * szProduct [I] Product's GUID string
3055 * szFeature [I] Feature's GUID string
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
)
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
;
3103 szwFilePath
= strdupAtoW( szFilePath
);
3108 if( lpVersionBuf
&& pcchVersionBuf
&& *pcchVersionBuf
)
3110 lpwVersionBuff
= msi_alloc(*pcchVersionBuf
*sizeof(WCHAR
));
3111 if( !lpwVersionBuff
)
3115 if( lpLangBuf
&& pcchLangBuf
&& *pcchLangBuf
)
3117 lpwLangBuff
= msi_alloc(*pcchLangBuf
*sizeof(WCHAR
));
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
);
3133 msi_free(szwFilePath
);
3134 msi_free(lpwVersionBuff
);
3135 msi_free(lpwLangBuff
);
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
;
3149 VS_FIXEDFILEINFO
*ffi
;
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
;
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
;
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
;
3185 if (verbuf
) *verbuf
= 0;
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
;
3201 if (langbuf
) *langbuf
= 0;
3205 msi_free( version
);
3210 /******************************************************************
3211 * MsiGetFileVersionW [MSI.@]
3213 UINT WINAPI
MsiGetFileVersionW( LPCWSTR path
, LPWSTR verbuf
, LPDWORD verlen
,
3214 LPWSTR langbuf
, LPDWORD langlen
)
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
)
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
;
3234 strcpyW( verbuf
, version
);
3235 ret
= ERROR_SUCCESS
;
3238 msi_free( version
);
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
)
3270 feat
= strdupAtoW( szFeature
);
3271 if (szFeature
&& !feat
)
3274 ret
= MsiGetFeatureUsageW( prod
, feat
, pdwUseCount
, pwDateUsed
);
3283 /***********************************************************************
3284 * MsiUseFeatureExW [MSI.@]
3286 INSTALLSTATE WINAPI
MsiUseFeatureExW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3287 DWORD dwInstallMode
, DWORD dwReserved
)
3291 TRACE("%s %s %i %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
3292 dwInstallMode
, dwReserved
);
3294 state
= MsiQueryFeatureStateW( szProduct
, szFeature
);
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
) );
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
)
3324 feat
= strdupAtoW( szFeature
);
3325 if (szFeature
&& !feat
)
3328 ret
= MsiUseFeatureExW( prod
, feat
, dwInstallMode
, dwReserved
);
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
)
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
);
3362 static WCHAR
*reg_get_sz( HKEY hkey
, const WCHAR
*name
)
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
);
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];
3388 if (MSIREG_OpenUserComponentsKey( szComponent
, &hkey
, FALSE
)) return ERROR_UNKNOWN_COMPONENT
;
3390 desc
= reg_get_multisz( hkey
, szQualifier
);
3392 if (!desc
) return ERROR_INDEX_ABSENT
;
3394 /* FIXME: handle multiple descriptors */
3395 ret
= MsiDecomposeDescriptorW( desc
, product
, feature
, comp
, &size
);
3397 if (ret
!= ERROR_SUCCESS
) return ret
;
3399 if (!szProduct
) szProduct
= product
;
3402 MSIINSTALLCONTEXT ctx
;
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
)
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
;
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
)
3473 szwQualifier
= strdupAtoW( szQualifier
);
3474 if (szQualifier
&& !szwQualifier
)
3477 szwProduct
= strdupAtoW( szProduct
);
3478 if (szProduct
&& !szwProduct
)
3481 path
.unicode
= FALSE
;
3482 path
.str
.a
= lpPathBuf
;
3484 r
= MSI_ProvideQualifiedComponentEx(szwComponent
, szwQualifier
,
3485 dwInstallMode
, szwProduct
, Unused1
,
3486 Unused2
, &path
, pcchPathBuf
);
3488 msi_free(szwProduct
);
3489 msi_free(szwComponent
);
3490 msi_free(szwQualifier
);
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
;
3531 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct
), lpUserNameBuf
,
3532 pcchUserNameBuf
, lpOrgNameBuf
, pcchOrgNameBuf
, lpSerialBuf
,
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
)
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
;
3566 state
= USERINFOSTATE_PRESENT
;
3568 if (pcchUserNameBuf
)
3570 if (lpUserNameBuf
&& !user
)
3572 (*pcchUserNameBuf
)--;
3576 r
= msi_strcpy_to_awstring(user
, -1, lpUserNameBuf
, pcchUserNameBuf
);
3577 if (r
== ERROR_MORE_DATA
)
3579 state
= USERINFOSTATE_MOREDATA
;
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
;
3605 r
= msi_strcpy_to_awstring(serial
, -1, lpSerialBuf
, pcchSerialBuf
);
3606 if (r
== ERROR_MORE_DATA
)
3607 state
= USERINFOSTATE_MOREDATA
;
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
;
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
;
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
);
3679 UINT WINAPI
MsiCollectUserInfoW(LPCWSTR szProduct
)
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
);
3695 return ERROR_CALL_NOT_IMPLEMENTED
;
3697 rc
= ACTION_PerformUIAction(package
, szFirstRun
, SCRIPT_NONE
);
3698 msiobj_release( &package
->hdr
);
3700 MsiCloseHandle(handle
);
3705 UINT WINAPI
MsiCollectUserInfoA(LPCSTR szProduct
)
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
);
3721 return ERROR_CALL_NOT_IMPLEMENTED
;
3723 rc
= ACTION_PerformUIAction(package
, szFirstRun
, SCRIPT_NONE
);
3724 msiobj_release( &package
->hdr
);
3726 MsiCloseHandle(handle
);
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
)
3745 feat
= strdupAtoW( szFeature
);
3746 if (szFeature
&& !feat
)
3749 r
= MsiConfigureFeatureW(prod
, feat
, eInstallState
);
3758 /***********************************************************************
3759 * MsiConfigureFeatureW [MSI.@]
3761 UINT WINAPI
MsiConfigureFeatureW(LPCWSTR szProduct
, LPCWSTR szFeature
, INSTALLSTATE eInstallState
)
3763 MSIPACKAGE
*package
= NULL
;
3765 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
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
;
3779 case INSTALLSTATE_LOCAL
:
3780 case INSTALLSTATE_SOURCE
:
3781 case INSTALLSTATE_ABSENT
:
3782 case INSTALLSTATE_ADVERTISED
:
3785 return ERROR_INVALID_PARAMETER
;
3788 r
= MSI_OpenProductW( szProduct
, &package
);
3789 if (r
!= ERROR_SUCCESS
)
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
)
3808 r
= MSI_SetFeatureStateW( package
, szFeature
, eInstallState
);
3809 if (r
!= ERROR_SUCCESS
)
3812 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3815 msiobj_release( &package
->hdr
);
3820 /***********************************************************************
3821 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3823 * Notes: undocumented
3825 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved
)
3827 WCHAR path
[MAX_PATH
];
3829 TRACE("%d\n", 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
)
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];
3860 target
= strdupAtoW( szShortcutTarget
);
3861 if (szShortcutTarget
&& !target
)
3862 return ERROR_OUTOFMEMORY
;
3866 r
= MsiGetShortcutTargetW( target
, product
, feature
, component
);
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
);
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
;
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
,
3904 if( SUCCEEDED( r
) )
3906 IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
,
3908 IShellLinkDataList_Release( dl
);
3911 IPersistFile_Release( pf
);
3914 if (SUCCEEDED(init
))
3917 TRACE("darwin = %p\n", darwin
);
3924 ret
= MsiDecomposeDescriptorW( darwin
->szwDarwinID
,
3925 szProductCode
, szFeatureId
, szComponentCode
, &sz
);
3926 LocalFree( darwin
);
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
;
3939 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
], reinstallmode
[11];
3940 WCHAR
*ptr
, *cmdline
;
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
)
3949 ptr
= reinstallmode
;
3951 if (dwReinstallMode
& REINSTALLMODE_FILEMISSING
)
3953 if (dwReinstallMode
& REINSTALLMODE_FILEOLDERVERSION
)
3955 if (dwReinstallMode
& REINSTALLMODE_FILEEQUALVERSION
)
3957 if (dwReinstallMode
& REINSTALLMODE_FILEEXACT
)
3959 if (dwReinstallMode
& REINSTALLMODE_FILEVERIFY
)
3961 if (dwReinstallMode
& REINSTALLMODE_FILEREPLACE
)
3963 if (dwReinstallMode
& REINSTALLMODE_USERDATA
)
3965 if (dwReinstallMode
& REINSTALLMODE_MACHINEDATA
)
3967 if (dwReinstallMode
& REINSTALLMODE_SHORTCUT
)
3969 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
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
);
3984 r
= MSI_OpenProductW( szProduct
, &package
);
3986 if (r
!= ERROR_SUCCESS
)
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
);
4005 UINT WINAPI
MsiReinstallFeatureA( LPCSTR szProduct
, LPCSTR szFeature
,
4006 DWORD dwReinstallMode
)
4012 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
4015 wszProduct
= strdupAtoW(szProduct
);
4016 wszFeature
= strdupAtoW(szFeature
);
4018 rc
= MsiReinstallFeatureW(wszProduct
, wszFeature
, dwReinstallMode
);
4020 msi_free(wszProduct
);
4021 msi_free(wszFeature
);
4028 unsigned int buf
[4];
4029 unsigned char in
[64];
4030 unsigned char digest
[16];
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
;
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
)))
4059 MD5Update( &ctx
, p
, length
);
4061 UnmapViewOfFile( p
);
4063 memcpy( hash
->dwData
, ctx
.digest
, sizeof(hash
->dwData
) );
4066 CloseHandle( mapping
);
4071 /* Empty file -> set hash to 0 */
4072 memset( hash
->dwData
, 0, sizeof(hash
->dwData
) );
4076 CloseHandle( handle
);
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
);
4089 return ERROR_INVALID_PARAMETER
;
4092 return ERROR_PATH_NOT_FOUND
;
4095 return ERROR_INVALID_PARAMETER
;
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
)
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
);
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
);
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
);
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
);
4178 *prev
= gUIHandlerRecord
;
4180 gUIHandlerRecord
= handler
;
4182 gUIContext
= context
;
4184 return ERROR_SUCCESS
;
4187 /***********************************************************************
4188 * MsiInstallMissingComponentA [MSI.@]
4190 UINT WINAPI
MsiInstallMissingComponentA( LPCSTR product
, LPCSTR component
, INSTALLSTATE state
)
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
);
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
;
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
)
4238 if (!(bufW
= msi_alloc( ++lenW
* sizeof(WCHAR
) )))
4240 r
= ERROR_OUTOFMEMORY
;
4244 r
= MsiProvideComponentW( productW
, featureW
, componentW
, mode
, bufW
, &lenW
);
4245 if (r
!= ERROR_SUCCESS
)
4248 len
= WideCharToMultiByte( CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
4252 r
= ERROR_MORE_DATA
;
4254 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1, buf
, *buflen
, NULL
, NULL
);
4260 msi_free( productW
);
4261 msi_free( featureW
);
4262 msi_free( componentW
);
4267 UINT WINAPI
MsiProvideComponentW( LPCWSTR product
, LPCWSTR feature
, LPCWSTR component
, DWORD mode
, LPWSTR buf
, LPDWORD buflen
)
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
);
4277 case INSTALLMODE_NODETECTION
:
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
);
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
;
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
)
4315 FIXME("%s %u %p %p\n", debugstr_a(name
), attrs
, id
, event
);
4317 nameW
= strdupAtoW( name
);
4319 return ERROR_OUTOFMEMORY
;
4321 r
= MsiBeginTransactionW( nameW
, attrs
, id
, event
);
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
;