2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
35 #include "msiserver.h"
48 #include "wine/debug.h"
49 #include "wine/unicode.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
53 static const WCHAR installerW
[] = {'\\','I','n','s','t','a','l','l','e','r',0};
55 UINT
msi_locate_product(LPCWSTR szProduct
, MSIINSTALLCONTEXT
*context
)
59 *context
= MSIINSTALLCONTEXT_NONE
;
60 if (!szProduct
) return ERROR_UNKNOWN_PRODUCT
;
62 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
63 &hkey
, FALSE
) == ERROR_SUCCESS
)
64 *context
= MSIINSTALLCONTEXT_USERMANAGED
;
65 else if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
66 &hkey
, FALSE
) == ERROR_SUCCESS
)
67 *context
= MSIINSTALLCONTEXT_MACHINE
;
68 else if (MSIREG_OpenProductKey(szProduct
, NULL
,
69 MSIINSTALLCONTEXT_USERUNMANAGED
,
70 &hkey
, FALSE
) == ERROR_SUCCESS
)
71 *context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
75 if (*context
== MSIINSTALLCONTEXT_NONE
)
76 return ERROR_UNKNOWN_PRODUCT
;
81 UINT WINAPI
MsiOpenProductA(LPCSTR szProduct
, MSIHANDLE
*phProduct
)
84 LPWSTR szwProd
= NULL
;
86 TRACE("%s %p\n",debugstr_a(szProduct
), phProduct
);
90 szwProd
= strdupAtoW( szProduct
);
92 return ERROR_OUTOFMEMORY
;
95 r
= MsiOpenProductW( szwProd
, phProduct
);
102 static UINT
MSI_OpenProductW(LPCWSTR szProduct
, MSIPACKAGE
**package
)
107 MSIINSTALLCONTEXT context
;
109 static const WCHAR managed
[] = {
110 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
111 static const WCHAR local
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
113 TRACE("%s %p\n", debugstr_w(szProduct
), package
);
115 r
= msi_locate_product(szProduct
, &context
);
116 if (r
!= ERROR_SUCCESS
)
119 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &props
, FALSE
);
120 if (r
!= ERROR_SUCCESS
)
121 return ERROR_UNKNOWN_PRODUCT
;
123 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
124 path
= msi_reg_get_val_str(props
, managed
);
126 path
= msi_reg_get_val_str(props
, local
);
128 r
= ERROR_UNKNOWN_PRODUCT
;
130 if (!path
|| GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
133 if (PathIsRelativeW(path
))
135 r
= ERROR_INSTALL_PACKAGE_OPEN_FAILED
;
139 r
= MSI_OpenPackageW(path
, package
);
147 UINT WINAPI
MsiOpenProductW(LPCWSTR szProduct
, MSIHANDLE
*phProduct
)
149 MSIPACKAGE
*package
= NULL
;
150 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
153 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
154 return ERROR_INVALID_PARAMETER
;
157 return ERROR_INVALID_PARAMETER
;
159 r
= MSI_OpenProductW(szProduct
, &package
);
160 if (r
!= ERROR_SUCCESS
)
163 *phProduct
= alloc_msihandle(&package
->hdr
);
165 r
= ERROR_NOT_ENOUGH_MEMORY
;
167 msiobj_release(&package
->hdr
);
171 UINT WINAPI
MsiAdvertiseProductA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
172 LPCSTR szTransforms
, LANGID lgidLanguage
)
174 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath
),
175 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
), lgidLanguage
);
176 return ERROR_CALL_NOT_IMPLEMENTED
;
179 UINT WINAPI
MsiAdvertiseProductW(LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
180 LPCWSTR szTransforms
, LANGID lgidLanguage
)
182 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath
),
183 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
), lgidLanguage
);
184 return ERROR_CALL_NOT_IMPLEMENTED
;
187 UINT WINAPI
MsiAdvertiseProductExA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
188 LPCSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
190 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath
),
191 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
),
192 lgidLanguage
, dwPlatform
, dwOptions
);
193 return ERROR_CALL_NOT_IMPLEMENTED
;
196 UINT WINAPI
MsiAdvertiseProductExW( LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
197 LPCWSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
199 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath
),
200 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
),
201 lgidLanguage
, dwPlatform
, dwOptions
);
202 return ERROR_CALL_NOT_IMPLEMENTED
;
205 UINT WINAPI
MsiInstallProductA(LPCSTR szPackagePath
, LPCSTR szCommandLine
)
207 LPWSTR szwPath
= NULL
, szwCommand
= NULL
;
208 UINT r
= ERROR_OUTOFMEMORY
;
210 TRACE("%s %s\n",debugstr_a(szPackagePath
), debugstr_a(szCommandLine
));
214 szwPath
= strdupAtoW( szPackagePath
);
221 szwCommand
= strdupAtoW( szCommandLine
);
226 r
= MsiInstallProductW( szwPath
, szwCommand
);
230 msi_free( szwCommand
);
235 UINT WINAPI
MsiInstallProductW(LPCWSTR szPackagePath
, LPCWSTR szCommandLine
)
237 MSIPACKAGE
*package
= NULL
;
240 TRACE("%s %s\n",debugstr_w(szPackagePath
), debugstr_w(szCommandLine
));
243 return ERROR_INVALID_PARAMETER
;
246 return ERROR_PATH_NOT_FOUND
;
248 r
= MSI_OpenPackageW( szPackagePath
, &package
);
249 if (r
== ERROR_SUCCESS
)
251 r
= MSI_InstallPackage( package
, szPackagePath
, szCommandLine
);
252 msiobj_release( &package
->hdr
);
258 UINT WINAPI
MsiReinstallProductA(LPCSTR szProduct
, DWORD dwReinstallMode
)
263 TRACE("%s %08x\n", debugstr_a(szProduct
), dwReinstallMode
);
265 wszProduct
= strdupAtoW(szProduct
);
267 rc
= MsiReinstallProductW(wszProduct
, dwReinstallMode
);
269 msi_free(wszProduct
);
273 UINT WINAPI
MsiReinstallProductW(LPCWSTR szProduct
, DWORD dwReinstallMode
)
275 TRACE("%s %08x\n", debugstr_w(szProduct
), dwReinstallMode
);
277 return MsiReinstallFeatureW(szProduct
, szAll
, dwReinstallMode
);
280 UINT WINAPI
MsiApplyPatchA(LPCSTR szPatchPackage
, LPCSTR szInstallPackage
,
281 INSTALLTYPE eInstallType
, LPCSTR szCommandLine
)
283 LPWSTR patch_package
= NULL
;
284 LPWSTR install_package
= NULL
;
285 LPWSTR command_line
= NULL
;
286 UINT r
= ERROR_OUTOFMEMORY
;
288 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage
), debugstr_a(szInstallPackage
),
289 eInstallType
, debugstr_a(szCommandLine
));
291 if (szPatchPackage
&& !(patch_package
= strdupAtoW(szPatchPackage
)))
294 if (szInstallPackage
&& !(install_package
= strdupAtoW(szInstallPackage
)))
297 if (szCommandLine
&& !(command_line
= strdupAtoW(szCommandLine
)))
300 r
= MsiApplyPatchW(patch_package
, install_package
, eInstallType
, command_line
);
303 msi_free(patch_package
);
304 msi_free(install_package
);
305 msi_free(command_line
);
310 static UINT
get_patch_product_codes( LPCWSTR szPatchPackage
, WCHAR
***product_codes
)
312 MSIHANDLE patch
, info
= 0;
315 static WCHAR empty
[] = {0};
318 r
= MsiOpenDatabaseW( szPatchPackage
, MSIDBOPEN_READONLY
, &patch
);
319 if (r
!= ERROR_SUCCESS
)
322 r
= MsiGetSummaryInformationW( patch
, NULL
, 0, &info
);
323 if (r
!= ERROR_SUCCESS
)
327 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, empty
, &size
);
328 if (r
!= ERROR_MORE_DATA
|| !size
|| type
!= VT_LPSTR
)
330 ERR("Failed to read product codes from patch\n");
331 r
= ERROR_FUNCTION_FAILED
;
335 codes
= msi_alloc( ++size
* sizeof(WCHAR
) );
338 r
= ERROR_OUTOFMEMORY
;
342 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, codes
, &size
);
343 if (r
== ERROR_SUCCESS
)
344 *product_codes
= msi_split_string( codes
, ';' );
347 MsiCloseHandle( info
);
348 MsiCloseHandle( patch
);
353 static UINT
MSI_ApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szProductCode
, LPCWSTR szCommandLine
)
355 UINT i
, r
= ERROR_FUNCTION_FAILED
;
357 LPCWSTR cmd_ptr
= szCommandLine
;
358 LPWSTR cmd
, *codes
= NULL
;
359 BOOL succeeded
= FALSE
;
361 static const WCHAR fmt
[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
362 static const WCHAR empty
[] = {0};
364 if (!szPatchPackage
|| !szPatchPackage
[0])
365 return ERROR_INVALID_PARAMETER
;
367 if (!szProductCode
&& (r
= get_patch_product_codes( szPatchPackage
, &codes
)))
373 size
= strlenW(cmd_ptr
) + strlenW(fmt
) + strlenW(szPatchPackage
) + 1;
374 cmd
= msi_alloc(size
* sizeof(WCHAR
));
378 return ERROR_OUTOFMEMORY
;
380 sprintfW(cmd
, fmt
, cmd_ptr
, szPatchPackage
);
383 r
= MsiConfigureProductExW(szProductCode
, INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
386 for (i
= 0; codes
[i
]; i
++)
388 r
= MsiConfigureProductExW(codes
[i
], INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
389 if (r
== ERROR_SUCCESS
)
391 TRACE("patch applied\n");
405 UINT WINAPI
MsiApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szInstallPackage
,
406 INSTALLTYPE eInstallType
, LPCWSTR szCommandLine
)
408 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage
), debugstr_w(szInstallPackage
),
409 eInstallType
, debugstr_w(szCommandLine
));
411 if (szInstallPackage
|| eInstallType
== INSTALLTYPE_NETWORK_IMAGE
||
412 eInstallType
== INSTALLTYPE_SINGLE_INSTANCE
)
414 FIXME("Only reading target products from patch\n");
415 return ERROR_CALL_NOT_IMPLEMENTED
;
418 return MSI_ApplyPatchW(szPatchPackage
, NULL
, szCommandLine
);
421 UINT WINAPI
MsiApplyMultiplePatchesA(LPCSTR szPatchPackages
,
422 LPCSTR szProductCode
, LPCSTR szPropertiesList
)
424 LPWSTR patch_packages
= NULL
;
425 LPWSTR product_code
= NULL
;
426 LPWSTR properties_list
= NULL
;
427 UINT r
= ERROR_OUTOFMEMORY
;
429 TRACE("%s %s %s\n", debugstr_a(szPatchPackages
), debugstr_a(szProductCode
),
430 debugstr_a(szPropertiesList
));
432 if (!szPatchPackages
|| !szPatchPackages
[0])
433 return ERROR_INVALID_PARAMETER
;
435 if (!(patch_packages
= strdupAtoW(szPatchPackages
)))
436 return ERROR_OUTOFMEMORY
;
438 if (szProductCode
&& !(product_code
= strdupAtoW(szProductCode
)))
441 if (szPropertiesList
&& !(properties_list
= strdupAtoW(szPropertiesList
)))
444 r
= MsiApplyMultiplePatchesW(patch_packages
, product_code
, properties_list
);
447 msi_free(patch_packages
);
448 msi_free(product_code
);
449 msi_free(properties_list
);
454 UINT WINAPI
MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages
,
455 LPCWSTR szProductCode
, LPCWSTR szPropertiesList
)
457 UINT r
= ERROR_SUCCESS
;
460 TRACE("%s %s %s\n", debugstr_w(szPatchPackages
), debugstr_w(szProductCode
),
461 debugstr_w(szPropertiesList
));
463 if (!szPatchPackages
|| !szPatchPackages
[0])
464 return ERROR_INVALID_PARAMETER
;
466 beg
= end
= szPatchPackages
;
472 while (*beg
== ' ') beg
++;
473 while (*end
&& *end
!= ';') end
++;
476 while (len
&& beg
[len
- 1] == ' ') len
--;
478 if (!len
) return ERROR_INVALID_NAME
;
480 patch
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
482 return ERROR_OUTOFMEMORY
;
484 memcpy(patch
, beg
, len
* sizeof(WCHAR
));
487 r
= MSI_ApplyPatchW(patch
, szProductCode
, szPropertiesList
);
490 if (r
!= ERROR_SUCCESS
|| !*end
)
498 static void free_patchinfo( DWORD count
, MSIPATCHSEQUENCEINFOW
*info
)
501 for (i
= 0; i
< count
; i
++) msi_free( (WCHAR
*)info
[i
].szPatchData
);
505 static MSIPATCHSEQUENCEINFOW
*patchinfoAtoW( DWORD count
, const MSIPATCHSEQUENCEINFOA
*info
)
508 MSIPATCHSEQUENCEINFOW
*ret
;
510 if (!(ret
= msi_alloc( count
* sizeof(MSIPATCHSEQUENCEINFOW
) ))) return NULL
;
511 for (i
= 0; i
< count
; i
++)
513 if (info
[i
].szPatchData
&& !(ret
[i
].szPatchData
= strdupAtoW( info
[i
].szPatchData
)))
515 free_patchinfo( i
, ret
);
518 ret
[i
].ePatchDataType
= info
[i
].ePatchDataType
;
519 ret
[i
].dwOrder
= info
[i
].dwOrder
;
520 ret
[i
].uStatus
= info
[i
].uStatus
;
525 UINT WINAPI
MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath
,
526 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
529 WCHAR
*package_path
= NULL
;
530 MSIPATCHSEQUENCEINFOW
*psi
;
532 TRACE("%s, %u, %p\n", debugstr_a(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
534 if (szProductPackagePath
&& !(package_path
= strdupAtoW( szProductPackagePath
)))
535 return ERROR_OUTOFMEMORY
;
537 if (!(psi
= patchinfoAtoW( cPatchInfo
, pPatchInfo
)))
539 msi_free( package_path
);
540 return ERROR_OUTOFMEMORY
;
542 r
= MsiDetermineApplicablePatchesW( package_path
, cPatchInfo
, psi
);
543 if (r
== ERROR_SUCCESS
)
545 for (i
= 0; i
< cPatchInfo
; i
++)
547 pPatchInfo
[i
].dwOrder
= psi
[i
].dwOrder
;
548 pPatchInfo
[i
].uStatus
= psi
[i
].uStatus
;
551 msi_free( package_path
);
552 free_patchinfo( cPatchInfo
, psi
);
556 static UINT
MSI_ApplicablePatchW( MSIPACKAGE
*package
, LPCWSTR patch
)
559 MSIDATABASE
*patch_db
;
562 r
= MSI_OpenDatabaseW( patch
, MSIDBOPEN_READONLY
, &patch_db
);
563 if (r
!= ERROR_SUCCESS
)
565 WARN("failed to open patch file %s\n", debugstr_w(patch
));
569 r
= msi_get_suminfo( patch_db
->storage
, 0, &si
);
570 if (r
!= ERROR_SUCCESS
)
572 msiobj_release( &patch_db
->hdr
);
573 return ERROR_FUNCTION_FAILED
;
576 r
= msi_check_patch_applicable( package
, si
);
577 if (r
!= ERROR_SUCCESS
)
578 TRACE("patch not applicable\n");
580 msiobj_release( &patch_db
->hdr
);
581 msiobj_release( &si
->hdr
);
585 /* IXMLDOMDocument should be set to XPath mode already */
586 static UINT
MSI_ApplicablePatchXML( MSIPACKAGE
*package
, IXMLDOMDocument
*desc
)
588 static const WCHAR queryW
[] = {'M','s','i','P','a','t','c','h','/',
589 'T','a','r','g','e','t','P','r','o','d','u','c','t','/',
590 'T','a','r','g','e','t','P','r','o','d','u','c','t','C','o','d','e',0};
591 UINT r
= ERROR_FUNCTION_FAILED
;
592 IXMLDOMNodeList
*list
;
598 product_code
= msi_dup_property( package
->db
, szProductCode
);
601 /* FIXME: the property ProductCode should be written into the DB somewhere */
602 ERR("no product code to check\n");
603 return ERROR_SUCCESS
;
606 s
= SysAllocString(queryW
);
607 hr
= IXMLDOMDocument_selectNodes( desc
, s
, &list
);
610 return ERROR_INVALID_PATCH_XML
;
612 while (IXMLDOMNodeList_nextNode( list
, &node
) == S_OK
&& r
!= ERROR_SUCCESS
)
614 hr
= IXMLDOMNode_get_text( node
, &s
);
615 IXMLDOMNode_Release( node
);
618 if (!strcmpW( s
, product_code
)) r
= ERROR_SUCCESS
;
622 IXMLDOMNodeList_Release( list
);
624 if (r
!= ERROR_SUCCESS
)
625 TRACE("patch not applicable\n");
627 msi_free( product_code
);
631 static UINT
determine_patch_sequence( MSIPACKAGE
*package
, DWORD count
, MSIPATCHSEQUENCEINFOW
*info
)
633 IXMLDOMDocument
*desc
= NULL
;
637 FIXME("patch ordering not supported\n");
639 for (i
= 0; i
< count
; i
++)
641 switch (info
[i
].ePatchDataType
)
643 case MSIPATCH_DATATYPE_PATCHFILE
:
645 if (MSI_ApplicablePatchW( package
, info
[i
].szPatchData
) != ERROR_SUCCESS
)
647 info
[i
].dwOrder
= ~0u;
648 info
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
653 info
[i
].uStatus
= ERROR_SUCCESS
;
657 case MSIPATCH_DATATYPE_XMLPATH
:
658 case MSIPATCH_DATATYPE_XMLBLOB
:
666 hr
= CoCreateInstance( &CLSID_DOMDocument30
, NULL
, CLSCTX_INPROC_SERVER
,
667 &IID_IXMLDOMDocument
, (void**)&desc
);
670 ERR("failed to create DOMDocument30 instance, 0x%08x\n", hr
);
671 return ERROR_FUNCTION_FAILED
;
675 s
= SysAllocString( info
[i
].szPatchData
);
676 if (info
[i
].ePatchDataType
== MSIPATCH_DATATYPE_XMLPATH
)
680 V_VT(&src
) = VT_BSTR
;
682 hr
= IXMLDOMDocument_load( desc
, src
, &b
);
685 hr
= IXMLDOMDocument_loadXML( desc
, s
, &b
);
689 ERR("failed to parse patch description\n");
690 IXMLDOMDocument_Release( desc
);
694 if (MSI_ApplicablePatchXML( package
, desc
) != ERROR_SUCCESS
)
696 info
[i
].dwOrder
= ~0u;
697 info
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
702 info
[i
].uStatus
= ERROR_SUCCESS
;
708 FIXME("unknown patch data type %u\n", info
[i
].ePatchDataType
);
710 info
[i
].uStatus
= ERROR_SUCCESS
;
715 TRACE("szPatchData: %s\n", debugstr_w(info
[i
].szPatchData
));
716 TRACE("ePatchDataType: %u\n", info
[i
].ePatchDataType
);
717 TRACE("dwOrder: %u\n", info
[i
].dwOrder
);
718 TRACE("uStatus: %u\n", info
[i
].uStatus
);
721 if (desc
) IXMLDOMDocument_Release( desc
);
723 return ERROR_SUCCESS
;
726 UINT WINAPI
MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath
,
727 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
732 TRACE("%s, %u, %p\n", debugstr_w(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
734 r
= MSI_OpenPackageW( szProductPackagePath
, &package
);
735 if (r
!= ERROR_SUCCESS
)
737 ERR("failed to open package %u\n", r
);
740 r
= determine_patch_sequence( package
, cPatchInfo
, pPatchInfo
);
741 msiobj_release( &package
->hdr
);
745 UINT WINAPI
MsiDeterminePatchSequenceA( LPCSTR product
, LPCSTR usersid
,
746 MSIINSTALLCONTEXT context
, DWORD count
, PMSIPATCHSEQUENCEINFOA patchinfo
)
749 WCHAR
*productW
, *usersidW
= NULL
;
750 MSIPATCHSEQUENCEINFOW
*patchinfoW
;
752 TRACE("%s, %s, %d, %d, %p\n", debugstr_a(product
), debugstr_a(usersid
),
753 context
, count
, patchinfo
);
755 if (!product
) return ERROR_INVALID_PARAMETER
;
756 if (!(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
757 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
759 msi_free( productW
);
760 return ERROR_OUTOFMEMORY
;
762 if (!(patchinfoW
= patchinfoAtoW( count
, patchinfo
)))
764 msi_free( productW
);
765 msi_free( usersidW
);
766 return ERROR_OUTOFMEMORY
;
768 r
= MsiDeterminePatchSequenceW( productW
, usersidW
, context
, count
, patchinfoW
);
769 if (r
== ERROR_SUCCESS
)
771 for (i
= 0; i
< count
; i
++)
773 patchinfo
[i
].dwOrder
= patchinfoW
[i
].dwOrder
;
774 patchinfo
[i
].uStatus
= patchinfoW
[i
].uStatus
;
777 msi_free( productW
);
778 msi_free( usersidW
);
779 free_patchinfo( count
, patchinfoW
);
783 static UINT
open_package( const WCHAR
*product
, const WCHAR
*usersid
,
784 MSIINSTALLCONTEXT context
, MSIPACKAGE
**package
)
788 WCHAR
*localpath
, sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
790 r
= MSIREG_OpenInstallProps( product
, context
, usersid
, &props
, FALSE
);
791 if (r
!= ERROR_SUCCESS
) return ERROR_BAD_CONFIGURATION
;
793 if ((localpath
= msi_reg_get_val_str( props
, szLocalPackage
)))
795 strcpyW( sourcepath
, localpath
);
796 msi_free( localpath
);
798 RegCloseKey( props
);
799 if (!localpath
|| GetFileAttributesW( sourcepath
) == INVALID_FILE_ATTRIBUTES
)
801 DWORD sz
= sizeof(sourcepath
);
802 MsiSourceListGetInfoW( product
, usersid
, context
, MSICODE_PRODUCT
,
803 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
804 sz
= sizeof(filename
);
805 MsiSourceListGetInfoW( product
, usersid
, context
, MSICODE_PRODUCT
,
806 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
807 strcatW( sourcepath
, filename
);
809 if (GetFileAttributesW( sourcepath
) == INVALID_FILE_ATTRIBUTES
)
810 return ERROR_INSTALL_SOURCE_ABSENT
;
812 return MSI_OpenPackageW( sourcepath
, package
);
815 UINT WINAPI
MsiDeterminePatchSequenceW( LPCWSTR product
, LPCWSTR usersid
,
816 MSIINSTALLCONTEXT context
, DWORD count
, PMSIPATCHSEQUENCEINFOW patchinfo
)
821 TRACE("%s, %s, %d, %d, %p\n", debugstr_w(product
), debugstr_w(usersid
),
822 context
, count
, patchinfo
);
824 if (!product
) return ERROR_INVALID_PARAMETER
;
825 r
= open_package( product
, usersid
, context
, &package
);
826 if (r
!= ERROR_SUCCESS
) return r
;
828 r
= determine_patch_sequence( package
, count
, patchinfo
);
829 msiobj_release( &package
->hdr
);
833 UINT WINAPI
MsiConfigureProductExW(LPCWSTR szProduct
, int iInstallLevel
,
834 INSTALLSTATE eInstallState
, LPCWSTR szCommandLine
)
836 MSIPACKAGE
* package
= NULL
;
837 MSIINSTALLCONTEXT context
;
840 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
843 static const WCHAR szInstalled
[] = {
844 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
845 static const WCHAR szMaxInstallLevel
[] = {
846 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
847 static const WCHAR szRemoveAll
[] = {
848 ' ','R','E','M','O','V','E','=','A','L','L',0};
849 static const WCHAR szMachine
[] = {
850 ' ','A','L','L','U','S','E','R','S','=','1',0};
852 TRACE("%s %d %d %s\n",debugstr_w(szProduct
), iInstallLevel
, eInstallState
,
853 debugstr_w(szCommandLine
));
855 if (!szProduct
|| lstrlenW(szProduct
) != GUID_SIZE
- 1)
856 return ERROR_INVALID_PARAMETER
;
858 if (eInstallState
== INSTALLSTATE_ADVERTISED
||
859 eInstallState
== INSTALLSTATE_SOURCE
)
861 FIXME("State %d not implemented\n", eInstallState
);
862 return ERROR_CALL_NOT_IMPLEMENTED
;
865 r
= msi_locate_product(szProduct
, &context
);
866 if (r
!= ERROR_SUCCESS
)
869 r
= open_package(szProduct
, NULL
, context
, &package
);
870 if (r
!= ERROR_SUCCESS
)
873 sz
= lstrlenW(szInstalled
) + 1;
876 sz
+= lstrlenW(szCommandLine
);
878 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
879 sz
+= lstrlenW(szMaxInstallLevel
);
881 if (eInstallState
== INSTALLSTATE_ABSENT
)
882 sz
+= lstrlenW(szRemoveAll
);
884 if (context
== MSIINSTALLCONTEXT_MACHINE
)
885 sz
+= lstrlenW(szMachine
);
887 commandline
= msi_alloc(sz
* sizeof(WCHAR
));
890 r
= ERROR_OUTOFMEMORY
;
896 lstrcpyW(commandline
,szCommandLine
);
898 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
899 lstrcatW(commandline
, szMaxInstallLevel
);
901 if (eInstallState
== INSTALLSTATE_ABSENT
)
902 lstrcatW(commandline
, szRemoveAll
);
904 if (context
== MSIINSTALLCONTEXT_MACHINE
)
905 lstrcatW(commandline
, szMachine
);
907 sz
= sizeof(sourcepath
);
908 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
909 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
911 sz
= sizeof(filename
);
912 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
913 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
915 strcatW(sourcepath
, filename
);
917 r
= MSI_InstallPackage( package
, sourcepath
, commandline
);
919 msi_free(commandline
);
922 msiobj_release( &package
->hdr
);
927 UINT WINAPI
MsiConfigureProductExA(LPCSTR szProduct
, int iInstallLevel
,
928 INSTALLSTATE eInstallState
, LPCSTR szCommandLine
)
930 LPWSTR szwProduct
= NULL
;
931 LPWSTR szwCommandLine
= NULL
;
932 UINT r
= ERROR_OUTOFMEMORY
;
936 szwProduct
= strdupAtoW( szProduct
);
943 szwCommandLine
= strdupAtoW( szCommandLine
);
948 r
= MsiConfigureProductExW( szwProduct
, iInstallLevel
, eInstallState
,
951 msi_free( szwProduct
);
952 msi_free( szwCommandLine
);
957 UINT WINAPI
MsiConfigureProductA(LPCSTR szProduct
, int iInstallLevel
,
958 INSTALLSTATE eInstallState
)
960 LPWSTR szwProduct
= NULL
;
963 TRACE("%s %d %d\n",debugstr_a(szProduct
), iInstallLevel
, eInstallState
);
967 szwProduct
= strdupAtoW( szProduct
);
969 return ERROR_OUTOFMEMORY
;
972 r
= MsiConfigureProductW( szwProduct
, iInstallLevel
, eInstallState
);
973 msi_free( szwProduct
);
978 UINT WINAPI
MsiConfigureProductW(LPCWSTR szProduct
, int iInstallLevel
,
979 INSTALLSTATE eInstallState
)
981 return MsiConfigureProductExW(szProduct
, iInstallLevel
, eInstallState
, NULL
);
984 UINT WINAPI
MsiGetProductCodeA(LPCSTR szComponent
, LPSTR szBuffer
)
986 LPWSTR szwComponent
= NULL
;
988 WCHAR szwBuffer
[GUID_SIZE
];
990 TRACE("%s %p\n", debugstr_a(szComponent
), szBuffer
);
994 szwComponent
= strdupAtoW( szComponent
);
996 return ERROR_OUTOFMEMORY
;
1000 r
= MsiGetProductCodeW( szwComponent
, szwBuffer
);
1003 WideCharToMultiByte(CP_ACP
, 0, szwBuffer
, -1, szBuffer
, GUID_SIZE
, NULL
, NULL
);
1005 msi_free( szwComponent
);
1010 UINT WINAPI
MsiGetProductCodeW(LPCWSTR szComponent
, LPWSTR szBuffer
)
1013 HKEY compkey
, prodkey
;
1014 WCHAR squashed_comp
[SQUASHED_GUID_SIZE
], squashed_prod
[SQUASHED_GUID_SIZE
];
1015 DWORD sz
= sizeof(squashed_prod
)/sizeof(squashed_prod
[0]);
1017 TRACE("%s %p\n", debugstr_w(szComponent
), szBuffer
);
1019 if (!szComponent
|| !*szComponent
)
1020 return ERROR_INVALID_PARAMETER
;
1022 if (!squash_guid( szComponent
, squashed_comp
))
1023 return ERROR_INVALID_PARAMETER
;
1025 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &compkey
, FALSE
) != ERROR_SUCCESS
&&
1026 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &compkey
, FALSE
) != ERROR_SUCCESS
)
1028 return ERROR_UNKNOWN_COMPONENT
;
1031 rc
= RegEnumValueW( compkey
, 0, squashed_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
1032 if (rc
!= ERROR_SUCCESS
)
1034 RegCloseKey(compkey
);
1035 return ERROR_UNKNOWN_COMPONENT
;
1038 /* check simple case, only one product */
1039 rc
= RegEnumValueW( compkey
, 1, squashed_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
1040 if (rc
== ERROR_NO_MORE_ITEMS
)
1047 while ((rc
= RegEnumValueW( compkey
, index
, squashed_prod
, &sz
, NULL
, NULL
, NULL
, NULL
)) !=
1048 ERROR_NO_MORE_ITEMS
)
1052 unsquash_guid( squashed_prod
, szBuffer
);
1054 if (MSIREG_OpenProductKey(szBuffer
, NULL
,
1055 MSIINSTALLCONTEXT_USERMANAGED
,
1056 &prodkey
, FALSE
) == ERROR_SUCCESS
||
1057 MSIREG_OpenProductKey(szBuffer
, NULL
,
1058 MSIINSTALLCONTEXT_USERUNMANAGED
,
1059 &prodkey
, FALSE
) == ERROR_SUCCESS
||
1060 MSIREG_OpenProductKey(szBuffer
, NULL
,
1061 MSIINSTALLCONTEXT_MACHINE
,
1062 &prodkey
, FALSE
) == ERROR_SUCCESS
)
1064 RegCloseKey(prodkey
);
1070 rc
= ERROR_INSTALL_FAILURE
;
1073 RegCloseKey(compkey
);
1074 unsquash_guid( squashed_prod
, szBuffer
);
1078 static WCHAR
*reg_get_value( HKEY hkey
, const WCHAR
*name
, DWORD
*type
)
1082 if ((res
= RegQueryValueExW( hkey
, name
, NULL
, type
, NULL
, NULL
)) != ERROR_SUCCESS
) return NULL
;
1084 if (*type
== REG_SZ
) return msi_reg_get_val_str( hkey
, name
);
1085 if (*type
== REG_DWORD
)
1087 static const WCHAR fmt
[] = {'%','u',0};
1091 if (!msi_reg_get_val_dword( hkey
, name
, &val
)) return NULL
;
1092 sprintfW( temp
, fmt
, val
);
1093 return strdupW( temp
);
1096 ERR( "unhandled value type %u\n", *type
);
1100 static UINT
MSI_GetProductInfo(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1101 awstring
*szValue
, LPDWORD pcchValueBuf
)
1103 static WCHAR empty
[] = {0};
1104 static const WCHAR sourcelist
[] = {'S','o','u','r','c','e','L','i','s','t',0};
1105 static const WCHAR display_name
[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
1106 static const WCHAR display_version
[] = {'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1107 static const WCHAR assignment
[] = {'A','s','s','i','g','n','m','e','n','t',0};
1108 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
1109 UINT r
= ERROR_UNKNOWN_PROPERTY
;
1110 HKEY prodkey
, userdata
, source
;
1111 WCHAR
*val
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
], packagecode
[GUID_SIZE
];
1112 BOOL badconfig
= FALSE
;
1114 DWORD type
= REG_NONE
;
1116 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
1117 debugstr_w(szAttribute
), szValue
, pcchValueBuf
);
1119 if ((szValue
->str
.w
&& !pcchValueBuf
) || !szProduct
|| !szAttribute
)
1120 return ERROR_INVALID_PARAMETER
;
1122 if (!squash_guid( szProduct
, squashed_pc
))
1123 return ERROR_INVALID_PARAMETER
;
1125 if ((r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1126 MSIINSTALLCONTEXT_USERMANAGED
,
1127 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
1128 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1129 MSIINSTALLCONTEXT_USERUNMANAGED
,
1130 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
1131 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1132 MSIINSTALLCONTEXT_MACHINE
,
1133 &prodkey
, FALSE
)) == ERROR_SUCCESS
)
1135 context
= MSIINSTALLCONTEXT_MACHINE
;
1138 if (!strcmpW( szAttribute
, INSTALLPROPERTY_HELPLINKW
) ||
1139 !strcmpW( szAttribute
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1140 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLDATEW
) ||
1141 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1142 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1143 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1144 !strcmpW( szAttribute
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1145 !strcmpW( szAttribute
, INSTALLPROPERTY_PUBLISHERW
) ||
1146 !strcmpW( szAttribute
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1147 !strcmpW( szAttribute
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1148 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMINORW
) ||
1149 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1150 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1151 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTIDW
) ||
1152 !strcmpW( szAttribute
, INSTALLPROPERTY_REGCOMPANYW
) ||
1153 !strcmpW( szAttribute
, INSTALLPROPERTY_REGOWNERW
))
1157 r
= ERROR_UNKNOWN_PRODUCT
;
1160 if (MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
))
1162 r
= ERROR_UNKNOWN_PROPERTY
;
1166 if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1167 szAttribute
= display_name
;
1168 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
))
1169 szAttribute
= display_version
;
1171 val
= reg_get_value(userdata
, szAttribute
, &type
);
1174 RegCloseKey(userdata
);
1176 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTANCETYPEW
) ||
1177 !strcmpW( szAttribute
, INSTALLPROPERTY_TRANSFORMSW
) ||
1178 !strcmpW( szAttribute
, INSTALLPROPERTY_LANGUAGEW
) ||
1179 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1180 !strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
) ||
1181 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
) ||
1182 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONW
) ||
1183 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTICONW
) ||
1184 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1185 !strcmpW( szAttribute
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1189 r
= ERROR_UNKNOWN_PRODUCT
;
1193 if (!strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1194 szAttribute
= assignment
;
1196 if (!strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
))
1198 res
= RegOpenKeyW(prodkey
, sourcelist
, &source
);
1199 if (res
!= ERROR_SUCCESS
)
1201 r
= ERROR_UNKNOWN_PRODUCT
;
1205 val
= reg_get_value(source
, szAttribute
, &type
);
1209 RegCloseKey(source
);
1213 val
= reg_get_value(prodkey
, szAttribute
, &type
);
1218 if (val
!= empty
&& type
!= REG_DWORD
&&
1219 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
))
1221 if (lstrlenW( val
) != SQUASHED_GUID_SIZE
- 1)
1225 unsquash_guid(val
, packagecode
);
1227 val
= strdupW(packagecode
);
1234 r
= ERROR_UNKNOWN_PROPERTY
;
1240 int len
= strlenW( val
);
1242 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1243 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1244 * can't rely on its value.
1246 if (szValue
->str
.a
|| szValue
->str
.w
)
1248 DWORD size
= *pcchValueBuf
;
1250 r
= msi_strcpy_to_awstring( val
, len
, szValue
, &size
);
1252 r
= ERROR_MORE_DATA
;
1256 *pcchValueBuf
= len
;
1260 r
= ERROR_BAD_CONFIGURATION
;
1266 RegCloseKey(prodkey
);
1270 UINT WINAPI
MsiGetProductInfoA(LPCSTR szProduct
, LPCSTR szAttribute
,
1271 LPSTR szBuffer
, LPDWORD pcchValueBuf
)
1273 LPWSTR szwProduct
, szwAttribute
= NULL
;
1274 UINT r
= ERROR_OUTOFMEMORY
;
1277 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szAttribute
),
1278 szBuffer
, pcchValueBuf
);
1280 szwProduct
= strdupAtoW( szProduct
);
1281 if( szProduct
&& !szwProduct
)
1284 szwAttribute
= strdupAtoW( szAttribute
);
1285 if( szAttribute
&& !szwAttribute
)
1288 buffer
.unicode
= FALSE
;
1289 buffer
.str
.a
= szBuffer
;
1291 r
= MSI_GetProductInfo( szwProduct
, szwAttribute
,
1292 &buffer
, pcchValueBuf
);
1295 msi_free( szwProduct
);
1296 msi_free( szwAttribute
);
1301 UINT WINAPI
MsiGetProductInfoW(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1302 LPWSTR szBuffer
, LPDWORD pcchValueBuf
)
1306 TRACE("%s %s %p %p\n", debugstr_w(szProduct
), debugstr_w(szAttribute
),
1307 szBuffer
, pcchValueBuf
);
1309 buffer
.unicode
= TRUE
;
1310 buffer
.str
.w
= szBuffer
;
1312 return MSI_GetProductInfo( szProduct
, szAttribute
,
1313 &buffer
, pcchValueBuf
);
1316 UINT WINAPI
MsiGetProductInfoExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1317 MSIINSTALLCONTEXT dwContext
, LPCSTR szProperty
,
1318 LPSTR szValue
, LPDWORD pcchValue
)
1320 LPWSTR product
= NULL
;
1321 LPWSTR usersid
= NULL
;
1322 LPWSTR property
= NULL
;
1323 LPWSTR value
= NULL
;
1327 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode
),
1328 debugstr_a(szUserSid
), dwContext
, debugstr_a(szProperty
),
1329 szValue
, pcchValue
);
1331 if (szValue
&& !pcchValue
)
1332 return ERROR_INVALID_PARAMETER
;
1334 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1335 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1336 if (szProperty
) property
= strdupAtoW(szProperty
);
1338 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1340 if (r
!= ERROR_SUCCESS
)
1343 value
= msi_alloc(++len
* sizeof(WCHAR
));
1346 r
= ERROR_OUTOFMEMORY
;
1350 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1352 if (r
!= ERROR_SUCCESS
)
1358 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
1359 if (*pcchValue
>= len
)
1360 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
1363 r
= ERROR_MORE_DATA
;
1368 if (*pcchValue
<= len
|| !szValue
)
1369 len
= len
* sizeof(WCHAR
) - 1;
1371 *pcchValue
= len
- 1;
1382 static UINT
msi_copy_outval(LPWSTR val
, LPWSTR out
, LPDWORD size
)
1384 UINT r
= ERROR_SUCCESS
;
1387 return ERROR_UNKNOWN_PROPERTY
;
1391 if (strlenW(val
) >= *size
)
1393 r
= ERROR_MORE_DATA
;
1402 *size
= lstrlenW(val
);
1407 UINT WINAPI
MsiGetProductInfoExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
1408 MSIINSTALLCONTEXT dwContext
, LPCWSTR szProperty
,
1409 LPWSTR szValue
, LPDWORD pcchValue
)
1411 static const WCHAR five
[] = {'5',0};
1412 static const WCHAR displayname
[] = {
1413 'D','i','s','p','l','a','y','N','a','m','e',0};
1414 static const WCHAR displayversion
[] = {
1415 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1416 static const WCHAR managed_local_package
[] = {
1417 'M','a','n','a','g','e','d','L','o','c','a','l',
1418 'P','a','c','k','a','g','e',0};
1419 WCHAR
*val
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
];
1420 LPCWSTR package
= NULL
;
1421 HKEY props
= NULL
, prod
, classes
= NULL
, managed
, hkey
= NULL
;
1423 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1425 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode
),
1426 debugstr_w(szUserSid
), dwContext
, debugstr_w(szProperty
),
1427 szValue
, pcchValue
);
1429 if (!szProductCode
|| !squash_guid( szProductCode
, squashed_pc
))
1430 return ERROR_INVALID_PARAMETER
;
1432 if (szValue
&& !pcchValue
)
1433 return ERROR_INVALID_PARAMETER
;
1435 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1436 dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1437 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1438 return ERROR_INVALID_PARAMETER
;
1440 if (!szProperty
|| !*szProperty
)
1441 return ERROR_INVALID_PARAMETER
;
1443 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1444 return ERROR_INVALID_PARAMETER
;
1446 /* FIXME: dwContext is provided, no need to search for it */
1447 MSIREG_OpenProductKey(szProductCode
, NULL
,MSIINSTALLCONTEXT_USERMANAGED
,
1449 MSIREG_OpenProductKey(szProductCode
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1452 MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
, &props
, FALSE
);
1454 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1456 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1458 if (!props
&& !prod
)
1461 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1463 package
= managed_local_package
;
1465 if (!props
&& !managed
)
1468 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1470 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1471 MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
, &classes
, FALSE
);
1473 if (!props
&& !classes
)
1477 if (!strcmpW( szProperty
, INSTALLPROPERTY_HELPLINKW
) ||
1478 !strcmpW( szProperty
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1479 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
) ||
1480 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1481 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1482 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1483 !strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1484 !strcmpW( szProperty
, INSTALLPROPERTY_PUBLISHERW
) ||
1485 !strcmpW( szProperty
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1486 !strcmpW( szProperty
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1487 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMINORW
) ||
1488 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1489 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1490 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTIDW
) ||
1491 !strcmpW( szProperty
, INSTALLPROPERTY_REGCOMPANYW
) ||
1492 !strcmpW( szProperty
, INSTALLPROPERTY_REGOWNERW
) ||
1493 !strcmpW( szProperty
, INSTALLPROPERTY_INSTANCETYPEW
))
1495 val
= reg_get_value(props
, package
, &type
);
1498 if (prod
|| classes
)
1499 r
= ERROR_UNKNOWN_PROPERTY
;
1506 if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1507 szProperty
= displayname
;
1508 else if (!strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
))
1509 szProperty
= displayversion
;
1511 val
= reg_get_value(props
, szProperty
, &type
);
1513 val
= strdupW(szEmpty
);
1515 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1517 else if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
) ||
1518 !strcmpW( szProperty
, INSTALLPROPERTY_LANGUAGEW
) ||
1519 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1520 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGECODEW
) ||
1521 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONW
) ||
1522 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTICONW
) ||
1523 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1524 !strcmpW( szProperty
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1526 if (!prod
&& !classes
)
1529 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1531 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1533 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1536 val
= reg_get_value(hkey
, szProperty
, &type
);
1538 val
= strdupW(szEmpty
);
1540 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1542 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTSTATEW
))
1544 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1548 val
= reg_get_value(props
, package
, &type
);
1553 val
= strdupW(five
);
1556 val
= strdupW(szOne
);
1558 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1561 else if (props
&& (val
= reg_get_value(props
, package
, &type
)))
1564 val
= strdupW(five
);
1565 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1569 if (prod
|| managed
)
1570 val
= strdupW(szOne
);
1574 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1576 else if (!strcmpW( szProperty
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1578 if (!prod
&& !classes
)
1582 val
= strdupW(szEmpty
);
1583 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1586 r
= ERROR_UNKNOWN_PROPERTY
;
1591 RegCloseKey(managed
);
1592 RegCloseKey(classes
);
1598 UINT WINAPI
MsiGetPatchFileListA(LPCSTR szProductCode
, LPCSTR szPatchList
,
1599 LPDWORD pcFiles
, MSIHANDLE
**pphFileRecords
)
1601 FIXME("(%s, %s, %p, %p) stub!\n", debugstr_a(szProductCode
),
1602 debugstr_a(szPatchList
), pcFiles
, pphFileRecords
);
1603 return ERROR_FUNCTION_FAILED
;
1606 UINT WINAPI
MsiGetPatchFileListW(LPCWSTR szProductCode
, LPCWSTR szPatchList
,
1607 LPDWORD pcFiles
, MSIHANDLE
**pphFileRecords
)
1609 FIXME("(%s, %s, %p, %p) stub!\n", debugstr_w(szProductCode
),
1610 debugstr_w(szPatchList
), pcFiles
, pphFileRecords
);
1611 return ERROR_FUNCTION_FAILED
;
1614 UINT WINAPI
MsiGetPatchInfoExA(LPCSTR szPatchCode
, LPCSTR szProductCode
,
1615 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1616 LPCSTR szProperty
, LPSTR lpValue
, DWORD
*pcchValue
)
1618 LPWSTR patch
= NULL
, product
= NULL
, usersid
= NULL
;
1619 LPWSTR property
= NULL
, val
= NULL
;
1623 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode
),
1624 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
,
1625 debugstr_a(szProperty
), lpValue
, pcchValue
);
1627 if (lpValue
&& !pcchValue
)
1628 return ERROR_INVALID_PARAMETER
;
1630 if (szPatchCode
) patch
= strdupAtoW(szPatchCode
);
1631 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1632 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1633 if (szProperty
) property
= strdupAtoW(szProperty
);
1636 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1638 if (r
!= ERROR_SUCCESS
)
1641 val
= msi_alloc(++len
* sizeof(WCHAR
));
1644 r
= ERROR_OUTOFMEMORY
;
1648 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1650 if (r
!= ERROR_SUCCESS
|| !pcchValue
)
1654 WideCharToMultiByte(CP_ACP
, 0, val
, -1, lpValue
,
1655 *pcchValue
- 1, NULL
, NULL
);
1657 len
= lstrlenW(val
);
1658 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1662 r
= ERROR_MORE_DATA
;
1663 lpValue
[*pcchValue
- 1] = '\0';
1666 *pcchValue
= len
* sizeof(WCHAR
);
1681 UINT WINAPI
MsiGetPatchInfoExW(LPCWSTR szPatchCode
, LPCWSTR szProductCode
,
1682 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1683 LPCWSTR szProperty
, LPWSTR lpValue
, DWORD
*pcchValue
)
1685 static const WCHAR szManagedPackage
[] =
1686 {'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
1687 WCHAR
*val
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
], squashed_patch
[SQUASHED_GUID_SIZE
];
1688 HKEY udprod
= 0, prod
= 0, props
= 0;
1689 HKEY patch
= 0, patches
= 0;
1690 HKEY udpatch
= 0, datakey
= 0;
1691 HKEY prodpatches
= 0;
1692 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1696 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode
),
1697 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
,
1698 debugstr_w(szProperty
), lpValue
, pcchValue
);
1700 if (!szProductCode
|| !squash_guid( szProductCode
, squashed_pc
))
1701 return ERROR_INVALID_PARAMETER
;
1703 if (!szPatchCode
|| !squash_guid( szPatchCode
, squashed_patch
))
1704 return ERROR_INVALID_PARAMETER
;
1707 return ERROR_INVALID_PARAMETER
;
1709 if (lpValue
&& !pcchValue
)
1710 return ERROR_INVALID_PARAMETER
;
1712 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1713 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1714 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1715 return ERROR_INVALID_PARAMETER
;
1717 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1718 return ERROR_INVALID_PARAMETER
;
1720 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
1721 return ERROR_INVALID_PARAMETER
;
1723 if (MSIREG_OpenUserDataProductKey(szProductCode
, dwContext
, NULL
,
1724 &udprod
, FALSE
) != ERROR_SUCCESS
)
1727 if (MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
,
1728 &props
, FALSE
) != ERROR_SUCCESS
)
1731 r
= ERROR_UNKNOWN_PATCH
;
1733 res
= RegOpenKeyExW(udprod
, szPatches
, 0, KEY_WOW64_64KEY
|KEY_READ
, &patches
);
1734 if (res
!= ERROR_SUCCESS
)
1737 res
= RegOpenKeyExW( patches
, squashed_patch
, 0, KEY_WOW64_64KEY
|KEY_READ
, &patch
);
1738 if (res
!= ERROR_SUCCESS
)
1741 if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
))
1743 if (MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
,
1744 &prod
, FALSE
) != ERROR_SUCCESS
)
1747 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_WOW64_64KEY
|KEY_ALL_ACCESS
, &prodpatches
);
1748 if (res
!= ERROR_SUCCESS
)
1751 datakey
= prodpatches
;
1752 szProperty
= squashed_patch
;
1756 if (MSIREG_OpenUserDataPatchKey(szPatchCode
, dwContext
,
1757 &udpatch
, FALSE
) != ERROR_SUCCESS
)
1760 if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1762 if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1763 szProperty
= szManagedPackage
;
1766 else if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
))
1769 szProperty
= szInstalled
;
1771 else if (!strcmpW( szProperty
, INSTALLPROPERTY_UNINSTALLABLEW
) ||
1772 !strcmpW( szProperty
, INSTALLPROPERTY_PATCHSTATEW
) ||
1773 !strcmpW( szProperty
, INSTALLPROPERTY_DISPLAYNAMEW
) ||
1774 !strcmpW( szProperty
, INSTALLPROPERTY_MOREINFOURLW
))
1780 r
= ERROR_UNKNOWN_PROPERTY
;
1785 val
= reg_get_value(datakey
, szProperty
, &type
);
1787 val
= strdupW(szEmpty
);
1795 lstrcpynW(lpValue
, val
, *pcchValue
);
1797 len
= lstrlenW(val
);
1798 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1801 r
= ERROR_MORE_DATA
;
1803 *pcchValue
= len
* sizeof(WCHAR
);
1810 RegCloseKey(prodpatches
);
1813 RegCloseKey(patches
);
1814 RegCloseKey(udpatch
);
1816 RegCloseKey(udprod
);
1821 UINT WINAPI
MsiGetPatchInfoA( LPCSTR patch
, LPCSTR attr
, LPSTR buffer
, LPDWORD buflen
)
1823 UINT r
= ERROR_OUTOFMEMORY
;
1825 LPWSTR patchW
= NULL
, attrW
= NULL
, bufferW
= NULL
;
1827 TRACE("%s %s %p %p\n", debugstr_a(patch
), debugstr_a(attr
), buffer
, buflen
);
1829 if (!patch
|| !attr
)
1830 return ERROR_INVALID_PARAMETER
;
1832 if (!(patchW
= strdupAtoW( patch
)))
1835 if (!(attrW
= strdupAtoW( attr
)))
1839 r
= MsiGetPatchInfoW( patchW
, attrW
, NULL
, &size
);
1840 if (r
!= ERROR_SUCCESS
)
1844 if (!(bufferW
= msi_alloc( size
* sizeof(WCHAR
) )))
1846 r
= ERROR_OUTOFMEMORY
;
1850 r
= MsiGetPatchInfoW( patchW
, attrW
, bufferW
, &size
);
1851 if (r
== ERROR_SUCCESS
)
1853 int len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
1855 r
= ERROR_MORE_DATA
;
1857 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *buflen
, NULL
, NULL
);
1865 msi_free( bufferW
);
1869 UINT WINAPI
MsiGetPatchInfoW( LPCWSTR patch
, LPCWSTR attr
, LPWSTR buffer
, LPDWORD buflen
)
1872 WCHAR product
[GUID_SIZE
];
1875 TRACE("%s %s %p %p\n", debugstr_w(patch
), debugstr_w(attr
), buffer
, buflen
);
1877 if (!patch
|| !attr
)
1878 return ERROR_INVALID_PARAMETER
;
1880 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW
, attr
))
1881 return ERROR_UNKNOWN_PROPERTY
;
1886 r
= MsiEnumProductsW( index
, product
);
1887 if (r
!= ERROR_SUCCESS
)
1890 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, attr
, buffer
, buflen
);
1891 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1894 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, attr
, buffer
, buflen
);
1895 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1898 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_MACHINE
, attr
, buffer
, buflen
);
1899 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1905 return ERROR_UNKNOWN_PRODUCT
;
1908 UINT WINAPI
MsiEnableLogA(DWORD dwLogMode
, LPCSTR szLogFile
, DWORD attributes
)
1910 LPWSTR szwLogFile
= NULL
;
1913 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_a(szLogFile
), attributes
);
1917 szwLogFile
= strdupAtoW( szLogFile
);
1919 return ERROR_OUTOFMEMORY
;
1921 r
= MsiEnableLogW( dwLogMode
, szwLogFile
, attributes
);
1922 msi_free( szwLogFile
);
1926 UINT WINAPI
MsiEnableLogW(DWORD dwLogMode
, LPCWSTR szLogFile
, DWORD attributes
)
1928 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_w(szLogFile
), attributes
);
1930 msi_free(gszLogFile
);
1936 if (!(attributes
& INSTALLLOGATTRIBUTES_APPEND
))
1937 DeleteFileW(szLogFile
);
1938 file
= CreateFileW(szLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
,
1939 FILE_ATTRIBUTE_NORMAL
, NULL
);
1940 if (file
!= INVALID_HANDLE_VALUE
)
1942 gszLogFile
= strdupW(szLogFile
);
1946 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile
), GetLastError());
1949 return ERROR_SUCCESS
;
1952 UINT WINAPI
MsiEnumComponentCostsA( MSIHANDLE handle
, LPCSTR component
, DWORD index
,
1953 INSTALLSTATE state
, LPSTR drive
, DWORD
*buflen
,
1954 int *cost
, int *temp
)
1958 WCHAR
*driveW
, *componentW
= NULL
;
1960 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle
, debugstr_a(component
), index
,
1961 state
, drive
, buflen
, cost
, temp
);
1963 if (!drive
|| !buflen
) return ERROR_INVALID_PARAMETER
;
1964 if (component
&& !(componentW
= strdupAtoW( component
))) return ERROR_OUTOFMEMORY
;
1967 if (!(driveW
= msi_alloc( len
* sizeof(WCHAR
) )))
1969 msi_free( componentW
);
1970 return ERROR_OUTOFMEMORY
;
1972 r
= MsiEnumComponentCostsW( handle
, componentW
, index
, state
, driveW
, buflen
, cost
, temp
);
1975 WideCharToMultiByte( CP_ACP
, 0, driveW
, -1, drive
, len
, NULL
, NULL
);
1977 msi_free( componentW
);
1982 static UINT
set_drive( WCHAR
*buffer
, WCHAR letter
)
1990 UINT WINAPI
MsiEnumComponentCostsW( MSIHANDLE handle
, LPCWSTR component
, DWORD index
,
1991 INSTALLSTATE state
, LPWSTR drive
, DWORD
*buflen
,
1992 int *cost
, int *temp
)
1994 UINT r
= ERROR_NO_MORE_ITEMS
;
1995 MSICOMPONENT
*comp
= NULL
;
1996 MSIPACKAGE
*package
;
1999 WCHAR path
[MAX_PATH
];
2001 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle
, debugstr_w(component
), index
,
2002 state
, drive
, buflen
, cost
, temp
);
2004 if (!drive
|| !buflen
|| !cost
|| !temp
) return ERROR_INVALID_PARAMETER
;
2005 if (!(package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
)))
2008 IWineMsiRemotePackage
*remote_package
;
2011 if (!(remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
)))
2012 return ERROR_INVALID_HANDLE
;
2014 if (component
&& !(bname
= SysAllocString( component
)))
2016 IWineMsiRemotePackage_Release( remote_package
);
2017 return ERROR_OUTOFMEMORY
;
2019 hr
= IWineMsiRemotePackage_EnumComponentCosts( remote_package
, bname
, index
, state
, drive
, buflen
, cost
, temp
);
2020 IWineMsiRemotePackage_Release( remote_package
);
2021 SysFreeString( bname
);
2024 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
) return HRESULT_CODE(hr
);
2025 return ERROR_FUNCTION_FAILED
;
2027 return ERROR_SUCCESS
;
2030 if (!msi_get_property_int( package
->db
, szCostingComplete
, 0 ))
2032 msiobj_release( &package
->hdr
);
2033 return ERROR_FUNCTION_NOT_CALLED
;
2035 if (component
&& component
[0] && !(comp
= msi_get_loaded_component( package
, component
)))
2037 msiobj_release( &package
->hdr
);
2038 return ERROR_UNKNOWN_COMPONENT
;
2043 msiobj_release( &package
->hdr
);
2044 return ERROR_MORE_DATA
;
2048 msiobj_release( &package
->hdr
);
2049 return ERROR_NO_MORE_ITEMS
;
2054 GetWindowsDirectoryW( path
, MAX_PATH
);
2055 if (component
&& component
[0])
2057 if (msi_is_global_assembly( comp
)) *temp
= comp
->Cost
;
2058 if (!comp
->Enabled
|| !comp
->KeyPath
)
2061 *buflen
= set_drive( drive
, path
[0] );
2064 else if ((file
= msi_get_loaded_file( package
, comp
->KeyPath
)))
2066 *cost
= max( 8, comp
->Cost
/ 512 );
2067 *buflen
= set_drive( drive
, file
->TargetPath
[0] );
2071 else if (IStorage_Stat( package
->db
->storage
, &stat
, STATFLAG_NONAME
) == S_OK
)
2073 *temp
= max( 8, stat
.cbSize
.QuadPart
/ 512 );
2074 *buflen
= set_drive( drive
, path
[0] );
2077 msiobj_release( &package
->hdr
);
2081 UINT WINAPI
MsiQueryComponentStateA(LPCSTR szProductCode
,
2082 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
2083 LPCSTR szComponent
, INSTALLSTATE
*pdwState
)
2085 LPWSTR prodcode
= NULL
, usersid
= NULL
, comp
= NULL
;
2088 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode
),
2089 debugstr_a(szUserSid
), dwContext
, debugstr_a(szComponent
), pdwState
);
2091 if (szProductCode
&& !(prodcode
= strdupAtoW(szProductCode
)))
2092 return ERROR_OUTOFMEMORY
;
2094 if (szUserSid
&& !(usersid
= strdupAtoW(szUserSid
)))
2095 return ERROR_OUTOFMEMORY
;
2097 if (szComponent
&& !(comp
= strdupAtoW(szComponent
)))
2098 return ERROR_OUTOFMEMORY
;
2100 r
= MsiQueryComponentStateW(prodcode
, usersid
, dwContext
, comp
, pdwState
);
2109 static BOOL
msi_comp_find_prod_key(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
2114 r
= MSIREG_OpenProductKey(prodcode
, NULL
, context
, &hkey
, FALSE
);
2116 return (r
== ERROR_SUCCESS
);
2119 static BOOL
msi_comp_find_package(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
2127 static const WCHAR local_package
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
2128 static const WCHAR managed_local_package
[] = {
2129 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
2132 r
= MSIREG_OpenInstallProps(prodcode
, context
, NULL
, &hkey
, FALSE
);
2133 if (r
!= ERROR_SUCCESS
)
2136 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
2137 package
= managed_local_package
;
2139 package
= local_package
;
2142 res
= RegQueryValueExW(hkey
, package
, NULL
, NULL
, NULL
, &sz
);
2145 return (res
== ERROR_SUCCESS
);
2148 static UINT
msi_comp_find_prodcode(WCHAR
*squashed_pc
,
2149 MSIINSTALLCONTEXT context
,
2150 LPCWSTR comp
, LPWSTR val
, DWORD
*sz
)
2156 if (context
== MSIINSTALLCONTEXT_MACHINE
)
2157 r
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2159 r
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2161 if (r
!= ERROR_SUCCESS
)
2164 res
= RegQueryValueExW( hkey
, squashed_pc
, NULL
, NULL
, (BYTE
*)val
, sz
);
2165 if (res
!= ERROR_SUCCESS
)
2172 UINT WINAPI
MsiQueryComponentStateW(LPCWSTR szProductCode
,
2173 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
2174 LPCWSTR szComponent
, INSTALLSTATE
*pdwState
)
2176 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
2180 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode
),
2181 debugstr_w(szUserSid
), dwContext
, debugstr_w(szComponent
), pdwState
);
2183 if (!pdwState
|| !szComponent
)
2184 return ERROR_INVALID_PARAMETER
;
2186 if (!szProductCode
|| !*szProductCode
|| lstrlenW(szProductCode
) != GUID_SIZE
- 1)
2187 return ERROR_INVALID_PARAMETER
;
2189 if (!squash_guid( szProductCode
, squashed_pc
))
2190 return ERROR_INVALID_PARAMETER
;
2192 found
= msi_comp_find_prod_key(szProductCode
, dwContext
);
2194 if (!msi_comp_find_package(szProductCode
, dwContext
))
2198 *pdwState
= INSTALLSTATE_UNKNOWN
;
2199 return ERROR_UNKNOWN_COMPONENT
;
2202 return ERROR_UNKNOWN_PRODUCT
;
2205 *pdwState
= INSTALLSTATE_UNKNOWN
;
2208 if (msi_comp_find_prodcode( squashed_pc
, dwContext
, szComponent
, NULL
, &sz
))
2209 return ERROR_UNKNOWN_COMPONENT
;
2212 *pdwState
= INSTALLSTATE_NOTUSED
;
2218 if (!(val
= msi_alloc( sz
))) return ERROR_OUTOFMEMORY
;
2219 if ((r
= msi_comp_find_prodcode( squashed_pc
, dwContext
, szComponent
, val
, &sz
)))
2225 if (lstrlenW(val
) > 2 &&
2226 val
[0] >= '0' && val
[0] <= '9' && val
[1] >= '0' && val
[1] <= '9' && val
[2] != ':')
2228 *pdwState
= INSTALLSTATE_SOURCE
;
2231 *pdwState
= INSTALLSTATE_LOCAL
;
2235 TRACE("-> %d\n", *pdwState
);
2236 return ERROR_SUCCESS
;
2239 INSTALLSTATE WINAPI
MsiQueryProductStateA(LPCSTR szProduct
)
2241 LPWSTR szwProduct
= NULL
;
2246 szwProduct
= strdupAtoW( szProduct
);
2248 return ERROR_OUTOFMEMORY
;
2250 r
= MsiQueryProductStateW( szwProduct
);
2251 msi_free( szwProduct
);
2255 INSTALLSTATE WINAPI
MsiQueryProductStateW(LPCWSTR szProduct
)
2257 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
2258 INSTALLSTATE state
= INSTALLSTATE_ADVERTISED
;
2259 HKEY prodkey
= 0, userdata
= 0;
2263 TRACE("%s\n", debugstr_w(szProduct
));
2265 if (!szProduct
|| !*szProduct
)
2266 return INSTALLSTATE_INVALIDARG
;
2268 if (lstrlenW(szProduct
) != GUID_SIZE
- 1)
2269 return INSTALLSTATE_INVALIDARG
;
2271 if (szProduct
[0] != '{' || szProduct
[37] != '}')
2272 return INSTALLSTATE_UNKNOWN
;
2274 SetLastError( ERROR_SUCCESS
);
2276 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
2277 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2278 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2279 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2280 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2281 &prodkey
, FALSE
) == ERROR_SUCCESS
)
2283 context
= MSIINSTALLCONTEXT_MACHINE
;
2286 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
2287 if (r
!= ERROR_SUCCESS
)
2290 if (!msi_reg_get_val_dword(userdata
, szWindowsInstaller
, &val
))
2294 state
= INSTALLSTATE_DEFAULT
;
2296 state
= INSTALLSTATE_UNKNOWN
;
2301 state
= INSTALLSTATE_UNKNOWN
;
2304 state
= INSTALLSTATE_ABSENT
;
2307 RegCloseKey(prodkey
);
2308 RegCloseKey(userdata
);
2309 TRACE("-> %d\n", state
);
2313 INSTALLUILEVEL WINAPI
MsiSetInternalUI(INSTALLUILEVEL dwUILevel
, HWND
*phWnd
)
2315 INSTALLUILEVEL old
= gUILevel
;
2316 HWND oldwnd
= gUIhwnd
;
2318 TRACE("%08x %p\n", dwUILevel
, phWnd
);
2320 gUILevel
= dwUILevel
;
2329 INSTALLUI_HANDLERA WINAPI
MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler
,
2330 DWORD dwMessageFilter
, LPVOID pvContext
)
2332 INSTALLUI_HANDLERA prev
= gUIHandlerA
;
2334 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2336 gUIHandlerA
= puiHandler
;
2338 gUIFilter
= dwMessageFilter
;
2339 gUIContext
= pvContext
;
2344 INSTALLUI_HANDLERW WINAPI
MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler
,
2345 DWORD dwMessageFilter
, LPVOID pvContext
)
2347 INSTALLUI_HANDLERW prev
= gUIHandlerW
;
2349 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2352 gUIHandlerW
= puiHandler
;
2353 gUIFilter
= dwMessageFilter
;
2354 gUIContext
= pvContext
;
2359 /******************************************************************
2360 * MsiLoadStringW [MSI.@]
2362 * Loads a string from MSI's string resources.
2366 * handle [I] only -1 is handled currently
2367 * id [I] id of the string to be loaded
2368 * lpBuffer [O] buffer for the string to be written to
2369 * nBufferMax [I] maximum size of the buffer in characters
2370 * lang [I] the preferred language for the string
2374 * If successful, this function returns the language id of the string loaded
2375 * If the function fails, the function returns zero.
2379 * The type of the first parameter is unknown. LoadString's prototype
2380 * suggests that it might be a module handle. I have made it an MSI handle
2381 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2382 * handle. Maybe strings can be stored in an MSI database somehow.
2384 LANGID WINAPI
MsiLoadStringW( MSIHANDLE handle
, UINT id
, LPWSTR lpBuffer
,
2385 int nBufferMax
, LANGID lang
)
2392 TRACE("%d %u %p %d %d\n", handle
, id
, lpBuffer
, nBufferMax
, lang
);
2395 FIXME("don't know how to deal with handle = %08x\n", handle
);
2398 lang
= GetUserDefaultLangID();
2400 hres
= FindResourceExW( msi_hInstance
, (LPCWSTR
) RT_STRING
,
2404 hResData
= LoadResource( msi_hInstance
, hres
);
2407 p
= LockResource( hResData
);
2411 for (i
= 0; i
< (id
& 0xf); i
++) p
+= *p
+ 1;
2414 if( nBufferMax
<= len
)
2417 memcpy( lpBuffer
, p
+1, len
* sizeof(WCHAR
));
2418 lpBuffer
[ len
] = 0;
2420 TRACE("found -> %s\n", debugstr_w(lpBuffer
));
2424 LANGID WINAPI
MsiLoadStringA( MSIHANDLE handle
, UINT id
, LPSTR lpBuffer
,
2425 int nBufferMax
, LANGID lang
)
2431 bufW
= msi_alloc(nBufferMax
*sizeof(WCHAR
));
2432 r
= MsiLoadStringW(handle
, id
, bufW
, nBufferMax
, lang
);
2435 len
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
2436 if( len
<= nBufferMax
)
2437 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1,
2438 lpBuffer
, nBufferMax
, NULL
, NULL
);
2446 INSTALLSTATE WINAPI
MsiLocateComponentA(LPCSTR szComponent
, LPSTR lpPathBuf
,
2449 char szProduct
[GUID_SIZE
];
2451 TRACE("%s %p %p\n", debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2453 if (!szComponent
|| !pcchBuf
)
2454 return INSTALLSTATE_INVALIDARG
;
2456 if (MsiGetProductCodeA( szComponent
, szProduct
) != ERROR_SUCCESS
)
2457 return INSTALLSTATE_UNKNOWN
;
2459 return MsiGetComponentPathA( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2462 INSTALLSTATE WINAPI
MsiLocateComponentW(LPCWSTR szComponent
, LPWSTR lpPathBuf
,
2465 WCHAR szProduct
[GUID_SIZE
];
2467 TRACE("%s %p %p\n", debugstr_w(szComponent
), lpPathBuf
, pcchBuf
);
2469 if (!szComponent
|| !pcchBuf
)
2470 return INSTALLSTATE_INVALIDARG
;
2472 if (MsiGetProductCodeW( szComponent
, szProduct
) != ERROR_SUCCESS
)
2473 return INSTALLSTATE_UNKNOWN
;
2475 return MsiGetComponentPathW( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2478 UINT WINAPI
MsiMessageBoxA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2479 WORD wLanguageId
, DWORD f
)
2481 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_a(lpText
), debugstr_a(lpCaption
),
2482 uType
, wLanguageId
, f
);
2483 return MessageBoxExA(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2486 UINT WINAPI
MsiMessageBoxW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2487 WORD wLanguageId
, DWORD f
)
2489 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_w(lpText
), debugstr_w(lpCaption
),
2490 uType
, wLanguageId
, f
);
2491 return MessageBoxExW(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2494 UINT WINAPI
MsiMessageBoxExA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2495 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2497 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_a(lpText
),
2498 debugstr_a(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2499 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2502 UINT WINAPI
MsiMessageBoxExW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR 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_w(lpText
),
2506 debugstr_w(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2507 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2510 UINT WINAPI
MsiProvideAssemblyA( LPCSTR szAssemblyName
, LPCSTR szAppContext
,
2511 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPSTR lpPathBuf
,
2512 LPDWORD pcchPathBuf
)
2514 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName
),
2515 debugstr_a(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2517 return ERROR_CALL_NOT_IMPLEMENTED
;
2520 UINT WINAPI
MsiProvideAssemblyW( LPCWSTR szAssemblyName
, LPCWSTR szAppContext
,
2521 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPWSTR lpPathBuf
,
2522 LPDWORD pcchPathBuf
)
2524 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName
),
2525 debugstr_w(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2527 return ERROR_CALL_NOT_IMPLEMENTED
;
2530 UINT WINAPI
MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor
,
2531 LPSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2533 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2534 return ERROR_CALL_NOT_IMPLEMENTED
;
2537 UINT WINAPI
MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor
,
2538 LPWSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2540 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2541 return ERROR_CALL_NOT_IMPLEMENTED
;
2544 HRESULT WINAPI
MsiGetFileSignatureInformationA( LPCSTR path
, DWORD flags
, PCCERT_CONTEXT
*cert
,
2545 LPBYTE hash
, LPDWORD hashlen
)
2548 WCHAR
*pathW
= NULL
;
2550 TRACE("%s %08x %p %p %p\n", debugstr_a(path
), flags
, cert
, hash
, hashlen
);
2552 if (path
&& !(pathW
= strdupAtoW( path
))) return E_OUTOFMEMORY
;
2553 r
= MsiGetFileSignatureInformationW( pathW
, flags
, cert
, hash
, hashlen
);
2558 HRESULT WINAPI
MsiGetFileSignatureInformationW( LPCWSTR path
, DWORD flags
, PCCERT_CONTEXT
*cert
,
2559 LPBYTE hash
, LPDWORD hashlen
)
2561 static GUID generic_verify_v2
= WINTRUST_ACTION_GENERIC_VERIFY_V2
;
2564 WINTRUST_FILE_INFO info
;
2565 CRYPT_PROVIDER_SGNR
*signer
;
2566 CRYPT_PROVIDER_CERT
*provider
;
2568 TRACE("%s %08x %p %p %p\n", debugstr_w(path
), flags
, cert
, hash
, hashlen
);
2570 if (!path
|| !cert
) return E_INVALIDARG
;
2572 info
.cbStruct
= sizeof(info
);
2573 info
.pcwszFilePath
= path
;
2575 info
.pgKnownSubject
= NULL
;
2577 data
.cbStruct
= sizeof(data
);
2578 data
.pPolicyCallbackData
= NULL
;
2579 data
.pSIPClientData
= NULL
;
2580 data
.dwUIChoice
= WTD_UI_NONE
;
2581 data
.fdwRevocationChecks
= WTD_REVOKE_WHOLECHAIN
;
2582 data
.dwUnionChoice
= WTD_CHOICE_FILE
;
2583 data
.u
.pFile
= &info
;
2584 data
.dwStateAction
= WTD_STATEACTION_VERIFY
;
2585 data
.hWVTStateData
= NULL
;
2586 data
.pwszURLReference
= NULL
;
2587 data
.dwProvFlags
= 0;
2588 data
.dwUIContext
= WTD_UICONTEXT_INSTALL
;
2589 hr
= WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2591 if (FAILED(hr
)) goto done
;
2593 if (!(signer
= WTHelperGetProvSignerFromChain( data
.hWVTStateData
, 0, FALSE
, 0 )))
2595 hr
= TRUST_E_NOSIGNATURE
;
2600 DWORD len
= signer
->psSigner
->EncryptedHash
.cbData
;
2604 hr
= HRESULT_FROM_WIN32(ERROR_MORE_DATA
);
2607 memcpy( hash
, signer
->psSigner
->EncryptedHash
.pbData
, len
);
2610 if (!(provider
= WTHelperGetProvCertFromChain( signer
, 0 )))
2612 hr
= TRUST_E_PROVIDER_UNKNOWN
;
2615 *cert
= CertDuplicateCertificateContext( provider
->pCert
);
2618 data
.dwStateAction
= WTD_STATEACTION_CLOSE
;
2619 WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2623 /******************************************************************
2624 * MsiGetProductPropertyA [MSI.@]
2626 UINT WINAPI
MsiGetProductPropertyA(MSIHANDLE hProduct
, LPCSTR szProperty
,
2627 LPSTR szValue
, LPDWORD pccbValue
)
2629 LPWSTR prop
= NULL
, val
= NULL
;
2633 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_a(szProperty
),
2634 szValue
, pccbValue
);
2636 if (szValue
&& !pccbValue
)
2637 return ERROR_INVALID_PARAMETER
;
2639 if (szProperty
) prop
= strdupAtoW(szProperty
);
2642 r
= MsiGetProductPropertyW(hProduct
, prop
, NULL
, &len
);
2643 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2646 if (r
== ERROR_SUCCESS
)
2648 if (szValue
) *szValue
= '\0';
2649 if (pccbValue
) *pccbValue
= 0;
2653 val
= msi_alloc(++len
* sizeof(WCHAR
));
2656 r
= ERROR_OUTOFMEMORY
;
2660 r
= MsiGetProductPropertyW(hProduct
, prop
, val
, &len
);
2661 if (r
!= ERROR_SUCCESS
)
2664 len
= WideCharToMultiByte(CP_ACP
, 0, val
, -1, NULL
, 0, NULL
, NULL
);
2667 WideCharToMultiByte(CP_ACP
, 0, val
, -1, szValue
,
2668 *pccbValue
, NULL
, NULL
);
2672 if (len
> *pccbValue
)
2673 r
= ERROR_MORE_DATA
;
2675 *pccbValue
= len
- 1;
2685 /******************************************************************
2686 * MsiGetProductPropertyW [MSI.@]
2688 UINT WINAPI
MsiGetProductPropertyW(MSIHANDLE hProduct
, LPCWSTR szProperty
,
2689 LPWSTR szValue
, LPDWORD pccbValue
)
2691 MSIPACKAGE
*package
;
2692 MSIQUERY
*view
= NULL
;
2693 MSIRECORD
*rec
= NULL
;
2697 static const WCHAR query
[] = {
2698 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2699 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2700 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2702 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_w(szProperty
),
2703 szValue
, pccbValue
);
2706 return ERROR_INVALID_PARAMETER
;
2708 if (szValue
&& !pccbValue
)
2709 return ERROR_INVALID_PARAMETER
;
2711 package
= msihandle2msiinfo(hProduct
, MSIHANDLETYPE_PACKAGE
);
2713 return ERROR_INVALID_HANDLE
;
2715 r
= MSI_OpenQuery(package
->db
, &view
, query
, szProperty
);
2716 if (r
!= ERROR_SUCCESS
)
2719 r
= MSI_ViewExecute(view
, 0);
2720 if (r
!= ERROR_SUCCESS
)
2723 r
= MSI_ViewFetch(view
, &rec
);
2724 if (r
!= ERROR_SUCCESS
)
2727 val
= MSI_RecordGetString(rec
, 2);
2731 if (lstrlenW(val
) >= *pccbValue
)
2733 if (szValue
) lstrcpynW(szValue
, val
, *pccbValue
);
2734 r
= ERROR_MORE_DATA
;
2738 if (szValue
) lstrcpyW(szValue
, val
);
2742 *pccbValue
= lstrlenW(val
);
2747 MSI_ViewClose(view
);
2748 msiobj_release(&view
->hdr
);
2749 if (rec
) msiobj_release(&rec
->hdr
);
2754 if (szValue
) *szValue
= '\0';
2755 if (pccbValue
) *pccbValue
= 0;
2759 msiobj_release(&package
->hdr
);
2763 UINT WINAPI
MsiVerifyPackageA( LPCSTR szPackage
)
2766 LPWSTR szPack
= NULL
;
2768 TRACE("%s\n", debugstr_a(szPackage
) );
2772 szPack
= strdupAtoW( szPackage
);
2774 return ERROR_OUTOFMEMORY
;
2777 r
= MsiVerifyPackageW( szPack
);
2784 UINT WINAPI
MsiVerifyPackageW( LPCWSTR szPackage
)
2789 TRACE("%s\n", debugstr_w(szPackage
) );
2791 r
= MsiOpenDatabaseW( szPackage
, MSIDBOPEN_READONLY
, &handle
);
2792 MsiCloseHandle( handle
);
2797 static BOOL
open_userdata_comp_key( const WCHAR
*comp
, const WCHAR
*usersid
, MSIINSTALLCONTEXT ctx
,
2800 if (ctx
& MSIINSTALLCONTEXT_MACHINE
)
2802 if (!MSIREG_OpenUserDataComponentKey( comp
, szLocalSid
, hkey
, FALSE
)) return TRUE
;
2804 if (ctx
& (MSIINSTALLCONTEXT_USERMANAGED
|MSIINSTALLCONTEXT_USERUNMANAGED
))
2806 if (usersid
&& !strcmpiW( usersid
, szAllSid
))
2808 FIXME( "only looking at the current user\n" );
2811 if (!MSIREG_OpenUserDataComponentKey( comp
, usersid
, hkey
, FALSE
)) return TRUE
;
2816 static INSTALLSTATE
MSI_GetComponentPath( const WCHAR
*szProduct
, const WCHAR
*szComponent
,
2817 const WCHAR
*szUserSid
, MSIINSTALLCONTEXT ctx
,
2818 awstring
*lpPathBuf
, DWORD
*pcchBuf
)
2820 static const WCHAR wininstaller
[] =
2821 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2822 WCHAR
*path
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
], squashed_comp
[SQUASHED_GUID_SIZE
];
2827 if (!szProduct
|| !szComponent
)
2828 return INSTALLSTATE_INVALIDARG
;
2830 if (lpPathBuf
->str
.w
&& !pcchBuf
)
2831 return INSTALLSTATE_INVALIDARG
;
2833 if (!squash_guid( szProduct
, squashed_pc
) || !squash_guid( szComponent
, squashed_comp
))
2834 return INSTALLSTATE_INVALIDARG
;
2836 if (szUserSid
&& ctx
== MSIINSTALLCONTEXT_MACHINE
)
2837 return INSTALLSTATE_INVALIDARG
;
2839 state
= INSTALLSTATE_UNKNOWN
;
2841 if (open_userdata_comp_key( szComponent
, szUserSid
, ctx
, &hkey
))
2843 path
= msi_reg_get_val_str( hkey
, squashed_pc
);
2846 state
= INSTALLSTATE_ABSENT
;
2848 if ((!MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
, NULL
, &hkey
, FALSE
) ||
2849 !MSIREG_OpenUserDataProductKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
, NULL
, &hkey
, FALSE
)) &&
2850 msi_reg_get_val_dword(hkey
, wininstaller
, &version
) &&
2851 GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2854 state
= INSTALLSTATE_LOCAL
;
2858 if (state
!= INSTALLSTATE_LOCAL
&&
2859 (!MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, &hkey
, FALSE
) ||
2860 !MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
, &hkey
, FALSE
)))
2864 if (open_userdata_comp_key( szComponent
, szUserSid
, ctx
, &hkey
))
2867 path
= msi_reg_get_val_str( hkey
, squashed_pc
);
2870 state
= INSTALLSTATE_ABSENT
;
2872 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2873 state
= INSTALLSTATE_LOCAL
;
2878 return INSTALLSTATE_UNKNOWN
;
2880 if (state
== INSTALLSTATE_LOCAL
&& !*path
)
2881 state
= INSTALLSTATE_NOTUSED
;
2883 if (msi_strcpy_to_awstring(path
, -1, lpPathBuf
, pcchBuf
) == ERROR_MORE_DATA
)
2884 state
= INSTALLSTATE_MOREDATA
;
2890 /******************************************************************
2891 * MsiGetComponentPathExW [MSI.@]
2893 INSTALLSTATE WINAPI
MsiGetComponentPathExW( LPCWSTR product
, LPCWSTR comp
, LPCWSTR usersid
,
2894 MSIINSTALLCONTEXT ctx
, LPWSTR buf
, LPDWORD buflen
)
2898 TRACE( "%s %s %s 0x%x %p %p\n", debugstr_w(product
), debugstr_w(comp
), debugstr_w(usersid
),
2901 path
.unicode
= TRUE
;
2904 return MSI_GetComponentPath( product
, comp
, usersid
, ctx
, &path
, buflen
);
2907 INSTALLSTATE WINAPI
MsiGetComponentPathExA( LPCSTR product
, LPCSTR comp
, LPCSTR usersid
,
2908 MSIINSTALLCONTEXT ctx
, LPSTR buf
, LPDWORD buflen
)
2910 WCHAR
*productW
= NULL
, *compW
= NULL
, *usersidW
= NULL
;
2911 INSTALLSTATE r
= INSTALLSTATE_UNKNOWN
;
2914 TRACE( "%s %s %s 0x%x %p %p\n", debugstr_a(product
), debugstr_a(comp
), debugstr_a(usersid
),
2917 if (product
&& !(productW
= strdupAtoW( product
))) return INSTALLSTATE_UNKNOWN
;
2918 if (comp
&& !(compW
= strdupAtoW( comp
))) goto end
;
2919 if (usersid
&& !(usersidW
= strdupAtoW( usersid
))) goto end
;
2921 path
.unicode
= FALSE
;
2924 r
= MSI_GetComponentPath( productW
, compW
, usersidW
, ctx
, &path
, buflen
);
2927 msi_free( productW
);
2929 msi_free( usersidW
);
2934 /******************************************************************
2935 * MsiGetComponentPathW [MSI.@]
2937 INSTALLSTATE WINAPI
MsiGetComponentPathW( LPCWSTR product
, LPCWSTR comp
, LPWSTR buf
, LPDWORD buflen
)
2939 return MsiGetComponentPathExW( product
, comp
, szAllSid
, MSIINSTALLCONTEXT_ALL
, buf
, buflen
);
2942 /******************************************************************
2943 * MsiGetComponentPathA [MSI.@]
2945 INSTALLSTATE WINAPI
MsiGetComponentPathA( LPCSTR product
, LPCSTR comp
, LPSTR buf
, LPDWORD buflen
)
2947 return MsiGetComponentPathExA( product
, comp
, "s-1-1-0", MSIINSTALLCONTEXT_ALL
, buf
, buflen
);
2950 static UINT
query_feature_state( const WCHAR
*product
, const WCHAR
*squashed
, const WCHAR
*usersid
,
2951 MSIINSTALLCONTEXT ctx
, const WCHAR
*feature
, INSTALLSTATE
*state
)
2955 WCHAR
*parent
, *components
, *path
;
2957 BOOL missing
= FALSE
, source
= FALSE
;
2958 WCHAR comp
[GUID_SIZE
];
2961 if (ctx
!= MSIINSTALLCONTEXT_MACHINE
) SetLastError( ERROR_SUCCESS
);
2963 if (MSIREG_OpenFeaturesKey( product
, usersid
, ctx
, &hkey
, FALSE
)) return ERROR_UNKNOWN_PRODUCT
;
2965 parent
= msi_reg_get_val_str( hkey
, feature
);
2966 RegCloseKey( hkey
);
2967 if (!parent
) return ERROR_UNKNOWN_FEATURE
;
2969 *state
= (parent
[0] == 6) ? INSTALLSTATE_ABSENT
: INSTALLSTATE_LOCAL
;
2971 if (*state
== INSTALLSTATE_ABSENT
)
2972 return ERROR_SUCCESS
;
2974 r
= MSIREG_OpenUserDataFeaturesKey( product
, usersid
, ctx
, &hkey
, FALSE
);
2975 if (r
!= ERROR_SUCCESS
)
2977 *state
= INSTALLSTATE_ADVERTISED
;
2978 return ERROR_SUCCESS
;
2980 components
= msi_reg_get_val_str( hkey
, feature
);
2981 RegCloseKey( hkey
);
2983 TRACE("buffer = %s\n", debugstr_w(components
));
2987 *state
= INSTALLSTATE_ADVERTISED
;
2988 return ERROR_SUCCESS
;
2990 for (p
= components
; *p
&& *p
!= 2 ; p
+= 20)
2992 if (!decode_base85_guid( p
, &guid
))
2994 if (p
!= components
) break;
2995 msi_free( components
);
2996 *state
= INSTALLSTATE_BADCONFIG
;
2997 return ERROR_BAD_CONFIGURATION
;
2999 StringFromGUID2( &guid
, comp
, GUID_SIZE
);
3000 if (ctx
== MSIINSTALLCONTEXT_MACHINE
)
3001 r
= MSIREG_OpenUserDataComponentKey( comp
, szLocalSid
, &hkey
, FALSE
);
3003 r
= MSIREG_OpenUserDataComponentKey( comp
, usersid
, &hkey
, FALSE
);
3005 if (r
!= ERROR_SUCCESS
)
3007 msi_free( components
);
3008 *state
= INSTALLSTATE_ADVERTISED
;
3009 return ERROR_SUCCESS
;
3011 path
= msi_reg_get_val_str( hkey
, squashed
);
3012 if (!path
) missing
= TRUE
;
3013 else if (strlenW( path
) > 2 &&
3014 path
[0] >= '0' && path
[0] <= '9' &&
3015 path
[1] >= '0' && path
[1] <= '9')
3021 msi_free( components
);
3024 *state
= INSTALLSTATE_ADVERTISED
;
3026 *state
= INSTALLSTATE_SOURCE
;
3028 *state
= INSTALLSTATE_LOCAL
;
3030 TRACE("returning state %d\n", *state
);
3031 return ERROR_SUCCESS
;
3034 UINT WINAPI
MsiQueryFeatureStateExA( LPCSTR product
, LPCSTR usersid
, MSIINSTALLCONTEXT ctx
,
3035 LPCSTR feature
, INSTALLSTATE
*state
)
3038 WCHAR
*productW
= NULL
, *usersidW
= NULL
, *featureW
= NULL
;
3040 if (product
&& !(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
3041 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
3043 msi_free( productW
);
3044 return ERROR_OUTOFMEMORY
;
3046 if (feature
&& !(featureW
= strdupAtoW( feature
)))
3048 msi_free( productW
);
3049 msi_free( usersidW
);
3050 return ERROR_OUTOFMEMORY
;
3052 r
= MsiQueryFeatureStateExW( productW
, usersidW
, ctx
, featureW
, state
);
3053 msi_free( productW
);
3054 msi_free( usersidW
);
3055 msi_free( featureW
);
3059 UINT WINAPI
MsiQueryFeatureStateExW( LPCWSTR product
, LPCWSTR usersid
, MSIINSTALLCONTEXT ctx
,
3060 LPCWSTR feature
, INSTALLSTATE
*state
)
3063 if (!squash_guid( product
, squashed
)) return ERROR_INVALID_PARAMETER
;
3064 return query_feature_state( product
, squashed
, usersid
, ctx
, feature
, state
);
3067 /******************************************************************
3068 * MsiQueryFeatureStateA [MSI.@]
3070 INSTALLSTATE WINAPI
MsiQueryFeatureStateA(LPCSTR szProduct
, LPCSTR szFeature
)
3072 LPWSTR szwProduct
= NULL
, szwFeature
= NULL
;
3073 INSTALLSTATE rc
= INSTALLSTATE_UNKNOWN
;
3075 szwProduct
= strdupAtoW( szProduct
);
3076 if ( szProduct
&& !szwProduct
)
3079 szwFeature
= strdupAtoW( szFeature
);
3080 if ( szFeature
&& !szwFeature
)
3083 rc
= MsiQueryFeatureStateW(szwProduct
, szwFeature
);
3086 msi_free( szwProduct
);
3087 msi_free( szwFeature
);
3092 /******************************************************************
3093 * MsiQueryFeatureStateW [MSI.@]
3095 * Checks the state of a feature
3098 * szProduct [I] Product's GUID string
3099 * szFeature [I] Feature's GUID string
3102 * INSTALLSTATE_LOCAL Feature is installed and usable
3103 * INSTALLSTATE_ABSENT Feature is absent
3104 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
3105 * INSTALLSTATE_UNKNOWN An error occurred
3106 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
3109 INSTALLSTATE WINAPI
MsiQueryFeatureStateW(LPCWSTR szProduct
, LPCWSTR szFeature
)
3115 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szFeature
));
3117 if (!szProduct
|| !szFeature
|| !squash_guid( szProduct
, squashed
))
3118 return INSTALLSTATE_INVALIDARG
;
3120 r
= query_feature_state( szProduct
, squashed
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, szFeature
, &state
);
3121 if (r
== ERROR_SUCCESS
|| r
== ERROR_BAD_CONFIGURATION
) return state
;
3123 r
= query_feature_state( szProduct
, squashed
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, szFeature
, &state
);
3124 if (r
== ERROR_SUCCESS
|| r
== ERROR_BAD_CONFIGURATION
) return state
;
3126 r
= query_feature_state( szProduct
, squashed
, NULL
, MSIINSTALLCONTEXT_MACHINE
, szFeature
, &state
);
3127 if (r
== ERROR_SUCCESS
|| r
== ERROR_BAD_CONFIGURATION
) return state
;
3129 return INSTALLSTATE_UNKNOWN
;
3132 /******************************************************************
3133 * MsiGetFileVersionA [MSI.@]
3135 UINT WINAPI
MsiGetFileVersionA(LPCSTR szFilePath
, LPSTR lpVersionBuf
,
3136 LPDWORD pcchVersionBuf
, LPSTR lpLangBuf
, LPDWORD pcchLangBuf
)
3138 LPWSTR szwFilePath
= NULL
, lpwVersionBuff
= NULL
, lpwLangBuff
= NULL
;
3139 UINT ret
= ERROR_OUTOFMEMORY
;
3141 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
3142 (lpLangBuf
&& !pcchLangBuf
))
3143 return ERROR_INVALID_PARAMETER
;
3147 szwFilePath
= strdupAtoW( szFilePath
);
3152 if( lpVersionBuf
&& pcchVersionBuf
&& *pcchVersionBuf
)
3154 lpwVersionBuff
= msi_alloc(*pcchVersionBuf
*sizeof(WCHAR
));
3155 if( !lpwVersionBuff
)
3159 if( lpLangBuf
&& pcchLangBuf
&& *pcchLangBuf
)
3161 lpwLangBuff
= msi_alloc(*pcchLangBuf
*sizeof(WCHAR
));
3166 ret
= MsiGetFileVersionW(szwFilePath
, lpwVersionBuff
, pcchVersionBuf
,
3167 lpwLangBuff
, pcchLangBuf
);
3169 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwVersionBuff
)
3170 WideCharToMultiByte(CP_ACP
, 0, lpwVersionBuff
, -1,
3171 lpVersionBuf
, *pcchVersionBuf
+ 1, NULL
, NULL
);
3172 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwLangBuff
)
3173 WideCharToMultiByte(CP_ACP
, 0, lpwLangBuff
, -1,
3174 lpLangBuf
, *pcchLangBuf
+ 1, NULL
, NULL
);
3177 msi_free(szwFilePath
);
3178 msi_free(lpwVersionBuff
);
3179 msi_free(lpwLangBuff
);
3184 static UINT
get_file_version( const WCHAR
*path
, WCHAR
*verbuf
, DWORD
*verlen
,
3185 WCHAR
*langbuf
, DWORD
*langlen
)
3187 static const WCHAR szVersionResource
[] = {'\\',0};
3188 static const WCHAR szVersionFormat
[] = {'%','d','.','%','d','.','%','d','.','%','d',0};
3189 static const WCHAR szLangFormat
[] = {'%','d',0};
3190 UINT ret
= ERROR_MORE_DATA
;
3193 VS_FIXEDFILEINFO
*ffi
;
3197 if (!(len
= GetFileVersionInfoSizeW( path
, NULL
)))
3199 error
= GetLastError();
3200 if (error
== ERROR_BAD_PATHNAME
) return ERROR_FILE_NOT_FOUND
;
3201 if (error
== ERROR_RESOURCE_DATA_NOT_FOUND
) return ERROR_FILE_INVALID
;
3204 if (!(version
= msi_alloc( len
))) return ERROR_OUTOFMEMORY
;
3205 if (!GetFileVersionInfoW( path
, 0, len
, version
))
3207 msi_free( version
);
3208 return GetLastError();
3210 if (!verbuf
&& !verlen
&& !langbuf
&& !langlen
)
3212 msi_free( version
);
3213 return ERROR_SUCCESS
;
3217 if (VerQueryValueW( version
, szVersionResource
, (LPVOID
*)&ffi
, &len
) && len
> 0)
3219 sprintfW( tmp
, szVersionFormat
,
3220 HIWORD(ffi
->dwFileVersionMS
), LOWORD(ffi
->dwFileVersionMS
),
3221 HIWORD(ffi
->dwFileVersionLS
), LOWORD(ffi
->dwFileVersionLS
) );
3222 if (verbuf
) lstrcpynW( verbuf
, tmp
, *verlen
);
3223 len
= strlenW( tmp
);
3224 if (*verlen
> len
) ret
= ERROR_SUCCESS
;
3229 if (verbuf
) *verbuf
= 0;
3235 if (VerQueryValueW( version
, szLangResource
, (LPVOID
*)&lang
, &len
) && len
> 0)
3237 sprintfW( tmp
, szLangFormat
, *lang
);
3238 if (langbuf
) lstrcpynW( langbuf
, tmp
, *langlen
);
3239 len
= strlenW( tmp
);
3240 if (*langlen
> len
) ret
= ERROR_SUCCESS
;
3245 if (langbuf
) *langbuf
= 0;
3249 msi_free( version
);
3254 /******************************************************************
3255 * MsiGetFileVersionW [MSI.@]
3257 UINT WINAPI
MsiGetFileVersionW( LPCWSTR path
, LPWSTR verbuf
, LPDWORD verlen
,
3258 LPWSTR langbuf
, LPDWORD langlen
)
3262 TRACE("%s %p %u %p %u\n", debugstr_w(path
), verbuf
, verlen
? *verlen
: 0,
3263 langbuf
, langlen
? *langlen
: 0);
3265 if ((verbuf
&& !verlen
) || (langbuf
&& !langlen
))
3266 return ERROR_INVALID_PARAMETER
;
3268 ret
= get_file_version( path
, verbuf
, verlen
, langbuf
, langlen
);
3269 if (ret
== ERROR_RESOURCE_DATA_NOT_FOUND
&& verlen
)
3272 WCHAR
*version
= msi_font_version_from_file( path
);
3273 if (!version
) return ERROR_FILE_INVALID
;
3274 len
= strlenW( version
);
3275 if (len
>= *verlen
) ret
= ERROR_MORE_DATA
;
3278 strcpyW( verbuf
, version
);
3279 ret
= ERROR_SUCCESS
;
3282 msi_free( version
);
3287 /***********************************************************************
3288 * MsiGetFeatureUsageW [MSI.@]
3290 UINT WINAPI
MsiGetFeatureUsageW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3291 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
3293 FIXME("%s %s %p %p\n",debugstr_w(szProduct
), debugstr_w(szFeature
),
3294 pdwUseCount
, pwDateUsed
);
3295 return ERROR_CALL_NOT_IMPLEMENTED
;
3298 /***********************************************************************
3299 * MsiGetFeatureUsageA [MSI.@]
3301 UINT WINAPI
MsiGetFeatureUsageA( LPCSTR szProduct
, LPCSTR szFeature
,
3302 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
3304 LPWSTR prod
= NULL
, feat
= NULL
;
3305 UINT ret
= ERROR_OUTOFMEMORY
;
3307 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3308 pdwUseCount
, pwDateUsed
);
3310 prod
= strdupAtoW( szProduct
);
3311 if (szProduct
&& !prod
)
3314 feat
= strdupAtoW( szFeature
);
3315 if (szFeature
&& !feat
)
3318 ret
= MsiGetFeatureUsageW( prod
, feat
, pdwUseCount
, pwDateUsed
);
3327 /***********************************************************************
3328 * MsiUseFeatureExW [MSI.@]
3330 INSTALLSTATE WINAPI
MsiUseFeatureExW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3331 DWORD dwInstallMode
, DWORD dwReserved
)
3335 TRACE("%s %s %i %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
3336 dwInstallMode
, dwReserved
);
3338 state
= MsiQueryFeatureStateW( szProduct
, szFeature
);
3341 return INSTALLSTATE_INVALIDARG
;
3343 if (state
== INSTALLSTATE_LOCAL
&& dwInstallMode
!= INSTALLMODE_NODETECTION
)
3345 FIXME("mark product %s feature %s as used\n",
3346 debugstr_w(szProduct
), debugstr_w(szFeature
) );
3352 /***********************************************************************
3353 * MsiUseFeatureExA [MSI.@]
3355 INSTALLSTATE WINAPI
MsiUseFeatureExA( LPCSTR szProduct
, LPCSTR szFeature
,
3356 DWORD dwInstallMode
, DWORD dwReserved
)
3358 INSTALLSTATE ret
= INSTALLSTATE_UNKNOWN
;
3359 LPWSTR prod
= NULL
, feat
= NULL
;
3361 TRACE("%s %s %i %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3362 dwInstallMode
, dwReserved
);
3364 prod
= strdupAtoW( szProduct
);
3365 if (szProduct
&& !prod
)
3368 feat
= strdupAtoW( szFeature
);
3369 if (szFeature
&& !feat
)
3372 ret
= MsiUseFeatureExW( prod
, feat
, dwInstallMode
, dwReserved
);
3381 /***********************************************************************
3382 * MsiUseFeatureW [MSI.@]
3384 INSTALLSTATE WINAPI
MsiUseFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
)
3386 return MsiUseFeatureExW(szProduct
, szFeature
, 0, 0);
3389 /***********************************************************************
3390 * MsiUseFeatureA [MSI.@]
3392 INSTALLSTATE WINAPI
MsiUseFeatureA( LPCSTR szProduct
, LPCSTR szFeature
)
3394 return MsiUseFeatureExA(szProduct
, szFeature
, 0, 0);
3397 static WCHAR
*reg_get_multisz( HKEY hkey
, const WCHAR
*name
)
3401 if (RegQueryValueExW( hkey
, name
, NULL
, &type
, NULL
, &len
) || type
!= REG_MULTI_SZ
) return NULL
;
3402 if ((ret
= msi_alloc( len
))) RegQueryValueExW( hkey
, name
, NULL
, NULL
, (BYTE
*)ret
, &len
);
3406 static WCHAR
*reg_get_sz( HKEY hkey
, const WCHAR
*name
)
3410 if (RegQueryValueExW( hkey
, name
, NULL
, &type
, NULL
, &len
) || type
!= REG_SZ
) return NULL
;
3411 if ((ret
= msi_alloc( len
))) RegQueryValueExW( hkey
, name
, NULL
, NULL
, (BYTE
*)ret
, &len
);
3415 #define BASE85_SIZE 20
3417 /***********************************************************************
3418 * MSI_ProvideQualifiedComponentEx [internal]
3420 static UINT
MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent
,
3421 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3422 DWORD Unused1
, DWORD Unused2
, awstring
*lpPathBuf
,
3423 LPDWORD pcchPathBuf
)
3425 WCHAR product
[MAX_FEATURE_CHARS
+1], comp
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1];
3432 if (MSIREG_OpenUserComponentsKey( szComponent
, &hkey
, FALSE
)) return ERROR_UNKNOWN_COMPONENT
;
3434 desc
= reg_get_multisz( hkey
, szQualifier
);
3436 if (!desc
) return ERROR_INDEX_ABSENT
;
3438 /* FIXME: handle multiple descriptors */
3439 ret
= MsiDecomposeDescriptorW( desc
, product
, feature
, comp
, &size
);
3441 if (ret
!= ERROR_SUCCESS
) return ret
;
3443 if (!szProduct
) szProduct
= product
;
3446 MSIINSTALLCONTEXT ctx
;
3450 /* use the first component of the feature if the descriptor component is empty */
3451 if ((ret
= msi_locate_product( szProduct
, &ctx
))) return ret
;
3452 if ((ret
= MSIREG_OpenUserDataFeaturesKey( szProduct
, NULL
, ctx
, &hkey
, FALSE
)))
3454 return ERROR_FILE_NOT_FOUND
;
3456 components
= reg_get_sz( hkey
, feature
);
3457 RegCloseKey( hkey
);
3458 if (!components
) return ERROR_FILE_NOT_FOUND
;
3460 if (strlenW( components
) < BASE85_SIZE
|| !decode_base85_guid( components
, &guid
))
3462 msi_free( components
);
3463 return ERROR_FILE_NOT_FOUND
;
3465 msi_free( components
);
3466 StringFromGUID2( &guid
, comp
, sizeof(comp
)/sizeof(comp
[0]) );
3469 state
= MSI_GetComponentPath( szProduct
, comp
, szAllSid
, MSIINSTALLCONTEXT_ALL
, lpPathBuf
, pcchPathBuf
);
3471 if (state
== INSTALLSTATE_MOREDATA
) return ERROR_MORE_DATA
;
3472 if (state
!= INSTALLSTATE_LOCAL
) return ERROR_FILE_NOT_FOUND
;
3473 return ERROR_SUCCESS
;
3476 /***********************************************************************
3477 * MsiProvideQualifiedComponentExW [MSI.@]
3479 UINT WINAPI
MsiProvideQualifiedComponentExW(LPCWSTR szComponent
,
3480 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3481 DWORD Unused1
, DWORD Unused2
, LPWSTR lpPathBuf
,
3482 LPDWORD pcchPathBuf
)
3486 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_w(szComponent
),
3487 debugstr_w(szQualifier
), dwInstallMode
, debugstr_w(szProduct
),
3488 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3490 path
.unicode
= TRUE
;
3491 path
.str
.w
= lpPathBuf
;
3493 return MSI_ProvideQualifiedComponentEx(szComponent
, szQualifier
,
3494 dwInstallMode
, szProduct
, Unused1
, Unused2
, &path
, pcchPathBuf
);
3497 /***********************************************************************
3498 * MsiProvideQualifiedComponentExA [MSI.@]
3500 UINT WINAPI
MsiProvideQualifiedComponentExA(LPCSTR szComponent
,
3501 LPCSTR szQualifier
, DWORD dwInstallMode
, LPCSTR szProduct
,
3502 DWORD Unused1
, DWORD Unused2
, LPSTR lpPathBuf
,
3503 LPDWORD pcchPathBuf
)
3505 LPWSTR szwComponent
, szwQualifier
= NULL
, szwProduct
= NULL
;
3506 UINT r
= ERROR_OUTOFMEMORY
;
3509 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent
),
3510 debugstr_a(szQualifier
), dwInstallMode
, debugstr_a(szProduct
),
3511 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3513 szwComponent
= strdupAtoW( szComponent
);
3514 if (szComponent
&& !szwComponent
)
3517 szwQualifier
= strdupAtoW( szQualifier
);
3518 if (szQualifier
&& !szwQualifier
)
3521 szwProduct
= strdupAtoW( szProduct
);
3522 if (szProduct
&& !szwProduct
)
3525 path
.unicode
= FALSE
;
3526 path
.str
.a
= lpPathBuf
;
3528 r
= MSI_ProvideQualifiedComponentEx(szwComponent
, szwQualifier
,
3529 dwInstallMode
, szwProduct
, Unused1
,
3530 Unused2
, &path
, pcchPathBuf
);
3532 msi_free(szwProduct
);
3533 msi_free(szwComponent
);
3534 msi_free(szwQualifier
);
3539 /***********************************************************************
3540 * MsiProvideQualifiedComponentW [MSI.@]
3542 UINT WINAPI
MsiProvideQualifiedComponentW( LPCWSTR szComponent
,
3543 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPWSTR lpPathBuf
,
3544 LPDWORD pcchPathBuf
)
3546 return MsiProvideQualifiedComponentExW(szComponent
, szQualifier
,
3547 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3550 /***********************************************************************
3551 * MsiProvideQualifiedComponentA [MSI.@]
3553 UINT WINAPI
MsiProvideQualifiedComponentA( LPCSTR szComponent
,
3554 LPCSTR szQualifier
, DWORD dwInstallMode
, LPSTR lpPathBuf
,
3555 LPDWORD pcchPathBuf
)
3557 return MsiProvideQualifiedComponentExA(szComponent
, szQualifier
,
3558 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3561 /***********************************************************************
3562 * MSI_GetUserInfo [internal]
3564 static USERINFOSTATE
MSI_GetUserInfo(LPCWSTR szProduct
,
3565 awstring
*lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3566 awstring
*lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3567 awstring
*lpSerialBuf
, LPDWORD pcchSerialBuf
)
3569 WCHAR
*user
, *org
, *serial
, squashed_pc
[SQUASHED_GUID_SIZE
];
3570 USERINFOSTATE state
;
3575 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct
), lpUserNameBuf
,
3576 pcchUserNameBuf
, lpOrgNameBuf
, pcchOrgNameBuf
, lpSerialBuf
,
3579 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
3580 return USERINFOSTATE_INVALIDARG
;
3582 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
3583 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3584 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3585 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3586 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
3587 &hkey
, FALSE
) != ERROR_SUCCESS
)
3589 return USERINFOSTATE_UNKNOWN
;
3592 if (MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3593 NULL
, &props
, FALSE
) != ERROR_SUCCESS
&&
3594 MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
3595 NULL
, &props
, FALSE
) != ERROR_SUCCESS
)
3598 return USERINFOSTATE_ABSENT
;
3601 user
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGOWNERW
);
3602 org
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGCOMPANYW
);
3603 serial
= msi_reg_get_val_str(props
, INSTALLPROPERTY_PRODUCTIDW
);
3604 state
= USERINFOSTATE_ABSENT
;
3610 state
= USERINFOSTATE_PRESENT
;
3612 if (pcchUserNameBuf
)
3614 if (lpUserNameBuf
&& !user
)
3616 (*pcchUserNameBuf
)--;
3620 r
= msi_strcpy_to_awstring(user
, -1, lpUserNameBuf
, pcchUserNameBuf
);
3621 if (r
== ERROR_MORE_DATA
)
3623 state
= USERINFOSTATE_MOREDATA
;
3631 if (!orgptr
) orgptr
= szEmpty
;
3633 r
= msi_strcpy_to_awstring(orgptr
, -1, lpOrgNameBuf
, pcchOrgNameBuf
);
3634 if (r
== ERROR_MORE_DATA
)
3636 state
= USERINFOSTATE_MOREDATA
;
3649 r
= msi_strcpy_to_awstring(serial
, -1, lpSerialBuf
, pcchSerialBuf
);
3650 if (r
== ERROR_MORE_DATA
)
3651 state
= USERINFOSTATE_MOREDATA
;
3662 /***********************************************************************
3663 * MsiGetUserInfoW [MSI.@]
3665 USERINFOSTATE WINAPI
MsiGetUserInfoW(LPCWSTR szProduct
,
3666 LPWSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3667 LPWSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3668 LPWSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3670 awstring user
, org
, serial
;
3672 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3673 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3674 (lpSerialBuf
&& !pcchSerialBuf
))
3675 return USERINFOSTATE_INVALIDARG
;
3677 user
.unicode
= TRUE
;
3678 user
.str
.w
= lpUserNameBuf
;
3680 org
.str
.w
= lpOrgNameBuf
;
3681 serial
.unicode
= TRUE
;
3682 serial
.str
.w
= lpSerialBuf
;
3684 return MSI_GetUserInfo( szProduct
, &user
, pcchUserNameBuf
,
3685 &org
, pcchOrgNameBuf
,
3686 &serial
, pcchSerialBuf
);
3689 USERINFOSTATE WINAPI
MsiGetUserInfoA(LPCSTR szProduct
,
3690 LPSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3691 LPSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3692 LPSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3694 awstring user
, org
, serial
;
3698 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3699 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3700 (lpSerialBuf
&& !pcchSerialBuf
))
3701 return USERINFOSTATE_INVALIDARG
;
3703 prod
= strdupAtoW( szProduct
);
3704 if (szProduct
&& !prod
)
3705 return ERROR_OUTOFMEMORY
;
3707 user
.unicode
= FALSE
;
3708 user
.str
.a
= lpUserNameBuf
;
3709 org
.unicode
= FALSE
;
3710 org
.str
.a
= lpOrgNameBuf
;
3711 serial
.unicode
= FALSE
;
3712 serial
.str
.a
= lpSerialBuf
;
3714 r
= MSI_GetUserInfo( prod
, &user
, pcchUserNameBuf
,
3715 &org
, pcchOrgNameBuf
,
3716 &serial
, pcchSerialBuf
);
3723 UINT WINAPI
MsiCollectUserInfoW(LPCWSTR szProduct
)
3727 MSIPACKAGE
*package
;
3728 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3730 TRACE("(%s)\n",debugstr_w(szProduct
));
3732 rc
= MsiOpenProductW(szProduct
,&handle
);
3733 if (rc
!= ERROR_SUCCESS
)
3734 return ERROR_INVALID_PARAMETER
;
3736 /* MsiCollectUserInfo cannot be called from a custom action. */
3737 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3739 return ERROR_CALL_NOT_IMPLEMENTED
;
3741 rc
= ACTION_PerformUIAction(package
, szFirstRun
, SCRIPT_NONE
);
3742 msiobj_release( &package
->hdr
);
3744 MsiCloseHandle(handle
);
3749 UINT WINAPI
MsiCollectUserInfoA(LPCSTR szProduct
)
3753 MSIPACKAGE
*package
;
3754 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3756 TRACE("(%s)\n",debugstr_a(szProduct
));
3758 rc
= MsiOpenProductA(szProduct
,&handle
);
3759 if (rc
!= ERROR_SUCCESS
)
3760 return ERROR_INVALID_PARAMETER
;
3762 /* MsiCollectUserInfo cannot be called from a custom action. */
3763 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3765 return ERROR_CALL_NOT_IMPLEMENTED
;
3767 rc
= ACTION_PerformUIAction(package
, szFirstRun
, SCRIPT_NONE
);
3768 msiobj_release( &package
->hdr
);
3770 MsiCloseHandle(handle
);
3775 /***********************************************************************
3776 * MsiConfigureFeatureA [MSI.@]
3778 UINT WINAPI
MsiConfigureFeatureA(LPCSTR szProduct
, LPCSTR szFeature
, INSTALLSTATE eInstallState
)
3780 LPWSTR prod
, feat
= NULL
;
3781 UINT r
= ERROR_OUTOFMEMORY
;
3783 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
), eInstallState
);
3785 prod
= strdupAtoW( szProduct
);
3786 if (szProduct
&& !prod
)
3789 feat
= strdupAtoW( szFeature
);
3790 if (szFeature
&& !feat
)
3793 r
= MsiConfigureFeatureW(prod
, feat
, eInstallState
);
3802 /***********************************************************************
3803 * MsiConfigureFeatureW [MSI.@]
3805 UINT WINAPI
MsiConfigureFeatureW(LPCWSTR szProduct
, LPCWSTR szFeature
, INSTALLSTATE eInstallState
)
3807 MSIPACKAGE
*package
= NULL
;
3809 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
3812 TRACE("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
), eInstallState
);
3814 if (!szProduct
|| !szFeature
)
3815 return ERROR_INVALID_PARAMETER
;
3817 switch (eInstallState
)
3819 case INSTALLSTATE_DEFAULT
:
3820 /* FIXME: how do we figure out the default location? */
3821 eInstallState
= INSTALLSTATE_LOCAL
;
3823 case INSTALLSTATE_LOCAL
:
3824 case INSTALLSTATE_SOURCE
:
3825 case INSTALLSTATE_ABSENT
:
3826 case INSTALLSTATE_ADVERTISED
:
3829 return ERROR_INVALID_PARAMETER
;
3832 r
= MSI_OpenProductW( szProduct
, &package
);
3833 if (r
!= ERROR_SUCCESS
)
3836 sz
= sizeof(sourcepath
);
3837 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3838 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3840 sz
= sizeof(filename
);
3841 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3842 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3844 lstrcatW( sourcepath
, filename
);
3846 MsiSetInternalUI( INSTALLUILEVEL_BASIC
, NULL
);
3848 r
= ACTION_PerformUIAction( package
, szCostInitialize
, SCRIPT_NONE
);
3849 if (r
!= ERROR_SUCCESS
)
3852 r
= MSI_SetFeatureStateW( package
, szFeature
, eInstallState
);
3853 if (r
!= ERROR_SUCCESS
)
3856 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3859 msiobj_release( &package
->hdr
);
3864 /***********************************************************************
3865 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3867 * Notes: undocumented
3869 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved
)
3871 WCHAR path
[MAX_PATH
];
3873 TRACE("%d\n", dwReserved
);
3877 FIXME("dwReserved=%d\n", dwReserved
);
3878 return ERROR_INVALID_PARAMETER
;
3881 if (!GetWindowsDirectoryW(path
, MAX_PATH
))
3882 return ERROR_FUNCTION_FAILED
;
3884 lstrcatW(path
, installerW
);
3886 if (!CreateDirectoryW(path
, NULL
) && GetLastError() != ERROR_ALREADY_EXISTS
)
3887 return ERROR_FUNCTION_FAILED
;
3889 return ERROR_SUCCESS
;
3892 /***********************************************************************
3893 * MsiGetShortcutTargetA [MSI.@]
3895 UINT WINAPI
MsiGetShortcutTargetA( LPCSTR szShortcutTarget
,
3896 LPSTR szProductCode
, LPSTR szFeatureId
,
3897 LPSTR szComponentCode
)
3900 const int len
= MAX_FEATURE_CHARS
+1;
3901 WCHAR product
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1];
3904 target
= strdupAtoW( szShortcutTarget
);
3905 if (szShortcutTarget
&& !target
)
3906 return ERROR_OUTOFMEMORY
;
3910 r
= MsiGetShortcutTargetW( target
, product
, feature
, component
);
3912 if (r
== ERROR_SUCCESS
)
3914 WideCharToMultiByte( CP_ACP
, 0, product
, -1, szProductCode
, len
, NULL
, NULL
);
3915 WideCharToMultiByte( CP_ACP
, 0, feature
, -1, szFeatureId
, len
, NULL
, NULL
);
3916 WideCharToMultiByte( CP_ACP
, 0, component
, -1, szComponentCode
, len
, NULL
, NULL
);
3921 /***********************************************************************
3922 * MsiGetShortcutTargetW [MSI.@]
3924 UINT WINAPI
MsiGetShortcutTargetW( LPCWSTR szShortcutTarget
,
3925 LPWSTR szProductCode
, LPWSTR szFeatureId
,
3926 LPWSTR szComponentCode
)
3928 IShellLinkDataList
*dl
= NULL
;
3929 IPersistFile
*pf
= NULL
;
3930 LPEXP_DARWIN_LINK darwin
= NULL
;
3933 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget
),
3934 szProductCode
, szFeatureId
, szComponentCode
);
3936 init
= CoInitialize(NULL
);
3938 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3939 &IID_IPersistFile
, (LPVOID
*) &pf
);
3940 if( SUCCEEDED( r
) )
3942 r
= IPersistFile_Load( pf
, szShortcutTarget
,
3943 STGM_READ
| STGM_SHARE_DENY_WRITE
);
3944 if( SUCCEEDED( r
) )
3946 r
= IPersistFile_QueryInterface( pf
, &IID_IShellLinkDataList
,
3948 if( SUCCEEDED( r
) )
3950 IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
,
3952 IShellLinkDataList_Release( dl
);
3955 IPersistFile_Release( pf
);
3958 if (SUCCEEDED(init
))
3961 TRACE("darwin = %p\n", darwin
);
3968 ret
= MsiDecomposeDescriptorW( darwin
->szwDarwinID
,
3969 szProductCode
, szFeatureId
, szComponentCode
, &sz
);
3970 LocalFree( darwin
);
3974 return ERROR_FUNCTION_FAILED
;
3977 UINT WINAPI
MsiReinstallFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
, DWORD dwReinstallMode
)
3979 static const WCHAR fmtW
[] = {'%','s','=','%','s',' ','%','s','=','%','s',0};
3980 MSIPACKAGE
*package
;
3981 MSIINSTALLCONTEXT context
;
3983 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
], reinstallmode
[11];
3984 WCHAR
*ptr
, *cmdline
;
3987 TRACE("%s, %s, 0x%08x\n", debugstr_w(szProduct
), debugstr_w(szFeature
), dwReinstallMode
);
3989 r
= msi_locate_product( szProduct
, &context
);
3990 if (r
!= ERROR_SUCCESS
)
3993 ptr
= reinstallmode
;
3995 if (dwReinstallMode
& REINSTALLMODE_FILEMISSING
)
3997 if (dwReinstallMode
& REINSTALLMODE_FILEOLDERVERSION
)
3999 if (dwReinstallMode
& REINSTALLMODE_FILEEQUALVERSION
)
4001 if (dwReinstallMode
& REINSTALLMODE_FILEEXACT
)
4003 if (dwReinstallMode
& REINSTALLMODE_FILEVERIFY
)
4005 if (dwReinstallMode
& REINSTALLMODE_FILEREPLACE
)
4007 if (dwReinstallMode
& REINSTALLMODE_USERDATA
)
4009 if (dwReinstallMode
& REINSTALLMODE_MACHINEDATA
)
4011 if (dwReinstallMode
& REINSTALLMODE_SHORTCUT
)
4013 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
4017 sz
= sizeof(sourcepath
);
4018 MsiSourceListGetInfoW( szProduct
, NULL
, context
, MSICODE_PRODUCT
,
4019 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
4020 sz
= sizeof(filename
);
4021 MsiSourceListGetInfoW( szProduct
, NULL
, context
, MSICODE_PRODUCT
,
4022 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
4023 strcatW( sourcepath
, filename
);
4025 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
4026 r
= MSI_OpenPackageW( sourcepath
, &package
);
4028 r
= MSI_OpenProductW( szProduct
, &package
);
4030 if (r
!= ERROR_SUCCESS
)
4033 sz
= (strlenW( fmtW
) + strlenW( szReinstallMode
) + strlenW( reinstallmode
)) * sizeof(WCHAR
);
4034 sz
+= (strlenW( szReinstall
) + strlenW( szFeature
)) * sizeof(WCHAR
);
4035 if (!(cmdline
= msi_alloc( sz
)))
4037 msiobj_release( &package
->hdr
);
4038 return ERROR_OUTOFMEMORY
;
4040 sprintfW( cmdline
, fmtW
, szReinstallMode
, reinstallmode
, szReinstall
, szFeature
);
4042 r
= MSI_InstallPackage( package
, sourcepath
, cmdline
);
4043 msiobj_release( &package
->hdr
);
4044 msi_free( cmdline
);
4049 UINT WINAPI
MsiReinstallFeatureA( LPCSTR szProduct
, LPCSTR szFeature
,
4050 DWORD dwReinstallMode
)
4056 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
4059 wszProduct
= strdupAtoW(szProduct
);
4060 wszFeature
= strdupAtoW(szFeature
);
4062 rc
= MsiReinstallFeatureW(wszProduct
, wszFeature
, dwReinstallMode
);
4064 msi_free(wszProduct
);
4065 msi_free(wszFeature
);
4072 unsigned int buf
[4];
4073 unsigned char in
[64];
4074 unsigned char digest
[16];
4077 extern VOID WINAPI
MD5Init( MD5_CTX
*);
4078 extern VOID WINAPI
MD5Update( MD5_CTX
*, const unsigned char *, unsigned int );
4079 extern VOID WINAPI
MD5Final( MD5_CTX
*);
4081 UINT
msi_get_filehash( const WCHAR
*path
, MSIFILEHASHINFO
*hash
)
4083 HANDLE handle
, mapping
;
4086 UINT r
= ERROR_FUNCTION_FAILED
;
4088 handle
= CreateFileW( path
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, 0, NULL
);
4089 if (handle
== INVALID_HANDLE_VALUE
)
4091 WARN("can't open file %u\n", GetLastError());
4092 return ERROR_FILE_NOT_FOUND
;
4094 if ((length
= GetFileSize( handle
, NULL
)))
4096 if ((mapping
= CreateFileMappingW( handle
, NULL
, PAGE_READONLY
, 0, 0, NULL
)))
4098 if ((p
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, length
)))
4103 MD5Update( &ctx
, p
, length
);
4105 UnmapViewOfFile( p
);
4107 memcpy( hash
->dwData
, ctx
.digest
, sizeof(hash
->dwData
) );
4110 CloseHandle( mapping
);
4115 /* Empty file -> set hash to 0 */
4116 memset( hash
->dwData
, 0, sizeof(hash
->dwData
) );
4120 CloseHandle( handle
);
4124 /***********************************************************************
4125 * MsiGetFileHashW [MSI.@]
4127 UINT WINAPI
MsiGetFileHashW( LPCWSTR szFilePath
, DWORD dwOptions
,
4128 PMSIFILEHASHINFO pHash
)
4130 TRACE("%s %08x %p\n", debugstr_w(szFilePath
), dwOptions
, pHash
);
4133 return ERROR_INVALID_PARAMETER
;
4136 return ERROR_PATH_NOT_FOUND
;
4139 return ERROR_INVALID_PARAMETER
;
4141 return ERROR_INVALID_PARAMETER
;
4142 if (pHash
->dwFileHashInfoSize
< sizeof *pHash
)
4143 return ERROR_INVALID_PARAMETER
;
4145 return msi_get_filehash( szFilePath
, pHash
);
4148 /***********************************************************************
4149 * MsiGetFileHashA [MSI.@]
4151 UINT WINAPI
MsiGetFileHashA( LPCSTR szFilePath
, DWORD dwOptions
,
4152 PMSIFILEHASHINFO pHash
)
4157 TRACE("%s %08x %p\n", debugstr_a(szFilePath
), dwOptions
, pHash
);
4159 file
= strdupAtoW( szFilePath
);
4160 if (szFilePath
&& !file
)
4161 return ERROR_OUTOFMEMORY
;
4163 r
= MsiGetFileHashW( file
, dwOptions
, pHash
);
4168 /***********************************************************************
4169 * MsiAdvertiseScriptW [MSI.@]
4171 UINT WINAPI
MsiAdvertiseScriptW( LPCWSTR szScriptFile
, DWORD dwFlags
,
4172 PHKEY phRegData
, BOOL fRemoveItems
)
4174 FIXME("%s %08x %p %d\n",
4175 debugstr_w( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
4176 return ERROR_CALL_NOT_IMPLEMENTED
;
4179 /***********************************************************************
4180 * MsiAdvertiseScriptA [MSI.@]
4182 UINT WINAPI
MsiAdvertiseScriptA( LPCSTR szScriptFile
, DWORD dwFlags
,
4183 PHKEY phRegData
, BOOL fRemoveItems
)
4185 FIXME("%s %08x %p %d\n",
4186 debugstr_a( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
4187 return ERROR_CALL_NOT_IMPLEMENTED
;
4190 /***********************************************************************
4191 * MsiIsProductElevatedW [MSI.@]
4193 UINT WINAPI
MsiIsProductElevatedW( LPCWSTR szProduct
, BOOL
*pfElevated
)
4195 FIXME("%s %p - stub\n",
4196 debugstr_w( szProduct
), pfElevated
);
4198 return ERROR_SUCCESS
;
4201 /***********************************************************************
4202 * MsiIsProductElevatedA [MSI.@]
4204 UINT WINAPI
MsiIsProductElevatedA( LPCSTR szProduct
, BOOL
*pfElevated
)
4206 FIXME("%s %p - stub\n",
4207 debugstr_a( szProduct
), pfElevated
);
4209 return ERROR_SUCCESS
;
4212 /***********************************************************************
4213 * MsiSetExternalUIRecord [MSI.@]
4215 UINT WINAPI
MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler
,
4216 DWORD filter
, LPVOID context
,
4217 PINSTALLUI_HANDLER_RECORD prev
)
4219 TRACE("%p %08x %p %p\n", handler
, filter
, context
, prev
);
4222 *prev
= gUIHandlerRecord
;
4224 gUIHandlerRecord
= handler
;
4226 gUIContext
= context
;
4228 return ERROR_SUCCESS
;
4231 /***********************************************************************
4232 * MsiInstallMissingComponentA [MSI.@]
4234 UINT WINAPI
MsiInstallMissingComponentA( LPCSTR product
, LPCSTR component
, INSTALLSTATE state
)
4237 WCHAR
*productW
= NULL
, *componentW
= NULL
;
4239 TRACE("%s, %s, %d\n", debugstr_a(product
), debugstr_a(component
), state
);
4241 if (product
&& !(productW
= strdupAtoW( product
)))
4242 return ERROR_OUTOFMEMORY
;
4244 if (component
&& !(componentW
= strdupAtoW( component
)))
4246 msi_free( productW
);
4247 return ERROR_OUTOFMEMORY
;
4250 r
= MsiInstallMissingComponentW( productW
, componentW
, state
);
4251 msi_free( productW
);
4252 msi_free( componentW
);
4256 /***********************************************************************
4257 * MsiInstallMissingComponentW [MSI.@]
4259 UINT WINAPI
MsiInstallMissingComponentW(LPCWSTR szProduct
, LPCWSTR szComponent
, INSTALLSTATE eInstallState
)
4261 FIXME("(%s %s %d\n", debugstr_w(szProduct
), debugstr_w(szComponent
), eInstallState
);
4262 return ERROR_SUCCESS
;
4265 UINT WINAPI
MsiProvideComponentA( LPCSTR product
, LPCSTR feature
, LPCSTR component
, DWORD mode
, LPSTR buf
, LPDWORD buflen
)
4267 WCHAR
*productW
= NULL
, *componentW
= NULL
, *featureW
= NULL
, *bufW
= NULL
;
4268 UINT r
= ERROR_OUTOFMEMORY
;
4272 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_a(product
), debugstr_a(component
), debugstr_a(feature
), mode
, buf
, buflen
);
4274 if (product
&& !(productW
= strdupAtoW( product
))) goto done
;
4275 if (feature
&& !(featureW
= strdupAtoW( feature
))) goto done
;
4276 if (component
&& !(componentW
= strdupAtoW( component
))) goto done
;
4278 r
= MsiProvideComponentW( productW
, featureW
, componentW
, mode
, NULL
, &lenW
);
4279 if (r
!= ERROR_SUCCESS
)
4282 if (!(bufW
= msi_alloc( ++lenW
* sizeof(WCHAR
) )))
4284 r
= ERROR_OUTOFMEMORY
;
4288 r
= MsiProvideComponentW( productW
, featureW
, componentW
, mode
, bufW
, &lenW
);
4289 if (r
!= ERROR_SUCCESS
)
4292 len
= WideCharToMultiByte( CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
4296 r
= ERROR_MORE_DATA
;
4298 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1, buf
, *buflen
, NULL
, NULL
);
4304 msi_free( productW
);
4305 msi_free( featureW
);
4306 msi_free( componentW
);
4311 UINT WINAPI
MsiProvideComponentW( LPCWSTR product
, LPCWSTR feature
, LPCWSTR component
, DWORD mode
, LPWSTR buf
, LPDWORD buflen
)
4315 TRACE("%s, %s, %s, %x, %p, %p\n", debugstr_w(product
), debugstr_w(component
), debugstr_w(feature
), mode
, buf
, buflen
);
4317 state
= MsiQueryFeatureStateW( product
, feature
);
4318 TRACE("feature state: %d\n", state
);
4321 case INSTALLMODE_NODETECTION
:
4325 FIXME("mode %x not implemented\n", mode
);
4326 return ERROR_INSTALL_FAILURE
;
4329 state
= MsiGetComponentPathW( product
, component
, buf
, buflen
);
4330 TRACE("component state: %d\n", state
);
4333 case INSTALLSTATE_INVALIDARG
:
4334 return ERROR_INVALID_PARAMETER
;
4336 case INSTALLSTATE_MOREDATA
:
4337 return ERROR_MORE_DATA
;
4339 case INSTALLSTATE_ADVERTISED
:
4340 case INSTALLSTATE_LOCAL
:
4341 case INSTALLSTATE_SOURCE
:
4342 MsiUseFeatureW( product
, feature
);
4343 return ERROR_SUCCESS
;
4346 TRACE("MsiGetComponentPathW returned %d\n", state
);
4347 return ERROR_INSTALL_FAILURE
;
4351 /***********************************************************************
4352 * MsiBeginTransactionA [MSI.@]
4354 UINT WINAPI
MsiBeginTransactionA( LPCSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
4359 FIXME("%s %u %p %p\n", debugstr_a(name
), attrs
, id
, event
);
4361 nameW
= strdupAtoW( name
);
4363 return ERROR_OUTOFMEMORY
;
4365 r
= MsiBeginTransactionW( nameW
, attrs
, id
, event
);
4370 /***********************************************************************
4371 * MsiBeginTransactionW [MSI.@]
4373 UINT WINAPI
MsiBeginTransactionW( LPCWSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
4375 FIXME("%s %u %p %p\n", debugstr_w(name
), attrs
, id
, event
);
4377 *id
= (MSIHANDLE
)0xdeadbeef;
4378 *event
= (HANDLE
)0xdeadbeef;
4380 return ERROR_SUCCESS
;
4383 /***********************************************************************
4384 * MsiJoinTransaction [MSI.@]
4386 UINT WINAPI
MsiJoinTransaction( MSIHANDLE handle
, DWORD attrs
, HANDLE
*event
)
4388 FIXME("%u %08x %p\n", handle
, attrs
, event
);
4390 *event
= (HANDLE
)0xdeadbeef;
4391 return ERROR_SUCCESS
;
4394 /***********************************************************************
4395 * MsiEndTransaction [MSI.@]
4397 UINT WINAPI
MsiEndTransaction( DWORD state
)
4399 FIXME("%u\n", state
);
4400 return ERROR_SUCCESS
;
4403 UINT WINAPI
Migrate10CachedPackagesW(void* a
, void* b
, void* c
, DWORD d
)
4405 FIXME("%p,%p,%p,%08x\n", a
, b
, c
, d
);
4406 return ERROR_SUCCESS
;
4409 /***********************************************************************
4410 * MsiRemovePatchesA [MSI.@]
4412 UINT WINAPI
MsiRemovePatchesA(LPCSTR patchlist
, LPCSTR product
, INSTALLTYPE type
, LPCSTR propertylist
)
4414 FIXME("(%s %s %d %s\n", debugstr_a(patchlist
), debugstr_a(product
), type
, debugstr_a(propertylist
));
4415 return ERROR_SUCCESS
;
4418 /***********************************************************************
4419 * MsiRemovePatchesW [MSI.@]
4421 UINT WINAPI
MsiRemovePatchesW(LPCWSTR patchlist
, LPCWSTR product
, INSTALLTYPE type
, LPCWSTR propertylist
)
4423 FIXME("(%s %s %d %s\n", debugstr_w(patchlist
), debugstr_w(product
), type
, debugstr_w(propertylist
));
4424 return ERROR_SUCCESS
;