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
49 #include "wine/debug.h"
50 #include "wine/exception.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
56 UINT
msi_locate_product(LPCWSTR szProduct
, MSIINSTALLCONTEXT
*context
)
60 *context
= MSIINSTALLCONTEXT_NONE
;
61 if (!szProduct
) return ERROR_UNKNOWN_PRODUCT
;
63 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
64 &hkey
, FALSE
) == ERROR_SUCCESS
)
65 *context
= MSIINSTALLCONTEXT_USERMANAGED
;
66 else if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
67 &hkey
, FALSE
) == ERROR_SUCCESS
)
68 *context
= MSIINSTALLCONTEXT_MACHINE
;
69 else if (MSIREG_OpenProductKey(szProduct
, NULL
,
70 MSIINSTALLCONTEXT_USERUNMANAGED
,
71 &hkey
, FALSE
) == ERROR_SUCCESS
)
72 *context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
76 if (*context
== MSIINSTALLCONTEXT_NONE
)
77 return ERROR_UNKNOWN_PRODUCT
;
82 UINT WINAPI
MsiOpenProductA(LPCSTR szProduct
, MSIHANDLE
*phProduct
)
85 LPWSTR szwProd
= NULL
;
87 TRACE("%s %p\n",debugstr_a(szProduct
), phProduct
);
91 szwProd
= strdupAtoW( szProduct
);
93 return ERROR_OUTOFMEMORY
;
96 r
= MsiOpenProductW( szwProd
, phProduct
);
103 static UINT
MSI_OpenProductW(LPCWSTR szProduct
, MSIPACKAGE
**package
)
108 MSIINSTALLCONTEXT context
;
110 TRACE("%s %p\n", debugstr_w(szProduct
), package
);
112 r
= msi_locate_product(szProduct
, &context
);
113 if (r
!= ERROR_SUCCESS
)
116 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &props
, FALSE
);
117 if (r
!= ERROR_SUCCESS
)
118 return ERROR_UNKNOWN_PRODUCT
;
120 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
121 path
= msi_reg_get_val_str(props
, L
"ManagedLocalPackage");
123 path
= msi_reg_get_val_str(props
, L
"LocalPackage");
125 r
= ERROR_UNKNOWN_PRODUCT
;
127 if (!path
|| GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
130 if (PathIsRelativeW(path
))
132 r
= ERROR_INSTALL_PACKAGE_OPEN_FAILED
;
136 r
= MSI_OpenPackageW(path
, 0, package
);
144 UINT WINAPI
MsiOpenProductW(LPCWSTR szProduct
, MSIHANDLE
*phProduct
)
146 MSIPACKAGE
*package
= NULL
;
147 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
150 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
151 return ERROR_INVALID_PARAMETER
;
154 return ERROR_INVALID_PARAMETER
;
156 r
= MSI_OpenProductW(szProduct
, &package
);
157 if (r
!= ERROR_SUCCESS
)
160 *phProduct
= alloc_msihandle(&package
->hdr
);
162 r
= ERROR_NOT_ENOUGH_MEMORY
;
164 msiobj_release(&package
->hdr
);
168 UINT WINAPI
MsiAdvertiseProductA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
169 LPCSTR szTransforms
, LANGID lgidLanguage
)
171 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath
),
172 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
), lgidLanguage
);
173 return ERROR_CALL_NOT_IMPLEMENTED
;
176 UINT WINAPI
MsiAdvertiseProductW(LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
177 LPCWSTR szTransforms
, LANGID lgidLanguage
)
179 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath
),
180 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
), lgidLanguage
);
181 return ERROR_CALL_NOT_IMPLEMENTED
;
184 UINT WINAPI
MsiAdvertiseProductExA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
185 LPCSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
187 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath
),
188 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
),
189 lgidLanguage
, dwPlatform
, dwOptions
);
190 return ERROR_CALL_NOT_IMPLEMENTED
;
193 UINT WINAPI
MsiAdvertiseProductExW( LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
194 LPCWSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
196 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath
),
197 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
),
198 lgidLanguage
, dwPlatform
, dwOptions
);
199 return ERROR_CALL_NOT_IMPLEMENTED
;
202 UINT WINAPI
MsiInstallProductA(LPCSTR szPackagePath
, LPCSTR szCommandLine
)
204 LPWSTR szwPath
= NULL
, szwCommand
= NULL
;
205 UINT r
= ERROR_OUTOFMEMORY
;
207 TRACE("%s %s\n",debugstr_a(szPackagePath
), debugstr_a(szCommandLine
));
211 szwPath
= strdupAtoW( szPackagePath
);
218 szwCommand
= strdupAtoW( szCommandLine
);
223 r
= MsiInstallProductW( szwPath
, szwCommand
);
227 msi_free( szwCommand
);
232 UINT WINAPI
MsiInstallProductW(LPCWSTR szPackagePath
, LPCWSTR szCommandLine
)
234 MSIPACKAGE
*package
= NULL
;
235 const WCHAR
*reinstallmode
;
239 TRACE("%s %s\n",debugstr_w(szPackagePath
), debugstr_w(szCommandLine
));
242 return ERROR_INVALID_PARAMETER
;
245 return ERROR_PATH_NOT_FOUND
;
247 reinstallmode
= msi_get_command_line_option(szCommandLine
, L
"REINSTALLMODE", &len
);
252 if (reinstallmode
[--len
] == 'v' || reinstallmode
[len
] == 'V')
254 options
|= WINE_OPENPACKAGEFLAGS_RECACHE
;
260 r
= MSI_OpenPackageW( szPackagePath
, options
, &package
);
261 if (r
== ERROR_SUCCESS
)
263 r
= MSI_InstallPackage( package
, szPackagePath
, szCommandLine
);
264 msiobj_release( &package
->hdr
);
270 UINT WINAPI
MsiReinstallProductA(LPCSTR szProduct
, DWORD dwReinstallMode
)
275 TRACE("%s %08x\n", debugstr_a(szProduct
), dwReinstallMode
);
277 wszProduct
= strdupAtoW(szProduct
);
279 rc
= MsiReinstallProductW(wszProduct
, dwReinstallMode
);
281 msi_free(wszProduct
);
285 UINT WINAPI
MsiReinstallProductW(LPCWSTR szProduct
, DWORD dwReinstallMode
)
287 TRACE("%s %08x\n", debugstr_w(szProduct
), dwReinstallMode
);
289 return MsiReinstallFeatureW(szProduct
, L
"ALL", dwReinstallMode
);
292 UINT WINAPI
MsiApplyPatchA(LPCSTR szPatchPackage
, LPCSTR szInstallPackage
,
293 INSTALLTYPE eInstallType
, LPCSTR szCommandLine
)
295 LPWSTR patch_package
= NULL
;
296 LPWSTR install_package
= NULL
;
297 LPWSTR command_line
= NULL
;
298 UINT r
= ERROR_OUTOFMEMORY
;
300 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage
), debugstr_a(szInstallPackage
),
301 eInstallType
, debugstr_a(szCommandLine
));
303 if (szPatchPackage
&& !(patch_package
= strdupAtoW(szPatchPackage
)))
306 if (szInstallPackage
&& !(install_package
= strdupAtoW(szInstallPackage
)))
309 if (szCommandLine
&& !(command_line
= strdupAtoW(szCommandLine
)))
312 r
= MsiApplyPatchW(patch_package
, install_package
, eInstallType
, command_line
);
315 msi_free(patch_package
);
316 msi_free(install_package
);
317 msi_free(command_line
);
322 static UINT
get_patch_product_codes( LPCWSTR szPatchPackage
, WCHAR
***product_codes
)
324 MSIHANDLE patch
, info
= 0;
327 static WCHAR empty
[] = L
"";
330 r
= MsiOpenDatabaseW( szPatchPackage
, MSIDBOPEN_READONLY
, &patch
);
331 if (r
!= ERROR_SUCCESS
)
334 r
= MsiGetSummaryInformationW( patch
, NULL
, 0, &info
);
335 if (r
!= ERROR_SUCCESS
)
339 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, empty
, &size
);
340 if (r
!= ERROR_MORE_DATA
|| !size
|| type
!= VT_LPSTR
)
342 ERR("Failed to read product codes from patch\n");
343 r
= ERROR_FUNCTION_FAILED
;
347 codes
= msi_alloc( ++size
* sizeof(WCHAR
) );
350 r
= ERROR_OUTOFMEMORY
;
354 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, codes
, &size
);
355 if (r
== ERROR_SUCCESS
)
356 *product_codes
= msi_split_string( codes
, ';' );
359 MsiCloseHandle( info
);
360 MsiCloseHandle( patch
);
365 static UINT
MSI_ApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szProductCode
, LPCWSTR szCommandLine
)
367 UINT i
, r
= ERROR_FUNCTION_FAILED
;
369 LPCWSTR cmd_ptr
= szCommandLine
;
370 LPWSTR cmd
, *codes
= NULL
;
371 BOOL succeeded
= FALSE
;
373 if (!szPatchPackage
|| !szPatchPackage
[0])
374 return ERROR_INVALID_PARAMETER
;
376 if (!szProductCode
&& (r
= get_patch_product_codes( szPatchPackage
, &codes
)))
382 size
= lstrlenW(cmd_ptr
) + lstrlenW(L
"%s PATCH=\"%s\"") + lstrlenW(szPatchPackage
) + 1;
383 cmd
= msi_alloc(size
* sizeof(WCHAR
));
387 return ERROR_OUTOFMEMORY
;
389 swprintf(cmd
, size
, L
"%s PATCH=\"%s\"", cmd_ptr
, szPatchPackage
);
392 r
= MsiConfigureProductExW(szProductCode
, INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
395 for (i
= 0; codes
[i
]; i
++)
397 r
= MsiConfigureProductExW(codes
[i
], INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
398 if (r
== ERROR_SUCCESS
)
400 TRACE("patch applied\n");
414 UINT WINAPI
MsiApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szInstallPackage
,
415 INSTALLTYPE eInstallType
, LPCWSTR szCommandLine
)
417 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage
), debugstr_w(szInstallPackage
),
418 eInstallType
, debugstr_w(szCommandLine
));
420 if (szInstallPackage
|| eInstallType
== INSTALLTYPE_NETWORK_IMAGE
||
421 eInstallType
== INSTALLTYPE_SINGLE_INSTANCE
)
423 FIXME("Only reading target products from patch\n");
424 return ERROR_CALL_NOT_IMPLEMENTED
;
427 return MSI_ApplyPatchW(szPatchPackage
, NULL
, szCommandLine
);
430 UINT WINAPI
MsiApplyMultiplePatchesA(LPCSTR szPatchPackages
,
431 LPCSTR szProductCode
, LPCSTR szPropertiesList
)
433 LPWSTR patch_packages
= NULL
;
434 LPWSTR product_code
= NULL
;
435 LPWSTR properties_list
= NULL
;
436 UINT r
= ERROR_OUTOFMEMORY
;
438 TRACE("%s %s %s\n", debugstr_a(szPatchPackages
), debugstr_a(szProductCode
),
439 debugstr_a(szPropertiesList
));
441 if (!szPatchPackages
|| !szPatchPackages
[0])
442 return ERROR_INVALID_PARAMETER
;
444 if (!(patch_packages
= strdupAtoW(szPatchPackages
)))
445 return ERROR_OUTOFMEMORY
;
447 if (szProductCode
&& !(product_code
= strdupAtoW(szProductCode
)))
450 if (szPropertiesList
&& !(properties_list
= strdupAtoW(szPropertiesList
)))
453 r
= MsiApplyMultiplePatchesW(patch_packages
, product_code
, properties_list
);
456 msi_free(patch_packages
);
457 msi_free(product_code
);
458 msi_free(properties_list
);
463 UINT WINAPI
MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages
,
464 LPCWSTR szProductCode
, LPCWSTR szPropertiesList
)
466 UINT r
= ERROR_SUCCESS
;
469 TRACE("%s %s %s\n", debugstr_w(szPatchPackages
), debugstr_w(szProductCode
),
470 debugstr_w(szPropertiesList
));
472 if (!szPatchPackages
|| !szPatchPackages
[0])
473 return ERROR_INVALID_PARAMETER
;
475 beg
= end
= szPatchPackages
;
481 while (*beg
== ' ') beg
++;
482 while (*end
&& *end
!= ';') end
++;
485 while (len
&& beg
[len
- 1] == ' ') len
--;
487 if (!len
) return ERROR_INVALID_NAME
;
489 patch
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
491 return ERROR_OUTOFMEMORY
;
493 memcpy(patch
, beg
, len
* sizeof(WCHAR
));
496 r
= MSI_ApplyPatchW(patch
, szProductCode
, szPropertiesList
);
499 if (r
!= ERROR_SUCCESS
|| !*end
)
507 static void free_patchinfo( DWORD count
, MSIPATCHSEQUENCEINFOW
*info
)
510 for (i
= 0; i
< count
; i
++) msi_free( (WCHAR
*)info
[i
].szPatchData
);
514 static MSIPATCHSEQUENCEINFOW
*patchinfoAtoW( DWORD count
, const MSIPATCHSEQUENCEINFOA
*info
)
517 MSIPATCHSEQUENCEINFOW
*ret
;
519 if (!(ret
= msi_alloc( count
* sizeof(MSIPATCHSEQUENCEINFOW
) ))) return NULL
;
520 for (i
= 0; i
< count
; i
++)
522 if (info
[i
].szPatchData
&& !(ret
[i
].szPatchData
= strdupAtoW( info
[i
].szPatchData
)))
524 free_patchinfo( i
, ret
);
527 ret
[i
].ePatchDataType
= info
[i
].ePatchDataType
;
528 ret
[i
].dwOrder
= info
[i
].dwOrder
;
529 ret
[i
].uStatus
= info
[i
].uStatus
;
534 UINT WINAPI
MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath
,
535 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
538 WCHAR
*package_path
= NULL
;
539 MSIPATCHSEQUENCEINFOW
*psi
;
541 TRACE("%s, %u, %p\n", debugstr_a(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
543 if (szProductPackagePath
&& !(package_path
= strdupAtoW( szProductPackagePath
)))
544 return ERROR_OUTOFMEMORY
;
546 if (!(psi
= patchinfoAtoW( cPatchInfo
, pPatchInfo
)))
548 msi_free( package_path
);
549 return ERROR_OUTOFMEMORY
;
551 r
= MsiDetermineApplicablePatchesW( package_path
, cPatchInfo
, psi
);
552 if (r
== ERROR_SUCCESS
)
554 for (i
= 0; i
< cPatchInfo
; i
++)
556 pPatchInfo
[i
].dwOrder
= psi
[i
].dwOrder
;
557 pPatchInfo
[i
].uStatus
= psi
[i
].uStatus
;
560 msi_free( package_path
);
561 free_patchinfo( cPatchInfo
, psi
);
565 static UINT
MSI_ApplicablePatchW( MSIPACKAGE
*package
, LPCWSTR patch
)
568 MSIDATABASE
*patch_db
;
571 r
= MSI_OpenDatabaseW( patch
, MSIDBOPEN_READONLY
, &patch_db
);
572 if (r
!= ERROR_SUCCESS
)
574 WARN("failed to open patch file %s\n", debugstr_w(patch
));
578 r
= msi_get_suminfo( patch_db
->storage
, 0, &si
);
579 if (r
!= ERROR_SUCCESS
)
581 msiobj_release( &patch_db
->hdr
);
582 return ERROR_FUNCTION_FAILED
;
585 r
= msi_check_patch_applicable( package
, si
);
586 if (r
!= ERROR_SUCCESS
)
587 TRACE("patch not applicable\n");
589 msiobj_release( &patch_db
->hdr
);
590 msiobj_release( &si
->hdr
);
594 /* IXMLDOMDocument should be set to XPath mode already */
595 static UINT
MSI_ApplicablePatchXML( MSIPACKAGE
*package
, IXMLDOMDocument
*desc
)
597 UINT r
= ERROR_FUNCTION_FAILED
;
598 IXMLDOMNodeList
*list
;
604 product_code
= msi_dup_property( package
->db
, L
"ProductCode" );
607 /* FIXME: the property ProductCode should be written into the DB somewhere */
608 ERR("no product code to check\n");
609 return ERROR_SUCCESS
;
612 s
= SysAllocString( L
"MsiPatch/TargetProduct/TargetProductCode" );
613 hr
= IXMLDOMDocument_selectNodes( desc
, s
, &list
);
616 return ERROR_INVALID_PATCH_XML
;
618 while (IXMLDOMNodeList_nextNode( list
, &node
) == S_OK
&& r
!= ERROR_SUCCESS
)
620 hr
= IXMLDOMNode_get_text( node
, &s
);
621 IXMLDOMNode_Release( node
);
624 if (!wcscmp( s
, product_code
)) r
= ERROR_SUCCESS
;
628 IXMLDOMNodeList_Release( list
);
630 if (r
!= ERROR_SUCCESS
)
631 TRACE("patch not applicable\n");
633 msi_free( product_code
);
637 static UINT
determine_patch_sequence( MSIPACKAGE
*package
, DWORD count
, MSIPATCHSEQUENCEINFOW
*info
)
639 IXMLDOMDocument
*desc
= NULL
;
643 FIXME("patch ordering not supported\n");
645 for (i
= 0; i
< count
; i
++)
647 switch (info
[i
].ePatchDataType
)
649 case MSIPATCH_DATATYPE_PATCHFILE
:
651 if (MSI_ApplicablePatchW( package
, info
[i
].szPatchData
) != ERROR_SUCCESS
)
653 info
[i
].dwOrder
= ~0u;
654 info
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
659 info
[i
].uStatus
= ERROR_SUCCESS
;
663 case MSIPATCH_DATATYPE_XMLPATH
:
664 case MSIPATCH_DATATYPE_XMLBLOB
:
672 hr
= CoCreateInstance( &CLSID_DOMDocument30
, NULL
, CLSCTX_INPROC_SERVER
,
673 &IID_IXMLDOMDocument
, (void**)&desc
);
676 ERR("failed to create DOMDocument30 instance, 0x%08x\n", hr
);
677 return ERROR_FUNCTION_FAILED
;
681 s
= SysAllocString( info
[i
].szPatchData
);
682 if (info
[i
].ePatchDataType
== MSIPATCH_DATATYPE_XMLPATH
)
686 V_VT(&src
) = VT_BSTR
;
688 hr
= IXMLDOMDocument_load( desc
, src
, &b
);
691 hr
= IXMLDOMDocument_loadXML( desc
, s
, &b
);
695 ERR("failed to parse patch description\n");
696 IXMLDOMDocument_Release( desc
);
700 if (MSI_ApplicablePatchXML( package
, desc
) != ERROR_SUCCESS
)
702 info
[i
].dwOrder
= ~0u;
703 info
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
708 info
[i
].uStatus
= ERROR_SUCCESS
;
714 FIXME("unknown patch data type %u\n", info
[i
].ePatchDataType
);
716 info
[i
].uStatus
= ERROR_SUCCESS
;
721 TRACE("szPatchData: %s\n", debugstr_w(info
[i
].szPatchData
));
722 TRACE("ePatchDataType: %u\n", info
[i
].ePatchDataType
);
723 TRACE("dwOrder: %u\n", info
[i
].dwOrder
);
724 TRACE("uStatus: %u\n", info
[i
].uStatus
);
727 if (desc
) IXMLDOMDocument_Release( desc
);
729 return ERROR_SUCCESS
;
732 UINT WINAPI
MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath
,
733 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
738 TRACE("%s, %u, %p\n", debugstr_w(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
740 r
= MSI_OpenPackageW( szProductPackagePath
, 0, &package
);
741 if (r
!= ERROR_SUCCESS
)
743 ERR("failed to open package %u\n", r
);
746 r
= determine_patch_sequence( package
, cPatchInfo
, pPatchInfo
);
747 msiobj_release( &package
->hdr
);
751 UINT WINAPI
MsiDeterminePatchSequenceA( LPCSTR product
, LPCSTR usersid
,
752 MSIINSTALLCONTEXT context
, DWORD count
, PMSIPATCHSEQUENCEINFOA patchinfo
)
755 WCHAR
*productW
, *usersidW
= NULL
;
756 MSIPATCHSEQUENCEINFOW
*patchinfoW
;
758 TRACE("%s, %s, %d, %d, %p\n", debugstr_a(product
), debugstr_a(usersid
),
759 context
, count
, patchinfo
);
761 if (!product
) return ERROR_INVALID_PARAMETER
;
762 if (!(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
763 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
765 msi_free( productW
);
766 return ERROR_OUTOFMEMORY
;
768 if (!(patchinfoW
= patchinfoAtoW( count
, patchinfo
)))
770 msi_free( productW
);
771 msi_free( usersidW
);
772 return ERROR_OUTOFMEMORY
;
774 r
= MsiDeterminePatchSequenceW( productW
, usersidW
, context
, count
, patchinfoW
);
775 if (r
== ERROR_SUCCESS
)
777 for (i
= 0; i
< count
; i
++)
779 patchinfo
[i
].dwOrder
= patchinfoW
[i
].dwOrder
;
780 patchinfo
[i
].uStatus
= patchinfoW
[i
].uStatus
;
783 msi_free( productW
);
784 msi_free( usersidW
);
785 free_patchinfo( count
, patchinfoW
);
789 static UINT
open_package( const WCHAR
*product
, const WCHAR
*usersid
,
790 MSIINSTALLCONTEXT context
, MSIPACKAGE
**package
)
794 WCHAR
*localpath
, sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
796 r
= MSIREG_OpenInstallProps( product
, context
, usersid
, &props
, FALSE
);
797 if (r
!= ERROR_SUCCESS
) return ERROR_BAD_CONFIGURATION
;
799 if ((localpath
= msi_reg_get_val_str( props
, L
"LocalPackage" )))
801 lstrcpyW( sourcepath
, localpath
);
802 msi_free( localpath
);
804 RegCloseKey( props
);
805 if (!localpath
|| GetFileAttributesW( sourcepath
) == INVALID_FILE_ATTRIBUTES
)
807 DWORD sz
= sizeof(sourcepath
);
808 MsiSourceListGetInfoW( product
, usersid
, context
, MSICODE_PRODUCT
,
809 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
810 sz
= sizeof(filename
);
811 MsiSourceListGetInfoW( product
, usersid
, context
, MSICODE_PRODUCT
,
812 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
813 lstrcatW( sourcepath
, filename
);
815 if (GetFileAttributesW( sourcepath
) == INVALID_FILE_ATTRIBUTES
)
816 return ERROR_INSTALL_SOURCE_ABSENT
;
818 return MSI_OpenPackageW( sourcepath
, 0, package
);
821 UINT WINAPI
MsiDeterminePatchSequenceW( LPCWSTR product
, LPCWSTR usersid
,
822 MSIINSTALLCONTEXT context
, DWORD count
, PMSIPATCHSEQUENCEINFOW patchinfo
)
827 TRACE("%s, %s, %d, %d, %p\n", debugstr_w(product
), debugstr_w(usersid
),
828 context
, count
, patchinfo
);
830 if (!product
) return ERROR_INVALID_PARAMETER
;
831 r
= open_package( product
, usersid
, context
, &package
);
832 if (r
!= ERROR_SUCCESS
) return r
;
834 r
= determine_patch_sequence( package
, count
, patchinfo
);
835 msiobj_release( &package
->hdr
);
839 UINT WINAPI
MsiConfigureProductExW(LPCWSTR szProduct
, int iInstallLevel
,
840 INSTALLSTATE eInstallState
, LPCWSTR szCommandLine
)
842 MSIPACKAGE
* package
= NULL
;
843 MSIINSTALLCONTEXT context
;
846 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
849 TRACE("%s %d %d %s\n",debugstr_w(szProduct
), iInstallLevel
, eInstallState
,
850 debugstr_w(szCommandLine
));
852 if (!szProduct
|| lstrlenW(szProduct
) != GUID_SIZE
- 1)
853 return ERROR_INVALID_PARAMETER
;
855 if (eInstallState
== INSTALLSTATE_ADVERTISED
||
856 eInstallState
== INSTALLSTATE_SOURCE
)
858 FIXME("State %d not implemented\n", eInstallState
);
859 return ERROR_CALL_NOT_IMPLEMENTED
;
862 r
= msi_locate_product(szProduct
, &context
);
863 if (r
!= ERROR_SUCCESS
)
866 r
= open_package(szProduct
, NULL
, context
, &package
);
867 if (r
!= ERROR_SUCCESS
)
870 sz
= lstrlenW(L
" Installed=1") + 1;
873 sz
+= lstrlenW(szCommandLine
);
875 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
876 sz
+= lstrlenW(L
" INSTALLLEVEL=32767");
878 if (eInstallState
== INSTALLSTATE_ABSENT
)
879 sz
+= lstrlenW(L
" REMOVE=ALL");
881 if (context
== MSIINSTALLCONTEXT_MACHINE
)
882 sz
+= lstrlenW(L
" ALLUSERS=1");
884 commandline
= msi_alloc(sz
* sizeof(WCHAR
));
887 r
= ERROR_OUTOFMEMORY
;
893 lstrcpyW(commandline
, szCommandLine
);
895 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
896 lstrcatW(commandline
, L
" INSTALLLEVEL=32767");
898 if (eInstallState
== INSTALLSTATE_ABSENT
)
899 lstrcatW(commandline
, L
" REMOVE=ALL");
901 if (context
== MSIINSTALLCONTEXT_MACHINE
)
902 lstrcatW(commandline
, L
" ALLUSERS=1");
904 sz
= sizeof(sourcepath
);
905 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
906 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
908 sz
= sizeof(filename
);
909 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
910 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
912 lstrcatW(sourcepath
, filename
);
914 r
= MSI_InstallPackage( package
, sourcepath
, commandline
);
916 msi_free(commandline
);
919 msiobj_release( &package
->hdr
);
924 UINT WINAPI
MsiConfigureProductExA(LPCSTR szProduct
, int iInstallLevel
,
925 INSTALLSTATE eInstallState
, LPCSTR szCommandLine
)
927 LPWSTR szwProduct
= NULL
;
928 LPWSTR szwCommandLine
= NULL
;
929 UINT r
= ERROR_OUTOFMEMORY
;
933 szwProduct
= strdupAtoW( szProduct
);
940 szwCommandLine
= strdupAtoW( szCommandLine
);
945 r
= MsiConfigureProductExW( szwProduct
, iInstallLevel
, eInstallState
,
948 msi_free( szwProduct
);
949 msi_free( szwCommandLine
);
954 UINT WINAPI
MsiConfigureProductA(LPCSTR szProduct
, int iInstallLevel
,
955 INSTALLSTATE eInstallState
)
957 LPWSTR szwProduct
= NULL
;
960 TRACE("%s %d %d\n",debugstr_a(szProduct
), iInstallLevel
, eInstallState
);
964 szwProduct
= strdupAtoW( szProduct
);
966 return ERROR_OUTOFMEMORY
;
969 r
= MsiConfigureProductW( szwProduct
, iInstallLevel
, eInstallState
);
970 msi_free( szwProduct
);
975 UINT WINAPI
MsiConfigureProductW(LPCWSTR szProduct
, int iInstallLevel
,
976 INSTALLSTATE eInstallState
)
978 return MsiConfigureProductExW(szProduct
, iInstallLevel
, eInstallState
, NULL
);
981 UINT WINAPI
MsiGetProductCodeA(LPCSTR szComponent
, LPSTR szBuffer
)
983 LPWSTR szwComponent
= NULL
;
985 WCHAR szwBuffer
[GUID_SIZE
];
987 TRACE("%s %p\n", debugstr_a(szComponent
), szBuffer
);
991 szwComponent
= strdupAtoW( szComponent
);
993 return ERROR_OUTOFMEMORY
;
997 r
= MsiGetProductCodeW( szwComponent
, szwBuffer
);
1000 WideCharToMultiByte(CP_ACP
, 0, szwBuffer
, -1, szBuffer
, GUID_SIZE
, NULL
, NULL
);
1002 msi_free( szwComponent
);
1007 UINT WINAPI
MsiGetProductCodeW(LPCWSTR szComponent
, LPWSTR szBuffer
)
1010 HKEY compkey
, prodkey
;
1011 WCHAR squashed_comp
[SQUASHED_GUID_SIZE
], squashed_prod
[SQUASHED_GUID_SIZE
];
1012 DWORD sz
= ARRAY_SIZE(squashed_prod
);
1014 TRACE("%s %p\n", debugstr_w(szComponent
), szBuffer
);
1016 if (!szComponent
|| !*szComponent
)
1017 return ERROR_INVALID_PARAMETER
;
1019 if (!squash_guid( szComponent
, squashed_comp
))
1020 return ERROR_INVALID_PARAMETER
;
1022 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &compkey
, FALSE
) != ERROR_SUCCESS
&&
1023 MSIREG_OpenUserDataComponentKey(szComponent
, L
"S-1-5-18", &compkey
, FALSE
) != ERROR_SUCCESS
)
1025 return ERROR_UNKNOWN_COMPONENT
;
1028 rc
= RegEnumValueW( compkey
, 0, squashed_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
1029 if (rc
!= ERROR_SUCCESS
)
1031 RegCloseKey(compkey
);
1032 return ERROR_UNKNOWN_COMPONENT
;
1035 /* check simple case, only one product */
1036 rc
= RegEnumValueW( compkey
, 1, squashed_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
1037 if (rc
== ERROR_NO_MORE_ITEMS
)
1044 while ((rc
= RegEnumValueW( compkey
, index
, squashed_prod
, &sz
, NULL
, NULL
, NULL
, NULL
)) !=
1045 ERROR_NO_MORE_ITEMS
)
1049 unsquash_guid( squashed_prod
, szBuffer
);
1051 if (MSIREG_OpenProductKey(szBuffer
, NULL
,
1052 MSIINSTALLCONTEXT_USERMANAGED
,
1053 &prodkey
, FALSE
) == ERROR_SUCCESS
||
1054 MSIREG_OpenProductKey(szBuffer
, NULL
,
1055 MSIINSTALLCONTEXT_USERUNMANAGED
,
1056 &prodkey
, FALSE
) == ERROR_SUCCESS
||
1057 MSIREG_OpenProductKey(szBuffer
, NULL
,
1058 MSIINSTALLCONTEXT_MACHINE
,
1059 &prodkey
, FALSE
) == ERROR_SUCCESS
)
1061 RegCloseKey(prodkey
);
1067 rc
= ERROR_INSTALL_FAILURE
;
1070 RegCloseKey(compkey
);
1071 unsquash_guid( squashed_prod
, szBuffer
);
1075 static WCHAR
*reg_get_value( HKEY hkey
, const WCHAR
*name
, DWORD
*type
)
1079 if ((res
= RegQueryValueExW( hkey
, name
, NULL
, type
, NULL
, NULL
)) != ERROR_SUCCESS
) return NULL
;
1081 if (*type
== REG_SZ
) return msi_reg_get_val_str( hkey
, name
);
1082 if (*type
== REG_DWORD
)
1087 if (!msi_reg_get_val_dword( hkey
, name
, &val
)) return NULL
;
1088 swprintf( temp
, ARRAY_SIZE(temp
), L
"%u", val
);
1089 return strdupW( temp
);
1092 ERR( "unhandled value type %u\n", *type
);
1096 static UINT
MSI_GetProductInfo(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1097 awstring
*szValue
, LPDWORD pcchValueBuf
)
1099 static WCHAR empty
[] = L
"";
1100 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
1101 UINT r
= ERROR_UNKNOWN_PROPERTY
;
1102 HKEY prodkey
, userdata
, source
;
1103 WCHAR
*val
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
], packagecode
[GUID_SIZE
];
1104 BOOL badconfig
= FALSE
;
1106 DWORD type
= REG_NONE
;
1108 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
1109 debugstr_w(szAttribute
), szValue
, pcchValueBuf
);
1111 if ((szValue
->str
.w
&& !pcchValueBuf
) || !szProduct
|| !szAttribute
)
1112 return ERROR_INVALID_PARAMETER
;
1114 if (!squash_guid( szProduct
, squashed_pc
))
1115 return ERROR_INVALID_PARAMETER
;
1117 if ((r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1118 MSIINSTALLCONTEXT_USERMANAGED
,
1119 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
1120 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1121 MSIINSTALLCONTEXT_USERUNMANAGED
,
1122 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
1123 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1124 MSIINSTALLCONTEXT_MACHINE
,
1125 &prodkey
, FALSE
)) == ERROR_SUCCESS
)
1127 context
= MSIINSTALLCONTEXT_MACHINE
;
1130 if (!wcscmp( szAttribute
, INSTALLPROPERTY_HELPLINKW
) ||
1131 !wcscmp( szAttribute
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1132 !wcscmp( szAttribute
, INSTALLPROPERTY_INSTALLDATEW
) ||
1133 !wcscmp( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1134 !wcscmp( szAttribute
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1135 !wcscmp( szAttribute
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1136 !wcscmp( szAttribute
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1137 !wcscmp( szAttribute
, INSTALLPROPERTY_PUBLISHERW
) ||
1138 !wcscmp( szAttribute
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1139 !wcscmp( szAttribute
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1140 !wcscmp( szAttribute
, INSTALLPROPERTY_VERSIONMINORW
) ||
1141 !wcscmp( szAttribute
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1142 !wcscmp( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1143 !wcscmp( szAttribute
, INSTALLPROPERTY_PRODUCTIDW
) ||
1144 !wcscmp( szAttribute
, INSTALLPROPERTY_REGCOMPANYW
) ||
1145 !wcscmp( szAttribute
, INSTALLPROPERTY_REGOWNERW
))
1149 r
= ERROR_UNKNOWN_PRODUCT
;
1152 if (MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
))
1154 r
= ERROR_UNKNOWN_PROPERTY
;
1158 if (!wcscmp( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1159 szAttribute
= L
"DisplayName";
1160 else if (!wcscmp( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
))
1161 szAttribute
= L
"DisplayVersion";
1163 val
= reg_get_value(userdata
, szAttribute
, &type
);
1166 RegCloseKey(userdata
);
1168 else if (!wcscmp( szAttribute
, INSTALLPROPERTY_INSTANCETYPEW
) ||
1169 !wcscmp( szAttribute
, INSTALLPROPERTY_TRANSFORMSW
) ||
1170 !wcscmp( szAttribute
, INSTALLPROPERTY_LANGUAGEW
) ||
1171 !wcscmp( szAttribute
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1172 !wcscmp( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
) ||
1173 !wcscmp( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
) ||
1174 !wcscmp( szAttribute
, INSTALLPROPERTY_VERSIONW
) ||
1175 !wcscmp( szAttribute
, INSTALLPROPERTY_PRODUCTICONW
) ||
1176 !wcscmp( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1177 !wcscmp( szAttribute
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1181 r
= ERROR_UNKNOWN_PRODUCT
;
1185 if (!wcscmp( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1186 szAttribute
= L
"Assignment";
1188 if (!wcscmp( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
))
1190 res
= RegOpenKeyW(prodkey
, L
"SourceList", &source
);
1191 if (res
!= ERROR_SUCCESS
)
1193 r
= ERROR_UNKNOWN_PRODUCT
;
1197 val
= reg_get_value(source
, szAttribute
, &type
);
1201 RegCloseKey(source
);
1205 val
= reg_get_value(prodkey
, szAttribute
, &type
);
1210 if (val
!= empty
&& type
!= REG_DWORD
&&
1211 !wcscmp( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
))
1213 if (lstrlenW( val
) != SQUASHED_GUID_SIZE
- 1)
1217 unsquash_guid(val
, packagecode
);
1219 val
= strdupW(packagecode
);
1226 r
= ERROR_UNKNOWN_PROPERTY
;
1232 int len
= lstrlenW( val
);
1234 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1235 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1236 * can't rely on its value.
1238 if (szValue
->str
.a
|| szValue
->str
.w
)
1240 DWORD size
= *pcchValueBuf
;
1242 r
= msi_strcpy_to_awstring( val
, len
, szValue
, &size
);
1244 r
= ERROR_MORE_DATA
;
1248 *pcchValueBuf
= len
;
1252 r
= ERROR_BAD_CONFIGURATION
;
1258 RegCloseKey(prodkey
);
1262 UINT WINAPI
MsiGetProductInfoA(LPCSTR szProduct
, LPCSTR szAttribute
,
1263 LPSTR szBuffer
, LPDWORD pcchValueBuf
)
1265 LPWSTR szwProduct
, szwAttribute
= NULL
;
1266 UINT r
= ERROR_OUTOFMEMORY
;
1269 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szAttribute
),
1270 szBuffer
, pcchValueBuf
);
1272 szwProduct
= strdupAtoW( szProduct
);
1273 if( szProduct
&& !szwProduct
)
1276 szwAttribute
= strdupAtoW( szAttribute
);
1277 if( szAttribute
&& !szwAttribute
)
1280 buffer
.unicode
= FALSE
;
1281 buffer
.str
.a
= szBuffer
;
1283 r
= MSI_GetProductInfo( szwProduct
, szwAttribute
,
1284 &buffer
, pcchValueBuf
);
1287 msi_free( szwProduct
);
1288 msi_free( szwAttribute
);
1293 UINT WINAPI
MsiGetProductInfoW(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1294 LPWSTR szBuffer
, LPDWORD pcchValueBuf
)
1298 TRACE("%s %s %p %p\n", debugstr_w(szProduct
), debugstr_w(szAttribute
),
1299 szBuffer
, pcchValueBuf
);
1301 buffer
.unicode
= TRUE
;
1302 buffer
.str
.w
= szBuffer
;
1304 return MSI_GetProductInfo( szProduct
, szAttribute
,
1305 &buffer
, pcchValueBuf
);
1308 UINT WINAPI
MsiGetProductInfoExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1309 MSIINSTALLCONTEXT dwContext
, LPCSTR szProperty
,
1310 LPSTR szValue
, LPDWORD pcchValue
)
1312 LPWSTR product
= NULL
;
1313 LPWSTR usersid
= NULL
;
1314 LPWSTR property
= NULL
;
1315 LPWSTR value
= NULL
;
1319 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode
),
1320 debugstr_a(szUserSid
), dwContext
, debugstr_a(szProperty
),
1321 szValue
, pcchValue
);
1323 if (szValue
&& !pcchValue
)
1324 return ERROR_INVALID_PARAMETER
;
1326 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1327 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1328 if (szProperty
) property
= strdupAtoW(szProperty
);
1330 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1332 if (r
!= ERROR_SUCCESS
)
1335 value
= msi_alloc(++len
* sizeof(WCHAR
));
1338 r
= ERROR_OUTOFMEMORY
;
1342 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1344 if (r
!= ERROR_SUCCESS
)
1350 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
1351 if (*pcchValue
>= len
)
1352 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
1355 r
= ERROR_MORE_DATA
;
1360 if (*pcchValue
<= len
|| !szValue
)
1361 len
= len
* sizeof(WCHAR
) - 1;
1363 *pcchValue
= len
- 1;
1374 static UINT
msi_copy_outval(LPWSTR val
, LPWSTR out
, LPDWORD size
)
1376 UINT r
= ERROR_SUCCESS
;
1379 return ERROR_UNKNOWN_PROPERTY
;
1383 if (lstrlenW(val
) >= *size
)
1385 r
= ERROR_MORE_DATA
;
1394 *size
= lstrlenW(val
);
1399 UINT WINAPI
MsiGetProductInfoExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
1400 MSIINSTALLCONTEXT dwContext
, LPCWSTR szProperty
,
1401 LPWSTR szValue
, LPDWORD pcchValue
)
1403 WCHAR
*val
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
];
1404 LPCWSTR package
= NULL
;
1405 HKEY props
= NULL
, prod
, classes
= NULL
, managed
, hkey
= NULL
;
1407 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1409 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode
),
1410 debugstr_w(szUserSid
), dwContext
, debugstr_w(szProperty
),
1411 szValue
, pcchValue
);
1413 if (!szProductCode
|| !squash_guid( szProductCode
, squashed_pc
))
1414 return ERROR_INVALID_PARAMETER
;
1416 if (szValue
&& !pcchValue
)
1417 return ERROR_INVALID_PARAMETER
;
1419 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1420 dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1421 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1422 return ERROR_INVALID_PARAMETER
;
1424 if (!szProperty
|| !*szProperty
)
1425 return ERROR_INVALID_PARAMETER
;
1427 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1428 return ERROR_INVALID_PARAMETER
;
1430 /* FIXME: dwContext is provided, no need to search for it */
1431 MSIREG_OpenProductKey(szProductCode
, NULL
,MSIINSTALLCONTEXT_USERMANAGED
,
1433 MSIREG_OpenProductKey(szProductCode
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1436 MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
, &props
, FALSE
);
1438 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1440 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1442 if (!props
&& !prod
)
1445 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1447 package
= L
"ManagedLocalPackage";
1449 if (!props
&& !managed
)
1452 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1454 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1455 MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
, &classes
, FALSE
);
1457 if (!props
&& !classes
)
1461 if (!wcscmp( szProperty
, INSTALLPROPERTY_HELPLINKW
) ||
1462 !wcscmp( szProperty
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1463 !wcscmp( szProperty
, INSTALLPROPERTY_INSTALLDATEW
) ||
1464 !wcscmp( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1465 !wcscmp( szProperty
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1466 !wcscmp( szProperty
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1467 !wcscmp( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1468 !wcscmp( szProperty
, INSTALLPROPERTY_PUBLISHERW
) ||
1469 !wcscmp( szProperty
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1470 !wcscmp( szProperty
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1471 !wcscmp( szProperty
, INSTALLPROPERTY_VERSIONMINORW
) ||
1472 !wcscmp( szProperty
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1473 !wcscmp( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1474 !wcscmp( szProperty
, INSTALLPROPERTY_PRODUCTIDW
) ||
1475 !wcscmp( szProperty
, INSTALLPROPERTY_REGCOMPANYW
) ||
1476 !wcscmp( szProperty
, INSTALLPROPERTY_REGOWNERW
) ||
1477 !wcscmp( szProperty
, INSTALLPROPERTY_INSTANCETYPEW
))
1479 val
= reg_get_value(props
, package
, &type
);
1482 if (prod
|| classes
)
1483 r
= ERROR_UNKNOWN_PROPERTY
;
1490 if (!wcscmp( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1491 szProperty
= L
"DisplayName";
1492 else if (!wcscmp( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
))
1493 szProperty
= L
"DisplayVersion";
1495 val
= reg_get_value(props
, szProperty
, &type
);
1499 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1501 else if (!wcscmp( szProperty
, INSTALLPROPERTY_TRANSFORMSW
) ||
1502 !wcscmp( szProperty
, INSTALLPROPERTY_LANGUAGEW
) ||
1503 !wcscmp( szProperty
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1504 !wcscmp( szProperty
, INSTALLPROPERTY_PACKAGECODEW
) ||
1505 !wcscmp( szProperty
, INSTALLPROPERTY_VERSIONW
) ||
1506 !wcscmp( szProperty
, INSTALLPROPERTY_PRODUCTICONW
) ||
1507 !wcscmp( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1508 !wcscmp( szProperty
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1510 if (!prod
&& !classes
)
1513 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1515 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1517 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1520 val
= reg_get_value(hkey
, szProperty
, &type
);
1524 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1526 else if (!wcscmp( szProperty
, INSTALLPROPERTY_PRODUCTSTATEW
))
1528 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1532 val
= reg_get_value(props
, package
, &type
);
1537 val
= strdupW(L
"5");
1540 val
= strdupW(L
"1");
1542 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1545 else if (props
&& (val
= reg_get_value(props
, package
, &type
)))
1548 val
= strdupW(L
"5");
1549 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1553 if (prod
|| managed
)
1554 val
= strdupW(L
"1");
1558 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1560 else if (!wcscmp( szProperty
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1562 if (!prod
&& !classes
)
1567 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1570 r
= ERROR_UNKNOWN_PROPERTY
;
1575 RegCloseKey(managed
);
1576 RegCloseKey(classes
);
1582 UINT WINAPI
MsiGetPatchFileListA(LPCSTR szProductCode
, LPCSTR szPatchList
,
1583 LPDWORD pcFiles
, MSIHANDLE
**pphFileRecords
)
1585 FIXME("(%s, %s, %p, %p) stub!\n", debugstr_a(szProductCode
),
1586 debugstr_a(szPatchList
), pcFiles
, pphFileRecords
);
1587 return ERROR_FUNCTION_FAILED
;
1590 UINT WINAPI
MsiGetPatchFileListW(LPCWSTR szProductCode
, LPCWSTR szPatchList
,
1591 LPDWORD pcFiles
, MSIHANDLE
**pphFileRecords
)
1593 FIXME("(%s, %s, %p, %p) stub!\n", debugstr_w(szProductCode
),
1594 debugstr_w(szPatchList
), pcFiles
, pphFileRecords
);
1595 return ERROR_FUNCTION_FAILED
;
1598 UINT WINAPI
MsiGetPatchInfoExA(LPCSTR szPatchCode
, LPCSTR szProductCode
,
1599 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1600 LPCSTR szProperty
, LPSTR lpValue
, DWORD
*pcchValue
)
1602 LPWSTR patch
= NULL
, product
= NULL
, usersid
= NULL
;
1603 LPWSTR property
= NULL
, val
= NULL
;
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 WCHAR
*val
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
], squashed_patch
[SQUASHED_GUID_SIZE
];
1670 HKEY udprod
= 0, prod
= 0, props
= 0;
1671 HKEY patch
= 0, patches
= 0;
1672 HKEY udpatch
= 0, datakey
= 0;
1673 HKEY prodpatches
= 0;
1674 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1678 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode
),
1679 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
,
1680 debugstr_w(szProperty
), lpValue
, pcchValue
);
1682 if (!szProductCode
|| !squash_guid( szProductCode
, squashed_pc
))
1683 return ERROR_INVALID_PARAMETER
;
1685 if (!szPatchCode
|| !squash_guid( szPatchCode
, squashed_patch
))
1686 return ERROR_INVALID_PARAMETER
;
1689 return ERROR_INVALID_PARAMETER
;
1691 if (lpValue
&& !pcchValue
)
1692 return ERROR_INVALID_PARAMETER
;
1694 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1695 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1696 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1697 return ERROR_INVALID_PARAMETER
;
1699 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1700 return ERROR_INVALID_PARAMETER
;
1702 if (szUserSid
&& !wcscmp( szUserSid
, L
"S-1-5-18" ))
1703 return ERROR_INVALID_PARAMETER
;
1705 if (MSIREG_OpenUserDataProductKey(szProductCode
, dwContext
, NULL
,
1706 &udprod
, FALSE
) != ERROR_SUCCESS
)
1709 if (MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
,
1710 &props
, FALSE
) != ERROR_SUCCESS
)
1713 r
= ERROR_UNKNOWN_PATCH
;
1715 res
= RegOpenKeyExW(udprod
, L
"Patches", 0, KEY_READ
, &patches
);
1716 if (res
!= ERROR_SUCCESS
)
1719 res
= RegOpenKeyExW( patches
, squashed_patch
, 0, KEY_READ
, &patch
);
1720 if (res
!= ERROR_SUCCESS
)
1723 if (!wcscmp( szProperty
, INSTALLPROPERTY_TRANSFORMSW
))
1725 if (MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
,
1726 &prod
, FALSE
) != ERROR_SUCCESS
)
1729 res
= RegOpenKeyExW(prod
, L
"Patches", 0, KEY_ALL_ACCESS
, &prodpatches
);
1730 if (res
!= ERROR_SUCCESS
)
1733 datakey
= prodpatches
;
1734 szProperty
= squashed_patch
;
1738 if (MSIREG_OpenUserDataPatchKey(szPatchCode
, dwContext
,
1739 &udpatch
, FALSE
) != ERROR_SUCCESS
)
1742 if (!wcscmp( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1744 if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1745 szProperty
= L
"ManagedLocalPackage";
1748 else if (!wcscmp( szProperty
, INSTALLPROPERTY_INSTALLDATEW
))
1751 szProperty
= L
"Installed";
1753 else if (!wcscmp( szProperty
, INSTALLPROPERTY_UNINSTALLABLEW
) ||
1754 !wcscmp( szProperty
, INSTALLPROPERTY_PATCHSTATEW
) ||
1755 !wcscmp( szProperty
, INSTALLPROPERTY_DISPLAYNAMEW
) ||
1756 !wcscmp( szProperty
, INSTALLPROPERTY_MOREINFOURLW
))
1762 r
= ERROR_UNKNOWN_PROPERTY
;
1767 val
= reg_get_value(datakey
, szProperty
, &type
);
1777 lstrcpynW(lpValue
, val
, *pcchValue
);
1779 len
= lstrlenW(val
);
1780 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1783 r
= ERROR_MORE_DATA
;
1785 *pcchValue
= len
* sizeof(WCHAR
);
1792 RegCloseKey(prodpatches
);
1795 RegCloseKey(patches
);
1796 RegCloseKey(udpatch
);
1798 RegCloseKey(udprod
);
1803 UINT WINAPI
MsiGetPatchInfoA( LPCSTR patch
, LPCSTR attr
, LPSTR buffer
, LPDWORD buflen
)
1805 UINT r
= ERROR_OUTOFMEMORY
;
1807 LPWSTR patchW
= NULL
, attrW
= NULL
, bufferW
= NULL
;
1809 TRACE("%s %s %p %p\n", debugstr_a(patch
), debugstr_a(attr
), buffer
, buflen
);
1811 if (!patch
|| !attr
)
1812 return ERROR_INVALID_PARAMETER
;
1814 if (!(patchW
= strdupAtoW( patch
)))
1817 if (!(attrW
= strdupAtoW( attr
)))
1821 r
= MsiGetPatchInfoW( patchW
, attrW
, NULL
, &size
);
1822 if (r
!= ERROR_SUCCESS
)
1826 if (!(bufferW
= msi_alloc( size
* sizeof(WCHAR
) )))
1828 r
= ERROR_OUTOFMEMORY
;
1832 r
= MsiGetPatchInfoW( patchW
, attrW
, bufferW
, &size
);
1833 if (r
== ERROR_SUCCESS
)
1835 int len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
1837 r
= ERROR_MORE_DATA
;
1839 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *buflen
, NULL
, NULL
);
1847 msi_free( bufferW
);
1851 UINT WINAPI
MsiGetPatchInfoW( LPCWSTR patch
, LPCWSTR attr
, LPWSTR buffer
, LPDWORD buflen
)
1854 WCHAR product
[GUID_SIZE
];
1857 TRACE("%s %s %p %p\n", debugstr_w(patch
), debugstr_w(attr
), buffer
, buflen
);
1859 if (!patch
|| !attr
)
1860 return ERROR_INVALID_PARAMETER
;
1862 if (wcscmp( INSTALLPROPERTY_LOCALPACKAGEW
, attr
))
1863 return ERROR_UNKNOWN_PROPERTY
;
1868 r
= MsiEnumProductsW( index
, product
);
1869 if (r
!= ERROR_SUCCESS
)
1872 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, attr
, buffer
, buflen
);
1873 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1876 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, attr
, buffer
, buflen
);
1877 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1880 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_MACHINE
, attr
, buffer
, buflen
);
1881 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1887 return ERROR_UNKNOWN_PRODUCT
;
1890 UINT WINAPI
MsiEnableLogA(DWORD dwLogMode
, LPCSTR szLogFile
, DWORD attributes
)
1892 LPWSTR szwLogFile
= NULL
;
1895 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_a(szLogFile
), attributes
);
1899 szwLogFile
= strdupAtoW( szLogFile
);
1901 return ERROR_OUTOFMEMORY
;
1903 r
= MsiEnableLogW( dwLogMode
, szwLogFile
, attributes
);
1904 msi_free( szwLogFile
);
1908 UINT WINAPI
MsiEnableLogW(DWORD dwLogMode
, LPCWSTR szLogFile
, DWORD attributes
)
1910 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_w(szLogFile
), attributes
);
1912 msi_free(gszLogFile
);
1918 if (!(attributes
& INSTALLLOGATTRIBUTES_APPEND
))
1919 DeleteFileW(szLogFile
);
1920 file
= CreateFileW(szLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
,
1921 FILE_ATTRIBUTE_NORMAL
, NULL
);
1922 if (file
!= INVALID_HANDLE_VALUE
)
1924 gszLogFile
= strdupW(szLogFile
);
1928 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile
), GetLastError());
1931 return ERROR_SUCCESS
;
1934 UINT WINAPI
MsiEnumComponentCostsA( MSIHANDLE handle
, LPCSTR component
, DWORD index
,
1935 INSTALLSTATE state
, LPSTR drive
, DWORD
*buflen
,
1936 int *cost
, int *temp
)
1940 WCHAR
*driveW
, *componentW
= NULL
;
1942 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle
, debugstr_a(component
), index
,
1943 state
, drive
, buflen
, cost
, temp
);
1945 if (!drive
|| !buflen
) return ERROR_INVALID_PARAMETER
;
1946 if (component
&& !(componentW
= strdupAtoW( component
))) return ERROR_OUTOFMEMORY
;
1949 if (!(driveW
= msi_alloc( len
* sizeof(WCHAR
) )))
1951 msi_free( componentW
);
1952 return ERROR_OUTOFMEMORY
;
1954 r
= MsiEnumComponentCostsW( handle
, componentW
, index
, state
, driveW
, buflen
, cost
, temp
);
1957 WideCharToMultiByte( CP_ACP
, 0, driveW
, -1, drive
, len
, NULL
, NULL
);
1959 msi_free( componentW
);
1964 static UINT
set_drive( WCHAR
*buffer
, WCHAR letter
)
1972 UINT WINAPI
MsiEnumComponentCostsW( MSIHANDLE handle
, LPCWSTR component
, DWORD index
,
1973 INSTALLSTATE state
, LPWSTR drive
, DWORD
*buflen
,
1974 int *cost
, int *temp
)
1976 UINT r
= ERROR_NO_MORE_ITEMS
;
1977 MSICOMPONENT
*comp
= NULL
;
1978 MSIPACKAGE
*package
;
1981 WCHAR path
[MAX_PATH
];
1983 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle
, debugstr_w(component
), index
,
1984 state
, drive
, buflen
, cost
, temp
);
1986 if (!drive
|| !buflen
|| !cost
|| !temp
) return ERROR_INVALID_PARAMETER
;
1987 if (!(package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
)))
1992 if (!(remote
= msi_get_remote(handle
)))
1993 return ERROR_INVALID_HANDLE
;
1997 r
= remote_EnumComponentCosts(remote
, component
, index
, state
, buffer
, cost
, temp
);
1999 __EXCEPT(rpc_filter
)
2001 r
= GetExceptionCode();
2005 if (r
== ERROR_SUCCESS
)
2007 lstrcpynW(drive
, buffer
, *buflen
);
2009 r
= ERROR_MORE_DATA
;
2015 if (!msi_get_property_int( package
->db
, L
"CostingComplete", 0 ))
2017 msiobj_release( &package
->hdr
);
2018 return ERROR_FUNCTION_NOT_CALLED
;
2020 if (component
&& component
[0] && !(comp
= msi_get_loaded_component( package
, component
)))
2022 msiobj_release( &package
->hdr
);
2023 return ERROR_UNKNOWN_COMPONENT
;
2028 msiobj_release( &package
->hdr
);
2029 return ERROR_MORE_DATA
;
2033 msiobj_release( &package
->hdr
);
2034 return ERROR_NO_MORE_ITEMS
;
2039 GetWindowsDirectoryW( path
, MAX_PATH
);
2040 if (component
&& component
[0])
2042 if (msi_is_global_assembly( comp
)) *temp
= comp
->Cost
;
2043 if (!comp
->Enabled
|| !comp
->KeyPath
)
2046 *buflen
= set_drive( drive
, path
[0] );
2049 else if ((file
= msi_get_loaded_file( package
, comp
->KeyPath
)))
2051 *cost
= max( 8, comp
->Cost
/ 512 );
2052 *buflen
= set_drive( drive
, file
->TargetPath
[0] );
2056 else if (IStorage_Stat( package
->db
->storage
, &stat
, STATFLAG_NONAME
) == S_OK
)
2058 *temp
= max( 8, stat
.cbSize
.QuadPart
/ 512 );
2059 *buflen
= set_drive( drive
, path
[0] );
2062 msiobj_release( &package
->hdr
);
2066 UINT WINAPI
MsiQueryComponentStateA(LPCSTR szProductCode
,
2067 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
2068 LPCSTR szComponent
, INSTALLSTATE
*pdwState
)
2070 LPWSTR prodcode
= NULL
, usersid
= NULL
, comp
= NULL
;
2073 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode
),
2074 debugstr_a(szUserSid
), dwContext
, debugstr_a(szComponent
), pdwState
);
2076 if (szProductCode
&& !(prodcode
= strdupAtoW(szProductCode
)))
2077 return ERROR_OUTOFMEMORY
;
2079 if (szUserSid
&& !(usersid
= strdupAtoW(szUserSid
)))
2080 return ERROR_OUTOFMEMORY
;
2082 if (szComponent
&& !(comp
= strdupAtoW(szComponent
)))
2083 return ERROR_OUTOFMEMORY
;
2085 r
= MsiQueryComponentStateW(prodcode
, usersid
, dwContext
, comp
, pdwState
);
2094 static BOOL
msi_comp_find_prod_key(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
2099 r
= MSIREG_OpenProductKey(prodcode
, NULL
, context
, &hkey
, FALSE
);
2101 return (r
== ERROR_SUCCESS
);
2104 static BOOL
msi_comp_find_package(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
2112 r
= MSIREG_OpenInstallProps(prodcode
, context
, NULL
, &hkey
, FALSE
);
2113 if (r
!= ERROR_SUCCESS
)
2116 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
2117 package
= L
"ManagedLocalPackage";
2119 package
= L
"LocalPackage";
2122 res
= RegQueryValueExW(hkey
, package
, NULL
, NULL
, NULL
, &sz
);
2125 return (res
== ERROR_SUCCESS
);
2128 static UINT
msi_comp_find_prodcode(WCHAR
*squashed_pc
,
2129 MSIINSTALLCONTEXT context
,
2130 LPCWSTR comp
, LPWSTR val
, DWORD
*sz
)
2136 if (context
== MSIINSTALLCONTEXT_MACHINE
)
2137 r
= MSIREG_OpenUserDataComponentKey(comp
, L
"S-1-5-18", &hkey
, FALSE
);
2139 r
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2141 if (r
!= ERROR_SUCCESS
)
2144 res
= RegQueryValueExW( hkey
, squashed_pc
, NULL
, NULL
, (BYTE
*)val
, sz
);
2145 if (res
!= ERROR_SUCCESS
)
2152 UINT WINAPI
MsiQueryComponentStateW(LPCWSTR szProductCode
,
2153 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
2154 LPCWSTR szComponent
, INSTALLSTATE
*pdwState
)
2156 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
2160 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode
),
2161 debugstr_w(szUserSid
), dwContext
, debugstr_w(szComponent
), pdwState
);
2163 if (!pdwState
|| !szComponent
)
2164 return ERROR_INVALID_PARAMETER
;
2166 if (!szProductCode
|| !*szProductCode
|| lstrlenW(szProductCode
) != GUID_SIZE
- 1)
2167 return ERROR_INVALID_PARAMETER
;
2169 if (!squash_guid( szProductCode
, squashed_pc
))
2170 return ERROR_INVALID_PARAMETER
;
2172 found
= msi_comp_find_prod_key(szProductCode
, dwContext
);
2174 if (!msi_comp_find_package(szProductCode
, dwContext
))
2178 *pdwState
= INSTALLSTATE_UNKNOWN
;
2179 return ERROR_UNKNOWN_COMPONENT
;
2182 return ERROR_UNKNOWN_PRODUCT
;
2185 *pdwState
= INSTALLSTATE_UNKNOWN
;
2188 if (msi_comp_find_prodcode( squashed_pc
, dwContext
, szComponent
, NULL
, &sz
))
2189 return ERROR_UNKNOWN_COMPONENT
;
2192 *pdwState
= INSTALLSTATE_NOTUSED
;
2198 if (!(val
= msi_alloc( sz
))) return ERROR_OUTOFMEMORY
;
2199 if ((r
= msi_comp_find_prodcode( squashed_pc
, dwContext
, szComponent
, val
, &sz
)))
2205 if (lstrlenW(val
) > 2 &&
2206 val
[0] >= '0' && val
[0] <= '9' && val
[1] >= '0' && val
[1] <= '9' && val
[2] != ':')
2208 *pdwState
= INSTALLSTATE_SOURCE
;
2211 *pdwState
= INSTALLSTATE_LOCAL
;
2215 TRACE("-> %d\n", *pdwState
);
2216 return ERROR_SUCCESS
;
2219 INSTALLSTATE WINAPI
MsiQueryProductStateA(LPCSTR szProduct
)
2221 LPWSTR szwProduct
= NULL
;
2226 szwProduct
= strdupAtoW( szProduct
);
2228 return ERROR_OUTOFMEMORY
;
2230 r
= MsiQueryProductStateW( szwProduct
);
2231 msi_free( szwProduct
);
2235 INSTALLSTATE WINAPI
MsiQueryProductStateW(LPCWSTR szProduct
)
2237 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
2238 INSTALLSTATE state
= INSTALLSTATE_ADVERTISED
;
2239 HKEY prodkey
= 0, userdata
= 0;
2243 TRACE("%s\n", debugstr_w(szProduct
));
2245 if (!szProduct
|| !*szProduct
)
2246 return INSTALLSTATE_INVALIDARG
;
2248 if (lstrlenW(szProduct
) != GUID_SIZE
- 1)
2249 return INSTALLSTATE_INVALIDARG
;
2251 if (szProduct
[0] != '{' || szProduct
[37] != '}')
2252 return INSTALLSTATE_UNKNOWN
;
2254 SetLastError( ERROR_SUCCESS
);
2256 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
2257 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2258 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2259 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2260 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2261 &prodkey
, FALSE
) == ERROR_SUCCESS
)
2263 context
= MSIINSTALLCONTEXT_MACHINE
;
2266 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
2267 if (r
!= ERROR_SUCCESS
)
2270 if (!msi_reg_get_val_dword(userdata
, L
"WindowsInstaller", &val
))
2274 state
= INSTALLSTATE_DEFAULT
;
2276 state
= INSTALLSTATE_UNKNOWN
;
2281 state
= INSTALLSTATE_UNKNOWN
;
2284 state
= INSTALLSTATE_ABSENT
;
2287 RegCloseKey(prodkey
);
2288 RegCloseKey(userdata
);
2289 TRACE("-> %d\n", state
);
2293 INSTALLUILEVEL WINAPI
MsiSetInternalUI(INSTALLUILEVEL dwUILevel
, HWND
*phWnd
)
2295 INSTALLUILEVEL old
= gUILevel
;
2296 HWND oldwnd
= gUIhwnd
;
2298 TRACE("%08x %p\n", dwUILevel
, phWnd
);
2300 if (dwUILevel
& ~(INSTALLUILEVEL_MASK
|INSTALLUILEVEL_HIDECANCEL
|INSTALLUILEVEL_PROGRESSONLY
|
2301 INSTALLUILEVEL_ENDDIALOG
|INSTALLUILEVEL_SOURCERESONLY
))
2303 FIXME("Unrecognized flags %08x\n", dwUILevel
);
2304 return INSTALLUILEVEL_NOCHANGE
;
2307 if (dwUILevel
!= INSTALLUILEVEL_NOCHANGE
)
2308 gUILevel
= dwUILevel
;
2318 INSTALLUI_HANDLERA WINAPI
MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler
,
2319 DWORD dwMessageFilter
, LPVOID pvContext
)
2321 INSTALLUI_HANDLERA prev
= gUIHandlerA
;
2323 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2325 gUIHandlerA
= puiHandler
;
2327 gUIFilter
= dwMessageFilter
;
2328 gUIContext
= pvContext
;
2333 INSTALLUI_HANDLERW WINAPI
MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler
,
2334 DWORD dwMessageFilter
, LPVOID pvContext
)
2336 INSTALLUI_HANDLERW prev
= gUIHandlerW
;
2338 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2341 gUIHandlerW
= puiHandler
;
2342 gUIFilter
= dwMessageFilter
;
2343 gUIContext
= pvContext
;
2348 /******************************************************************
2349 * MsiLoadStringW [MSI.@]
2351 * Loads a string from MSI's string resources.
2355 * handle [I] only -1 is handled currently
2356 * id [I] id of the string to be loaded
2357 * lpBuffer [O] buffer for the string to be written to
2358 * nBufferMax [I] maximum size of the buffer in characters
2359 * lang [I] the preferred language for the string
2363 * If successful, this function returns the language id of the string loaded
2364 * If the function fails, the function returns zero.
2368 * The type of the first parameter is unknown. LoadString's prototype
2369 * suggests that it might be a module handle. I have made it an MSI handle
2370 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2371 * handle. Maybe strings can be stored in an MSI database somehow.
2373 LANGID WINAPI
MsiLoadStringW( MSIHANDLE handle
, UINT id
, LPWSTR lpBuffer
,
2374 int nBufferMax
, LANGID lang
)
2381 TRACE("%d %u %p %d %d\n", handle
, id
, lpBuffer
, nBufferMax
, lang
);
2384 FIXME("don't know how to deal with handle = %08x\n", handle
);
2387 lang
= GetUserDefaultLangID();
2389 hres
= FindResourceExW( msi_hInstance
, (LPCWSTR
) RT_STRING
,
2393 hResData
= LoadResource( msi_hInstance
, hres
);
2396 p
= LockResource( hResData
);
2400 for (i
= 0; i
< (id
& 0xf); i
++) p
+= *p
+ 1;
2403 if( nBufferMax
<= len
)
2406 memcpy( lpBuffer
, p
+1, len
* sizeof(WCHAR
));
2407 lpBuffer
[ len
] = 0;
2409 TRACE("found -> %s\n", debugstr_w(lpBuffer
));
2413 LANGID WINAPI
MsiLoadStringA( MSIHANDLE handle
, UINT id
, LPSTR lpBuffer
,
2414 int nBufferMax
, LANGID lang
)
2420 bufW
= msi_alloc(nBufferMax
*sizeof(WCHAR
));
2421 r
= MsiLoadStringW(handle
, id
, bufW
, nBufferMax
, lang
);
2424 len
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
2425 if( len
<= nBufferMax
)
2426 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1,
2427 lpBuffer
, nBufferMax
, NULL
, NULL
);
2435 INSTALLSTATE WINAPI
MsiLocateComponentA(LPCSTR szComponent
, LPSTR lpPathBuf
,
2438 char szProduct
[GUID_SIZE
];
2440 TRACE("%s %p %p\n", debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2442 if (!szComponent
|| !pcchBuf
)
2443 return INSTALLSTATE_INVALIDARG
;
2445 if (MsiGetProductCodeA( szComponent
, szProduct
) != ERROR_SUCCESS
)
2446 return INSTALLSTATE_UNKNOWN
;
2448 return MsiGetComponentPathA( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2451 INSTALLSTATE WINAPI
MsiLocateComponentW(LPCWSTR szComponent
, LPWSTR lpPathBuf
,
2454 WCHAR szProduct
[GUID_SIZE
];
2456 TRACE("%s %p %p\n", debugstr_w(szComponent
), lpPathBuf
, pcchBuf
);
2458 if (!szComponent
|| !pcchBuf
)
2459 return INSTALLSTATE_INVALIDARG
;
2461 if (MsiGetProductCodeW( szComponent
, szProduct
) != ERROR_SUCCESS
)
2462 return INSTALLSTATE_UNKNOWN
;
2464 return MsiGetComponentPathW( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2467 UINT WINAPI
MsiMessageBoxA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2468 WORD wLanguageId
, DWORD f
)
2470 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_a(lpText
), debugstr_a(lpCaption
),
2471 uType
, wLanguageId
, f
);
2472 return MessageBoxExA(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2475 UINT WINAPI
MsiMessageBoxW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2476 WORD wLanguageId
, DWORD f
)
2478 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_w(lpText
), debugstr_w(lpCaption
),
2479 uType
, wLanguageId
, f
);
2480 return MessageBoxExW(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2483 UINT WINAPI
MsiMessageBoxExA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2484 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2486 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_a(lpText
),
2487 debugstr_a(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2488 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2491 UINT WINAPI
MsiMessageBoxExW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2492 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2494 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_w(lpText
),
2495 debugstr_w(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2496 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2499 UINT WINAPI
MsiProvideAssemblyA( LPCSTR szAssemblyName
, LPCSTR szAppContext
,
2500 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPSTR lpPathBuf
,
2501 LPDWORD pcchPathBuf
)
2503 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName
),
2504 debugstr_a(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2506 return ERROR_CALL_NOT_IMPLEMENTED
;
2509 UINT WINAPI
MsiProvideAssemblyW( LPCWSTR szAssemblyName
, LPCWSTR szAppContext
,
2510 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPWSTR lpPathBuf
,
2511 LPDWORD pcchPathBuf
)
2513 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName
),
2514 debugstr_w(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2516 return ERROR_CALL_NOT_IMPLEMENTED
;
2519 UINT WINAPI
MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor
,
2520 LPSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2522 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2523 return ERROR_CALL_NOT_IMPLEMENTED
;
2526 UINT WINAPI
MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor
,
2527 LPWSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2529 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2530 return ERROR_CALL_NOT_IMPLEMENTED
;
2533 HRESULT WINAPI
MsiGetFileSignatureInformationA( LPCSTR path
, DWORD flags
, PCCERT_CONTEXT
*cert
,
2534 LPBYTE hash
, LPDWORD hashlen
)
2537 WCHAR
*pathW
= NULL
;
2539 TRACE("%s %08x %p %p %p\n", debugstr_a(path
), flags
, cert
, hash
, hashlen
);
2541 if (path
&& !(pathW
= strdupAtoW( path
))) return E_OUTOFMEMORY
;
2542 r
= MsiGetFileSignatureInformationW( pathW
, flags
, cert
, hash
, hashlen
);
2547 HRESULT WINAPI
MsiGetFileSignatureInformationW( LPCWSTR path
, DWORD flags
, PCCERT_CONTEXT
*cert
,
2548 LPBYTE hash
, LPDWORD hashlen
)
2550 static GUID generic_verify_v2
= WINTRUST_ACTION_GENERIC_VERIFY_V2
;
2553 WINTRUST_FILE_INFO info
;
2554 CRYPT_PROVIDER_SGNR
*signer
;
2555 CRYPT_PROVIDER_CERT
*provider
;
2557 TRACE("%s %08x %p %p %p\n", debugstr_w(path
), flags
, cert
, hash
, hashlen
);
2559 if (!path
|| !cert
) return E_INVALIDARG
;
2561 info
.cbStruct
= sizeof(info
);
2562 info
.pcwszFilePath
= path
;
2564 info
.pgKnownSubject
= NULL
;
2566 data
.cbStruct
= sizeof(data
);
2567 data
.pPolicyCallbackData
= NULL
;
2568 data
.pSIPClientData
= NULL
;
2569 data
.dwUIChoice
= WTD_UI_NONE
;
2570 data
.fdwRevocationChecks
= WTD_REVOKE_WHOLECHAIN
;
2571 data
.dwUnionChoice
= WTD_CHOICE_FILE
;
2572 data
.u
.pFile
= &info
;
2573 data
.dwStateAction
= WTD_STATEACTION_VERIFY
;
2574 data
.hWVTStateData
= NULL
;
2575 data
.pwszURLReference
= NULL
;
2576 data
.dwProvFlags
= 0;
2577 data
.dwUIContext
= WTD_UICONTEXT_INSTALL
;
2578 hr
= WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2580 if (FAILED(hr
)) goto done
;
2582 if (!(signer
= WTHelperGetProvSignerFromChain( data
.hWVTStateData
, 0, FALSE
, 0 )))
2584 hr
= TRUST_E_NOSIGNATURE
;
2589 DWORD len
= signer
->psSigner
->EncryptedHash
.cbData
;
2593 hr
= HRESULT_FROM_WIN32(ERROR_MORE_DATA
);
2596 memcpy( hash
, signer
->psSigner
->EncryptedHash
.pbData
, len
);
2599 if (!(provider
= WTHelperGetProvCertFromChain( signer
, 0 )))
2601 hr
= TRUST_E_PROVIDER_UNKNOWN
;
2604 *cert
= CertDuplicateCertificateContext( provider
->pCert
);
2607 data
.dwStateAction
= WTD_STATEACTION_CLOSE
;
2608 WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2612 /******************************************************************
2613 * MsiGetProductPropertyA [MSI.@]
2615 UINT WINAPI
MsiGetProductPropertyA(MSIHANDLE hProduct
, LPCSTR szProperty
,
2616 LPSTR szValue
, LPDWORD pccbValue
)
2618 LPWSTR prop
= NULL
, val
= NULL
;
2622 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_a(szProperty
),
2623 szValue
, pccbValue
);
2625 if (szValue
&& !pccbValue
)
2626 return ERROR_INVALID_PARAMETER
;
2628 if (szProperty
) prop
= strdupAtoW(szProperty
);
2631 r
= MsiGetProductPropertyW(hProduct
, prop
, NULL
, &len
);
2632 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2635 if (r
== ERROR_SUCCESS
)
2637 if (szValue
) *szValue
= '\0';
2638 if (pccbValue
) *pccbValue
= 0;
2642 val
= msi_alloc(++len
* sizeof(WCHAR
));
2645 r
= ERROR_OUTOFMEMORY
;
2649 r
= MsiGetProductPropertyW(hProduct
, prop
, val
, &len
);
2650 if (r
!= ERROR_SUCCESS
)
2653 len
= WideCharToMultiByte(CP_ACP
, 0, val
, -1, NULL
, 0, NULL
, NULL
);
2656 WideCharToMultiByte(CP_ACP
, 0, val
, -1, szValue
,
2657 *pccbValue
, NULL
, NULL
);
2661 if (len
> *pccbValue
)
2662 r
= ERROR_MORE_DATA
;
2664 *pccbValue
= len
- 1;
2674 /******************************************************************
2675 * MsiGetProductPropertyW [MSI.@]
2677 UINT WINAPI
MsiGetProductPropertyW(MSIHANDLE hProduct
, LPCWSTR szProperty
,
2678 LPWSTR szValue
, LPDWORD pccbValue
)
2680 MSIPACKAGE
*package
;
2681 MSIQUERY
*view
= NULL
;
2682 MSIRECORD
*rec
= NULL
;
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
, L
"SELECT * FROM `Property` WHERE `Property` = '%s'", 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 BOOL
open_userdata_comp_key( const WCHAR
*comp
, const WCHAR
*usersid
, MSIINSTALLCONTEXT ctx
,
2784 if (ctx
& MSIINSTALLCONTEXT_MACHINE
)
2786 if (!MSIREG_OpenUserDataComponentKey( comp
, L
"S-1-5-18", hkey
, FALSE
)) return TRUE
;
2788 if (ctx
& (MSIINSTALLCONTEXT_USERMANAGED
|MSIINSTALLCONTEXT_USERUNMANAGED
))
2790 if (usersid
&& !wcsicmp( usersid
, L
"S-1-1-0" ))
2792 FIXME( "only looking at the current user\n" );
2795 if (!MSIREG_OpenUserDataComponentKey( comp
, usersid
, hkey
, FALSE
)) return TRUE
;
2800 static INSTALLSTATE
MSI_GetComponentPath( const WCHAR
*szProduct
, const WCHAR
*szComponent
,
2801 const WCHAR
*szUserSid
, MSIINSTALLCONTEXT ctx
,
2802 awstring
*lpPathBuf
, DWORD
*pcchBuf
)
2804 WCHAR
*path
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
], squashed_comp
[SQUASHED_GUID_SIZE
];
2809 if (!szProduct
|| !szComponent
)
2810 return INSTALLSTATE_INVALIDARG
;
2812 if (lpPathBuf
->str
.w
&& !pcchBuf
)
2813 return INSTALLSTATE_INVALIDARG
;
2815 if (!squash_guid( szProduct
, squashed_pc
) || !squash_guid( szComponent
, squashed_comp
))
2816 return INSTALLSTATE_INVALIDARG
;
2818 if (szUserSid
&& ctx
== MSIINSTALLCONTEXT_MACHINE
)
2819 return INSTALLSTATE_INVALIDARG
;
2821 state
= INSTALLSTATE_UNKNOWN
;
2823 if (open_userdata_comp_key( szComponent
, szUserSid
, ctx
, &hkey
))
2825 path
= msi_reg_get_val_str( hkey
, squashed_pc
);
2828 state
= INSTALLSTATE_ABSENT
;
2830 if ((!MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
, NULL
, &hkey
, FALSE
) ||
2831 !MSIREG_OpenUserDataProductKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
, NULL
, &hkey
, FALSE
)) &&
2832 msi_reg_get_val_dword(hkey
, L
"WindowsInstaller", &version
) &&
2833 GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2836 state
= INSTALLSTATE_LOCAL
;
2840 if (state
!= INSTALLSTATE_LOCAL
&&
2841 (!MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, &hkey
, FALSE
) ||
2842 !MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
, &hkey
, FALSE
)))
2846 if (open_userdata_comp_key( szComponent
, szUserSid
, ctx
, &hkey
))
2849 path
= msi_reg_get_val_str( hkey
, squashed_pc
);
2852 state
= INSTALLSTATE_ABSENT
;
2854 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2855 state
= INSTALLSTATE_LOCAL
;
2860 return INSTALLSTATE_UNKNOWN
;
2862 if (state
== INSTALLSTATE_LOCAL
&& !*path
)
2863 state
= INSTALLSTATE_NOTUSED
;
2865 if (msi_strcpy_to_awstring(path
, -1, lpPathBuf
, pcchBuf
) == ERROR_MORE_DATA
)
2866 state
= INSTALLSTATE_MOREDATA
;
2872 /******************************************************************
2873 * MsiGetComponentPathExW [MSI.@]
2875 INSTALLSTATE WINAPI
MsiGetComponentPathExW( LPCWSTR product
, LPCWSTR comp
, LPCWSTR usersid
,
2876 MSIINSTALLCONTEXT ctx
, LPWSTR buf
, LPDWORD buflen
)
2880 TRACE( "%s %s %s 0x%x %p %p\n", debugstr_w(product
), debugstr_w(comp
), debugstr_w(usersid
),
2883 path
.unicode
= TRUE
;
2886 return MSI_GetComponentPath( product
, comp
, usersid
, ctx
, &path
, buflen
);
2889 INSTALLSTATE WINAPI
MsiGetComponentPathExA( LPCSTR product
, LPCSTR comp
, LPCSTR usersid
,
2890 MSIINSTALLCONTEXT ctx
, LPSTR buf
, LPDWORD buflen
)
2892 WCHAR
*productW
= NULL
, *compW
= NULL
, *usersidW
= NULL
;
2893 INSTALLSTATE r
= INSTALLSTATE_UNKNOWN
;
2896 TRACE( "%s %s %s 0x%x %p %p\n", debugstr_a(product
), debugstr_a(comp
), debugstr_a(usersid
),
2899 if (product
&& !(productW
= strdupAtoW( product
))) return INSTALLSTATE_UNKNOWN
;
2900 if (comp
&& !(compW
= strdupAtoW( comp
))) goto end
;
2901 if (usersid
&& !(usersidW
= strdupAtoW( usersid
))) goto end
;
2903 path
.unicode
= FALSE
;
2906 r
= MSI_GetComponentPath( productW
, compW
, usersidW
, ctx
, &path
, buflen
);
2909 msi_free( productW
);
2911 msi_free( usersidW
);
2916 /******************************************************************
2917 * MsiGetComponentPathW [MSI.@]
2919 INSTALLSTATE WINAPI
MsiGetComponentPathW( LPCWSTR product
, LPCWSTR comp
, LPWSTR buf
, LPDWORD buflen
)
2921 return MsiGetComponentPathExW( product
, comp
, L
"S-1-1-0", MSIINSTALLCONTEXT_ALL
, buf
, buflen
);
2924 /******************************************************************
2925 * MsiGetComponentPathA [MSI.@]
2927 INSTALLSTATE WINAPI
MsiGetComponentPathA( LPCSTR product
, LPCSTR comp
, LPSTR buf
, LPDWORD buflen
)
2929 return MsiGetComponentPathExA( product
, comp
, "s-1-1-0", MSIINSTALLCONTEXT_ALL
, buf
, buflen
);
2932 static UINT
query_feature_state( const WCHAR
*product
, const WCHAR
*squashed
, const WCHAR
*usersid
,
2933 MSIINSTALLCONTEXT ctx
, const WCHAR
*feature
, INSTALLSTATE
*state
)
2937 WCHAR
*parent
, *components
, *path
;
2939 BOOL missing
= FALSE
, source
= FALSE
;
2940 WCHAR comp
[GUID_SIZE
];
2943 if (ctx
!= MSIINSTALLCONTEXT_MACHINE
) SetLastError( ERROR_SUCCESS
);
2945 if (MSIREG_OpenFeaturesKey( product
, usersid
, ctx
, &hkey
, FALSE
)) return ERROR_UNKNOWN_PRODUCT
;
2947 parent
= msi_reg_get_val_str( hkey
, feature
);
2948 RegCloseKey( hkey
);
2949 if (!parent
) return ERROR_UNKNOWN_FEATURE
;
2951 *state
= (parent
[0] == 6) ? INSTALLSTATE_ABSENT
: INSTALLSTATE_LOCAL
;
2953 if (*state
== INSTALLSTATE_ABSENT
)
2954 return ERROR_SUCCESS
;
2956 r
= MSIREG_OpenUserDataFeaturesKey( product
, usersid
, ctx
, &hkey
, FALSE
);
2957 if (r
!= ERROR_SUCCESS
)
2959 *state
= INSTALLSTATE_ADVERTISED
;
2960 return ERROR_SUCCESS
;
2962 components
= msi_reg_get_val_str( hkey
, feature
);
2963 RegCloseKey( hkey
);
2965 TRACE("buffer = %s\n", debugstr_w(components
));
2969 *state
= INSTALLSTATE_ADVERTISED
;
2970 return ERROR_SUCCESS
;
2972 for (p
= components
; *p
&& *p
!= 2 ; p
+= 20)
2974 if (!decode_base85_guid( p
, &guid
))
2976 if (p
!= components
) break;
2977 msi_free( components
);
2978 *state
= INSTALLSTATE_BADCONFIG
;
2979 return ERROR_BAD_CONFIGURATION
;
2981 StringFromGUID2( &guid
, comp
, GUID_SIZE
);
2982 if (ctx
== MSIINSTALLCONTEXT_MACHINE
)
2983 r
= MSIREG_OpenUserDataComponentKey( comp
, L
"S-1-5-18", &hkey
, FALSE
);
2985 r
= MSIREG_OpenUserDataComponentKey( comp
, usersid
, &hkey
, FALSE
);
2987 if (r
!= ERROR_SUCCESS
)
2989 msi_free( components
);
2990 *state
= INSTALLSTATE_ADVERTISED
;
2991 return ERROR_SUCCESS
;
2993 path
= msi_reg_get_val_str( hkey
, squashed
);
2994 if (!path
) missing
= TRUE
;
2995 else if (lstrlenW( path
) > 2 &&
2996 path
[0] >= '0' && path
[0] <= '9' &&
2997 path
[1] >= '0' && path
[1] <= '9')
3003 msi_free( components
);
3006 *state
= INSTALLSTATE_ADVERTISED
;
3008 *state
= INSTALLSTATE_SOURCE
;
3010 *state
= INSTALLSTATE_LOCAL
;
3012 TRACE("returning state %d\n", *state
);
3013 return ERROR_SUCCESS
;
3016 UINT WINAPI
MsiQueryFeatureStateExA( LPCSTR product
, LPCSTR usersid
, MSIINSTALLCONTEXT ctx
,
3017 LPCSTR feature
, INSTALLSTATE
*state
)
3020 WCHAR
*productW
= NULL
, *usersidW
= NULL
, *featureW
= NULL
;
3022 if (product
&& !(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
3023 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
3025 msi_free( productW
);
3026 return ERROR_OUTOFMEMORY
;
3028 if (feature
&& !(featureW
= strdupAtoW( feature
)))
3030 msi_free( productW
);
3031 msi_free( usersidW
);
3032 return ERROR_OUTOFMEMORY
;
3034 r
= MsiQueryFeatureStateExW( productW
, usersidW
, ctx
, featureW
, state
);
3035 msi_free( productW
);
3036 msi_free( usersidW
);
3037 msi_free( featureW
);
3041 UINT WINAPI
MsiQueryFeatureStateExW( LPCWSTR product
, LPCWSTR usersid
, MSIINSTALLCONTEXT ctx
,
3042 LPCWSTR feature
, INSTALLSTATE
*state
)
3045 if (!squash_guid( product
, squashed
)) return ERROR_INVALID_PARAMETER
;
3046 return query_feature_state( product
, squashed
, usersid
, ctx
, feature
, state
);
3049 /******************************************************************
3050 * MsiQueryFeatureStateA [MSI.@]
3052 INSTALLSTATE WINAPI
MsiQueryFeatureStateA(LPCSTR szProduct
, LPCSTR szFeature
)
3054 LPWSTR szwProduct
= NULL
, szwFeature
= NULL
;
3055 INSTALLSTATE rc
= INSTALLSTATE_UNKNOWN
;
3057 szwProduct
= strdupAtoW( szProduct
);
3058 if ( szProduct
&& !szwProduct
)
3061 szwFeature
= strdupAtoW( szFeature
);
3062 if ( szFeature
&& !szwFeature
)
3065 rc
= MsiQueryFeatureStateW(szwProduct
, szwFeature
);
3068 msi_free( szwProduct
);
3069 msi_free( szwFeature
);
3074 /******************************************************************
3075 * MsiQueryFeatureStateW [MSI.@]
3077 * Checks the state of a feature
3080 * szProduct [I] Product's GUID string
3081 * szFeature [I] Feature's GUID string
3084 * INSTALLSTATE_LOCAL Feature is installed and usable
3085 * INSTALLSTATE_ABSENT Feature is absent
3086 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
3087 * INSTALLSTATE_UNKNOWN An error occurred
3088 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
3091 INSTALLSTATE WINAPI
MsiQueryFeatureStateW(LPCWSTR szProduct
, LPCWSTR szFeature
)
3097 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szFeature
));
3099 if (!szProduct
|| !szFeature
|| !squash_guid( szProduct
, squashed
))
3100 return INSTALLSTATE_INVALIDARG
;
3102 r
= query_feature_state( szProduct
, squashed
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, szFeature
, &state
);
3103 if (r
== ERROR_SUCCESS
|| r
== ERROR_BAD_CONFIGURATION
) return state
;
3105 r
= query_feature_state( szProduct
, squashed
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, szFeature
, &state
);
3106 if (r
== ERROR_SUCCESS
|| r
== ERROR_BAD_CONFIGURATION
) return state
;
3108 r
= query_feature_state( szProduct
, squashed
, NULL
, MSIINSTALLCONTEXT_MACHINE
, szFeature
, &state
);
3109 if (r
== ERROR_SUCCESS
|| r
== ERROR_BAD_CONFIGURATION
) return state
;
3111 return INSTALLSTATE_UNKNOWN
;
3114 /******************************************************************
3115 * MsiGetFileVersionA [MSI.@]
3117 UINT WINAPI
MsiGetFileVersionA(LPCSTR szFilePath
, LPSTR lpVersionBuf
,
3118 LPDWORD pcchVersionBuf
, LPSTR lpLangBuf
, LPDWORD pcchLangBuf
)
3120 LPWSTR szwFilePath
= NULL
, lpwVersionBuff
= NULL
, lpwLangBuff
= NULL
;
3121 UINT ret
= ERROR_OUTOFMEMORY
;
3123 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
3124 (lpLangBuf
&& !pcchLangBuf
))
3125 return ERROR_INVALID_PARAMETER
;
3129 szwFilePath
= strdupAtoW( szFilePath
);
3134 if( lpVersionBuf
&& pcchVersionBuf
&& *pcchVersionBuf
)
3136 lpwVersionBuff
= msi_alloc(*pcchVersionBuf
*sizeof(WCHAR
));
3137 if( !lpwVersionBuff
)
3141 if( lpLangBuf
&& pcchLangBuf
&& *pcchLangBuf
)
3143 lpwLangBuff
= msi_alloc(*pcchLangBuf
*sizeof(WCHAR
));
3148 ret
= MsiGetFileVersionW(szwFilePath
, lpwVersionBuff
, pcchVersionBuf
,
3149 lpwLangBuff
, pcchLangBuf
);
3151 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwVersionBuff
)
3152 WideCharToMultiByte(CP_ACP
, 0, lpwVersionBuff
, -1,
3153 lpVersionBuf
, *pcchVersionBuf
+ 1, NULL
, NULL
);
3154 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwLangBuff
)
3155 WideCharToMultiByte(CP_ACP
, 0, lpwLangBuff
, -1,
3156 lpLangBuf
, *pcchLangBuf
+ 1, NULL
, NULL
);
3159 msi_free(szwFilePath
);
3160 msi_free(lpwVersionBuff
);
3161 msi_free(lpwLangBuff
);
3166 static UINT
get_file_version( const WCHAR
*path
, WCHAR
*verbuf
, DWORD
*verlen
,
3167 WCHAR
*langbuf
, DWORD
*langlen
)
3169 UINT ret
= ERROR_MORE_DATA
;
3172 VS_FIXEDFILEINFO
*ffi
;
3176 if (!(len
= GetFileVersionInfoSizeW( path
, NULL
)))
3178 error
= GetLastError();
3179 if (error
== ERROR_BAD_PATHNAME
) return ERROR_FILE_NOT_FOUND
;
3180 if (error
== ERROR_RESOURCE_DATA_NOT_FOUND
) return ERROR_FILE_INVALID
;
3183 if (!(version
= msi_alloc( len
))) return ERROR_OUTOFMEMORY
;
3184 if (!GetFileVersionInfoW( path
, 0, len
, version
))
3186 msi_free( version
);
3187 return GetLastError();
3189 if (!verbuf
&& !verlen
&& !langbuf
&& !langlen
)
3191 msi_free( version
);
3192 return ERROR_SUCCESS
;
3196 if (VerQueryValueW( version
, L
"\\", (LPVOID
*)&ffi
, &len
) && len
> 0)
3198 swprintf( tmp
, ARRAY_SIZE(tmp
), L
"%d.%d.%d.%d",
3199 HIWORD(ffi
->dwFileVersionMS
), LOWORD(ffi
->dwFileVersionMS
),
3200 HIWORD(ffi
->dwFileVersionLS
), LOWORD(ffi
->dwFileVersionLS
) );
3201 if (verbuf
) lstrcpynW( verbuf
, tmp
, *verlen
);
3202 len
= lstrlenW( tmp
);
3203 if (*verlen
> len
) ret
= ERROR_SUCCESS
;
3208 if (verbuf
) *verbuf
= 0;
3214 if (VerQueryValueW( version
, L
"\\VarFileInfo\\Translation", (LPVOID
*)&lang
, &len
) && len
> 0)
3216 swprintf( tmp
, ARRAY_SIZE(tmp
), L
"%d", *lang
);
3217 if (langbuf
) lstrcpynW( langbuf
, tmp
, *langlen
);
3218 len
= lstrlenW( tmp
);
3219 if (*langlen
> len
) ret
= ERROR_SUCCESS
;
3224 if (langbuf
) *langbuf
= 0;
3228 msi_free( version
);
3233 /******************************************************************
3234 * MsiGetFileVersionW [MSI.@]
3236 UINT WINAPI
MsiGetFileVersionW( LPCWSTR path
, LPWSTR verbuf
, LPDWORD verlen
,
3237 LPWSTR langbuf
, LPDWORD langlen
)
3241 TRACE("%s %p %u %p %u\n", debugstr_w(path
), verbuf
, verlen
? *verlen
: 0,
3242 langbuf
, langlen
? *langlen
: 0);
3244 if ((verbuf
&& !verlen
) || (langbuf
&& !langlen
))
3245 return ERROR_INVALID_PARAMETER
;
3247 ret
= get_file_version( path
, verbuf
, verlen
, langbuf
, langlen
);
3248 if (ret
== ERROR_RESOURCE_DATA_NOT_FOUND
&& verlen
)
3251 WCHAR
*version
= msi_get_font_file_version( NULL
, path
);
3252 if (!version
) return ERROR_FILE_INVALID
;
3253 len
= lstrlenW( version
);
3254 if (len
>= *verlen
) ret
= ERROR_MORE_DATA
;
3257 lstrcpyW( verbuf
, version
);
3258 ret
= ERROR_SUCCESS
;
3261 msi_free( version
);
3266 /***********************************************************************
3267 * MsiGetFeatureUsageW [MSI.@]
3269 UINT WINAPI
MsiGetFeatureUsageW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3270 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
3272 FIXME("%s %s %p %p\n",debugstr_w(szProduct
), debugstr_w(szFeature
),
3273 pdwUseCount
, pwDateUsed
);
3274 return ERROR_CALL_NOT_IMPLEMENTED
;
3277 /***********************************************************************
3278 * MsiGetFeatureUsageA [MSI.@]
3280 UINT WINAPI
MsiGetFeatureUsageA( LPCSTR szProduct
, LPCSTR szFeature
,
3281 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
3283 LPWSTR prod
= NULL
, feat
= NULL
;
3284 UINT ret
= ERROR_OUTOFMEMORY
;
3286 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3287 pdwUseCount
, pwDateUsed
);
3289 prod
= strdupAtoW( szProduct
);
3290 if (szProduct
&& !prod
)
3293 feat
= strdupAtoW( szFeature
);
3294 if (szFeature
&& !feat
)
3297 ret
= MsiGetFeatureUsageW( prod
, feat
, pdwUseCount
, pwDateUsed
);
3306 /***********************************************************************
3307 * MsiUseFeatureExW [MSI.@]
3309 INSTALLSTATE WINAPI
MsiUseFeatureExW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3310 DWORD dwInstallMode
, DWORD dwReserved
)
3314 TRACE("%s %s %i %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
3315 dwInstallMode
, dwReserved
);
3317 state
= MsiQueryFeatureStateW( szProduct
, szFeature
);
3320 return INSTALLSTATE_INVALIDARG
;
3322 if (state
== INSTALLSTATE_LOCAL
&& dwInstallMode
!= INSTALLMODE_NODETECTION
)
3324 FIXME("mark product %s feature %s as used\n",
3325 debugstr_w(szProduct
), debugstr_w(szFeature
) );
3331 /***********************************************************************
3332 * MsiUseFeatureExA [MSI.@]
3334 INSTALLSTATE WINAPI
MsiUseFeatureExA( LPCSTR szProduct
, LPCSTR szFeature
,
3335 DWORD dwInstallMode
, DWORD dwReserved
)
3337 INSTALLSTATE ret
= INSTALLSTATE_UNKNOWN
;
3338 LPWSTR prod
= NULL
, feat
= NULL
;
3340 TRACE("%s %s %i %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3341 dwInstallMode
, dwReserved
);
3343 prod
= strdupAtoW( szProduct
);
3344 if (szProduct
&& !prod
)
3347 feat
= strdupAtoW( szFeature
);
3348 if (szFeature
&& !feat
)
3351 ret
= MsiUseFeatureExW( prod
, feat
, dwInstallMode
, dwReserved
);
3360 /***********************************************************************
3361 * MsiUseFeatureW [MSI.@]
3363 INSTALLSTATE WINAPI
MsiUseFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
)
3365 return MsiUseFeatureExW(szProduct
, szFeature
, 0, 0);
3368 /***********************************************************************
3369 * MsiUseFeatureA [MSI.@]
3371 INSTALLSTATE WINAPI
MsiUseFeatureA( LPCSTR szProduct
, LPCSTR szFeature
)
3373 return MsiUseFeatureExA(szProduct
, szFeature
, 0, 0);
3376 static WCHAR
*reg_get_multisz( HKEY hkey
, const WCHAR
*name
)
3380 if (RegQueryValueExW( hkey
, name
, NULL
, &type
, NULL
, &len
) || type
!= REG_MULTI_SZ
) return NULL
;
3381 if ((ret
= msi_alloc( len
))) RegQueryValueExW( hkey
, name
, NULL
, NULL
, (BYTE
*)ret
, &len
);
3385 static WCHAR
*reg_get_sz( HKEY hkey
, const WCHAR
*name
)
3389 if (RegQueryValueExW( hkey
, name
, NULL
, &type
, NULL
, &len
) || type
!= REG_SZ
) return NULL
;
3390 if ((ret
= msi_alloc( len
))) RegQueryValueExW( hkey
, name
, NULL
, NULL
, (BYTE
*)ret
, &len
);
3394 #define BASE85_SIZE 20
3396 /***********************************************************************
3397 * MSI_ProvideQualifiedComponentEx [internal]
3399 static UINT
MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent
,
3400 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3401 DWORD Unused1
, DWORD Unused2
, awstring
*lpPathBuf
,
3402 LPDWORD pcchPathBuf
)
3404 WCHAR product
[MAX_FEATURE_CHARS
+1], comp
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1];
3411 if (MSIREG_OpenUserComponentsKey( szComponent
, &hkey
, FALSE
)) return ERROR_UNKNOWN_COMPONENT
;
3413 desc
= reg_get_multisz( hkey
, szQualifier
);
3415 if (!desc
) return ERROR_INDEX_ABSENT
;
3417 /* FIXME: handle multiple descriptors */
3418 ret
= MsiDecomposeDescriptorW( desc
, product
, feature
, comp
, &size
);
3420 if (ret
!= ERROR_SUCCESS
) return ret
;
3422 if (!szProduct
) szProduct
= product
;
3425 MSIINSTALLCONTEXT ctx
;
3429 /* use the first component of the feature if the descriptor component is empty */
3430 if ((ret
= msi_locate_product( szProduct
, &ctx
))) return ret
;
3431 if ((ret
= MSIREG_OpenUserDataFeaturesKey( szProduct
, NULL
, ctx
, &hkey
, FALSE
)))
3433 return ERROR_FILE_NOT_FOUND
;
3435 components
= reg_get_sz( hkey
, feature
);
3436 RegCloseKey( hkey
);
3437 if (!components
) return ERROR_FILE_NOT_FOUND
;
3439 if (lstrlenW( components
) < BASE85_SIZE
|| !decode_base85_guid( components
, &guid
))
3441 msi_free( components
);
3442 return ERROR_FILE_NOT_FOUND
;
3444 msi_free( components
);
3445 StringFromGUID2( &guid
, comp
, ARRAY_SIZE( comp
));
3448 state
= MSI_GetComponentPath( szProduct
, comp
, L
"S-1-1-0", MSIINSTALLCONTEXT_ALL
, lpPathBuf
, pcchPathBuf
);
3450 if (state
== INSTALLSTATE_MOREDATA
) return ERROR_MORE_DATA
;
3451 if (state
!= INSTALLSTATE_LOCAL
) return ERROR_FILE_NOT_FOUND
;
3452 return ERROR_SUCCESS
;
3455 /***********************************************************************
3456 * MsiProvideQualifiedComponentExW [MSI.@]
3458 UINT WINAPI
MsiProvideQualifiedComponentExW(LPCWSTR szComponent
,
3459 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3460 DWORD Unused1
, DWORD Unused2
, LPWSTR lpPathBuf
,
3461 LPDWORD pcchPathBuf
)
3465 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_w(szComponent
),
3466 debugstr_w(szQualifier
), dwInstallMode
, debugstr_w(szProduct
),
3467 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3469 path
.unicode
= TRUE
;
3470 path
.str
.w
= lpPathBuf
;
3472 return MSI_ProvideQualifiedComponentEx(szComponent
, szQualifier
,
3473 dwInstallMode
, szProduct
, Unused1
, Unused2
, &path
, pcchPathBuf
);
3476 /***********************************************************************
3477 * MsiProvideQualifiedComponentExA [MSI.@]
3479 UINT WINAPI
MsiProvideQualifiedComponentExA(LPCSTR szComponent
,
3480 LPCSTR szQualifier
, DWORD dwInstallMode
, LPCSTR szProduct
,
3481 DWORD Unused1
, DWORD Unused2
, LPSTR lpPathBuf
,
3482 LPDWORD pcchPathBuf
)
3484 LPWSTR szwComponent
, szwQualifier
= NULL
, szwProduct
= NULL
;
3485 UINT r
= ERROR_OUTOFMEMORY
;
3488 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent
),
3489 debugstr_a(szQualifier
), dwInstallMode
, debugstr_a(szProduct
),
3490 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3492 szwComponent
= strdupAtoW( szComponent
);
3493 if (szComponent
&& !szwComponent
)
3496 szwQualifier
= strdupAtoW( szQualifier
);
3497 if (szQualifier
&& !szwQualifier
)
3500 szwProduct
= strdupAtoW( szProduct
);
3501 if (szProduct
&& !szwProduct
)
3504 path
.unicode
= FALSE
;
3505 path
.str
.a
= lpPathBuf
;
3507 r
= MSI_ProvideQualifiedComponentEx(szwComponent
, szwQualifier
,
3508 dwInstallMode
, szwProduct
, Unused1
,
3509 Unused2
, &path
, pcchPathBuf
);
3511 msi_free(szwProduct
);
3512 msi_free(szwComponent
);
3513 msi_free(szwQualifier
);
3518 /***********************************************************************
3519 * MsiProvideQualifiedComponentW [MSI.@]
3521 UINT WINAPI
MsiProvideQualifiedComponentW( LPCWSTR szComponent
,
3522 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPWSTR lpPathBuf
,
3523 LPDWORD pcchPathBuf
)
3525 return MsiProvideQualifiedComponentExW(szComponent
, szQualifier
,
3526 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3529 /***********************************************************************
3530 * MsiProvideQualifiedComponentA [MSI.@]
3532 UINT WINAPI
MsiProvideQualifiedComponentA( LPCSTR szComponent
,
3533 LPCSTR szQualifier
, DWORD dwInstallMode
, LPSTR lpPathBuf
,
3534 LPDWORD pcchPathBuf
)
3536 return MsiProvideQualifiedComponentExA(szComponent
, szQualifier
,
3537 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3540 /***********************************************************************
3541 * MSI_GetUserInfo [internal]
3543 static USERINFOSTATE
MSI_GetUserInfo(LPCWSTR szProduct
,
3544 awstring
*lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3545 awstring
*lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3546 awstring
*lpSerialBuf
, LPDWORD pcchSerialBuf
)
3548 WCHAR
*user
, *org
, *serial
, squashed_pc
[SQUASHED_GUID_SIZE
];
3549 USERINFOSTATE state
;
3554 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct
), lpUserNameBuf
,
3555 pcchUserNameBuf
, lpOrgNameBuf
, pcchOrgNameBuf
, lpSerialBuf
,
3558 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
3559 return USERINFOSTATE_INVALIDARG
;
3561 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
3562 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3563 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3564 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3565 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
3566 &hkey
, FALSE
) != ERROR_SUCCESS
)
3568 return USERINFOSTATE_UNKNOWN
;
3571 if (MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3572 NULL
, &props
, FALSE
) != ERROR_SUCCESS
&&
3573 MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
3574 NULL
, &props
, FALSE
) != ERROR_SUCCESS
)
3577 return USERINFOSTATE_ABSENT
;
3580 user
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGOWNERW
);
3581 org
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGCOMPANYW
);
3582 serial
= msi_reg_get_val_str(props
, INSTALLPROPERTY_PRODUCTIDW
);
3583 state
= USERINFOSTATE_ABSENT
;
3589 state
= USERINFOSTATE_PRESENT
;
3591 if (pcchUserNameBuf
)
3593 if (lpUserNameBuf
&& !user
)
3595 (*pcchUserNameBuf
)--;
3599 r
= msi_strcpy_to_awstring(user
, -1, lpUserNameBuf
, pcchUserNameBuf
);
3600 if (r
== ERROR_MORE_DATA
)
3602 state
= USERINFOSTATE_MOREDATA
;
3610 if (!orgptr
) orgptr
= L
"";
3612 r
= msi_strcpy_to_awstring(orgptr
, -1, lpOrgNameBuf
, pcchOrgNameBuf
);
3613 if (r
== ERROR_MORE_DATA
)
3615 state
= USERINFOSTATE_MOREDATA
;
3628 r
= msi_strcpy_to_awstring(serial
, -1, lpSerialBuf
, pcchSerialBuf
);
3629 if (r
== ERROR_MORE_DATA
)
3630 state
= USERINFOSTATE_MOREDATA
;
3641 /***********************************************************************
3642 * MsiGetUserInfoW [MSI.@]
3644 USERINFOSTATE WINAPI
MsiGetUserInfoW(LPCWSTR szProduct
,
3645 LPWSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3646 LPWSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3647 LPWSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3649 awstring user
, org
, serial
;
3651 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3652 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3653 (lpSerialBuf
&& !pcchSerialBuf
))
3654 return USERINFOSTATE_INVALIDARG
;
3656 user
.unicode
= TRUE
;
3657 user
.str
.w
= lpUserNameBuf
;
3659 org
.str
.w
= lpOrgNameBuf
;
3660 serial
.unicode
= TRUE
;
3661 serial
.str
.w
= lpSerialBuf
;
3663 return MSI_GetUserInfo( szProduct
, &user
, pcchUserNameBuf
,
3664 &org
, pcchOrgNameBuf
,
3665 &serial
, pcchSerialBuf
);
3668 USERINFOSTATE WINAPI
MsiGetUserInfoA(LPCSTR szProduct
,
3669 LPSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3670 LPSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3671 LPSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3673 awstring user
, org
, serial
;
3677 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3678 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3679 (lpSerialBuf
&& !pcchSerialBuf
))
3680 return USERINFOSTATE_INVALIDARG
;
3682 prod
= strdupAtoW( szProduct
);
3683 if (szProduct
&& !prod
)
3684 return ERROR_OUTOFMEMORY
;
3686 user
.unicode
= FALSE
;
3687 user
.str
.a
= lpUserNameBuf
;
3688 org
.unicode
= FALSE
;
3689 org
.str
.a
= lpOrgNameBuf
;
3690 serial
.unicode
= FALSE
;
3691 serial
.str
.a
= lpSerialBuf
;
3693 r
= MSI_GetUserInfo( prod
, &user
, pcchUserNameBuf
,
3694 &org
, pcchOrgNameBuf
,
3695 &serial
, pcchSerialBuf
);
3702 UINT WINAPI
MsiCollectUserInfoW(LPCWSTR szProduct
)
3706 MSIPACKAGE
*package
;
3708 TRACE("(%s)\n",debugstr_w(szProduct
));
3710 rc
= MsiOpenProductW(szProduct
,&handle
);
3711 if (rc
!= ERROR_SUCCESS
)
3712 return ERROR_INVALID_PARAMETER
;
3714 /* MsiCollectUserInfo cannot be called from a custom action. */
3715 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3717 return ERROR_CALL_NOT_IMPLEMENTED
;
3719 rc
= ACTION_PerformAction(package
, L
"FirstRun");
3720 msiobj_release( &package
->hdr
);
3722 MsiCloseHandle(handle
);
3727 UINT WINAPI
MsiCollectUserInfoA(LPCSTR szProduct
)
3731 MSIPACKAGE
*package
;
3733 TRACE("(%s)\n",debugstr_a(szProduct
));
3735 rc
= MsiOpenProductA(szProduct
,&handle
);
3736 if (rc
!= ERROR_SUCCESS
)
3737 return ERROR_INVALID_PARAMETER
;
3739 /* MsiCollectUserInfo cannot be called from a custom action. */
3740 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3742 return ERROR_CALL_NOT_IMPLEMENTED
;
3744 rc
= ACTION_PerformAction(package
, L
"FirstRun");
3745 msiobj_release( &package
->hdr
);
3747 MsiCloseHandle(handle
);
3752 /***********************************************************************
3753 * MsiConfigureFeatureA [MSI.@]
3755 UINT WINAPI
MsiConfigureFeatureA(LPCSTR szProduct
, LPCSTR szFeature
, INSTALLSTATE eInstallState
)
3757 LPWSTR prod
, feat
= NULL
;
3758 UINT r
= ERROR_OUTOFMEMORY
;
3760 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
), eInstallState
);
3762 prod
= strdupAtoW( szProduct
);
3763 if (szProduct
&& !prod
)
3766 feat
= strdupAtoW( szFeature
);
3767 if (szFeature
&& !feat
)
3770 r
= MsiConfigureFeatureW(prod
, feat
, eInstallState
);
3779 /***********************************************************************
3780 * MsiConfigureFeatureW [MSI.@]
3782 UINT WINAPI
MsiConfigureFeatureW(LPCWSTR szProduct
, LPCWSTR szFeature
, INSTALLSTATE eInstallState
)
3784 MSIPACKAGE
*package
= NULL
;
3786 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
3789 TRACE("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
), eInstallState
);
3791 if (!szProduct
|| !szFeature
)
3792 return ERROR_INVALID_PARAMETER
;
3794 switch (eInstallState
)
3796 case INSTALLSTATE_DEFAULT
:
3797 /* FIXME: how do we figure out the default location? */
3798 eInstallState
= INSTALLSTATE_LOCAL
;
3800 case INSTALLSTATE_LOCAL
:
3801 case INSTALLSTATE_SOURCE
:
3802 case INSTALLSTATE_ABSENT
:
3803 case INSTALLSTATE_ADVERTISED
:
3806 return ERROR_INVALID_PARAMETER
;
3809 r
= MSI_OpenProductW( szProduct
, &package
);
3810 if (r
!= ERROR_SUCCESS
)
3813 sz
= sizeof(sourcepath
);
3814 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3815 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3817 sz
= sizeof(filename
);
3818 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3819 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3821 lstrcatW( sourcepath
, filename
);
3823 MsiSetInternalUI( INSTALLUILEVEL_BASIC
, NULL
);
3825 r
= ACTION_PerformAction(package
, L
"CostInitialize");
3826 if (r
!= ERROR_SUCCESS
)
3829 r
= MSI_SetFeatureStateW( package
, szFeature
, eInstallState
);
3830 if (r
!= ERROR_SUCCESS
)
3833 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3836 msiobj_release( &package
->hdr
);
3841 /***********************************************************************
3842 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3844 * Notes: undocumented
3846 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved
)
3848 WCHAR path
[MAX_PATH
];
3850 TRACE("%d\n", dwReserved
);
3854 FIXME("dwReserved=%d\n", dwReserved
);
3855 return ERROR_INVALID_PARAMETER
;
3858 if (!GetWindowsDirectoryW(path
, MAX_PATH
))
3859 return ERROR_FUNCTION_FAILED
;
3861 lstrcatW(path
, L
"\\Installer");
3863 if (!CreateDirectoryW(path
, NULL
) && GetLastError() != ERROR_ALREADY_EXISTS
)
3864 return ERROR_FUNCTION_FAILED
;
3866 return ERROR_SUCCESS
;
3869 /***********************************************************************
3870 * MsiGetShortcutTargetA [MSI.@]
3872 UINT WINAPI
MsiGetShortcutTargetA( LPCSTR szShortcutTarget
,
3873 LPSTR szProductCode
, LPSTR szFeatureId
,
3874 LPSTR szComponentCode
)
3877 const int len
= MAX_FEATURE_CHARS
+1;
3878 WCHAR product
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1];
3881 target
= strdupAtoW( szShortcutTarget
);
3882 if (szShortcutTarget
&& !target
)
3883 return ERROR_OUTOFMEMORY
;
3887 r
= MsiGetShortcutTargetW( target
, product
, feature
, component
);
3889 if (r
== ERROR_SUCCESS
)
3891 WideCharToMultiByte( CP_ACP
, 0, product
, -1, szProductCode
, len
, NULL
, NULL
);
3892 WideCharToMultiByte( CP_ACP
, 0, feature
, -1, szFeatureId
, len
, NULL
, NULL
);
3893 WideCharToMultiByte( CP_ACP
, 0, component
, -1, szComponentCode
, len
, NULL
, NULL
);
3898 /***********************************************************************
3899 * MsiGetShortcutTargetW [MSI.@]
3901 UINT WINAPI
MsiGetShortcutTargetW( LPCWSTR szShortcutTarget
,
3902 LPWSTR szProductCode
, LPWSTR szFeatureId
,
3903 LPWSTR szComponentCode
)
3905 IShellLinkDataList
*dl
= NULL
;
3906 IPersistFile
*pf
= NULL
;
3907 LPEXP_DARWIN_LINK darwin
= NULL
;
3910 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget
),
3911 szProductCode
, szFeatureId
, szComponentCode
);
3913 init
= CoInitialize(NULL
);
3915 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3916 &IID_IPersistFile
, (LPVOID
*) &pf
);
3917 if( SUCCEEDED( r
) )
3919 r
= IPersistFile_Load( pf
, szShortcutTarget
,
3920 STGM_READ
| STGM_SHARE_DENY_WRITE
);
3921 if( SUCCEEDED( r
) )
3923 r
= IPersistFile_QueryInterface( pf
, &IID_IShellLinkDataList
,
3925 if( SUCCEEDED( r
) )
3927 IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
,
3929 IShellLinkDataList_Release( dl
);
3932 IPersistFile_Release( pf
);
3935 if (SUCCEEDED(init
))
3938 TRACE("darwin = %p\n", darwin
);
3945 ret
= MsiDecomposeDescriptorW( darwin
->szwDarwinID
,
3946 szProductCode
, szFeatureId
, szComponentCode
, &sz
);
3947 LocalFree( darwin
);
3951 return ERROR_FUNCTION_FAILED
;
3954 UINT WINAPI
MsiReinstallFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
, DWORD dwReinstallMode
)
3956 MSIPACKAGE
*package
;
3957 MSIINSTALLCONTEXT context
;
3959 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
], reinstallmode
[11];
3960 WCHAR
*ptr
, *cmdline
;
3963 TRACE("%s, %s, 0x%08x\n", debugstr_w(szProduct
), debugstr_w(szFeature
), dwReinstallMode
);
3965 r
= msi_locate_product( szProduct
, &context
);
3966 if (r
!= ERROR_SUCCESS
)
3969 ptr
= reinstallmode
;
3971 if (dwReinstallMode
& REINSTALLMODE_FILEMISSING
)
3973 if (dwReinstallMode
& REINSTALLMODE_FILEOLDERVERSION
)
3975 if (dwReinstallMode
& REINSTALLMODE_FILEEQUALVERSION
)
3977 if (dwReinstallMode
& REINSTALLMODE_FILEEXACT
)
3979 if (dwReinstallMode
& REINSTALLMODE_FILEVERIFY
)
3981 if (dwReinstallMode
& REINSTALLMODE_FILEREPLACE
)
3983 if (dwReinstallMode
& REINSTALLMODE_USERDATA
)
3985 if (dwReinstallMode
& REINSTALLMODE_MACHINEDATA
)
3987 if (dwReinstallMode
& REINSTALLMODE_SHORTCUT
)
3989 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3993 sz
= sizeof(sourcepath
);
3994 MsiSourceListGetInfoW( szProduct
, NULL
, context
, MSICODE_PRODUCT
,
3995 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3996 sz
= sizeof(filename
);
3997 MsiSourceListGetInfoW( szProduct
, NULL
, context
, MSICODE_PRODUCT
,
3998 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3999 lstrcatW( sourcepath
, filename
);
4001 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
4002 r
= MSI_OpenPackageW( sourcepath
, 0, &package
);
4004 r
= MSI_OpenProductW( szProduct
, &package
);
4006 if (r
!= ERROR_SUCCESS
)
4009 sz
= (lstrlenW( L
"%s=%s %s=%s" ) + lstrlenW( L
"REINSTALLMODE" ) + lstrlenW( reinstallmode
)) * sizeof(WCHAR
);
4010 sz
+= (lstrlenW( L
"REINSTALL" ) + lstrlenW( szFeature
)) * sizeof(WCHAR
);
4011 if (!(cmdline
= msi_alloc( sz
)))
4013 msiobj_release( &package
->hdr
);
4014 return ERROR_OUTOFMEMORY
;
4016 swprintf( cmdline
, sz
/ sizeof(WCHAR
), L
"%s=%s %s=%s", L
"REINSTALLMODE", reinstallmode
, L
"REINSTALL", szFeature
);
4018 r
= MSI_InstallPackage( package
, sourcepath
, cmdline
);
4019 msiobj_release( &package
->hdr
);
4020 msi_free( cmdline
);
4025 UINT WINAPI
MsiReinstallFeatureA( LPCSTR szProduct
, LPCSTR szFeature
,
4026 DWORD dwReinstallMode
)
4032 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
4035 wszProduct
= strdupAtoW(szProduct
);
4036 wszFeature
= strdupAtoW(szFeature
);
4038 rc
= MsiReinstallFeatureW(wszProduct
, wszFeature
, dwReinstallMode
);
4040 msi_free(wszProduct
);
4041 msi_free(wszFeature
);
4048 unsigned int buf
[4];
4049 unsigned char in
[64];
4050 unsigned char digest
[16];
4053 extern VOID WINAPI
MD5Init( MD5_CTX
*);
4054 extern VOID WINAPI
MD5Update( MD5_CTX
*, const unsigned char *, unsigned int );
4055 extern VOID WINAPI
MD5Final( MD5_CTX
*);
4057 UINT
msi_get_filehash( MSIPACKAGE
*package
, const WCHAR
*path
, MSIFILEHASHINFO
*hash
)
4059 HANDLE handle
, mapping
;
4062 UINT r
= ERROR_FUNCTION_FAILED
;
4065 handle
= msi_create_file( package
, path
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_DELETE
, OPEN_EXISTING
, 0 );
4067 handle
= CreateFileW( path
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, 0, NULL
);
4068 if (handle
== INVALID_HANDLE_VALUE
)
4070 WARN("can't open file %u\n", GetLastError());
4071 return ERROR_FILE_NOT_FOUND
;
4073 if ((length
= GetFileSize( handle
, NULL
)))
4075 if ((mapping
= CreateFileMappingW( handle
, NULL
, PAGE_READONLY
, 0, 0, NULL
)))
4077 if ((p
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, length
)))
4082 MD5Update( &ctx
, p
, length
);
4084 UnmapViewOfFile( p
);
4086 memcpy( hash
->dwData
, ctx
.digest
, sizeof(hash
->dwData
) );
4089 CloseHandle( mapping
);
4094 /* Empty file -> set hash to 0 */
4095 memset( hash
->dwData
, 0, sizeof(hash
->dwData
) );
4099 CloseHandle( handle
);
4103 /***********************************************************************
4104 * MsiGetFileHashW [MSI.@]
4106 UINT WINAPI
MsiGetFileHashW( LPCWSTR szFilePath
, DWORD dwOptions
,
4107 PMSIFILEHASHINFO pHash
)
4109 TRACE("%s %08x %p\n", debugstr_w(szFilePath
), dwOptions
, pHash
);
4112 return ERROR_INVALID_PARAMETER
;
4115 return ERROR_PATH_NOT_FOUND
;
4118 return ERROR_INVALID_PARAMETER
;
4120 return ERROR_INVALID_PARAMETER
;
4121 if (pHash
->dwFileHashInfoSize
< sizeof *pHash
)
4122 return ERROR_INVALID_PARAMETER
;
4124 return msi_get_filehash( NULL
, szFilePath
, pHash
);
4127 /***********************************************************************
4128 * MsiGetFileHashA [MSI.@]
4130 UINT WINAPI
MsiGetFileHashA( LPCSTR szFilePath
, DWORD dwOptions
,
4131 PMSIFILEHASHINFO pHash
)
4136 TRACE("%s %08x %p\n", debugstr_a(szFilePath
), dwOptions
, pHash
);
4138 file
= strdupAtoW( szFilePath
);
4139 if (szFilePath
&& !file
)
4140 return ERROR_OUTOFMEMORY
;
4142 r
= MsiGetFileHashW( file
, dwOptions
, pHash
);
4147 /***********************************************************************
4148 * MsiAdvertiseScriptW [MSI.@]
4150 UINT WINAPI
MsiAdvertiseScriptW( LPCWSTR szScriptFile
, DWORD dwFlags
,
4151 PHKEY phRegData
, BOOL fRemoveItems
)
4153 FIXME("%s %08x %p %d\n",
4154 debugstr_w( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
4155 return ERROR_CALL_NOT_IMPLEMENTED
;
4158 /***********************************************************************
4159 * MsiAdvertiseScriptA [MSI.@]
4161 UINT WINAPI
MsiAdvertiseScriptA( LPCSTR szScriptFile
, DWORD dwFlags
,
4162 PHKEY phRegData
, BOOL fRemoveItems
)
4164 FIXME("%s %08x %p %d\n",
4165 debugstr_a( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
4166 return ERROR_CALL_NOT_IMPLEMENTED
;
4169 /***********************************************************************
4170 * MsiIsProductElevatedW [MSI.@]
4172 UINT WINAPI
MsiIsProductElevatedW( LPCWSTR szProduct
, BOOL
*pfElevated
)
4174 FIXME("%s %p - stub\n",
4175 debugstr_w( szProduct
), pfElevated
);
4177 return ERROR_SUCCESS
;
4180 /***********************************************************************
4181 * MsiIsProductElevatedA [MSI.@]
4183 UINT WINAPI
MsiIsProductElevatedA( LPCSTR szProduct
, BOOL
*pfElevated
)
4185 FIXME("%s %p - stub\n",
4186 debugstr_a( szProduct
), pfElevated
);
4188 return ERROR_SUCCESS
;
4191 /***********************************************************************
4192 * MsiSetExternalUIRecord [MSI.@]
4194 UINT WINAPI
MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler
,
4195 DWORD filter
, LPVOID context
,
4196 PINSTALLUI_HANDLER_RECORD prev
)
4198 TRACE("%p %08x %p %p\n", handler
, filter
, context
, prev
);
4201 *prev
= gUIHandlerRecord
;
4203 gUIHandlerRecord
= handler
;
4204 gUIFilterRecord
= filter
;
4205 gUIContextRecord
= context
;
4207 return ERROR_SUCCESS
;
4210 /***********************************************************************
4211 * MsiInstallMissingComponentA [MSI.@]
4213 UINT WINAPI
MsiInstallMissingComponentA( LPCSTR product
, LPCSTR component
, INSTALLSTATE state
)
4216 WCHAR
*productW
= NULL
, *componentW
= NULL
;
4218 TRACE("%s, %s, %d\n", debugstr_a(product
), debugstr_a(component
), state
);
4220 if (product
&& !(productW
= strdupAtoW( product
)))
4221 return ERROR_OUTOFMEMORY
;
4223 if (component
&& !(componentW
= strdupAtoW( component
)))
4225 msi_free( productW
);
4226 return ERROR_OUTOFMEMORY
;
4229 r
= MsiInstallMissingComponentW( productW
, componentW
, state
);
4230 msi_free( productW
);
4231 msi_free( componentW
);
4235 /***********************************************************************
4236 * MsiInstallMissingComponentW [MSI.@]
4238 UINT WINAPI
MsiInstallMissingComponentW(LPCWSTR szProduct
, LPCWSTR szComponent
, INSTALLSTATE eInstallState
)
4240 FIXME("(%s %s %d\n", debugstr_w(szProduct
), debugstr_w(szComponent
), eInstallState
);
4241 return ERROR_SUCCESS
;
4244 UINT WINAPI
MsiProvideComponentA( LPCSTR product
, LPCSTR feature
, LPCSTR component
, DWORD mode
, LPSTR buf
, LPDWORD buflen
)
4246 WCHAR
*productW
= NULL
, *componentW
= NULL
, *featureW
= NULL
, *bufW
= NULL
;
4247 UINT r
= ERROR_OUTOFMEMORY
;
4251 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_a(product
), debugstr_a(component
), debugstr_a(feature
), mode
, buf
, buflen
);
4253 if (product
&& !(productW
= strdupAtoW( product
))) goto done
;
4254 if (feature
&& !(featureW
= strdupAtoW( feature
))) goto done
;
4255 if (component
&& !(componentW
= strdupAtoW( component
))) goto done
;
4257 r
= MsiProvideComponentW( productW
, featureW
, componentW
, mode
, NULL
, &lenW
);
4258 if (r
!= ERROR_SUCCESS
)
4261 if (!(bufW
= msi_alloc( ++lenW
* sizeof(WCHAR
) )))
4263 r
= ERROR_OUTOFMEMORY
;
4267 r
= MsiProvideComponentW( productW
, featureW
, componentW
, mode
, bufW
, &lenW
);
4268 if (r
!= ERROR_SUCCESS
)
4271 len
= WideCharToMultiByte( CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
4275 r
= ERROR_MORE_DATA
;
4277 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1, buf
, *buflen
, NULL
, NULL
);
4283 msi_free( productW
);
4284 msi_free( featureW
);
4285 msi_free( componentW
);
4290 UINT WINAPI
MsiProvideComponentW( LPCWSTR product
, LPCWSTR feature
, LPCWSTR component
, DWORD mode
, LPWSTR buf
, LPDWORD buflen
)
4294 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_w(product
), debugstr_w(component
), debugstr_w(feature
), mode
, buf
, buflen
);
4296 state
= MsiQueryFeatureStateW( product
, feature
);
4297 TRACE("feature state: %d\n", state
);
4300 case INSTALLMODE_NODETECTION
:
4304 FIXME("mode %x not implemented\n", mode
);
4305 return ERROR_INSTALL_FAILURE
;
4308 state
= MsiGetComponentPathW( product
, component
, buf
, buflen
);
4309 TRACE("component state: %d\n", state
);
4312 case INSTALLSTATE_INVALIDARG
:
4313 return ERROR_INVALID_PARAMETER
;
4315 case INSTALLSTATE_MOREDATA
:
4316 return ERROR_MORE_DATA
;
4318 case INSTALLSTATE_ADVERTISED
:
4319 case INSTALLSTATE_LOCAL
:
4320 case INSTALLSTATE_SOURCE
:
4321 MsiUseFeatureW( product
, feature
);
4322 return ERROR_SUCCESS
;
4325 TRACE("MsiGetComponentPathW returned %d\n", state
);
4326 return ERROR_INSTALL_FAILURE
;
4330 /***********************************************************************
4331 * MsiBeginTransactionA [MSI.@]
4333 UINT WINAPI
MsiBeginTransactionA( LPCSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
4338 FIXME("%s %u %p %p\n", debugstr_a(name
), attrs
, id
, event
);
4340 nameW
= strdupAtoW( name
);
4342 return ERROR_OUTOFMEMORY
;
4344 r
= MsiBeginTransactionW( nameW
, attrs
, id
, event
);
4349 /***********************************************************************
4350 * MsiBeginTransactionW [MSI.@]
4352 UINT WINAPI
MsiBeginTransactionW( LPCWSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
4354 FIXME("%s %u %p %p\n", debugstr_w(name
), attrs
, id
, event
);
4356 *id
= (MSIHANDLE
)0xdeadbeef;
4357 *event
= (HANDLE
)0xdeadbeef;
4359 return ERROR_SUCCESS
;
4362 /***********************************************************************
4363 * MsiJoinTransaction [MSI.@]
4365 UINT WINAPI
MsiJoinTransaction( MSIHANDLE handle
, DWORD attrs
, HANDLE
*event
)
4367 FIXME("%u %08x %p\n", handle
, attrs
, event
);
4369 *event
= (HANDLE
)0xdeadbeef;
4370 return ERROR_SUCCESS
;
4373 /***********************************************************************
4374 * MsiEndTransaction [MSI.@]
4376 UINT WINAPI
MsiEndTransaction( DWORD state
)
4378 FIXME("%u\n", state
);
4379 return ERROR_SUCCESS
;
4382 UINT WINAPI
Migrate10CachedPackagesW(void* a
, void* b
, void* c
, DWORD d
)
4384 FIXME("%p,%p,%p,%08x\n", a
, b
, c
, d
);
4385 return ERROR_SUCCESS
;
4388 /***********************************************************************
4389 * MsiRemovePatchesA [MSI.@]
4391 UINT WINAPI
MsiRemovePatchesA(LPCSTR patchlist
, LPCSTR product
, INSTALLTYPE type
, LPCSTR propertylist
)
4393 FIXME("(%s %s %d %s\n", debugstr_a(patchlist
), debugstr_a(product
), type
, debugstr_a(propertylist
));
4394 return ERROR_SUCCESS
;
4397 /***********************************************************************
4398 * MsiRemovePatchesW [MSI.@]
4400 UINT WINAPI
MsiRemovePatchesW(LPCWSTR patchlist
, LPCWSTR product
, INSTALLTYPE type
, LPCWSTR propertylist
)
4402 FIXME("(%s %s %d %s\n", debugstr_w(patchlist
), debugstr_w(product
), type
, debugstr_w(propertylist
));
4403 return ERROR_SUCCESS
;