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/unicode.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
54 static const WCHAR installerW
[] = {'\\','I','n','s','t','a','l','l','e','r',0};
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 static const WCHAR managed
[] = {
111 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
112 static const WCHAR local
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
114 TRACE("%s %p\n", debugstr_w(szProduct
), package
);
116 r
= msi_locate_product(szProduct
, &context
);
117 if (r
!= ERROR_SUCCESS
)
120 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &props
, FALSE
);
121 if (r
!= ERROR_SUCCESS
)
122 return ERROR_UNKNOWN_PRODUCT
;
124 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
125 path
= msi_reg_get_val_str(props
, managed
);
127 path
= msi_reg_get_val_str(props
, local
);
129 r
= ERROR_UNKNOWN_PRODUCT
;
131 if (!path
|| GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
134 if (PathIsRelativeW(path
))
136 r
= ERROR_INSTALL_PACKAGE_OPEN_FAILED
;
140 r
= MSI_OpenPackageW(path
, package
);
148 UINT WINAPI
MsiOpenProductW(LPCWSTR szProduct
, MSIHANDLE
*phProduct
)
150 MSIPACKAGE
*package
= NULL
;
151 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
154 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
155 return ERROR_INVALID_PARAMETER
;
158 return ERROR_INVALID_PARAMETER
;
160 r
= MSI_OpenProductW(szProduct
, &package
);
161 if (r
!= ERROR_SUCCESS
)
164 *phProduct
= alloc_msihandle(&package
->hdr
);
166 r
= ERROR_NOT_ENOUGH_MEMORY
;
168 msiobj_release(&package
->hdr
);
172 UINT WINAPI
MsiAdvertiseProductA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
173 LPCSTR szTransforms
, LANGID lgidLanguage
)
175 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath
),
176 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
), lgidLanguage
);
177 return ERROR_CALL_NOT_IMPLEMENTED
;
180 UINT WINAPI
MsiAdvertiseProductW(LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
181 LPCWSTR szTransforms
, LANGID lgidLanguage
)
183 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath
),
184 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
), lgidLanguage
);
185 return ERROR_CALL_NOT_IMPLEMENTED
;
188 UINT WINAPI
MsiAdvertiseProductExA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
189 LPCSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
191 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath
),
192 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
),
193 lgidLanguage
, dwPlatform
, dwOptions
);
194 return ERROR_CALL_NOT_IMPLEMENTED
;
197 UINT WINAPI
MsiAdvertiseProductExW( LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
198 LPCWSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
200 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath
),
201 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
),
202 lgidLanguage
, dwPlatform
, dwOptions
);
203 return ERROR_CALL_NOT_IMPLEMENTED
;
206 UINT WINAPI
MsiInstallProductA(LPCSTR szPackagePath
, LPCSTR szCommandLine
)
208 LPWSTR szwPath
= NULL
, szwCommand
= NULL
;
209 UINT r
= ERROR_OUTOFMEMORY
;
211 TRACE("%s %s\n",debugstr_a(szPackagePath
), debugstr_a(szCommandLine
));
215 szwPath
= strdupAtoW( szPackagePath
);
222 szwCommand
= strdupAtoW( szCommandLine
);
227 r
= MsiInstallProductW( szwPath
, szwCommand
);
231 msi_free( szwCommand
);
236 UINT WINAPI
MsiInstallProductW(LPCWSTR szPackagePath
, LPCWSTR szCommandLine
)
238 MSIPACKAGE
*package
= NULL
;
241 TRACE("%s %s\n",debugstr_w(szPackagePath
), debugstr_w(szCommandLine
));
244 return ERROR_INVALID_PARAMETER
;
247 return ERROR_PATH_NOT_FOUND
;
249 r
= MSI_OpenPackageW( szPackagePath
, &package
);
250 if (r
== ERROR_SUCCESS
)
252 r
= MSI_InstallPackage( package
, szPackagePath
, szCommandLine
);
253 msiobj_release( &package
->hdr
);
259 UINT WINAPI
MsiReinstallProductA(LPCSTR szProduct
, DWORD dwReinstallMode
)
264 TRACE("%s %08x\n", debugstr_a(szProduct
), dwReinstallMode
);
266 wszProduct
= strdupAtoW(szProduct
);
268 rc
= MsiReinstallProductW(wszProduct
, dwReinstallMode
);
270 msi_free(wszProduct
);
274 UINT WINAPI
MsiReinstallProductW(LPCWSTR szProduct
, DWORD dwReinstallMode
)
276 TRACE("%s %08x\n", debugstr_w(szProduct
), dwReinstallMode
);
278 return MsiReinstallFeatureW(szProduct
, szAll
, dwReinstallMode
);
281 UINT WINAPI
MsiApplyPatchA(LPCSTR szPatchPackage
, LPCSTR szInstallPackage
,
282 INSTALLTYPE eInstallType
, LPCSTR szCommandLine
)
284 LPWSTR patch_package
= NULL
;
285 LPWSTR install_package
= NULL
;
286 LPWSTR command_line
= NULL
;
287 UINT r
= ERROR_OUTOFMEMORY
;
289 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage
), debugstr_a(szInstallPackage
),
290 eInstallType
, debugstr_a(szCommandLine
));
292 if (szPatchPackage
&& !(patch_package
= strdupAtoW(szPatchPackage
)))
295 if (szInstallPackage
&& !(install_package
= strdupAtoW(szInstallPackage
)))
298 if (szCommandLine
&& !(command_line
= strdupAtoW(szCommandLine
)))
301 r
= MsiApplyPatchW(patch_package
, install_package
, eInstallType
, command_line
);
304 msi_free(patch_package
);
305 msi_free(install_package
);
306 msi_free(command_line
);
311 static UINT
get_patch_product_codes( LPCWSTR szPatchPackage
, WCHAR
***product_codes
)
313 MSIHANDLE patch
, info
= 0;
316 static WCHAR empty
[] = {0};
319 r
= MsiOpenDatabaseW( szPatchPackage
, MSIDBOPEN_READONLY
, &patch
);
320 if (r
!= ERROR_SUCCESS
)
323 r
= MsiGetSummaryInformationW( patch
, NULL
, 0, &info
);
324 if (r
!= ERROR_SUCCESS
)
328 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, empty
, &size
);
329 if (r
!= ERROR_MORE_DATA
|| !size
|| type
!= VT_LPSTR
)
331 ERR("Failed to read product codes from patch\n");
332 r
= ERROR_FUNCTION_FAILED
;
336 codes
= msi_alloc( ++size
* sizeof(WCHAR
) );
339 r
= ERROR_OUTOFMEMORY
;
343 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, codes
, &size
);
344 if (r
== ERROR_SUCCESS
)
345 *product_codes
= msi_split_string( codes
, ';' );
348 MsiCloseHandle( info
);
349 MsiCloseHandle( patch
);
354 static UINT
MSI_ApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szProductCode
, LPCWSTR szCommandLine
)
356 UINT i
, r
= ERROR_FUNCTION_FAILED
;
358 LPCWSTR cmd_ptr
= szCommandLine
;
359 LPWSTR cmd
, *codes
= NULL
;
360 BOOL succeeded
= FALSE
;
362 static const WCHAR fmt
[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
363 static const WCHAR empty
[] = {0};
365 if (!szPatchPackage
|| !szPatchPackage
[0])
366 return ERROR_INVALID_PARAMETER
;
368 if (!szProductCode
&& (r
= get_patch_product_codes( szPatchPackage
, &codes
)))
374 size
= strlenW(cmd_ptr
) + strlenW(fmt
) + strlenW(szPatchPackage
) + 1;
375 cmd
= msi_alloc(size
* sizeof(WCHAR
));
379 return ERROR_OUTOFMEMORY
;
381 sprintfW(cmd
, fmt
, cmd_ptr
, szPatchPackage
);
384 r
= MsiConfigureProductExW(szProductCode
, INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
387 for (i
= 0; codes
[i
]; i
++)
389 r
= MsiConfigureProductExW(codes
[i
], INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
390 if (r
== ERROR_SUCCESS
)
392 TRACE("patch applied\n");
406 UINT WINAPI
MsiApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szInstallPackage
,
407 INSTALLTYPE eInstallType
, LPCWSTR szCommandLine
)
409 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage
), debugstr_w(szInstallPackage
),
410 eInstallType
, debugstr_w(szCommandLine
));
412 if (szInstallPackage
|| eInstallType
== INSTALLTYPE_NETWORK_IMAGE
||
413 eInstallType
== INSTALLTYPE_SINGLE_INSTANCE
)
415 FIXME("Only reading target products from patch\n");
416 return ERROR_CALL_NOT_IMPLEMENTED
;
419 return MSI_ApplyPatchW(szPatchPackage
, NULL
, szCommandLine
);
422 UINT WINAPI
MsiApplyMultiplePatchesA(LPCSTR szPatchPackages
,
423 LPCSTR szProductCode
, LPCSTR szPropertiesList
)
425 LPWSTR patch_packages
= NULL
;
426 LPWSTR product_code
= NULL
;
427 LPWSTR properties_list
= NULL
;
428 UINT r
= ERROR_OUTOFMEMORY
;
430 TRACE("%s %s %s\n", debugstr_a(szPatchPackages
), debugstr_a(szProductCode
),
431 debugstr_a(szPropertiesList
));
433 if (!szPatchPackages
|| !szPatchPackages
[0])
434 return ERROR_INVALID_PARAMETER
;
436 if (!(patch_packages
= strdupAtoW(szPatchPackages
)))
437 return ERROR_OUTOFMEMORY
;
439 if (szProductCode
&& !(product_code
= strdupAtoW(szProductCode
)))
442 if (szPropertiesList
&& !(properties_list
= strdupAtoW(szPropertiesList
)))
445 r
= MsiApplyMultiplePatchesW(patch_packages
, product_code
, properties_list
);
448 msi_free(patch_packages
);
449 msi_free(product_code
);
450 msi_free(properties_list
);
455 UINT WINAPI
MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages
,
456 LPCWSTR szProductCode
, LPCWSTR szPropertiesList
)
458 UINT r
= ERROR_SUCCESS
;
461 TRACE("%s %s %s\n", debugstr_w(szPatchPackages
), debugstr_w(szProductCode
),
462 debugstr_w(szPropertiesList
));
464 if (!szPatchPackages
|| !szPatchPackages
[0])
465 return ERROR_INVALID_PARAMETER
;
467 beg
= end
= szPatchPackages
;
473 while (*beg
== ' ') beg
++;
474 while (*end
&& *end
!= ';') end
++;
477 while (len
&& beg
[len
- 1] == ' ') len
--;
479 if (!len
) return ERROR_INVALID_NAME
;
481 patch
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
483 return ERROR_OUTOFMEMORY
;
485 memcpy(patch
, beg
, len
* sizeof(WCHAR
));
488 r
= MSI_ApplyPatchW(patch
, szProductCode
, szPropertiesList
);
491 if (r
!= ERROR_SUCCESS
|| !*end
)
499 static void free_patchinfo( DWORD count
, MSIPATCHSEQUENCEINFOW
*info
)
502 for (i
= 0; i
< count
; i
++) msi_free( (WCHAR
*)info
[i
].szPatchData
);
506 static MSIPATCHSEQUENCEINFOW
*patchinfoAtoW( DWORD count
, const MSIPATCHSEQUENCEINFOA
*info
)
509 MSIPATCHSEQUENCEINFOW
*ret
;
511 if (!(ret
= msi_alloc( count
* sizeof(MSIPATCHSEQUENCEINFOW
) ))) return NULL
;
512 for (i
= 0; i
< count
; i
++)
514 if (info
[i
].szPatchData
&& !(ret
[i
].szPatchData
= strdupAtoW( info
[i
].szPatchData
)))
516 free_patchinfo( i
, ret
);
519 ret
[i
].ePatchDataType
= info
[i
].ePatchDataType
;
520 ret
[i
].dwOrder
= info
[i
].dwOrder
;
521 ret
[i
].uStatus
= info
[i
].uStatus
;
526 UINT WINAPI
MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath
,
527 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
530 WCHAR
*package_path
= NULL
;
531 MSIPATCHSEQUENCEINFOW
*psi
;
533 TRACE("%s, %u, %p\n", debugstr_a(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
535 if (szProductPackagePath
&& !(package_path
= strdupAtoW( szProductPackagePath
)))
536 return ERROR_OUTOFMEMORY
;
538 if (!(psi
= patchinfoAtoW( cPatchInfo
, pPatchInfo
)))
540 msi_free( package_path
);
541 return ERROR_OUTOFMEMORY
;
543 r
= MsiDetermineApplicablePatchesW( package_path
, cPatchInfo
, psi
);
544 if (r
== ERROR_SUCCESS
)
546 for (i
= 0; i
< cPatchInfo
; i
++)
548 pPatchInfo
[i
].dwOrder
= psi
[i
].dwOrder
;
549 pPatchInfo
[i
].uStatus
= psi
[i
].uStatus
;
552 msi_free( package_path
);
553 free_patchinfo( cPatchInfo
, psi
);
557 static UINT
MSI_ApplicablePatchW( MSIPACKAGE
*package
, LPCWSTR patch
)
560 MSIDATABASE
*patch_db
;
563 r
= MSI_OpenDatabaseW( patch
, MSIDBOPEN_READONLY
, &patch_db
);
564 if (r
!= ERROR_SUCCESS
)
566 WARN("failed to open patch file %s\n", debugstr_w(patch
));
570 r
= msi_get_suminfo( patch_db
->storage
, 0, &si
);
571 if (r
!= ERROR_SUCCESS
)
573 msiobj_release( &patch_db
->hdr
);
574 return ERROR_FUNCTION_FAILED
;
577 r
= msi_check_patch_applicable( package
, si
);
578 if (r
!= ERROR_SUCCESS
)
579 TRACE("patch not applicable\n");
581 msiobj_release( &patch_db
->hdr
);
582 msiobj_release( &si
->hdr
);
586 /* IXMLDOMDocument should be set to XPath mode already */
587 static UINT
MSI_ApplicablePatchXML( MSIPACKAGE
*package
, IXMLDOMDocument
*desc
)
589 static const WCHAR queryW
[] = {'M','s','i','P','a','t','c','h','/',
590 'T','a','r','g','e','t','P','r','o','d','u','c','t','/',
591 'T','a','r','g','e','t','P','r','o','d','u','c','t','C','o','d','e',0};
592 UINT r
= ERROR_FUNCTION_FAILED
;
593 IXMLDOMNodeList
*list
;
599 product_code
= msi_dup_property( package
->db
, szProductCode
);
602 /* FIXME: the property ProductCode should be written into the DB somewhere */
603 ERR("no product code to check\n");
604 return ERROR_SUCCESS
;
607 s
= SysAllocString(queryW
);
608 hr
= IXMLDOMDocument_selectNodes( desc
, s
, &list
);
611 return ERROR_INVALID_PATCH_XML
;
613 while (IXMLDOMNodeList_nextNode( list
, &node
) == S_OK
&& r
!= ERROR_SUCCESS
)
615 hr
= IXMLDOMNode_get_text( node
, &s
);
616 IXMLDOMNode_Release( node
);
619 if (!strcmpW( s
, product_code
)) r
= ERROR_SUCCESS
;
623 IXMLDOMNodeList_Release( list
);
625 if (r
!= ERROR_SUCCESS
)
626 TRACE("patch not applicable\n");
628 msi_free( product_code
);
632 static UINT
determine_patch_sequence( MSIPACKAGE
*package
, DWORD count
, MSIPATCHSEQUENCEINFOW
*info
)
634 IXMLDOMDocument
*desc
= NULL
;
638 FIXME("patch ordering not supported\n");
640 for (i
= 0; i
< count
; i
++)
642 switch (info
[i
].ePatchDataType
)
644 case MSIPATCH_DATATYPE_PATCHFILE
:
646 if (MSI_ApplicablePatchW( package
, info
[i
].szPatchData
) != ERROR_SUCCESS
)
648 info
[i
].dwOrder
= ~0u;
649 info
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
654 info
[i
].uStatus
= ERROR_SUCCESS
;
658 case MSIPATCH_DATATYPE_XMLPATH
:
659 case MSIPATCH_DATATYPE_XMLBLOB
:
667 hr
= CoCreateInstance( &CLSID_DOMDocument30
, NULL
, CLSCTX_INPROC_SERVER
,
668 &IID_IXMLDOMDocument
, (void**)&desc
);
671 ERR("failed to create DOMDocument30 instance, 0x%08x\n", hr
);
672 return ERROR_FUNCTION_FAILED
;
676 s
= SysAllocString( info
[i
].szPatchData
);
677 if (info
[i
].ePatchDataType
== MSIPATCH_DATATYPE_XMLPATH
)
681 V_VT(&src
) = VT_BSTR
;
683 hr
= IXMLDOMDocument_load( desc
, src
, &b
);
686 hr
= IXMLDOMDocument_loadXML( desc
, s
, &b
);
690 ERR("failed to parse patch description\n");
691 IXMLDOMDocument_Release( desc
);
695 if (MSI_ApplicablePatchXML( package
, desc
) != ERROR_SUCCESS
)
697 info
[i
].dwOrder
= ~0u;
698 info
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
703 info
[i
].uStatus
= ERROR_SUCCESS
;
709 FIXME("unknown patch data type %u\n", info
[i
].ePatchDataType
);
711 info
[i
].uStatus
= ERROR_SUCCESS
;
716 TRACE("szPatchData: %s\n", debugstr_w(info
[i
].szPatchData
));
717 TRACE("ePatchDataType: %u\n", info
[i
].ePatchDataType
);
718 TRACE("dwOrder: %u\n", info
[i
].dwOrder
);
719 TRACE("uStatus: %u\n", info
[i
].uStatus
);
722 if (desc
) IXMLDOMDocument_Release( desc
);
724 return ERROR_SUCCESS
;
727 UINT WINAPI
MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath
,
728 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
733 TRACE("%s, %u, %p\n", debugstr_w(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
735 r
= MSI_OpenPackageW( szProductPackagePath
, &package
);
736 if (r
!= ERROR_SUCCESS
)
738 ERR("failed to open package %u\n", r
);
741 r
= determine_patch_sequence( package
, cPatchInfo
, pPatchInfo
);
742 msiobj_release( &package
->hdr
);
746 UINT WINAPI
MsiDeterminePatchSequenceA( LPCSTR product
, LPCSTR usersid
,
747 MSIINSTALLCONTEXT context
, DWORD count
, PMSIPATCHSEQUENCEINFOA patchinfo
)
750 WCHAR
*productW
, *usersidW
= NULL
;
751 MSIPATCHSEQUENCEINFOW
*patchinfoW
;
753 TRACE("%s, %s, %d, %d, %p\n", debugstr_a(product
), debugstr_a(usersid
),
754 context
, count
, patchinfo
);
756 if (!product
) return ERROR_INVALID_PARAMETER
;
757 if (!(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
758 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
760 msi_free( productW
);
761 return ERROR_OUTOFMEMORY
;
763 if (!(patchinfoW
= patchinfoAtoW( count
, patchinfo
)))
765 msi_free( productW
);
766 msi_free( usersidW
);
767 return ERROR_OUTOFMEMORY
;
769 r
= MsiDeterminePatchSequenceW( productW
, usersidW
, context
, count
, patchinfoW
);
770 if (r
== ERROR_SUCCESS
)
772 for (i
= 0; i
< count
; i
++)
774 patchinfo
[i
].dwOrder
= patchinfoW
[i
].dwOrder
;
775 patchinfo
[i
].uStatus
= patchinfoW
[i
].uStatus
;
778 msi_free( productW
);
779 msi_free( usersidW
);
780 free_patchinfo( count
, patchinfoW
);
784 static UINT
open_package( const WCHAR
*product
, const WCHAR
*usersid
,
785 MSIINSTALLCONTEXT context
, MSIPACKAGE
**package
)
789 WCHAR
*localpath
, sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
791 r
= MSIREG_OpenInstallProps( product
, context
, usersid
, &props
, FALSE
);
792 if (r
!= ERROR_SUCCESS
) return ERROR_BAD_CONFIGURATION
;
794 if ((localpath
= msi_reg_get_val_str( props
, szLocalPackage
)))
796 strcpyW( sourcepath
, localpath
);
797 msi_free( localpath
);
799 RegCloseKey( props
);
800 if (!localpath
|| GetFileAttributesW( sourcepath
) == INVALID_FILE_ATTRIBUTES
)
802 DWORD sz
= sizeof(sourcepath
);
803 MsiSourceListGetInfoW( product
, usersid
, context
, MSICODE_PRODUCT
,
804 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
805 sz
= sizeof(filename
);
806 MsiSourceListGetInfoW( product
, usersid
, context
, MSICODE_PRODUCT
,
807 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
808 strcatW( sourcepath
, filename
);
810 if (GetFileAttributesW( sourcepath
) == INVALID_FILE_ATTRIBUTES
)
811 return ERROR_INSTALL_SOURCE_ABSENT
;
813 return MSI_OpenPackageW( sourcepath
, package
);
816 UINT WINAPI
MsiDeterminePatchSequenceW( LPCWSTR product
, LPCWSTR usersid
,
817 MSIINSTALLCONTEXT context
, DWORD count
, PMSIPATCHSEQUENCEINFOW patchinfo
)
822 TRACE("%s, %s, %d, %d, %p\n", debugstr_w(product
), debugstr_w(usersid
),
823 context
, count
, patchinfo
);
825 if (!product
) return ERROR_INVALID_PARAMETER
;
826 r
= open_package( product
, usersid
, context
, &package
);
827 if (r
!= ERROR_SUCCESS
) return r
;
829 r
= determine_patch_sequence( package
, count
, patchinfo
);
830 msiobj_release( &package
->hdr
);
834 UINT WINAPI
MsiConfigureProductExW(LPCWSTR szProduct
, int iInstallLevel
,
835 INSTALLSTATE eInstallState
, LPCWSTR szCommandLine
)
837 MSIPACKAGE
* package
= NULL
;
838 MSIINSTALLCONTEXT context
;
841 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
844 static const WCHAR szInstalled
[] = {
845 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
846 static const WCHAR szMaxInstallLevel
[] = {
847 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
848 static const WCHAR szRemoveAll
[] = {
849 ' ','R','E','M','O','V','E','=','A','L','L',0};
850 static const WCHAR szMachine
[] = {
851 ' ','A','L','L','U','S','E','R','S','=','1',0};
853 TRACE("%s %d %d %s\n",debugstr_w(szProduct
), iInstallLevel
, eInstallState
,
854 debugstr_w(szCommandLine
));
856 if (!szProduct
|| lstrlenW(szProduct
) != GUID_SIZE
- 1)
857 return ERROR_INVALID_PARAMETER
;
859 if (eInstallState
== INSTALLSTATE_ADVERTISED
||
860 eInstallState
== INSTALLSTATE_SOURCE
)
862 FIXME("State %d not implemented\n", eInstallState
);
863 return ERROR_CALL_NOT_IMPLEMENTED
;
866 r
= msi_locate_product(szProduct
, &context
);
867 if (r
!= ERROR_SUCCESS
)
870 r
= open_package(szProduct
, NULL
, context
, &package
);
871 if (r
!= ERROR_SUCCESS
)
874 sz
= lstrlenW(szInstalled
) + 1;
877 sz
+= lstrlenW(szCommandLine
);
879 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
880 sz
+= lstrlenW(szMaxInstallLevel
);
882 if (eInstallState
== INSTALLSTATE_ABSENT
)
883 sz
+= lstrlenW(szRemoveAll
);
885 if (context
== MSIINSTALLCONTEXT_MACHINE
)
886 sz
+= lstrlenW(szMachine
);
888 commandline
= msi_alloc(sz
* sizeof(WCHAR
));
891 r
= ERROR_OUTOFMEMORY
;
897 lstrcpyW(commandline
,szCommandLine
);
899 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
900 lstrcatW(commandline
, szMaxInstallLevel
);
902 if (eInstallState
== INSTALLSTATE_ABSENT
)
903 lstrcatW(commandline
, szRemoveAll
);
905 if (context
== MSIINSTALLCONTEXT_MACHINE
)
906 lstrcatW(commandline
, szMachine
);
908 sz
= sizeof(sourcepath
);
909 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
910 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
912 sz
= sizeof(filename
);
913 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
914 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
916 strcatW(sourcepath
, filename
);
918 r
= MSI_InstallPackage( package
, sourcepath
, commandline
);
920 msi_free(commandline
);
923 msiobj_release( &package
->hdr
);
928 UINT WINAPI
MsiConfigureProductExA(LPCSTR szProduct
, int iInstallLevel
,
929 INSTALLSTATE eInstallState
, LPCSTR szCommandLine
)
931 LPWSTR szwProduct
= NULL
;
932 LPWSTR szwCommandLine
= NULL
;
933 UINT r
= ERROR_OUTOFMEMORY
;
937 szwProduct
= strdupAtoW( szProduct
);
944 szwCommandLine
= strdupAtoW( szCommandLine
);
949 r
= MsiConfigureProductExW( szwProduct
, iInstallLevel
, eInstallState
,
952 msi_free( szwProduct
);
953 msi_free( szwCommandLine
);
958 UINT WINAPI
MsiConfigureProductA(LPCSTR szProduct
, int iInstallLevel
,
959 INSTALLSTATE eInstallState
)
961 LPWSTR szwProduct
= NULL
;
964 TRACE("%s %d %d\n",debugstr_a(szProduct
), iInstallLevel
, eInstallState
);
968 szwProduct
= strdupAtoW( szProduct
);
970 return ERROR_OUTOFMEMORY
;
973 r
= MsiConfigureProductW( szwProduct
, iInstallLevel
, eInstallState
);
974 msi_free( szwProduct
);
979 UINT WINAPI
MsiConfigureProductW(LPCWSTR szProduct
, int iInstallLevel
,
980 INSTALLSTATE eInstallState
)
982 return MsiConfigureProductExW(szProduct
, iInstallLevel
, eInstallState
, NULL
);
985 UINT WINAPI
MsiGetProductCodeA(LPCSTR szComponent
, LPSTR szBuffer
)
987 LPWSTR szwComponent
= NULL
;
989 WCHAR szwBuffer
[GUID_SIZE
];
991 TRACE("%s %p\n", debugstr_a(szComponent
), szBuffer
);
995 szwComponent
= strdupAtoW( szComponent
);
997 return ERROR_OUTOFMEMORY
;
1001 r
= MsiGetProductCodeW( szwComponent
, szwBuffer
);
1004 WideCharToMultiByte(CP_ACP
, 0, szwBuffer
, -1, szBuffer
, GUID_SIZE
, NULL
, NULL
);
1006 msi_free( szwComponent
);
1011 UINT WINAPI
MsiGetProductCodeW(LPCWSTR szComponent
, LPWSTR szBuffer
)
1014 HKEY compkey
, prodkey
;
1015 WCHAR squashed_comp
[SQUASHED_GUID_SIZE
], squashed_prod
[SQUASHED_GUID_SIZE
];
1016 DWORD sz
= sizeof(squashed_prod
)/sizeof(squashed_prod
[0]);
1018 TRACE("%s %p\n", debugstr_w(szComponent
), szBuffer
);
1020 if (!szComponent
|| !*szComponent
)
1021 return ERROR_INVALID_PARAMETER
;
1023 if (!squash_guid( szComponent
, squashed_comp
))
1024 return ERROR_INVALID_PARAMETER
;
1026 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &compkey
, FALSE
) != ERROR_SUCCESS
&&
1027 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &compkey
, FALSE
) != ERROR_SUCCESS
)
1029 return ERROR_UNKNOWN_COMPONENT
;
1032 rc
= RegEnumValueW( compkey
, 0, squashed_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
1033 if (rc
!= ERROR_SUCCESS
)
1035 RegCloseKey(compkey
);
1036 return ERROR_UNKNOWN_COMPONENT
;
1039 /* check simple case, only one product */
1040 rc
= RegEnumValueW( compkey
, 1, squashed_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
1041 if (rc
== ERROR_NO_MORE_ITEMS
)
1048 while ((rc
= RegEnumValueW( compkey
, index
, squashed_prod
, &sz
, NULL
, NULL
, NULL
, NULL
)) !=
1049 ERROR_NO_MORE_ITEMS
)
1053 unsquash_guid( squashed_prod
, szBuffer
);
1055 if (MSIREG_OpenProductKey(szBuffer
, NULL
,
1056 MSIINSTALLCONTEXT_USERMANAGED
,
1057 &prodkey
, FALSE
) == ERROR_SUCCESS
||
1058 MSIREG_OpenProductKey(szBuffer
, NULL
,
1059 MSIINSTALLCONTEXT_USERUNMANAGED
,
1060 &prodkey
, FALSE
) == ERROR_SUCCESS
||
1061 MSIREG_OpenProductKey(szBuffer
, NULL
,
1062 MSIINSTALLCONTEXT_MACHINE
,
1063 &prodkey
, FALSE
) == ERROR_SUCCESS
)
1065 RegCloseKey(prodkey
);
1071 rc
= ERROR_INSTALL_FAILURE
;
1074 RegCloseKey(compkey
);
1075 unsquash_guid( squashed_prod
, szBuffer
);
1079 static WCHAR
*reg_get_value( HKEY hkey
, const WCHAR
*name
, DWORD
*type
)
1083 if ((res
= RegQueryValueExW( hkey
, name
, NULL
, type
, NULL
, NULL
)) != ERROR_SUCCESS
) return NULL
;
1085 if (*type
== REG_SZ
) return msi_reg_get_val_str( hkey
, name
);
1086 if (*type
== REG_DWORD
)
1088 static const WCHAR fmt
[] = {'%','u',0};
1092 if (!msi_reg_get_val_dword( hkey
, name
, &val
)) return NULL
;
1093 sprintfW( temp
, fmt
, val
);
1094 return strdupW( temp
);
1097 ERR( "unhandled value type %u\n", *type
);
1101 static UINT
MSI_GetProductInfo(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1102 awstring
*szValue
, LPDWORD pcchValueBuf
)
1104 static WCHAR empty
[] = {0};
1105 static const WCHAR sourcelist
[] = {'S','o','u','r','c','e','L','i','s','t',0};
1106 static const WCHAR display_name
[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
1107 static const WCHAR display_version
[] = {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1108 static const WCHAR assignment
[] = {'A','s','s','i','g','n','m','e','n','t',0};
1109 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
1110 UINT r
= ERROR_UNKNOWN_PROPERTY
;
1111 HKEY prodkey
, userdata
, source
;
1112 WCHAR
*val
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
], packagecode
[GUID_SIZE
];
1113 BOOL badconfig
= FALSE
;
1115 DWORD type
= REG_NONE
;
1117 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
1118 debugstr_w(szAttribute
), szValue
, pcchValueBuf
);
1120 if ((szValue
->str
.w
&& !pcchValueBuf
) || !szProduct
|| !szAttribute
)
1121 return ERROR_INVALID_PARAMETER
;
1123 if (!squash_guid( szProduct
, squashed_pc
))
1124 return ERROR_INVALID_PARAMETER
;
1126 if ((r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1127 MSIINSTALLCONTEXT_USERMANAGED
,
1128 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
1129 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1130 MSIINSTALLCONTEXT_USERUNMANAGED
,
1131 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
1132 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1133 MSIINSTALLCONTEXT_MACHINE
,
1134 &prodkey
, FALSE
)) == ERROR_SUCCESS
)
1136 context
= MSIINSTALLCONTEXT_MACHINE
;
1139 if (!strcmpW( szAttribute
, INSTALLPROPERTY_HELPLINKW
) ||
1140 !strcmpW( szAttribute
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1141 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLDATEW
) ||
1142 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1143 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1144 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1145 !strcmpW( szAttribute
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1146 !strcmpW( szAttribute
, INSTALLPROPERTY_PUBLISHERW
) ||
1147 !strcmpW( szAttribute
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1148 !strcmpW( szAttribute
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1149 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMINORW
) ||
1150 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1151 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1152 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTIDW
) ||
1153 !strcmpW( szAttribute
, INSTALLPROPERTY_REGCOMPANYW
) ||
1154 !strcmpW( szAttribute
, INSTALLPROPERTY_REGOWNERW
))
1158 r
= ERROR_UNKNOWN_PRODUCT
;
1161 if (MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
))
1163 r
= ERROR_UNKNOWN_PROPERTY
;
1167 if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1168 szAttribute
= display_name
;
1169 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
))
1170 szAttribute
= display_version
;
1172 val
= reg_get_value(userdata
, szAttribute
, &type
);
1175 RegCloseKey(userdata
);
1177 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTANCETYPEW
) ||
1178 !strcmpW( szAttribute
, INSTALLPROPERTY_TRANSFORMSW
) ||
1179 !strcmpW( szAttribute
, INSTALLPROPERTY_LANGUAGEW
) ||
1180 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1181 !strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
) ||
1182 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
) ||
1183 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONW
) ||
1184 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTICONW
) ||
1185 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1186 !strcmpW( szAttribute
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1190 r
= ERROR_UNKNOWN_PRODUCT
;
1194 if (!strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1195 szAttribute
= assignment
;
1197 if (!strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
))
1199 res
= RegOpenKeyW(prodkey
, sourcelist
, &source
);
1200 if (res
!= ERROR_SUCCESS
)
1202 r
= ERROR_UNKNOWN_PRODUCT
;
1206 val
= reg_get_value(source
, szAttribute
, &type
);
1210 RegCloseKey(source
);
1214 val
= reg_get_value(prodkey
, szAttribute
, &type
);
1219 if (val
!= empty
&& type
!= REG_DWORD
&&
1220 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
))
1222 if (lstrlenW( val
) != SQUASHED_GUID_SIZE
- 1)
1226 unsquash_guid(val
, packagecode
);
1228 val
= strdupW(packagecode
);
1235 r
= ERROR_UNKNOWN_PROPERTY
;
1241 int len
= strlenW( val
);
1243 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1244 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1245 * can't rely on its value.
1247 if (szValue
->str
.a
|| szValue
->str
.w
)
1249 DWORD size
= *pcchValueBuf
;
1251 r
= msi_strcpy_to_awstring( val
, len
, szValue
, &size
);
1253 r
= ERROR_MORE_DATA
;
1257 *pcchValueBuf
= len
;
1261 r
= ERROR_BAD_CONFIGURATION
;
1267 RegCloseKey(prodkey
);
1271 UINT WINAPI
MsiGetProductInfoA(LPCSTR szProduct
, LPCSTR szAttribute
,
1272 LPSTR szBuffer
, LPDWORD pcchValueBuf
)
1274 LPWSTR szwProduct
, szwAttribute
= NULL
;
1275 UINT r
= ERROR_OUTOFMEMORY
;
1278 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szAttribute
),
1279 szBuffer
, pcchValueBuf
);
1281 szwProduct
= strdupAtoW( szProduct
);
1282 if( szProduct
&& !szwProduct
)
1285 szwAttribute
= strdupAtoW( szAttribute
);
1286 if( szAttribute
&& !szwAttribute
)
1289 buffer
.unicode
= FALSE
;
1290 buffer
.str
.a
= szBuffer
;
1292 r
= MSI_GetProductInfo( szwProduct
, szwAttribute
,
1293 &buffer
, pcchValueBuf
);
1296 msi_free( szwProduct
);
1297 msi_free( szwAttribute
);
1302 UINT WINAPI
MsiGetProductInfoW(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1303 LPWSTR szBuffer
, LPDWORD pcchValueBuf
)
1307 TRACE("%s %s %p %p\n", debugstr_w(szProduct
), debugstr_w(szAttribute
),
1308 szBuffer
, pcchValueBuf
);
1310 buffer
.unicode
= TRUE
;
1311 buffer
.str
.w
= szBuffer
;
1313 return MSI_GetProductInfo( szProduct
, szAttribute
,
1314 &buffer
, pcchValueBuf
);
1317 UINT WINAPI
MsiGetProductInfoExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1318 MSIINSTALLCONTEXT dwContext
, LPCSTR szProperty
,
1319 LPSTR szValue
, LPDWORD pcchValue
)
1321 LPWSTR product
= NULL
;
1322 LPWSTR usersid
= NULL
;
1323 LPWSTR property
= NULL
;
1324 LPWSTR value
= NULL
;
1328 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode
),
1329 debugstr_a(szUserSid
), dwContext
, debugstr_a(szProperty
),
1330 szValue
, pcchValue
);
1332 if (szValue
&& !pcchValue
)
1333 return ERROR_INVALID_PARAMETER
;
1335 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1336 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1337 if (szProperty
) property
= strdupAtoW(szProperty
);
1339 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1341 if (r
!= ERROR_SUCCESS
)
1344 value
= msi_alloc(++len
* sizeof(WCHAR
));
1347 r
= ERROR_OUTOFMEMORY
;
1351 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1353 if (r
!= ERROR_SUCCESS
)
1359 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
1360 if (*pcchValue
>= len
)
1361 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
1364 r
= ERROR_MORE_DATA
;
1369 if (*pcchValue
<= len
|| !szValue
)
1370 len
= len
* sizeof(WCHAR
) - 1;
1372 *pcchValue
= len
- 1;
1383 static UINT
msi_copy_outval(LPWSTR val
, LPWSTR out
, LPDWORD size
)
1385 UINT r
= ERROR_SUCCESS
;
1388 return ERROR_UNKNOWN_PROPERTY
;
1392 if (strlenW(val
) >= *size
)
1394 r
= ERROR_MORE_DATA
;
1403 *size
= lstrlenW(val
);
1408 UINT WINAPI
MsiGetProductInfoExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
1409 MSIINSTALLCONTEXT dwContext
, LPCWSTR szProperty
,
1410 LPWSTR szValue
, LPDWORD pcchValue
)
1412 static const WCHAR five
[] = {'5',0};
1413 static const WCHAR displayname
[] = {
1414 'D','i','s','p','l','a','y','N','a','m','e',0};
1415 static const WCHAR displayversion
[] = {
1416 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1417 static const WCHAR managed_local_package
[] = {
1418 'M','a','n','a','g','e','d','L','o','c','a','l',
1419 'P','a','c','k','a','g','e',0};
1420 WCHAR
*val
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
];
1421 LPCWSTR package
= NULL
;
1422 HKEY props
= NULL
, prod
, classes
= NULL
, managed
, hkey
= NULL
;
1424 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1426 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode
),
1427 debugstr_w(szUserSid
), dwContext
, debugstr_w(szProperty
),
1428 szValue
, pcchValue
);
1430 if (!szProductCode
|| !squash_guid( szProductCode
, squashed_pc
))
1431 return ERROR_INVALID_PARAMETER
;
1433 if (szValue
&& !pcchValue
)
1434 return ERROR_INVALID_PARAMETER
;
1436 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1437 dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1438 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1439 return ERROR_INVALID_PARAMETER
;
1441 if (!szProperty
|| !*szProperty
)
1442 return ERROR_INVALID_PARAMETER
;
1444 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1445 return ERROR_INVALID_PARAMETER
;
1447 /* FIXME: dwContext is provided, no need to search for it */
1448 MSIREG_OpenProductKey(szProductCode
, NULL
,MSIINSTALLCONTEXT_USERMANAGED
,
1450 MSIREG_OpenProductKey(szProductCode
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1453 MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
, &props
, FALSE
);
1455 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1457 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1459 if (!props
&& !prod
)
1462 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1464 package
= managed_local_package
;
1466 if (!props
&& !managed
)
1469 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1471 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1472 MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
, &classes
, FALSE
);
1474 if (!props
&& !classes
)
1478 if (!strcmpW( szProperty
, INSTALLPROPERTY_HELPLINKW
) ||
1479 !strcmpW( szProperty
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1480 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
) ||
1481 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1482 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1483 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1484 !strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1485 !strcmpW( szProperty
, INSTALLPROPERTY_PUBLISHERW
) ||
1486 !strcmpW( szProperty
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1487 !strcmpW( szProperty
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1488 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMINORW
) ||
1489 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1490 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1491 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTIDW
) ||
1492 !strcmpW( szProperty
, INSTALLPROPERTY_REGCOMPANYW
) ||
1493 !strcmpW( szProperty
, INSTALLPROPERTY_REGOWNERW
) ||
1494 !strcmpW( szProperty
, INSTALLPROPERTY_INSTANCETYPEW
))
1496 val
= reg_get_value(props
, package
, &type
);
1499 if (prod
|| classes
)
1500 r
= ERROR_UNKNOWN_PROPERTY
;
1507 if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1508 szProperty
= displayname
;
1509 else if (!strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
))
1510 szProperty
= displayversion
;
1512 val
= reg_get_value(props
, szProperty
, &type
);
1514 val
= strdupW(szEmpty
);
1516 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1518 else if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
) ||
1519 !strcmpW( szProperty
, INSTALLPROPERTY_LANGUAGEW
) ||
1520 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1521 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGECODEW
) ||
1522 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONW
) ||
1523 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTICONW
) ||
1524 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1525 !strcmpW( szProperty
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1527 if (!prod
&& !classes
)
1530 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1532 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1534 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1537 val
= reg_get_value(hkey
, szProperty
, &type
);
1539 val
= strdupW(szEmpty
);
1541 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1543 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTSTATEW
))
1545 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1549 val
= reg_get_value(props
, package
, &type
);
1554 val
= strdupW(five
);
1557 val
= strdupW(szOne
);
1559 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1562 else if (props
&& (val
= reg_get_value(props
, package
, &type
)))
1565 val
= strdupW(five
);
1566 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1570 if (prod
|| managed
)
1571 val
= strdupW(szOne
);
1575 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1577 else if (!strcmpW( szProperty
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1579 if (!prod
&& !classes
)
1583 val
= strdupW(szEmpty
);
1584 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1587 r
= ERROR_UNKNOWN_PROPERTY
;
1592 RegCloseKey(managed
);
1593 RegCloseKey(classes
);
1599 UINT WINAPI
MsiGetPatchFileListA(LPCSTR szProductCode
, LPCSTR szPatchList
,
1600 LPDWORD pcFiles
, MSIHANDLE
**pphFileRecords
)
1602 FIXME("(%s, %s, %p, %p) stub!\n", debugstr_a(szProductCode
),
1603 debugstr_a(szPatchList
), pcFiles
, pphFileRecords
);
1604 return ERROR_FUNCTION_FAILED
;
1607 UINT WINAPI
MsiGetPatchFileListW(LPCWSTR szProductCode
, LPCWSTR szPatchList
,
1608 LPDWORD pcFiles
, MSIHANDLE
**pphFileRecords
)
1610 FIXME("(%s, %s, %p, %p) stub!\n", debugstr_w(szProductCode
),
1611 debugstr_w(szPatchList
), pcFiles
, pphFileRecords
);
1612 return ERROR_FUNCTION_FAILED
;
1615 UINT WINAPI
MsiGetPatchInfoExA(LPCSTR szPatchCode
, LPCSTR szProductCode
,
1616 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1617 LPCSTR szProperty
, LPSTR lpValue
, DWORD
*pcchValue
)
1619 LPWSTR patch
= NULL
, product
= NULL
, usersid
= NULL
;
1620 LPWSTR property
= NULL
, val
= NULL
;
1624 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode
),
1625 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
,
1626 debugstr_a(szProperty
), lpValue
, pcchValue
);
1628 if (lpValue
&& !pcchValue
)
1629 return ERROR_INVALID_PARAMETER
;
1631 if (szPatchCode
) patch
= strdupAtoW(szPatchCode
);
1632 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1633 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1634 if (szProperty
) property
= strdupAtoW(szProperty
);
1637 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1639 if (r
!= ERROR_SUCCESS
)
1642 val
= msi_alloc(++len
* sizeof(WCHAR
));
1645 r
= ERROR_OUTOFMEMORY
;
1649 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1651 if (r
!= ERROR_SUCCESS
|| !pcchValue
)
1655 WideCharToMultiByte(CP_ACP
, 0, val
, -1, lpValue
,
1656 *pcchValue
- 1, NULL
, NULL
);
1658 len
= lstrlenW(val
);
1659 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1663 r
= ERROR_MORE_DATA
;
1664 lpValue
[*pcchValue
- 1] = '\0';
1667 *pcchValue
= len
* sizeof(WCHAR
);
1682 UINT WINAPI
MsiGetPatchInfoExW(LPCWSTR szPatchCode
, LPCWSTR szProductCode
,
1683 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1684 LPCWSTR szProperty
, LPWSTR lpValue
, DWORD
*pcchValue
)
1686 static const WCHAR szManagedPackage
[] =
1687 {'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
1688 WCHAR
*val
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
], squashed_patch
[SQUASHED_GUID_SIZE
];
1689 HKEY udprod
= 0, prod
= 0, props
= 0;
1690 HKEY patch
= 0, patches
= 0;
1691 HKEY udpatch
= 0, datakey
= 0;
1692 HKEY prodpatches
= 0;
1693 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1697 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode
),
1698 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
,
1699 debugstr_w(szProperty
), lpValue
, pcchValue
);
1701 if (!szProductCode
|| !squash_guid( szProductCode
, squashed_pc
))
1702 return ERROR_INVALID_PARAMETER
;
1704 if (!szPatchCode
|| !squash_guid( szPatchCode
, squashed_patch
))
1705 return ERROR_INVALID_PARAMETER
;
1708 return ERROR_INVALID_PARAMETER
;
1710 if (lpValue
&& !pcchValue
)
1711 return ERROR_INVALID_PARAMETER
;
1713 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1714 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1715 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1716 return ERROR_INVALID_PARAMETER
;
1718 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1719 return ERROR_INVALID_PARAMETER
;
1721 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
1722 return ERROR_INVALID_PARAMETER
;
1724 if (MSIREG_OpenUserDataProductKey(szProductCode
, dwContext
, NULL
,
1725 &udprod
, FALSE
) != ERROR_SUCCESS
)
1728 if (MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
,
1729 &props
, FALSE
) != ERROR_SUCCESS
)
1732 r
= ERROR_UNKNOWN_PATCH
;
1734 res
= RegOpenKeyExW(udprod
, szPatches
, 0, KEY_WOW64_64KEY
|KEY_READ
, &patches
);
1735 if (res
!= ERROR_SUCCESS
)
1738 res
= RegOpenKeyExW( patches
, squashed_patch
, 0, KEY_WOW64_64KEY
|KEY_READ
, &patch
);
1739 if (res
!= ERROR_SUCCESS
)
1742 if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
))
1744 if (MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
,
1745 &prod
, FALSE
) != ERROR_SUCCESS
)
1748 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_WOW64_64KEY
|KEY_ALL_ACCESS
, &prodpatches
);
1749 if (res
!= ERROR_SUCCESS
)
1752 datakey
= prodpatches
;
1753 szProperty
= squashed_patch
;
1757 if (MSIREG_OpenUserDataPatchKey(szPatchCode
, dwContext
,
1758 &udpatch
, FALSE
) != ERROR_SUCCESS
)
1761 if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1763 if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1764 szProperty
= szManagedPackage
;
1767 else if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
))
1770 szProperty
= szInstalled
;
1772 else if (!strcmpW( szProperty
, INSTALLPROPERTY_UNINSTALLABLEW
) ||
1773 !strcmpW( szProperty
, INSTALLPROPERTY_PATCHSTATEW
) ||
1774 !strcmpW( szProperty
, INSTALLPROPERTY_DISPLAYNAMEW
) ||
1775 !strcmpW( szProperty
, INSTALLPROPERTY_MOREINFOURLW
))
1781 r
= ERROR_UNKNOWN_PROPERTY
;
1786 val
= reg_get_value(datakey
, szProperty
, &type
);
1788 val
= strdupW(szEmpty
);
1796 lstrcpynW(lpValue
, val
, *pcchValue
);
1798 len
= lstrlenW(val
);
1799 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1802 r
= ERROR_MORE_DATA
;
1804 *pcchValue
= len
* sizeof(WCHAR
);
1811 RegCloseKey(prodpatches
);
1814 RegCloseKey(patches
);
1815 RegCloseKey(udpatch
);
1817 RegCloseKey(udprod
);
1822 UINT WINAPI
MsiGetPatchInfoA( LPCSTR patch
, LPCSTR attr
, LPSTR buffer
, LPDWORD buflen
)
1824 UINT r
= ERROR_OUTOFMEMORY
;
1826 LPWSTR patchW
= NULL
, attrW
= NULL
, bufferW
= NULL
;
1828 TRACE("%s %s %p %p\n", debugstr_a(patch
), debugstr_a(attr
), buffer
, buflen
);
1830 if (!patch
|| !attr
)
1831 return ERROR_INVALID_PARAMETER
;
1833 if (!(patchW
= strdupAtoW( patch
)))
1836 if (!(attrW
= strdupAtoW( attr
)))
1840 r
= MsiGetPatchInfoW( patchW
, attrW
, NULL
, &size
);
1841 if (r
!= ERROR_SUCCESS
)
1845 if (!(bufferW
= msi_alloc( size
* sizeof(WCHAR
) )))
1847 r
= ERROR_OUTOFMEMORY
;
1851 r
= MsiGetPatchInfoW( patchW
, attrW
, bufferW
, &size
);
1852 if (r
== ERROR_SUCCESS
)
1854 int len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
1856 r
= ERROR_MORE_DATA
;
1858 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *buflen
, NULL
, NULL
);
1866 msi_free( bufferW
);
1870 UINT WINAPI
MsiGetPatchInfoW( LPCWSTR patch
, LPCWSTR attr
, LPWSTR buffer
, LPDWORD buflen
)
1873 WCHAR product
[GUID_SIZE
];
1876 TRACE("%s %s %p %p\n", debugstr_w(patch
), debugstr_w(attr
), buffer
, buflen
);
1878 if (!patch
|| !attr
)
1879 return ERROR_INVALID_PARAMETER
;
1881 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW
, attr
))
1882 return ERROR_UNKNOWN_PROPERTY
;
1887 r
= MsiEnumProductsW( index
, product
);
1888 if (r
!= ERROR_SUCCESS
)
1891 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, attr
, buffer
, buflen
);
1892 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1895 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, attr
, buffer
, buflen
);
1896 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1899 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_MACHINE
, attr
, buffer
, buflen
);
1900 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1906 return ERROR_UNKNOWN_PRODUCT
;
1909 UINT WINAPI
MsiEnableLogA(DWORD dwLogMode
, LPCSTR szLogFile
, DWORD attributes
)
1911 LPWSTR szwLogFile
= NULL
;
1914 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_a(szLogFile
), attributes
);
1918 szwLogFile
= strdupAtoW( szLogFile
);
1920 return ERROR_OUTOFMEMORY
;
1922 r
= MsiEnableLogW( dwLogMode
, szwLogFile
, attributes
);
1923 msi_free( szwLogFile
);
1927 UINT WINAPI
MsiEnableLogW(DWORD dwLogMode
, LPCWSTR szLogFile
, DWORD attributes
)
1929 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_w(szLogFile
), attributes
);
1931 msi_free(gszLogFile
);
1937 if (!(attributes
& INSTALLLOGATTRIBUTES_APPEND
))
1938 DeleteFileW(szLogFile
);
1939 file
= CreateFileW(szLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
,
1940 FILE_ATTRIBUTE_NORMAL
, NULL
);
1941 if (file
!= INVALID_HANDLE_VALUE
)
1943 gszLogFile
= strdupW(szLogFile
);
1947 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile
), GetLastError());
1950 return ERROR_SUCCESS
;
1953 UINT WINAPI
MsiEnumComponentCostsA( MSIHANDLE handle
, LPCSTR component
, DWORD index
,
1954 INSTALLSTATE state
, LPSTR drive
, DWORD
*buflen
,
1955 int *cost
, int *temp
)
1959 WCHAR
*driveW
, *componentW
= NULL
;
1961 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle
, debugstr_a(component
), index
,
1962 state
, drive
, buflen
, cost
, temp
);
1964 if (!drive
|| !buflen
) return ERROR_INVALID_PARAMETER
;
1965 if (component
&& !(componentW
= strdupAtoW( component
))) return ERROR_OUTOFMEMORY
;
1968 if (!(driveW
= msi_alloc( len
* sizeof(WCHAR
) )))
1970 msi_free( componentW
);
1971 return ERROR_OUTOFMEMORY
;
1973 r
= MsiEnumComponentCostsW( handle
, componentW
, index
, state
, driveW
, buflen
, cost
, temp
);
1976 WideCharToMultiByte( CP_ACP
, 0, driveW
, -1, drive
, len
, NULL
, NULL
);
1978 msi_free( componentW
);
1983 static UINT
set_drive( WCHAR
*buffer
, WCHAR letter
)
1991 UINT WINAPI
MsiEnumComponentCostsW( MSIHANDLE handle
, LPCWSTR component
, DWORD index
,
1992 INSTALLSTATE state
, LPWSTR drive
, DWORD
*buflen
,
1993 int *cost
, int *temp
)
1995 UINT r
= ERROR_NO_MORE_ITEMS
;
1996 MSICOMPONENT
*comp
= NULL
;
1997 MSIPACKAGE
*package
;
2000 WCHAR path
[MAX_PATH
];
2002 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle
, debugstr_w(component
), index
,
2003 state
, drive
, buflen
, cost
, temp
);
2005 if (!drive
|| !buflen
|| !cost
|| !temp
) return ERROR_INVALID_PARAMETER
;
2006 if (!(package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
)))
2012 if (!(remote
= msi_get_remote(handle
)))
2013 return ERROR_INVALID_HANDLE
;
2015 if (component
&& !(bname
= SysAllocString( component
)))
2016 return ERROR_OUTOFMEMORY
;
2018 hr
= remote_EnumComponentCosts(remote
, bname
, index
, state
, drive
, buflen
, cost
, temp
);
2020 SysFreeString( bname
);
2023 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
) return HRESULT_CODE(hr
);
2024 return ERROR_FUNCTION_FAILED
;
2026 return ERROR_SUCCESS
;
2029 if (!msi_get_property_int( package
->db
, szCostingComplete
, 0 ))
2031 msiobj_release( &package
->hdr
);
2032 return ERROR_FUNCTION_NOT_CALLED
;
2034 if (component
&& component
[0] && !(comp
= msi_get_loaded_component( package
, component
)))
2036 msiobj_release( &package
->hdr
);
2037 return ERROR_UNKNOWN_COMPONENT
;
2042 msiobj_release( &package
->hdr
);
2043 return ERROR_MORE_DATA
;
2047 msiobj_release( &package
->hdr
);
2048 return ERROR_NO_MORE_ITEMS
;
2053 GetWindowsDirectoryW( path
, MAX_PATH
);
2054 if (component
&& component
[0])
2056 if (msi_is_global_assembly( comp
)) *temp
= comp
->Cost
;
2057 if (!comp
->Enabled
|| !comp
->KeyPath
)
2060 *buflen
= set_drive( drive
, path
[0] );
2063 else if ((file
= msi_get_loaded_file( package
, comp
->KeyPath
)))
2065 *cost
= max( 8, comp
->Cost
/ 512 );
2066 *buflen
= set_drive( drive
, file
->TargetPath
[0] );
2070 else if (IStorage_Stat( package
->db
->storage
, &stat
, STATFLAG_NONAME
) == S_OK
)
2072 *temp
= max( 8, stat
.cbSize
.QuadPart
/ 512 );
2073 *buflen
= set_drive( drive
, path
[0] );
2076 msiobj_release( &package
->hdr
);
2080 UINT WINAPI
MsiQueryComponentStateA(LPCSTR szProductCode
,
2081 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
2082 LPCSTR szComponent
, INSTALLSTATE
*pdwState
)
2084 LPWSTR prodcode
= NULL
, usersid
= NULL
, comp
= NULL
;
2087 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode
),
2088 debugstr_a(szUserSid
), dwContext
, debugstr_a(szComponent
), pdwState
);
2090 if (szProductCode
&& !(prodcode
= strdupAtoW(szProductCode
)))
2091 return ERROR_OUTOFMEMORY
;
2093 if (szUserSid
&& !(usersid
= strdupAtoW(szUserSid
)))
2094 return ERROR_OUTOFMEMORY
;
2096 if (szComponent
&& !(comp
= strdupAtoW(szComponent
)))
2097 return ERROR_OUTOFMEMORY
;
2099 r
= MsiQueryComponentStateW(prodcode
, usersid
, dwContext
, comp
, pdwState
);
2108 static BOOL
msi_comp_find_prod_key(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
2113 r
= MSIREG_OpenProductKey(prodcode
, NULL
, context
, &hkey
, FALSE
);
2115 return (r
== ERROR_SUCCESS
);
2118 static BOOL
msi_comp_find_package(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
2126 static const WCHAR local_package
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
2127 static const WCHAR managed_local_package
[] = {
2128 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
2131 r
= MSIREG_OpenInstallProps(prodcode
, context
, NULL
, &hkey
, FALSE
);
2132 if (r
!= ERROR_SUCCESS
)
2135 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
2136 package
= managed_local_package
;
2138 package
= local_package
;
2141 res
= RegQueryValueExW(hkey
, package
, NULL
, NULL
, NULL
, &sz
);
2144 return (res
== ERROR_SUCCESS
);
2147 static UINT
msi_comp_find_prodcode(WCHAR
*squashed_pc
,
2148 MSIINSTALLCONTEXT context
,
2149 LPCWSTR comp
, LPWSTR val
, DWORD
*sz
)
2155 if (context
== MSIINSTALLCONTEXT_MACHINE
)
2156 r
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2158 r
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2160 if (r
!= ERROR_SUCCESS
)
2163 res
= RegQueryValueExW( hkey
, squashed_pc
, NULL
, NULL
, (BYTE
*)val
, sz
);
2164 if (res
!= ERROR_SUCCESS
)
2171 UINT WINAPI
MsiQueryComponentStateW(LPCWSTR szProductCode
,
2172 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
2173 LPCWSTR szComponent
, INSTALLSTATE
*pdwState
)
2175 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
2179 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode
),
2180 debugstr_w(szUserSid
), dwContext
, debugstr_w(szComponent
), pdwState
);
2182 if (!pdwState
|| !szComponent
)
2183 return ERROR_INVALID_PARAMETER
;
2185 if (!szProductCode
|| !*szProductCode
|| lstrlenW(szProductCode
) != GUID_SIZE
- 1)
2186 return ERROR_INVALID_PARAMETER
;
2188 if (!squash_guid( szProductCode
, squashed_pc
))
2189 return ERROR_INVALID_PARAMETER
;
2191 found
= msi_comp_find_prod_key(szProductCode
, dwContext
);
2193 if (!msi_comp_find_package(szProductCode
, dwContext
))
2197 *pdwState
= INSTALLSTATE_UNKNOWN
;
2198 return ERROR_UNKNOWN_COMPONENT
;
2201 return ERROR_UNKNOWN_PRODUCT
;
2204 *pdwState
= INSTALLSTATE_UNKNOWN
;
2207 if (msi_comp_find_prodcode( squashed_pc
, dwContext
, szComponent
, NULL
, &sz
))
2208 return ERROR_UNKNOWN_COMPONENT
;
2211 *pdwState
= INSTALLSTATE_NOTUSED
;
2217 if (!(val
= msi_alloc( sz
))) return ERROR_OUTOFMEMORY
;
2218 if ((r
= msi_comp_find_prodcode( squashed_pc
, dwContext
, szComponent
, val
, &sz
)))
2224 if (lstrlenW(val
) > 2 &&
2225 val
[0] >= '0' && val
[0] <= '9' && val
[1] >= '0' && val
[1] <= '9' && val
[2] != ':')
2227 *pdwState
= INSTALLSTATE_SOURCE
;
2230 *pdwState
= INSTALLSTATE_LOCAL
;
2234 TRACE("-> %d\n", *pdwState
);
2235 return ERROR_SUCCESS
;
2238 INSTALLSTATE WINAPI
MsiQueryProductStateA(LPCSTR szProduct
)
2240 LPWSTR szwProduct
= NULL
;
2245 szwProduct
= strdupAtoW( szProduct
);
2247 return ERROR_OUTOFMEMORY
;
2249 r
= MsiQueryProductStateW( szwProduct
);
2250 msi_free( szwProduct
);
2254 INSTALLSTATE WINAPI
MsiQueryProductStateW(LPCWSTR szProduct
)
2256 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
2257 INSTALLSTATE state
= INSTALLSTATE_ADVERTISED
;
2258 HKEY prodkey
= 0, userdata
= 0;
2262 TRACE("%s\n", debugstr_w(szProduct
));
2264 if (!szProduct
|| !*szProduct
)
2265 return INSTALLSTATE_INVALIDARG
;
2267 if (lstrlenW(szProduct
) != GUID_SIZE
- 1)
2268 return INSTALLSTATE_INVALIDARG
;
2270 if (szProduct
[0] != '{' || szProduct
[37] != '}')
2271 return INSTALLSTATE_UNKNOWN
;
2273 SetLastError( ERROR_SUCCESS
);
2275 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
2276 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2277 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2278 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2279 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2280 &prodkey
, FALSE
) == ERROR_SUCCESS
)
2282 context
= MSIINSTALLCONTEXT_MACHINE
;
2285 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
2286 if (r
!= ERROR_SUCCESS
)
2289 if (!msi_reg_get_val_dword(userdata
, szWindowsInstaller
, &val
))
2293 state
= INSTALLSTATE_DEFAULT
;
2295 state
= INSTALLSTATE_UNKNOWN
;
2300 state
= INSTALLSTATE_UNKNOWN
;
2303 state
= INSTALLSTATE_ABSENT
;
2306 RegCloseKey(prodkey
);
2307 RegCloseKey(userdata
);
2308 TRACE("-> %d\n", state
);
2312 INSTALLUILEVEL WINAPI
MsiSetInternalUI(INSTALLUILEVEL dwUILevel
, HWND
*phWnd
)
2314 INSTALLUILEVEL old
= gUILevel
;
2315 HWND oldwnd
= gUIhwnd
;
2317 TRACE("%08x %p\n", dwUILevel
, phWnd
);
2319 if (dwUILevel
& ~(INSTALLUILEVEL_MASK
|INSTALLUILEVEL_HIDECANCEL
|INSTALLUILEVEL_PROGRESSONLY
|
2320 INSTALLUILEVEL_ENDDIALOG
|INSTALLUILEVEL_SOURCERESONLY
))
2322 FIXME("Unrecognized flags %08x\n", dwUILevel
);
2323 return INSTALLUILEVEL_NOCHANGE
;
2326 if (dwUILevel
!= INSTALLUILEVEL_NOCHANGE
)
2327 gUILevel
= dwUILevel
;
2337 INSTALLUI_HANDLERA WINAPI
MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler
,
2338 DWORD dwMessageFilter
, LPVOID pvContext
)
2340 INSTALLUI_HANDLERA prev
= gUIHandlerA
;
2342 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2344 gUIHandlerA
= puiHandler
;
2346 gUIFilter
= dwMessageFilter
;
2347 gUIContext
= pvContext
;
2352 INSTALLUI_HANDLERW WINAPI
MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler
,
2353 DWORD dwMessageFilter
, LPVOID pvContext
)
2355 INSTALLUI_HANDLERW prev
= gUIHandlerW
;
2357 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2360 gUIHandlerW
= puiHandler
;
2361 gUIFilter
= dwMessageFilter
;
2362 gUIContext
= pvContext
;
2367 /******************************************************************
2368 * MsiLoadStringW [MSI.@]
2370 * Loads a string from MSI's string resources.
2374 * handle [I] only -1 is handled currently
2375 * id [I] id of the string to be loaded
2376 * lpBuffer [O] buffer for the string to be written to
2377 * nBufferMax [I] maximum size of the buffer in characters
2378 * lang [I] the preferred language for the string
2382 * If successful, this function returns the language id of the string loaded
2383 * If the function fails, the function returns zero.
2387 * The type of the first parameter is unknown. LoadString's prototype
2388 * suggests that it might be a module handle. I have made it an MSI handle
2389 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2390 * handle. Maybe strings can be stored in an MSI database somehow.
2392 LANGID WINAPI
MsiLoadStringW( MSIHANDLE handle
, UINT id
, LPWSTR lpBuffer
,
2393 int nBufferMax
, LANGID lang
)
2400 TRACE("%d %u %p %d %d\n", handle
, id
, lpBuffer
, nBufferMax
, lang
);
2403 FIXME("don't know how to deal with handle = %08x\n", handle
);
2406 lang
= GetUserDefaultLangID();
2408 hres
= FindResourceExW( msi_hInstance
, (LPCWSTR
) RT_STRING
,
2412 hResData
= LoadResource( msi_hInstance
, hres
);
2415 p
= LockResource( hResData
);
2419 for (i
= 0; i
< (id
& 0xf); i
++) p
+= *p
+ 1;
2422 if( nBufferMax
<= len
)
2425 memcpy( lpBuffer
, p
+1, len
* sizeof(WCHAR
));
2426 lpBuffer
[ len
] = 0;
2428 TRACE("found -> %s\n", debugstr_w(lpBuffer
));
2432 LANGID WINAPI
MsiLoadStringA( MSIHANDLE handle
, UINT id
, LPSTR lpBuffer
,
2433 int nBufferMax
, LANGID lang
)
2439 bufW
= msi_alloc(nBufferMax
*sizeof(WCHAR
));
2440 r
= MsiLoadStringW(handle
, id
, bufW
, nBufferMax
, lang
);
2443 len
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
2444 if( len
<= nBufferMax
)
2445 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1,
2446 lpBuffer
, nBufferMax
, NULL
, NULL
);
2454 INSTALLSTATE WINAPI
MsiLocateComponentA(LPCSTR szComponent
, LPSTR lpPathBuf
,
2457 char szProduct
[GUID_SIZE
];
2459 TRACE("%s %p %p\n", debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2461 if (!szComponent
|| !pcchBuf
)
2462 return INSTALLSTATE_INVALIDARG
;
2464 if (MsiGetProductCodeA( szComponent
, szProduct
) != ERROR_SUCCESS
)
2465 return INSTALLSTATE_UNKNOWN
;
2467 return MsiGetComponentPathA( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2470 INSTALLSTATE WINAPI
MsiLocateComponentW(LPCWSTR szComponent
, LPWSTR lpPathBuf
,
2473 WCHAR szProduct
[GUID_SIZE
];
2475 TRACE("%s %p %p\n", debugstr_w(szComponent
), lpPathBuf
, pcchBuf
);
2477 if (!szComponent
|| !pcchBuf
)
2478 return INSTALLSTATE_INVALIDARG
;
2480 if (MsiGetProductCodeW( szComponent
, szProduct
) != ERROR_SUCCESS
)
2481 return INSTALLSTATE_UNKNOWN
;
2483 return MsiGetComponentPathW( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2486 UINT WINAPI
MsiMessageBoxA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2487 WORD wLanguageId
, DWORD f
)
2489 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_a(lpText
), debugstr_a(lpCaption
),
2490 uType
, wLanguageId
, f
);
2491 return MessageBoxExA(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2494 UINT WINAPI
MsiMessageBoxW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2495 WORD wLanguageId
, DWORD f
)
2497 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_w(lpText
), debugstr_w(lpCaption
),
2498 uType
, wLanguageId
, f
);
2499 return MessageBoxExW(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2502 UINT WINAPI
MsiMessageBoxExA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2503 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2505 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_a(lpText
),
2506 debugstr_a(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2507 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2510 UINT WINAPI
MsiMessageBoxExW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2511 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2513 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_w(lpText
),
2514 debugstr_w(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2515 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2518 UINT WINAPI
MsiProvideAssemblyA( LPCSTR szAssemblyName
, LPCSTR szAppContext
,
2519 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPSTR lpPathBuf
,
2520 LPDWORD pcchPathBuf
)
2522 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName
),
2523 debugstr_a(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2525 return ERROR_CALL_NOT_IMPLEMENTED
;
2528 UINT WINAPI
MsiProvideAssemblyW( LPCWSTR szAssemblyName
, LPCWSTR szAppContext
,
2529 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPWSTR lpPathBuf
,
2530 LPDWORD pcchPathBuf
)
2532 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName
),
2533 debugstr_w(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2535 return ERROR_CALL_NOT_IMPLEMENTED
;
2538 UINT WINAPI
MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor
,
2539 LPSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2541 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2542 return ERROR_CALL_NOT_IMPLEMENTED
;
2545 UINT WINAPI
MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor
,
2546 LPWSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2548 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2549 return ERROR_CALL_NOT_IMPLEMENTED
;
2552 HRESULT WINAPI
MsiGetFileSignatureInformationA( LPCSTR path
, DWORD flags
, PCCERT_CONTEXT
*cert
,
2553 LPBYTE hash
, LPDWORD hashlen
)
2556 WCHAR
*pathW
= NULL
;
2558 TRACE("%s %08x %p %p %p\n", debugstr_a(path
), flags
, cert
, hash
, hashlen
);
2560 if (path
&& !(pathW
= strdupAtoW( path
))) return E_OUTOFMEMORY
;
2561 r
= MsiGetFileSignatureInformationW( pathW
, flags
, cert
, hash
, hashlen
);
2566 HRESULT WINAPI
MsiGetFileSignatureInformationW( LPCWSTR path
, DWORD flags
, PCCERT_CONTEXT
*cert
,
2567 LPBYTE hash
, LPDWORD hashlen
)
2569 static GUID generic_verify_v2
= WINTRUST_ACTION_GENERIC_VERIFY_V2
;
2572 WINTRUST_FILE_INFO info
;
2573 CRYPT_PROVIDER_SGNR
*signer
;
2574 CRYPT_PROVIDER_CERT
*provider
;
2576 TRACE("%s %08x %p %p %p\n", debugstr_w(path
), flags
, cert
, hash
, hashlen
);
2578 if (!path
|| !cert
) return E_INVALIDARG
;
2580 info
.cbStruct
= sizeof(info
);
2581 info
.pcwszFilePath
= path
;
2583 info
.pgKnownSubject
= NULL
;
2585 data
.cbStruct
= sizeof(data
);
2586 data
.pPolicyCallbackData
= NULL
;
2587 data
.pSIPClientData
= NULL
;
2588 data
.dwUIChoice
= WTD_UI_NONE
;
2589 data
.fdwRevocationChecks
= WTD_REVOKE_WHOLECHAIN
;
2590 data
.dwUnionChoice
= WTD_CHOICE_FILE
;
2591 data
.u
.pFile
= &info
;
2592 data
.dwStateAction
= WTD_STATEACTION_VERIFY
;
2593 data
.hWVTStateData
= NULL
;
2594 data
.pwszURLReference
= NULL
;
2595 data
.dwProvFlags
= 0;
2596 data
.dwUIContext
= WTD_UICONTEXT_INSTALL
;
2597 hr
= WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2599 if (FAILED(hr
)) goto done
;
2601 if (!(signer
= WTHelperGetProvSignerFromChain( data
.hWVTStateData
, 0, FALSE
, 0 )))
2603 hr
= TRUST_E_NOSIGNATURE
;
2608 DWORD len
= signer
->psSigner
->EncryptedHash
.cbData
;
2612 hr
= HRESULT_FROM_WIN32(ERROR_MORE_DATA
);
2615 memcpy( hash
, signer
->psSigner
->EncryptedHash
.pbData
, len
);
2618 if (!(provider
= WTHelperGetProvCertFromChain( signer
, 0 )))
2620 hr
= TRUST_E_PROVIDER_UNKNOWN
;
2623 *cert
= CertDuplicateCertificateContext( provider
->pCert
);
2626 data
.dwStateAction
= WTD_STATEACTION_CLOSE
;
2627 WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2631 /******************************************************************
2632 * MsiGetProductPropertyA [MSI.@]
2634 UINT WINAPI
MsiGetProductPropertyA(MSIHANDLE hProduct
, LPCSTR szProperty
,
2635 LPSTR szValue
, LPDWORD pccbValue
)
2637 LPWSTR prop
= NULL
, val
= NULL
;
2641 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_a(szProperty
),
2642 szValue
, pccbValue
);
2644 if (szValue
&& !pccbValue
)
2645 return ERROR_INVALID_PARAMETER
;
2647 if (szProperty
) prop
= strdupAtoW(szProperty
);
2650 r
= MsiGetProductPropertyW(hProduct
, prop
, NULL
, &len
);
2651 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2654 if (r
== ERROR_SUCCESS
)
2656 if (szValue
) *szValue
= '\0';
2657 if (pccbValue
) *pccbValue
= 0;
2661 val
= msi_alloc(++len
* sizeof(WCHAR
));
2664 r
= ERROR_OUTOFMEMORY
;
2668 r
= MsiGetProductPropertyW(hProduct
, prop
, val
, &len
);
2669 if (r
!= ERROR_SUCCESS
)
2672 len
= WideCharToMultiByte(CP_ACP
, 0, val
, -1, NULL
, 0, NULL
, NULL
);
2675 WideCharToMultiByte(CP_ACP
, 0, val
, -1, szValue
,
2676 *pccbValue
, NULL
, NULL
);
2680 if (len
> *pccbValue
)
2681 r
= ERROR_MORE_DATA
;
2683 *pccbValue
= len
- 1;
2693 /******************************************************************
2694 * MsiGetProductPropertyW [MSI.@]
2696 UINT WINAPI
MsiGetProductPropertyW(MSIHANDLE hProduct
, LPCWSTR szProperty
,
2697 LPWSTR szValue
, LPDWORD pccbValue
)
2699 MSIPACKAGE
*package
;
2700 MSIQUERY
*view
= NULL
;
2701 MSIRECORD
*rec
= NULL
;
2705 static const WCHAR query
[] = {
2706 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2707 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2708 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2710 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_w(szProperty
),
2711 szValue
, pccbValue
);
2714 return ERROR_INVALID_PARAMETER
;
2716 if (szValue
&& !pccbValue
)
2717 return ERROR_INVALID_PARAMETER
;
2719 package
= msihandle2msiinfo(hProduct
, MSIHANDLETYPE_PACKAGE
);
2721 return ERROR_INVALID_HANDLE
;
2723 r
= MSI_OpenQuery(package
->db
, &view
, query
, szProperty
);
2724 if (r
!= ERROR_SUCCESS
)
2727 r
= MSI_ViewExecute(view
, 0);
2728 if (r
!= ERROR_SUCCESS
)
2731 r
= MSI_ViewFetch(view
, &rec
);
2732 if (r
!= ERROR_SUCCESS
)
2735 val
= MSI_RecordGetString(rec
, 2);
2739 if (lstrlenW(val
) >= *pccbValue
)
2741 if (szValue
) lstrcpynW(szValue
, val
, *pccbValue
);
2742 r
= ERROR_MORE_DATA
;
2746 if (szValue
) lstrcpyW(szValue
, val
);
2750 *pccbValue
= lstrlenW(val
);
2755 MSI_ViewClose(view
);
2756 msiobj_release(&view
->hdr
);
2757 if (rec
) msiobj_release(&rec
->hdr
);
2762 if (szValue
) *szValue
= '\0';
2763 if (pccbValue
) *pccbValue
= 0;
2767 msiobj_release(&package
->hdr
);
2771 UINT WINAPI
MsiVerifyPackageA( LPCSTR szPackage
)
2774 LPWSTR szPack
= NULL
;
2776 TRACE("%s\n", debugstr_a(szPackage
) );
2780 szPack
= strdupAtoW( szPackage
);
2782 return ERROR_OUTOFMEMORY
;
2785 r
= MsiVerifyPackageW( szPack
);
2792 UINT WINAPI
MsiVerifyPackageW( LPCWSTR szPackage
)
2797 TRACE("%s\n", debugstr_w(szPackage
) );
2799 r
= MsiOpenDatabaseW( szPackage
, MSIDBOPEN_READONLY
, &handle
);
2800 MsiCloseHandle( handle
);
2805 static BOOL
open_userdata_comp_key( const WCHAR
*comp
, const WCHAR
*usersid
, MSIINSTALLCONTEXT ctx
,
2808 if (ctx
& MSIINSTALLCONTEXT_MACHINE
)
2810 if (!MSIREG_OpenUserDataComponentKey( comp
, szLocalSid
, hkey
, FALSE
)) return TRUE
;
2812 if (ctx
& (MSIINSTALLCONTEXT_USERMANAGED
|MSIINSTALLCONTEXT_USERUNMANAGED
))
2814 if (usersid
&& !strcmpiW( usersid
, szAllSid
))
2816 FIXME( "only looking at the current user\n" );
2819 if (!MSIREG_OpenUserDataComponentKey( comp
, usersid
, hkey
, FALSE
)) return TRUE
;
2824 static INSTALLSTATE
MSI_GetComponentPath( const WCHAR
*szProduct
, const WCHAR
*szComponent
,
2825 const WCHAR
*szUserSid
, MSIINSTALLCONTEXT ctx
,
2826 awstring
*lpPathBuf
, DWORD
*pcchBuf
)
2828 static const WCHAR wininstaller
[] =
2829 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2830 WCHAR
*path
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
], squashed_comp
[SQUASHED_GUID_SIZE
];
2835 if (!szProduct
|| !szComponent
)
2836 return INSTALLSTATE_INVALIDARG
;
2838 if (lpPathBuf
->str
.w
&& !pcchBuf
)
2839 return INSTALLSTATE_INVALIDARG
;
2841 if (!squash_guid( szProduct
, squashed_pc
) || !squash_guid( szComponent
, squashed_comp
))
2842 return INSTALLSTATE_INVALIDARG
;
2844 if (szUserSid
&& ctx
== MSIINSTALLCONTEXT_MACHINE
)
2845 return INSTALLSTATE_INVALIDARG
;
2847 state
= INSTALLSTATE_UNKNOWN
;
2849 if (open_userdata_comp_key( szComponent
, szUserSid
, ctx
, &hkey
))
2851 path
= msi_reg_get_val_str( hkey
, squashed_pc
);
2854 state
= INSTALLSTATE_ABSENT
;
2856 if ((!MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
, NULL
, &hkey
, FALSE
) ||
2857 !MSIREG_OpenUserDataProductKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
, NULL
, &hkey
, FALSE
)) &&
2858 msi_reg_get_val_dword(hkey
, wininstaller
, &version
) &&
2859 GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2862 state
= INSTALLSTATE_LOCAL
;
2866 if (state
!= INSTALLSTATE_LOCAL
&&
2867 (!MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, &hkey
, FALSE
) ||
2868 !MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
, &hkey
, FALSE
)))
2872 if (open_userdata_comp_key( szComponent
, szUserSid
, ctx
, &hkey
))
2875 path
= msi_reg_get_val_str( hkey
, squashed_pc
);
2878 state
= INSTALLSTATE_ABSENT
;
2880 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2881 state
= INSTALLSTATE_LOCAL
;
2886 return INSTALLSTATE_UNKNOWN
;
2888 if (state
== INSTALLSTATE_LOCAL
&& !*path
)
2889 state
= INSTALLSTATE_NOTUSED
;
2891 if (msi_strcpy_to_awstring(path
, -1, lpPathBuf
, pcchBuf
) == ERROR_MORE_DATA
)
2892 state
= INSTALLSTATE_MOREDATA
;
2898 /******************************************************************
2899 * MsiGetComponentPathExW [MSI.@]
2901 INSTALLSTATE WINAPI
MsiGetComponentPathExW( LPCWSTR product
, LPCWSTR comp
, LPCWSTR usersid
,
2902 MSIINSTALLCONTEXT ctx
, LPWSTR buf
, LPDWORD buflen
)
2906 TRACE( "%s %s %s 0x%x %p %p\n", debugstr_w(product
), debugstr_w(comp
), debugstr_w(usersid
),
2909 path
.unicode
= TRUE
;
2912 return MSI_GetComponentPath( product
, comp
, usersid
, ctx
, &path
, buflen
);
2915 INSTALLSTATE WINAPI
MsiGetComponentPathExA( LPCSTR product
, LPCSTR comp
, LPCSTR usersid
,
2916 MSIINSTALLCONTEXT ctx
, LPSTR buf
, LPDWORD buflen
)
2918 WCHAR
*productW
= NULL
, *compW
= NULL
, *usersidW
= NULL
;
2919 INSTALLSTATE r
= INSTALLSTATE_UNKNOWN
;
2922 TRACE( "%s %s %s 0x%x %p %p\n", debugstr_a(product
), debugstr_a(comp
), debugstr_a(usersid
),
2925 if (product
&& !(productW
= strdupAtoW( product
))) return INSTALLSTATE_UNKNOWN
;
2926 if (comp
&& !(compW
= strdupAtoW( comp
))) goto end
;
2927 if (usersid
&& !(usersidW
= strdupAtoW( usersid
))) goto end
;
2929 path
.unicode
= FALSE
;
2932 r
= MSI_GetComponentPath( productW
, compW
, usersidW
, ctx
, &path
, buflen
);
2935 msi_free( productW
);
2937 msi_free( usersidW
);
2942 /******************************************************************
2943 * MsiGetComponentPathW [MSI.@]
2945 INSTALLSTATE WINAPI
MsiGetComponentPathW( LPCWSTR product
, LPCWSTR comp
, LPWSTR buf
, LPDWORD buflen
)
2947 return MsiGetComponentPathExW( product
, comp
, szAllSid
, MSIINSTALLCONTEXT_ALL
, buf
, buflen
);
2950 /******************************************************************
2951 * MsiGetComponentPathA [MSI.@]
2953 INSTALLSTATE WINAPI
MsiGetComponentPathA( LPCSTR product
, LPCSTR comp
, LPSTR buf
, LPDWORD buflen
)
2955 return MsiGetComponentPathExA( product
, comp
, "s-1-1-0", MSIINSTALLCONTEXT_ALL
, buf
, buflen
);
2958 static UINT
query_feature_state( const WCHAR
*product
, const WCHAR
*squashed
, const WCHAR
*usersid
,
2959 MSIINSTALLCONTEXT ctx
, const WCHAR
*feature
, INSTALLSTATE
*state
)
2963 WCHAR
*parent
, *components
, *path
;
2965 BOOL missing
= FALSE
, source
= FALSE
;
2966 WCHAR comp
[GUID_SIZE
];
2969 if (ctx
!= MSIINSTALLCONTEXT_MACHINE
) SetLastError( ERROR_SUCCESS
);
2971 if (MSIREG_OpenFeaturesKey( product
, usersid
, ctx
, &hkey
, FALSE
)) return ERROR_UNKNOWN_PRODUCT
;
2973 parent
= msi_reg_get_val_str( hkey
, feature
);
2974 RegCloseKey( hkey
);
2975 if (!parent
) return ERROR_UNKNOWN_FEATURE
;
2977 *state
= (parent
[0] == 6) ? INSTALLSTATE_ABSENT
: INSTALLSTATE_LOCAL
;
2979 if (*state
== INSTALLSTATE_ABSENT
)
2980 return ERROR_SUCCESS
;
2982 r
= MSIREG_OpenUserDataFeaturesKey( product
, usersid
, ctx
, &hkey
, FALSE
);
2983 if (r
!= ERROR_SUCCESS
)
2985 *state
= INSTALLSTATE_ADVERTISED
;
2986 return ERROR_SUCCESS
;
2988 components
= msi_reg_get_val_str( hkey
, feature
);
2989 RegCloseKey( hkey
);
2991 TRACE("buffer = %s\n", debugstr_w(components
));
2995 *state
= INSTALLSTATE_ADVERTISED
;
2996 return ERROR_SUCCESS
;
2998 for (p
= components
; *p
&& *p
!= 2 ; p
+= 20)
3000 if (!decode_base85_guid( p
, &guid
))
3002 if (p
!= components
) break;
3003 msi_free( components
);
3004 *state
= INSTALLSTATE_BADCONFIG
;
3005 return ERROR_BAD_CONFIGURATION
;
3007 StringFromGUID2( &guid
, comp
, GUID_SIZE
);
3008 if (ctx
== MSIINSTALLCONTEXT_MACHINE
)
3009 r
= MSIREG_OpenUserDataComponentKey( comp
, szLocalSid
, &hkey
, FALSE
);
3011 r
= MSIREG_OpenUserDataComponentKey( comp
, usersid
, &hkey
, FALSE
);
3013 if (r
!= ERROR_SUCCESS
)
3015 msi_free( components
);
3016 *state
= INSTALLSTATE_ADVERTISED
;
3017 return ERROR_SUCCESS
;
3019 path
= msi_reg_get_val_str( hkey
, squashed
);
3020 if (!path
) missing
= TRUE
;
3021 else if (strlenW( path
) > 2 &&
3022 path
[0] >= '0' && path
[0] <= '9' &&
3023 path
[1] >= '0' && path
[1] <= '9')
3029 msi_free( components
);
3032 *state
= INSTALLSTATE_ADVERTISED
;
3034 *state
= INSTALLSTATE_SOURCE
;
3036 *state
= INSTALLSTATE_LOCAL
;
3038 TRACE("returning state %d\n", *state
);
3039 return ERROR_SUCCESS
;
3042 UINT WINAPI
MsiQueryFeatureStateExA( LPCSTR product
, LPCSTR usersid
, MSIINSTALLCONTEXT ctx
,
3043 LPCSTR feature
, INSTALLSTATE
*state
)
3046 WCHAR
*productW
= NULL
, *usersidW
= NULL
, *featureW
= NULL
;
3048 if (product
&& !(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
3049 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
3051 msi_free( productW
);
3052 return ERROR_OUTOFMEMORY
;
3054 if (feature
&& !(featureW
= strdupAtoW( feature
)))
3056 msi_free( productW
);
3057 msi_free( usersidW
);
3058 return ERROR_OUTOFMEMORY
;
3060 r
= MsiQueryFeatureStateExW( productW
, usersidW
, ctx
, featureW
, state
);
3061 msi_free( productW
);
3062 msi_free( usersidW
);
3063 msi_free( featureW
);
3067 UINT WINAPI
MsiQueryFeatureStateExW( LPCWSTR product
, LPCWSTR usersid
, MSIINSTALLCONTEXT ctx
,
3068 LPCWSTR feature
, INSTALLSTATE
*state
)
3071 if (!squash_guid( product
, squashed
)) return ERROR_INVALID_PARAMETER
;
3072 return query_feature_state( product
, squashed
, usersid
, ctx
, feature
, state
);
3075 /******************************************************************
3076 * MsiQueryFeatureStateA [MSI.@]
3078 INSTALLSTATE WINAPI
MsiQueryFeatureStateA(LPCSTR szProduct
, LPCSTR szFeature
)
3080 LPWSTR szwProduct
= NULL
, szwFeature
= NULL
;
3081 INSTALLSTATE rc
= INSTALLSTATE_UNKNOWN
;
3083 szwProduct
= strdupAtoW( szProduct
);
3084 if ( szProduct
&& !szwProduct
)
3087 szwFeature
= strdupAtoW( szFeature
);
3088 if ( szFeature
&& !szwFeature
)
3091 rc
= MsiQueryFeatureStateW(szwProduct
, szwFeature
);
3094 msi_free( szwProduct
);
3095 msi_free( szwFeature
);
3100 /******************************************************************
3101 * MsiQueryFeatureStateW [MSI.@]
3103 * Checks the state of a feature
3106 * szProduct [I] Product's GUID string
3107 * szFeature [I] Feature's GUID string
3110 * INSTALLSTATE_LOCAL Feature is installed and usable
3111 * INSTALLSTATE_ABSENT Feature is absent
3112 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
3113 * INSTALLSTATE_UNKNOWN An error occurred
3114 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
3117 INSTALLSTATE WINAPI
MsiQueryFeatureStateW(LPCWSTR szProduct
, LPCWSTR szFeature
)
3123 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szFeature
));
3125 if (!szProduct
|| !szFeature
|| !squash_guid( szProduct
, squashed
))
3126 return INSTALLSTATE_INVALIDARG
;
3128 r
= query_feature_state( szProduct
, squashed
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, szFeature
, &state
);
3129 if (r
== ERROR_SUCCESS
|| r
== ERROR_BAD_CONFIGURATION
) return state
;
3131 r
= query_feature_state( szProduct
, squashed
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, szFeature
, &state
);
3132 if (r
== ERROR_SUCCESS
|| r
== ERROR_BAD_CONFIGURATION
) return state
;
3134 r
= query_feature_state( szProduct
, squashed
, NULL
, MSIINSTALLCONTEXT_MACHINE
, szFeature
, &state
);
3135 if (r
== ERROR_SUCCESS
|| r
== ERROR_BAD_CONFIGURATION
) return state
;
3137 return INSTALLSTATE_UNKNOWN
;
3140 /******************************************************************
3141 * MsiGetFileVersionA [MSI.@]
3143 UINT WINAPI
MsiGetFileVersionA(LPCSTR szFilePath
, LPSTR lpVersionBuf
,
3144 LPDWORD pcchVersionBuf
, LPSTR lpLangBuf
, LPDWORD pcchLangBuf
)
3146 LPWSTR szwFilePath
= NULL
, lpwVersionBuff
= NULL
, lpwLangBuff
= NULL
;
3147 UINT ret
= ERROR_OUTOFMEMORY
;
3149 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
3150 (lpLangBuf
&& !pcchLangBuf
))
3151 return ERROR_INVALID_PARAMETER
;
3155 szwFilePath
= strdupAtoW( szFilePath
);
3160 if( lpVersionBuf
&& pcchVersionBuf
&& *pcchVersionBuf
)
3162 lpwVersionBuff
= msi_alloc(*pcchVersionBuf
*sizeof(WCHAR
));
3163 if( !lpwVersionBuff
)
3167 if( lpLangBuf
&& pcchLangBuf
&& *pcchLangBuf
)
3169 lpwLangBuff
= msi_alloc(*pcchLangBuf
*sizeof(WCHAR
));
3174 ret
= MsiGetFileVersionW(szwFilePath
, lpwVersionBuff
, pcchVersionBuf
,
3175 lpwLangBuff
, pcchLangBuf
);
3177 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwVersionBuff
)
3178 WideCharToMultiByte(CP_ACP
, 0, lpwVersionBuff
, -1,
3179 lpVersionBuf
, *pcchVersionBuf
+ 1, NULL
, NULL
);
3180 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwLangBuff
)
3181 WideCharToMultiByte(CP_ACP
, 0, lpwLangBuff
, -1,
3182 lpLangBuf
, *pcchLangBuf
+ 1, NULL
, NULL
);
3185 msi_free(szwFilePath
);
3186 msi_free(lpwVersionBuff
);
3187 msi_free(lpwLangBuff
);
3192 static UINT
get_file_version( const WCHAR
*path
, WCHAR
*verbuf
, DWORD
*verlen
,
3193 WCHAR
*langbuf
, DWORD
*langlen
)
3195 static const WCHAR szVersionResource
[] = {'\\',0};
3196 static const WCHAR szVersionFormat
[] = {'%','d','.','%','d','.','%','d','.','%','d',0};
3197 static const WCHAR szLangFormat
[] = {'%','d',0};
3198 UINT ret
= ERROR_MORE_DATA
;
3201 VS_FIXEDFILEINFO
*ffi
;
3205 if (!(len
= GetFileVersionInfoSizeW( path
, NULL
)))
3207 error
= GetLastError();
3208 if (error
== ERROR_BAD_PATHNAME
) return ERROR_FILE_NOT_FOUND
;
3209 if (error
== ERROR_RESOURCE_DATA_NOT_FOUND
) return ERROR_FILE_INVALID
;
3212 if (!(version
= msi_alloc( len
))) return ERROR_OUTOFMEMORY
;
3213 if (!GetFileVersionInfoW( path
, 0, len
, version
))
3215 msi_free( version
);
3216 return GetLastError();
3218 if (!verbuf
&& !verlen
&& !langbuf
&& !langlen
)
3220 msi_free( version
);
3221 return ERROR_SUCCESS
;
3225 if (VerQueryValueW( version
, szVersionResource
, (LPVOID
*)&ffi
, &len
) && len
> 0)
3227 sprintfW( tmp
, szVersionFormat
,
3228 HIWORD(ffi
->dwFileVersionMS
), LOWORD(ffi
->dwFileVersionMS
),
3229 HIWORD(ffi
->dwFileVersionLS
), LOWORD(ffi
->dwFileVersionLS
) );
3230 if (verbuf
) lstrcpynW( verbuf
, tmp
, *verlen
);
3231 len
= strlenW( tmp
);
3232 if (*verlen
> len
) ret
= ERROR_SUCCESS
;
3237 if (verbuf
) *verbuf
= 0;
3243 if (VerQueryValueW( version
, szLangResource
, (LPVOID
*)&lang
, &len
) && len
> 0)
3245 sprintfW( tmp
, szLangFormat
, *lang
);
3246 if (langbuf
) lstrcpynW( langbuf
, tmp
, *langlen
);
3247 len
= strlenW( tmp
);
3248 if (*langlen
> len
) ret
= ERROR_SUCCESS
;
3253 if (langbuf
) *langbuf
= 0;
3257 msi_free( version
);
3262 /******************************************************************
3263 * MsiGetFileVersionW [MSI.@]
3265 UINT WINAPI
MsiGetFileVersionW( LPCWSTR path
, LPWSTR verbuf
, LPDWORD verlen
,
3266 LPWSTR langbuf
, LPDWORD langlen
)
3270 TRACE("%s %p %u %p %u\n", debugstr_w(path
), verbuf
, verlen
? *verlen
: 0,
3271 langbuf
, langlen
? *langlen
: 0);
3273 if ((verbuf
&& !verlen
) || (langbuf
&& !langlen
))
3274 return ERROR_INVALID_PARAMETER
;
3276 ret
= get_file_version( path
, verbuf
, verlen
, langbuf
, langlen
);
3277 if (ret
== ERROR_RESOURCE_DATA_NOT_FOUND
&& verlen
)
3280 WCHAR
*version
= msi_font_version_from_file( path
);
3281 if (!version
) return ERROR_FILE_INVALID
;
3282 len
= strlenW( version
);
3283 if (len
>= *verlen
) ret
= ERROR_MORE_DATA
;
3286 strcpyW( verbuf
, version
);
3287 ret
= ERROR_SUCCESS
;
3290 msi_free( version
);
3295 /***********************************************************************
3296 * MsiGetFeatureUsageW [MSI.@]
3298 UINT WINAPI
MsiGetFeatureUsageW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3299 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
3301 FIXME("%s %s %p %p\n",debugstr_w(szProduct
), debugstr_w(szFeature
),
3302 pdwUseCount
, pwDateUsed
);
3303 return ERROR_CALL_NOT_IMPLEMENTED
;
3306 /***********************************************************************
3307 * MsiGetFeatureUsageA [MSI.@]
3309 UINT WINAPI
MsiGetFeatureUsageA( LPCSTR szProduct
, LPCSTR szFeature
,
3310 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
3312 LPWSTR prod
= NULL
, feat
= NULL
;
3313 UINT ret
= ERROR_OUTOFMEMORY
;
3315 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3316 pdwUseCount
, pwDateUsed
);
3318 prod
= strdupAtoW( szProduct
);
3319 if (szProduct
&& !prod
)
3322 feat
= strdupAtoW( szFeature
);
3323 if (szFeature
&& !feat
)
3326 ret
= MsiGetFeatureUsageW( prod
, feat
, pdwUseCount
, pwDateUsed
);
3335 /***********************************************************************
3336 * MsiUseFeatureExW [MSI.@]
3338 INSTALLSTATE WINAPI
MsiUseFeatureExW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3339 DWORD dwInstallMode
, DWORD dwReserved
)
3343 TRACE("%s %s %i %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
3344 dwInstallMode
, dwReserved
);
3346 state
= MsiQueryFeatureStateW( szProduct
, szFeature
);
3349 return INSTALLSTATE_INVALIDARG
;
3351 if (state
== INSTALLSTATE_LOCAL
&& dwInstallMode
!= INSTALLMODE_NODETECTION
)
3353 FIXME("mark product %s feature %s as used\n",
3354 debugstr_w(szProduct
), debugstr_w(szFeature
) );
3360 /***********************************************************************
3361 * MsiUseFeatureExA [MSI.@]
3363 INSTALLSTATE WINAPI
MsiUseFeatureExA( LPCSTR szProduct
, LPCSTR szFeature
,
3364 DWORD dwInstallMode
, DWORD dwReserved
)
3366 INSTALLSTATE ret
= INSTALLSTATE_UNKNOWN
;
3367 LPWSTR prod
= NULL
, feat
= NULL
;
3369 TRACE("%s %s %i %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3370 dwInstallMode
, dwReserved
);
3372 prod
= strdupAtoW( szProduct
);
3373 if (szProduct
&& !prod
)
3376 feat
= strdupAtoW( szFeature
);
3377 if (szFeature
&& !feat
)
3380 ret
= MsiUseFeatureExW( prod
, feat
, dwInstallMode
, dwReserved
);
3389 /***********************************************************************
3390 * MsiUseFeatureW [MSI.@]
3392 INSTALLSTATE WINAPI
MsiUseFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
)
3394 return MsiUseFeatureExW(szProduct
, szFeature
, 0, 0);
3397 /***********************************************************************
3398 * MsiUseFeatureA [MSI.@]
3400 INSTALLSTATE WINAPI
MsiUseFeatureA( LPCSTR szProduct
, LPCSTR szFeature
)
3402 return MsiUseFeatureExA(szProduct
, szFeature
, 0, 0);
3405 static WCHAR
*reg_get_multisz( HKEY hkey
, const WCHAR
*name
)
3409 if (RegQueryValueExW( hkey
, name
, NULL
, &type
, NULL
, &len
) || type
!= REG_MULTI_SZ
) return NULL
;
3410 if ((ret
= msi_alloc( len
))) RegQueryValueExW( hkey
, name
, NULL
, NULL
, (BYTE
*)ret
, &len
);
3414 static WCHAR
*reg_get_sz( HKEY hkey
, const WCHAR
*name
)
3418 if (RegQueryValueExW( hkey
, name
, NULL
, &type
, NULL
, &len
) || type
!= REG_SZ
) return NULL
;
3419 if ((ret
= msi_alloc( len
))) RegQueryValueExW( hkey
, name
, NULL
, NULL
, (BYTE
*)ret
, &len
);
3423 #define BASE85_SIZE 20
3425 /***********************************************************************
3426 * MSI_ProvideQualifiedComponentEx [internal]
3428 static UINT
MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent
,
3429 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3430 DWORD Unused1
, DWORD Unused2
, awstring
*lpPathBuf
,
3431 LPDWORD pcchPathBuf
)
3433 WCHAR product
[MAX_FEATURE_CHARS
+1], comp
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1];
3440 if (MSIREG_OpenUserComponentsKey( szComponent
, &hkey
, FALSE
)) return ERROR_UNKNOWN_COMPONENT
;
3442 desc
= reg_get_multisz( hkey
, szQualifier
);
3444 if (!desc
) return ERROR_INDEX_ABSENT
;
3446 /* FIXME: handle multiple descriptors */
3447 ret
= MsiDecomposeDescriptorW( desc
, product
, feature
, comp
, &size
);
3449 if (ret
!= ERROR_SUCCESS
) return ret
;
3451 if (!szProduct
) szProduct
= product
;
3454 MSIINSTALLCONTEXT ctx
;
3458 /* use the first component of the feature if the descriptor component is empty */
3459 if ((ret
= msi_locate_product( szProduct
, &ctx
))) return ret
;
3460 if ((ret
= MSIREG_OpenUserDataFeaturesKey( szProduct
, NULL
, ctx
, &hkey
, FALSE
)))
3462 return ERROR_FILE_NOT_FOUND
;
3464 components
= reg_get_sz( hkey
, feature
);
3465 RegCloseKey( hkey
);
3466 if (!components
) return ERROR_FILE_NOT_FOUND
;
3468 if (strlenW( components
) < BASE85_SIZE
|| !decode_base85_guid( components
, &guid
))
3470 msi_free( components
);
3471 return ERROR_FILE_NOT_FOUND
;
3473 msi_free( components
);
3474 StringFromGUID2( &guid
, comp
, sizeof(comp
)/sizeof(comp
[0]) );
3477 state
= MSI_GetComponentPath( szProduct
, comp
, szAllSid
, MSIINSTALLCONTEXT_ALL
, lpPathBuf
, pcchPathBuf
);
3479 if (state
== INSTALLSTATE_MOREDATA
) return ERROR_MORE_DATA
;
3480 if (state
!= INSTALLSTATE_LOCAL
) return ERROR_FILE_NOT_FOUND
;
3481 return ERROR_SUCCESS
;
3484 /***********************************************************************
3485 * MsiProvideQualifiedComponentExW [MSI.@]
3487 UINT WINAPI
MsiProvideQualifiedComponentExW(LPCWSTR szComponent
,
3488 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3489 DWORD Unused1
, DWORD Unused2
, LPWSTR lpPathBuf
,
3490 LPDWORD pcchPathBuf
)
3494 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_w(szComponent
),
3495 debugstr_w(szQualifier
), dwInstallMode
, debugstr_w(szProduct
),
3496 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3498 path
.unicode
= TRUE
;
3499 path
.str
.w
= lpPathBuf
;
3501 return MSI_ProvideQualifiedComponentEx(szComponent
, szQualifier
,
3502 dwInstallMode
, szProduct
, Unused1
, Unused2
, &path
, pcchPathBuf
);
3505 /***********************************************************************
3506 * MsiProvideQualifiedComponentExA [MSI.@]
3508 UINT WINAPI
MsiProvideQualifiedComponentExA(LPCSTR szComponent
,
3509 LPCSTR szQualifier
, DWORD dwInstallMode
, LPCSTR szProduct
,
3510 DWORD Unused1
, DWORD Unused2
, LPSTR lpPathBuf
,
3511 LPDWORD pcchPathBuf
)
3513 LPWSTR szwComponent
, szwQualifier
= NULL
, szwProduct
= NULL
;
3514 UINT r
= ERROR_OUTOFMEMORY
;
3517 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent
),
3518 debugstr_a(szQualifier
), dwInstallMode
, debugstr_a(szProduct
),
3519 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3521 szwComponent
= strdupAtoW( szComponent
);
3522 if (szComponent
&& !szwComponent
)
3525 szwQualifier
= strdupAtoW( szQualifier
);
3526 if (szQualifier
&& !szwQualifier
)
3529 szwProduct
= strdupAtoW( szProduct
);
3530 if (szProduct
&& !szwProduct
)
3533 path
.unicode
= FALSE
;
3534 path
.str
.a
= lpPathBuf
;
3536 r
= MSI_ProvideQualifiedComponentEx(szwComponent
, szwQualifier
,
3537 dwInstallMode
, szwProduct
, Unused1
,
3538 Unused2
, &path
, pcchPathBuf
);
3540 msi_free(szwProduct
);
3541 msi_free(szwComponent
);
3542 msi_free(szwQualifier
);
3547 /***********************************************************************
3548 * MsiProvideQualifiedComponentW [MSI.@]
3550 UINT WINAPI
MsiProvideQualifiedComponentW( LPCWSTR szComponent
,
3551 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPWSTR lpPathBuf
,
3552 LPDWORD pcchPathBuf
)
3554 return MsiProvideQualifiedComponentExW(szComponent
, szQualifier
,
3555 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3558 /***********************************************************************
3559 * MsiProvideQualifiedComponentA [MSI.@]
3561 UINT WINAPI
MsiProvideQualifiedComponentA( LPCSTR szComponent
,
3562 LPCSTR szQualifier
, DWORD dwInstallMode
, LPSTR lpPathBuf
,
3563 LPDWORD pcchPathBuf
)
3565 return MsiProvideQualifiedComponentExA(szComponent
, szQualifier
,
3566 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3569 /***********************************************************************
3570 * MSI_GetUserInfo [internal]
3572 static USERINFOSTATE
MSI_GetUserInfo(LPCWSTR szProduct
,
3573 awstring
*lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3574 awstring
*lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3575 awstring
*lpSerialBuf
, LPDWORD pcchSerialBuf
)
3577 WCHAR
*user
, *org
, *serial
, squashed_pc
[SQUASHED_GUID_SIZE
];
3578 USERINFOSTATE state
;
3583 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct
), lpUserNameBuf
,
3584 pcchUserNameBuf
, lpOrgNameBuf
, pcchOrgNameBuf
, lpSerialBuf
,
3587 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
3588 return USERINFOSTATE_INVALIDARG
;
3590 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
3591 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3592 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3593 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3594 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
3595 &hkey
, FALSE
) != ERROR_SUCCESS
)
3597 return USERINFOSTATE_UNKNOWN
;
3600 if (MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3601 NULL
, &props
, FALSE
) != ERROR_SUCCESS
&&
3602 MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
3603 NULL
, &props
, FALSE
) != ERROR_SUCCESS
)
3606 return USERINFOSTATE_ABSENT
;
3609 user
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGOWNERW
);
3610 org
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGCOMPANYW
);
3611 serial
= msi_reg_get_val_str(props
, INSTALLPROPERTY_PRODUCTIDW
);
3612 state
= USERINFOSTATE_ABSENT
;
3618 state
= USERINFOSTATE_PRESENT
;
3620 if (pcchUserNameBuf
)
3622 if (lpUserNameBuf
&& !user
)
3624 (*pcchUserNameBuf
)--;
3628 r
= msi_strcpy_to_awstring(user
, -1, lpUserNameBuf
, pcchUserNameBuf
);
3629 if (r
== ERROR_MORE_DATA
)
3631 state
= USERINFOSTATE_MOREDATA
;
3639 if (!orgptr
) orgptr
= szEmpty
;
3641 r
= msi_strcpy_to_awstring(orgptr
, -1, lpOrgNameBuf
, pcchOrgNameBuf
);
3642 if (r
== ERROR_MORE_DATA
)
3644 state
= USERINFOSTATE_MOREDATA
;
3657 r
= msi_strcpy_to_awstring(serial
, -1, lpSerialBuf
, pcchSerialBuf
);
3658 if (r
== ERROR_MORE_DATA
)
3659 state
= USERINFOSTATE_MOREDATA
;
3670 /***********************************************************************
3671 * MsiGetUserInfoW [MSI.@]
3673 USERINFOSTATE WINAPI
MsiGetUserInfoW(LPCWSTR szProduct
,
3674 LPWSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3675 LPWSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3676 LPWSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3678 awstring user
, org
, serial
;
3680 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3681 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3682 (lpSerialBuf
&& !pcchSerialBuf
))
3683 return USERINFOSTATE_INVALIDARG
;
3685 user
.unicode
= TRUE
;
3686 user
.str
.w
= lpUserNameBuf
;
3688 org
.str
.w
= lpOrgNameBuf
;
3689 serial
.unicode
= TRUE
;
3690 serial
.str
.w
= lpSerialBuf
;
3692 return MSI_GetUserInfo( szProduct
, &user
, pcchUserNameBuf
,
3693 &org
, pcchOrgNameBuf
,
3694 &serial
, pcchSerialBuf
);
3697 USERINFOSTATE WINAPI
MsiGetUserInfoA(LPCSTR szProduct
,
3698 LPSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3699 LPSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3700 LPSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3702 awstring user
, org
, serial
;
3706 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3707 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3708 (lpSerialBuf
&& !pcchSerialBuf
))
3709 return USERINFOSTATE_INVALIDARG
;
3711 prod
= strdupAtoW( szProduct
);
3712 if (szProduct
&& !prod
)
3713 return ERROR_OUTOFMEMORY
;
3715 user
.unicode
= FALSE
;
3716 user
.str
.a
= lpUserNameBuf
;
3717 org
.unicode
= FALSE
;
3718 org
.str
.a
= lpOrgNameBuf
;
3719 serial
.unicode
= FALSE
;
3720 serial
.str
.a
= lpSerialBuf
;
3722 r
= MSI_GetUserInfo( prod
, &user
, pcchUserNameBuf
,
3723 &org
, pcchOrgNameBuf
,
3724 &serial
, pcchSerialBuf
);
3731 UINT WINAPI
MsiCollectUserInfoW(LPCWSTR szProduct
)
3735 MSIPACKAGE
*package
;
3736 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3738 TRACE("(%s)\n",debugstr_w(szProduct
));
3740 rc
= MsiOpenProductW(szProduct
,&handle
);
3741 if (rc
!= ERROR_SUCCESS
)
3742 return ERROR_INVALID_PARAMETER
;
3744 /* MsiCollectUserInfo cannot be called from a custom action. */
3745 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3747 return ERROR_CALL_NOT_IMPLEMENTED
;
3749 rc
= ACTION_PerformAction(package
, szFirstRun
, SCRIPT_NONE
);
3750 msiobj_release( &package
->hdr
);
3752 MsiCloseHandle(handle
);
3757 UINT WINAPI
MsiCollectUserInfoA(LPCSTR szProduct
)
3761 MSIPACKAGE
*package
;
3762 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3764 TRACE("(%s)\n",debugstr_a(szProduct
));
3766 rc
= MsiOpenProductA(szProduct
,&handle
);
3767 if (rc
!= ERROR_SUCCESS
)
3768 return ERROR_INVALID_PARAMETER
;
3770 /* MsiCollectUserInfo cannot be called from a custom action. */
3771 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3773 return ERROR_CALL_NOT_IMPLEMENTED
;
3775 rc
= ACTION_PerformAction(package
, szFirstRun
, SCRIPT_NONE
);
3776 msiobj_release( &package
->hdr
);
3778 MsiCloseHandle(handle
);
3783 /***********************************************************************
3784 * MsiConfigureFeatureA [MSI.@]
3786 UINT WINAPI
MsiConfigureFeatureA(LPCSTR szProduct
, LPCSTR szFeature
, INSTALLSTATE eInstallState
)
3788 LPWSTR prod
, feat
= NULL
;
3789 UINT r
= ERROR_OUTOFMEMORY
;
3791 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
), eInstallState
);
3793 prod
= strdupAtoW( szProduct
);
3794 if (szProduct
&& !prod
)
3797 feat
= strdupAtoW( szFeature
);
3798 if (szFeature
&& !feat
)
3801 r
= MsiConfigureFeatureW(prod
, feat
, eInstallState
);
3810 /***********************************************************************
3811 * MsiConfigureFeatureW [MSI.@]
3813 UINT WINAPI
MsiConfigureFeatureW(LPCWSTR szProduct
, LPCWSTR szFeature
, INSTALLSTATE eInstallState
)
3815 MSIPACKAGE
*package
= NULL
;
3817 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
3820 TRACE("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
), eInstallState
);
3822 if (!szProduct
|| !szFeature
)
3823 return ERROR_INVALID_PARAMETER
;
3825 switch (eInstallState
)
3827 case INSTALLSTATE_DEFAULT
:
3828 /* FIXME: how do we figure out the default location? */
3829 eInstallState
= INSTALLSTATE_LOCAL
;
3831 case INSTALLSTATE_LOCAL
:
3832 case INSTALLSTATE_SOURCE
:
3833 case INSTALLSTATE_ABSENT
:
3834 case INSTALLSTATE_ADVERTISED
:
3837 return ERROR_INVALID_PARAMETER
;
3840 r
= MSI_OpenProductW( szProduct
, &package
);
3841 if (r
!= ERROR_SUCCESS
)
3844 sz
= sizeof(sourcepath
);
3845 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3846 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3848 sz
= sizeof(filename
);
3849 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3850 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3852 lstrcatW( sourcepath
, filename
);
3854 MsiSetInternalUI( INSTALLUILEVEL_BASIC
, NULL
);
3856 r
= ACTION_PerformAction( package
, szCostInitialize
, SCRIPT_NONE
);
3857 if (r
!= ERROR_SUCCESS
)
3860 r
= MSI_SetFeatureStateW( package
, szFeature
, eInstallState
);
3861 if (r
!= ERROR_SUCCESS
)
3864 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3867 msiobj_release( &package
->hdr
);
3872 /***********************************************************************
3873 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3875 * Notes: undocumented
3877 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved
)
3879 WCHAR path
[MAX_PATH
];
3881 TRACE("%d\n", dwReserved
);
3885 FIXME("dwReserved=%d\n", dwReserved
);
3886 return ERROR_INVALID_PARAMETER
;
3889 if (!GetWindowsDirectoryW(path
, MAX_PATH
))
3890 return ERROR_FUNCTION_FAILED
;
3892 lstrcatW(path
, installerW
);
3894 if (!CreateDirectoryW(path
, NULL
) && GetLastError() != ERROR_ALREADY_EXISTS
)
3895 return ERROR_FUNCTION_FAILED
;
3897 return ERROR_SUCCESS
;
3900 /***********************************************************************
3901 * MsiGetShortcutTargetA [MSI.@]
3903 UINT WINAPI
MsiGetShortcutTargetA( LPCSTR szShortcutTarget
,
3904 LPSTR szProductCode
, LPSTR szFeatureId
,
3905 LPSTR szComponentCode
)
3908 const int len
= MAX_FEATURE_CHARS
+1;
3909 WCHAR product
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1];
3912 target
= strdupAtoW( szShortcutTarget
);
3913 if (szShortcutTarget
&& !target
)
3914 return ERROR_OUTOFMEMORY
;
3918 r
= MsiGetShortcutTargetW( target
, product
, feature
, component
);
3920 if (r
== ERROR_SUCCESS
)
3922 WideCharToMultiByte( CP_ACP
, 0, product
, -1, szProductCode
, len
, NULL
, NULL
);
3923 WideCharToMultiByte( CP_ACP
, 0, feature
, -1, szFeatureId
, len
, NULL
, NULL
);
3924 WideCharToMultiByte( CP_ACP
, 0, component
, -1, szComponentCode
, len
, NULL
, NULL
);
3929 /***********************************************************************
3930 * MsiGetShortcutTargetW [MSI.@]
3932 UINT WINAPI
MsiGetShortcutTargetW( LPCWSTR szShortcutTarget
,
3933 LPWSTR szProductCode
, LPWSTR szFeatureId
,
3934 LPWSTR szComponentCode
)
3936 IShellLinkDataList
*dl
= NULL
;
3937 IPersistFile
*pf
= NULL
;
3938 LPEXP_DARWIN_LINK darwin
= NULL
;
3941 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget
),
3942 szProductCode
, szFeatureId
, szComponentCode
);
3944 init
= CoInitialize(NULL
);
3946 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3947 &IID_IPersistFile
, (LPVOID
*) &pf
);
3948 if( SUCCEEDED( r
) )
3950 r
= IPersistFile_Load( pf
, szShortcutTarget
,
3951 STGM_READ
| STGM_SHARE_DENY_WRITE
);
3952 if( SUCCEEDED( r
) )
3954 r
= IPersistFile_QueryInterface( pf
, &IID_IShellLinkDataList
,
3956 if( SUCCEEDED( r
) )
3958 IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
,
3960 IShellLinkDataList_Release( dl
);
3963 IPersistFile_Release( pf
);
3966 if (SUCCEEDED(init
))
3969 TRACE("darwin = %p\n", darwin
);
3976 ret
= MsiDecomposeDescriptorW( darwin
->szwDarwinID
,
3977 szProductCode
, szFeatureId
, szComponentCode
, &sz
);
3978 LocalFree( darwin
);
3982 return ERROR_FUNCTION_FAILED
;
3985 UINT WINAPI
MsiReinstallFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
, DWORD dwReinstallMode
)
3987 static const WCHAR fmtW
[] = {'%','s','=','%','s',' ','%','s','=','%','s',0};
3988 MSIPACKAGE
*package
;
3989 MSIINSTALLCONTEXT context
;
3991 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
], reinstallmode
[11];
3992 WCHAR
*ptr
, *cmdline
;
3995 TRACE("%s, %s, 0x%08x\n", debugstr_w(szProduct
), debugstr_w(szFeature
), dwReinstallMode
);
3997 r
= msi_locate_product( szProduct
, &context
);
3998 if (r
!= ERROR_SUCCESS
)
4001 ptr
= reinstallmode
;
4003 if (dwReinstallMode
& REINSTALLMODE_FILEMISSING
)
4005 if (dwReinstallMode
& REINSTALLMODE_FILEOLDERVERSION
)
4007 if (dwReinstallMode
& REINSTALLMODE_FILEEQUALVERSION
)
4009 if (dwReinstallMode
& REINSTALLMODE_FILEEXACT
)
4011 if (dwReinstallMode
& REINSTALLMODE_FILEVERIFY
)
4013 if (dwReinstallMode
& REINSTALLMODE_FILEREPLACE
)
4015 if (dwReinstallMode
& REINSTALLMODE_USERDATA
)
4017 if (dwReinstallMode
& REINSTALLMODE_MACHINEDATA
)
4019 if (dwReinstallMode
& REINSTALLMODE_SHORTCUT
)
4021 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
4025 sz
= sizeof(sourcepath
);
4026 MsiSourceListGetInfoW( szProduct
, NULL
, context
, MSICODE_PRODUCT
,
4027 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
4028 sz
= sizeof(filename
);
4029 MsiSourceListGetInfoW( szProduct
, NULL
, context
, MSICODE_PRODUCT
,
4030 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
4031 strcatW( sourcepath
, filename
);
4033 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
4034 r
= MSI_OpenPackageW( sourcepath
, &package
);
4036 r
= MSI_OpenProductW( szProduct
, &package
);
4038 if (r
!= ERROR_SUCCESS
)
4041 sz
= (strlenW( fmtW
) + strlenW( szReinstallMode
) + strlenW( reinstallmode
)) * sizeof(WCHAR
);
4042 sz
+= (strlenW( szReinstall
) + strlenW( szFeature
)) * sizeof(WCHAR
);
4043 if (!(cmdline
= msi_alloc( sz
)))
4045 msiobj_release( &package
->hdr
);
4046 return ERROR_OUTOFMEMORY
;
4048 sprintfW( cmdline
, fmtW
, szReinstallMode
, reinstallmode
, szReinstall
, szFeature
);
4050 r
= MSI_InstallPackage( package
, sourcepath
, cmdline
);
4051 msiobj_release( &package
->hdr
);
4052 msi_free( cmdline
);
4057 UINT WINAPI
MsiReinstallFeatureA( LPCSTR szProduct
, LPCSTR szFeature
,
4058 DWORD dwReinstallMode
)
4064 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
4067 wszProduct
= strdupAtoW(szProduct
);
4068 wszFeature
= strdupAtoW(szFeature
);
4070 rc
= MsiReinstallFeatureW(wszProduct
, wszFeature
, dwReinstallMode
);
4072 msi_free(wszProduct
);
4073 msi_free(wszFeature
);
4080 unsigned int buf
[4];
4081 unsigned char in
[64];
4082 unsigned char digest
[16];
4085 extern VOID WINAPI
MD5Init( MD5_CTX
*);
4086 extern VOID WINAPI
MD5Update( MD5_CTX
*, const unsigned char *, unsigned int );
4087 extern VOID WINAPI
MD5Final( MD5_CTX
*);
4089 UINT
msi_get_filehash( const WCHAR
*path
, MSIFILEHASHINFO
*hash
)
4091 HANDLE handle
, mapping
;
4094 UINT r
= ERROR_FUNCTION_FAILED
;
4096 handle
= CreateFileW( path
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, 0, NULL
);
4097 if (handle
== INVALID_HANDLE_VALUE
)
4099 WARN("can't open file %u\n", GetLastError());
4100 return ERROR_FILE_NOT_FOUND
;
4102 if ((length
= GetFileSize( handle
, NULL
)))
4104 if ((mapping
= CreateFileMappingW( handle
, NULL
, PAGE_READONLY
, 0, 0, NULL
)))
4106 if ((p
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, length
)))
4111 MD5Update( &ctx
, p
, length
);
4113 UnmapViewOfFile( p
);
4115 memcpy( hash
->dwData
, ctx
.digest
, sizeof(hash
->dwData
) );
4118 CloseHandle( mapping
);
4123 /* Empty file -> set hash to 0 */
4124 memset( hash
->dwData
, 0, sizeof(hash
->dwData
) );
4128 CloseHandle( handle
);
4132 /***********************************************************************
4133 * MsiGetFileHashW [MSI.@]
4135 UINT WINAPI
MsiGetFileHashW( LPCWSTR szFilePath
, DWORD dwOptions
,
4136 PMSIFILEHASHINFO pHash
)
4138 TRACE("%s %08x %p\n", debugstr_w(szFilePath
), dwOptions
, pHash
);
4141 return ERROR_INVALID_PARAMETER
;
4144 return ERROR_PATH_NOT_FOUND
;
4147 return ERROR_INVALID_PARAMETER
;
4149 return ERROR_INVALID_PARAMETER
;
4150 if (pHash
->dwFileHashInfoSize
< sizeof *pHash
)
4151 return ERROR_INVALID_PARAMETER
;
4153 return msi_get_filehash( szFilePath
, pHash
);
4156 /***********************************************************************
4157 * MsiGetFileHashA [MSI.@]
4159 UINT WINAPI
MsiGetFileHashA( LPCSTR szFilePath
, DWORD dwOptions
,
4160 PMSIFILEHASHINFO pHash
)
4165 TRACE("%s %08x %p\n", debugstr_a(szFilePath
), dwOptions
, pHash
);
4167 file
= strdupAtoW( szFilePath
);
4168 if (szFilePath
&& !file
)
4169 return ERROR_OUTOFMEMORY
;
4171 r
= MsiGetFileHashW( file
, dwOptions
, pHash
);
4176 /***********************************************************************
4177 * MsiAdvertiseScriptW [MSI.@]
4179 UINT WINAPI
MsiAdvertiseScriptW( LPCWSTR szScriptFile
, DWORD dwFlags
,
4180 PHKEY phRegData
, BOOL fRemoveItems
)
4182 FIXME("%s %08x %p %d\n",
4183 debugstr_w( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
4184 return ERROR_CALL_NOT_IMPLEMENTED
;
4187 /***********************************************************************
4188 * MsiAdvertiseScriptA [MSI.@]
4190 UINT WINAPI
MsiAdvertiseScriptA( LPCSTR szScriptFile
, DWORD dwFlags
,
4191 PHKEY phRegData
, BOOL fRemoveItems
)
4193 FIXME("%s %08x %p %d\n",
4194 debugstr_a( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
4195 return ERROR_CALL_NOT_IMPLEMENTED
;
4198 /***********************************************************************
4199 * MsiIsProductElevatedW [MSI.@]
4201 UINT WINAPI
MsiIsProductElevatedW( LPCWSTR szProduct
, BOOL
*pfElevated
)
4203 FIXME("%s %p - stub\n",
4204 debugstr_w( szProduct
), pfElevated
);
4206 return ERROR_SUCCESS
;
4209 /***********************************************************************
4210 * MsiIsProductElevatedA [MSI.@]
4212 UINT WINAPI
MsiIsProductElevatedA( LPCSTR szProduct
, BOOL
*pfElevated
)
4214 FIXME("%s %p - stub\n",
4215 debugstr_a( szProduct
), pfElevated
);
4217 return ERROR_SUCCESS
;
4220 /***********************************************************************
4221 * MsiSetExternalUIRecord [MSI.@]
4223 UINT WINAPI
MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler
,
4224 DWORD filter
, LPVOID context
,
4225 PINSTALLUI_HANDLER_RECORD prev
)
4227 TRACE("%p %08x %p %p\n", handler
, filter
, context
, prev
);
4230 *prev
= gUIHandlerRecord
;
4232 gUIHandlerRecord
= handler
;
4233 gUIFilterRecord
= filter
;
4234 gUIContextRecord
= context
;
4236 return ERROR_SUCCESS
;
4239 /***********************************************************************
4240 * MsiInstallMissingComponentA [MSI.@]
4242 UINT WINAPI
MsiInstallMissingComponentA( LPCSTR product
, LPCSTR component
, INSTALLSTATE state
)
4245 WCHAR
*productW
= NULL
, *componentW
= NULL
;
4247 TRACE("%s, %s, %d\n", debugstr_a(product
), debugstr_a(component
), state
);
4249 if (product
&& !(productW
= strdupAtoW( product
)))
4250 return ERROR_OUTOFMEMORY
;
4252 if (component
&& !(componentW
= strdupAtoW( component
)))
4254 msi_free( productW
);
4255 return ERROR_OUTOFMEMORY
;
4258 r
= MsiInstallMissingComponentW( productW
, componentW
, state
);
4259 msi_free( productW
);
4260 msi_free( componentW
);
4264 /***********************************************************************
4265 * MsiInstallMissingComponentW [MSI.@]
4267 UINT WINAPI
MsiInstallMissingComponentW(LPCWSTR szProduct
, LPCWSTR szComponent
, INSTALLSTATE eInstallState
)
4269 FIXME("(%s %s %d\n", debugstr_w(szProduct
), debugstr_w(szComponent
), eInstallState
);
4270 return ERROR_SUCCESS
;
4273 UINT WINAPI
MsiProvideComponentA( LPCSTR product
, LPCSTR feature
, LPCSTR component
, DWORD mode
, LPSTR buf
, LPDWORD buflen
)
4275 WCHAR
*productW
= NULL
, *componentW
= NULL
, *featureW
= NULL
, *bufW
= NULL
;
4276 UINT r
= ERROR_OUTOFMEMORY
;
4280 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_a(product
), debugstr_a(component
), debugstr_a(feature
), mode
, buf
, buflen
);
4282 if (product
&& !(productW
= strdupAtoW( product
))) goto done
;
4283 if (feature
&& !(featureW
= strdupAtoW( feature
))) goto done
;
4284 if (component
&& !(componentW
= strdupAtoW( component
))) goto done
;
4286 r
= MsiProvideComponentW( productW
, featureW
, componentW
, mode
, NULL
, &lenW
);
4287 if (r
!= ERROR_SUCCESS
)
4290 if (!(bufW
= msi_alloc( ++lenW
* sizeof(WCHAR
) )))
4292 r
= ERROR_OUTOFMEMORY
;
4296 r
= MsiProvideComponentW( productW
, featureW
, componentW
, mode
, bufW
, &lenW
);
4297 if (r
!= ERROR_SUCCESS
)
4300 len
= WideCharToMultiByte( CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
4304 r
= ERROR_MORE_DATA
;
4306 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1, buf
, *buflen
, NULL
, NULL
);
4312 msi_free( productW
);
4313 msi_free( featureW
);
4314 msi_free( componentW
);
4319 UINT WINAPI
MsiProvideComponentW( LPCWSTR product
, LPCWSTR feature
, LPCWSTR component
, DWORD mode
, LPWSTR buf
, LPDWORD buflen
)
4323 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_w(product
), debugstr_w(component
), debugstr_w(feature
), mode
, buf
, buflen
);
4325 state
= MsiQueryFeatureStateW( product
, feature
);
4326 TRACE("feature state: %d\n", state
);
4329 case INSTALLMODE_NODETECTION
:
4333 FIXME("mode %x not implemented\n", mode
);
4334 return ERROR_INSTALL_FAILURE
;
4337 state
= MsiGetComponentPathW( product
, component
, buf
, buflen
);
4338 TRACE("component state: %d\n", state
);
4341 case INSTALLSTATE_INVALIDARG
:
4342 return ERROR_INVALID_PARAMETER
;
4344 case INSTALLSTATE_MOREDATA
:
4345 return ERROR_MORE_DATA
;
4347 case INSTALLSTATE_ADVERTISED
:
4348 case INSTALLSTATE_LOCAL
:
4349 case INSTALLSTATE_SOURCE
:
4350 MsiUseFeatureW( product
, feature
);
4351 return ERROR_SUCCESS
;
4354 TRACE("MsiGetComponentPathW returned %d\n", state
);
4355 return ERROR_INSTALL_FAILURE
;
4359 /***********************************************************************
4360 * MsiBeginTransactionA [MSI.@]
4362 UINT WINAPI
MsiBeginTransactionA( LPCSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
4367 FIXME("%s %u %p %p\n", debugstr_a(name
), attrs
, id
, event
);
4369 nameW
= strdupAtoW( name
);
4371 return ERROR_OUTOFMEMORY
;
4373 r
= MsiBeginTransactionW( nameW
, attrs
, id
, event
);
4378 /***********************************************************************
4379 * MsiBeginTransactionW [MSI.@]
4381 UINT WINAPI
MsiBeginTransactionW( LPCWSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
4383 FIXME("%s %u %p %p\n", debugstr_w(name
), attrs
, id
, event
);
4385 *id
= (MSIHANDLE
)0xdeadbeef;
4386 *event
= (HANDLE
)0xdeadbeef;
4388 return ERROR_SUCCESS
;
4391 /***********************************************************************
4392 * MsiJoinTransaction [MSI.@]
4394 UINT WINAPI
MsiJoinTransaction( MSIHANDLE handle
, DWORD attrs
, HANDLE
*event
)
4396 FIXME("%u %08x %p\n", handle
, attrs
, event
);
4398 *event
= (HANDLE
)0xdeadbeef;
4399 return ERROR_SUCCESS
;
4402 /***********************************************************************
4403 * MsiEndTransaction [MSI.@]
4405 UINT WINAPI
MsiEndTransaction( DWORD state
)
4407 FIXME("%u\n", state
);
4408 return ERROR_SUCCESS
;
4411 UINT WINAPI
Migrate10CachedPackagesW(void* a
, void* b
, void* c
, DWORD d
)
4413 FIXME("%p,%p,%p,%08x\n", a
, b
, c
, d
);
4414 return ERROR_SUCCESS
;
4417 /***********************************************************************
4418 * MsiRemovePatchesA [MSI.@]
4420 UINT WINAPI
MsiRemovePatchesA(LPCSTR patchlist
, LPCSTR product
, INSTALLTYPE type
, LPCSTR propertylist
)
4422 FIXME("(%s %s %d %s\n", debugstr_a(patchlist
), debugstr_a(product
), type
, debugstr_a(propertylist
));
4423 return ERROR_SUCCESS
;
4426 /***********************************************************************
4427 * MsiRemovePatchesW [MSI.@]
4429 UINT WINAPI
MsiRemovePatchesW(LPCWSTR patchlist
, LPCWSTR product
, INSTALLTYPE type
, LPCWSTR propertylist
)
4431 FIXME("(%s %s %d %s\n", debugstr_w(patchlist
), debugstr_w(product
), type
, debugstr_w(propertylist
));
4432 return ERROR_SUCCESS
;