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"
45 #include "wine/debug.h"
46 #include "wine/unicode.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
50 static const WCHAR installerW
[] = {'\\','I','n','s','t','a','l','l','e','r',0};
52 static UINT
msi_locate_product(LPCWSTR szProduct
, MSIINSTALLCONTEXT
*context
)
56 *context
= MSIINSTALLCONTEXT_NONE
;
58 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
59 &hkey
, FALSE
) == ERROR_SUCCESS
)
60 *context
= MSIINSTALLCONTEXT_USERMANAGED
;
61 else if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
62 &hkey
, FALSE
) == ERROR_SUCCESS
)
63 *context
= MSIINSTALLCONTEXT_MACHINE
;
64 else if (MSIREG_OpenProductKey(szProduct
, NULL
,
65 MSIINSTALLCONTEXT_USERUNMANAGED
,
66 &hkey
, FALSE
) == ERROR_SUCCESS
)
67 *context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
71 if (*context
== MSIINSTALLCONTEXT_NONE
)
72 return ERROR_UNKNOWN_PRODUCT
;
77 UINT WINAPI
MsiOpenProductA(LPCSTR szProduct
, MSIHANDLE
*phProduct
)
80 LPWSTR szwProd
= NULL
;
82 TRACE("%s %p\n",debugstr_a(szProduct
), phProduct
);
86 szwProd
= strdupAtoW( szProduct
);
88 return ERROR_OUTOFMEMORY
;
91 r
= MsiOpenProductW( szwProd
, phProduct
);
98 static UINT
MSI_OpenProductW(LPCWSTR szProduct
, MSIPACKAGE
**package
)
103 MSIINSTALLCONTEXT context
;
105 static const WCHAR managed
[] = {
106 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
107 static const WCHAR local
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
109 TRACE("%s %p\n", debugstr_w(szProduct
), package
);
111 r
= msi_locate_product(szProduct
, &context
);
112 if (r
!= ERROR_SUCCESS
)
115 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &props
, FALSE
);
116 if (r
!= ERROR_SUCCESS
)
117 return ERROR_UNKNOWN_PRODUCT
;
119 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
120 path
= msi_reg_get_val_str(props
, managed
);
122 path
= msi_reg_get_val_str(props
, local
);
124 r
= ERROR_UNKNOWN_PRODUCT
;
126 if (!path
|| GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
129 if (PathIsRelativeW(path
))
131 r
= ERROR_INSTALL_PACKAGE_OPEN_FAILED
;
135 r
= MSI_OpenPackageW(path
, package
);
143 UINT WINAPI
MsiOpenProductW(LPCWSTR szProduct
, MSIHANDLE
*phProduct
)
145 MSIPACKAGE
*package
= NULL
;
146 WCHAR squished_pc
[GUID_SIZE
];
149 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
150 return ERROR_INVALID_PARAMETER
;
153 return ERROR_INVALID_PARAMETER
;
155 r
= MSI_OpenProductW(szProduct
, &package
);
156 if (r
!= ERROR_SUCCESS
)
159 *phProduct
= alloc_msihandle(&package
->hdr
);
161 r
= ERROR_NOT_ENOUGH_MEMORY
;
163 msiobj_release(&package
->hdr
);
167 UINT WINAPI
MsiAdvertiseProductA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
168 LPCSTR szTransforms
, LANGID lgidLanguage
)
170 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath
),
171 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
), lgidLanguage
);
172 return ERROR_CALL_NOT_IMPLEMENTED
;
175 UINT WINAPI
MsiAdvertiseProductW(LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
176 LPCWSTR szTransforms
, LANGID lgidLanguage
)
178 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath
),
179 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
), lgidLanguage
);
180 return ERROR_CALL_NOT_IMPLEMENTED
;
183 UINT WINAPI
MsiAdvertiseProductExA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
184 LPCSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
186 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath
),
187 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
),
188 lgidLanguage
, dwPlatform
, dwOptions
);
189 return ERROR_CALL_NOT_IMPLEMENTED
;
192 UINT WINAPI
MsiAdvertiseProductExW( LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
193 LPCWSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
195 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath
),
196 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
),
197 lgidLanguage
, dwPlatform
, dwOptions
);
198 return ERROR_CALL_NOT_IMPLEMENTED
;
201 UINT WINAPI
MsiInstallProductA(LPCSTR szPackagePath
, LPCSTR szCommandLine
)
203 LPWSTR szwPath
= NULL
, szwCommand
= NULL
;
204 UINT r
= ERROR_OUTOFMEMORY
;
206 TRACE("%s %s\n",debugstr_a(szPackagePath
), debugstr_a(szCommandLine
));
210 szwPath
= strdupAtoW( szPackagePath
);
217 szwCommand
= strdupAtoW( szCommandLine
);
222 r
= MsiInstallProductW( szwPath
, szwCommand
);
226 msi_free( szwCommand
);
231 UINT WINAPI
MsiInstallProductW(LPCWSTR szPackagePath
, LPCWSTR szCommandLine
)
233 MSIPACKAGE
*package
= NULL
;
236 TRACE("%s %s\n",debugstr_w(szPackagePath
), debugstr_w(szCommandLine
));
239 return ERROR_INVALID_PARAMETER
;
242 return ERROR_PATH_NOT_FOUND
;
244 r
= MSI_OpenPackageW( szPackagePath
, &package
);
245 if (r
== ERROR_SUCCESS
)
247 r
= MSI_InstallPackage( package
, szPackagePath
, szCommandLine
);
248 msiobj_release( &package
->hdr
);
254 UINT WINAPI
MsiReinstallProductA(LPCSTR szProduct
, DWORD dwReinstallMode
)
259 TRACE("%s %08x\n", debugstr_a(szProduct
), dwReinstallMode
);
261 wszProduct
= strdupAtoW(szProduct
);
263 rc
= MsiReinstallProductW(wszProduct
, dwReinstallMode
);
265 msi_free(wszProduct
);
269 UINT WINAPI
MsiReinstallProductW(LPCWSTR szProduct
, DWORD dwReinstallMode
)
271 TRACE("%s %08x\n", debugstr_w(szProduct
), dwReinstallMode
);
273 return MsiReinstallFeatureW(szProduct
, szAll
, dwReinstallMode
);
276 UINT WINAPI
MsiApplyPatchA(LPCSTR szPatchPackage
, LPCSTR szInstallPackage
,
277 INSTALLTYPE eInstallType
, LPCSTR szCommandLine
)
279 LPWSTR patch_package
= NULL
;
280 LPWSTR install_package
= NULL
;
281 LPWSTR command_line
= NULL
;
282 UINT r
= ERROR_OUTOFMEMORY
;
284 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage
), debugstr_a(szInstallPackage
),
285 eInstallType
, debugstr_a(szCommandLine
));
287 if (szPatchPackage
&& !(patch_package
= strdupAtoW(szPatchPackage
)))
290 if (szInstallPackage
&& !(install_package
= strdupAtoW(szInstallPackage
)))
293 if (szCommandLine
&& !(command_line
= strdupAtoW(szCommandLine
)))
296 r
= MsiApplyPatchW(patch_package
, install_package
, eInstallType
, command_line
);
299 msi_free(patch_package
);
300 msi_free(install_package
);
301 msi_free(command_line
);
307 static UINT
get_patch_product_codes( LPCWSTR szPatchPackage
, WCHAR
***product_codes
)
309 MSIHANDLE patch
, info
= 0;
312 static WCHAR empty
[] = {0};
315 r
= MsiOpenDatabaseW( szPatchPackage
, MSIDBOPEN_READONLY
, &patch
);
316 if (r
!= ERROR_SUCCESS
)
319 r
= MsiGetSummaryInformationW( patch
, NULL
, 0, &info
);
320 if (r
!= ERROR_SUCCESS
)
324 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, empty
, &size
);
325 if (r
!= ERROR_MORE_DATA
|| !size
|| type
!= VT_LPSTR
)
327 ERR("Failed to read product codes from patch\n");
328 r
= ERROR_FUNCTION_FAILED
;
332 codes
= msi_alloc( ++size
* sizeof(WCHAR
) );
335 r
= ERROR_OUTOFMEMORY
;
339 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, codes
, &size
);
340 if (r
== ERROR_SUCCESS
)
341 *product_codes
= msi_split_string( codes
, ';' );
344 MsiCloseHandle( info
);
345 MsiCloseHandle( patch
);
350 static UINT
MSI_ApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szProductCode
, LPCWSTR szCommandLine
)
354 LPCWSTR cmd_ptr
= szCommandLine
;
355 LPWSTR cmd
, *codes
= NULL
;
356 BOOL succeeded
= FALSE
;
358 static const WCHAR fmt
[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
359 static WCHAR empty
[] = {0};
361 if (!szPatchPackage
|| !szPatchPackage
[0])
362 return ERROR_INVALID_PARAMETER
;
364 if (!szProductCode
&& (r
= get_patch_product_codes( szPatchPackage
, &codes
)))
370 size
= strlenW(cmd_ptr
) + strlenW(fmt
) + strlenW(szPatchPackage
) + 1;
371 cmd
= msi_alloc(size
* sizeof(WCHAR
));
375 return ERROR_OUTOFMEMORY
;
377 sprintfW(cmd
, fmt
, cmd_ptr
, szPatchPackage
);
380 r
= MsiConfigureProductExW(szProductCode
, INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
383 for (i
= 0; codes
[i
]; i
++)
385 r
= MsiConfigureProductExW(codes
[i
], INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
386 if (r
== ERROR_SUCCESS
)
388 TRACE("patch applied\n");
402 UINT WINAPI
MsiApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szInstallPackage
,
403 INSTALLTYPE eInstallType
, LPCWSTR szCommandLine
)
405 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage
), debugstr_w(szInstallPackage
),
406 eInstallType
, debugstr_w(szCommandLine
));
408 if (szInstallPackage
|| eInstallType
== INSTALLTYPE_NETWORK_IMAGE
||
409 eInstallType
== INSTALLTYPE_SINGLE_INSTANCE
)
411 FIXME("Only reading target products from patch\n");
412 return ERROR_CALL_NOT_IMPLEMENTED
;
415 return MSI_ApplyPatchW(szPatchPackage
, NULL
, szCommandLine
);
418 UINT WINAPI
MsiApplyMultiplePatchesA(LPCSTR szPatchPackages
,
419 LPCSTR szProductCode
, LPCSTR szPropertiesList
)
421 LPWSTR patch_packages
= NULL
;
422 LPWSTR product_code
= NULL
;
423 LPWSTR properties_list
= NULL
;
424 UINT r
= ERROR_OUTOFMEMORY
;
426 TRACE("%s %s %s\n", debugstr_a(szPatchPackages
), debugstr_a(szProductCode
),
427 debugstr_a(szPropertiesList
));
429 if (!szPatchPackages
|| !szPatchPackages
[0])
430 return ERROR_INVALID_PARAMETER
;
432 if (!(patch_packages
= strdupAtoW(szPatchPackages
)))
433 return ERROR_OUTOFMEMORY
;
435 if (szProductCode
&& !(product_code
= strdupAtoW(szProductCode
)))
438 if (szPropertiesList
&& !(properties_list
= strdupAtoW(szPropertiesList
)))
441 r
= MsiApplyMultiplePatchesW(patch_packages
, product_code
, properties_list
);
444 msi_free(patch_packages
);
445 msi_free(product_code
);
446 msi_free(properties_list
);
451 UINT WINAPI
MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages
,
452 LPCWSTR szProductCode
, LPCWSTR szPropertiesList
)
454 UINT r
= ERROR_SUCCESS
;
457 TRACE("%s %s %s\n", debugstr_w(szPatchPackages
), debugstr_w(szProductCode
),
458 debugstr_w(szPropertiesList
));
460 if (!szPatchPackages
|| !szPatchPackages
[0])
461 return ERROR_INVALID_PARAMETER
;
463 beg
= end
= szPatchPackages
;
469 while (*beg
== ' ') beg
++;
470 while (*end
&& *end
!= ';') end
++;
473 while (len
&& beg
[len
- 1] == ' ') len
--;
475 if (!len
) return ERROR_INVALID_NAME
;
477 patch
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
479 return ERROR_OUTOFMEMORY
;
481 memcpy(patch
, beg
, len
* sizeof(WCHAR
));
484 r
= MSI_ApplyPatchW(patch
, szProductCode
, szPropertiesList
);
487 if (r
!= ERROR_SUCCESS
)
495 UINT WINAPI
MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath
,
496 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
499 WCHAR
*package_path
= NULL
;
500 MSIPATCHSEQUENCEINFOW
*psi
;
502 TRACE("(%s, %d, %p)\n", debugstr_a(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
504 if (szProductPackagePath
&& !(package_path
= strdupAtoW( szProductPackagePath
)))
505 return ERROR_OUTOFMEMORY
;
507 psi
= msi_alloc( cPatchInfo
* sizeof(*psi
) );
510 msi_free( package_path
);
511 return ERROR_OUTOFMEMORY
;
514 for (i
= 0; i
< cPatchInfo
; i
++)
516 psi
[i
].szPatchData
= strdupAtoW( pPatchInfo
[i
].szPatchData
);
517 psi
[i
].ePatchDataType
= pPatchInfo
[i
].ePatchDataType
;
520 r
= MsiDetermineApplicablePatchesW( package_path
, cPatchInfo
, psi
);
521 if (r
== ERROR_SUCCESS
)
523 for (i
= 0; i
< cPatchInfo
; i
++)
525 pPatchInfo
[i
].dwOrder
= psi
[i
].dwOrder
;
526 pPatchInfo
[i
].uStatus
= psi
[i
].uStatus
;
530 msi_free( package_path
);
531 for (i
= 0; i
< cPatchInfo
; i
++)
532 msi_free( (WCHAR
*)psi
[i
].szPatchData
);
537 static UINT
MSI_ApplicablePatchW( MSIPACKAGE
*package
, LPCWSTR patch
)
540 MSIDATABASE
*patch_db
;
541 UINT r
= ERROR_SUCCESS
;
543 r
= MSI_OpenDatabaseW( patch
, MSIDBOPEN_READONLY
, &patch_db
);
544 if (r
!= ERROR_SUCCESS
)
546 WARN("failed to open patch file %s\n", debugstr_w(patch
));
550 si
= MSI_GetSummaryInformationW( patch_db
->storage
, 0 );
553 msiobj_release( &patch_db
->hdr
);
554 return ERROR_FUNCTION_FAILED
;
557 r
= msi_check_patch_applicable( package
, si
);
558 if (r
!= ERROR_SUCCESS
)
559 TRACE("patch not applicable\n");
561 msiobj_release( &patch_db
->hdr
);
562 msiobj_release( &si
->hdr
);
566 UINT WINAPI
MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath
,
567 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
569 UINT i
, r
, ret
= ERROR_FUNCTION_FAILED
;
572 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
574 r
= MSI_OpenPackageW( szProductPackagePath
, &package
);
575 if (r
!= ERROR_SUCCESS
)
577 ERR("failed to open package %u\n", r
);
581 for (i
= 0; i
< cPatchInfo
; i
++)
583 switch (pPatchInfo
[i
].ePatchDataType
)
585 case MSIPATCH_DATATYPE_PATCHFILE
:
587 FIXME("patch ordering not supported\n");
588 r
= MSI_ApplicablePatchW( package
, pPatchInfo
[i
].szPatchData
);
589 if (r
!= ERROR_SUCCESS
)
591 pPatchInfo
[i
].dwOrder
= ~0u;
592 pPatchInfo
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
596 pPatchInfo
[i
].dwOrder
= i
;
597 pPatchInfo
[i
].uStatus
= ret
= ERROR_SUCCESS
;
603 FIXME("patch data type %u not supported\n", pPatchInfo
[i
].ePatchDataType
);
604 pPatchInfo
[i
].dwOrder
= ~0u;
605 pPatchInfo
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
610 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo
[i
].szPatchData
));
611 TRACE("ePatchDataType: %u\n", pPatchInfo
[i
].ePatchDataType
);
612 TRACE(" dwOrder: %u\n", pPatchInfo
[i
].dwOrder
);
613 TRACE(" uStatus: %u\n", pPatchInfo
[i
].uStatus
);
618 UINT WINAPI
MsiDeterminePatchSequenceA(LPCSTR szProductCode
, LPCSTR szUserSid
,
619 MSIINSTALLCONTEXT dwContext
, DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
621 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode
),
622 debugstr_a(szUserSid
), dwContext
, cPatchInfo
, pPatchInfo
);
624 return ERROR_CALL_NOT_IMPLEMENTED
;
627 UINT WINAPI
MsiDeterminePatchSequenceW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
628 MSIINSTALLCONTEXT dwContext
, DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
630 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode
),
631 debugstr_w(szUserSid
), dwContext
, cPatchInfo
, pPatchInfo
);
633 return ERROR_CALL_NOT_IMPLEMENTED
;
636 static UINT
msi_open_package(LPCWSTR product
, MSIINSTALLCONTEXT context
,
637 MSIPACKAGE
**package
)
643 WCHAR sourcepath
[MAX_PATH
];
644 WCHAR filename
[MAX_PATH
];
646 r
= MSIREG_OpenInstallProps(product
, context
, NULL
, &props
, FALSE
);
647 if (r
!= ERROR_SUCCESS
)
648 return ERROR_BAD_CONFIGURATION
;
650 localpack
= msi_reg_get_val_str(props
, szLocalPackage
);
653 lstrcpyW(sourcepath
, localpack
);
657 if (!localpack
|| GetFileAttributesW(sourcepath
) == INVALID_FILE_ATTRIBUTES
)
659 sz
= sizeof(sourcepath
);
660 MsiSourceListGetInfoW(product
, NULL
, context
, MSICODE_PRODUCT
,
661 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
663 sz
= sizeof(filename
);
664 MsiSourceListGetInfoW(product
, NULL
, context
, MSICODE_PRODUCT
,
665 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
667 lstrcatW(sourcepath
, filename
);
670 if (GetFileAttributesW(sourcepath
) == INVALID_FILE_ATTRIBUTES
)
671 return ERROR_INSTALL_SOURCE_ABSENT
;
673 return MSI_OpenPackageW(sourcepath
, package
);
676 UINT WINAPI
MsiConfigureProductExW(LPCWSTR szProduct
, int iInstallLevel
,
677 INSTALLSTATE eInstallState
, LPCWSTR szCommandLine
)
679 MSIPACKAGE
* package
= NULL
;
680 MSIINSTALLCONTEXT context
;
683 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
686 static const WCHAR szInstalled
[] = {
687 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
688 static const WCHAR szInstallLevel
[] = {
689 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
690 static const WCHAR szRemoveAll
[] = {
691 ' ','R','E','M','O','V','E','=','A','L','L',0};
692 static const WCHAR szMachine
[] = {
693 ' ','A','L','L','U','S','E','R','S','=','1',0};
695 TRACE("%s %d %d %s\n",debugstr_w(szProduct
), iInstallLevel
, eInstallState
,
696 debugstr_w(szCommandLine
));
698 if (!szProduct
|| lstrlenW(szProduct
) != GUID_SIZE
- 1)
699 return ERROR_INVALID_PARAMETER
;
701 if (eInstallState
== INSTALLSTATE_ADVERTISED
||
702 eInstallState
== INSTALLSTATE_SOURCE
)
704 FIXME("State %d not implemented\n", eInstallState
);
705 return ERROR_CALL_NOT_IMPLEMENTED
;
708 r
= msi_locate_product(szProduct
, &context
);
709 if (r
!= ERROR_SUCCESS
)
712 r
= msi_open_package(szProduct
, context
, &package
);
713 if (r
!= ERROR_SUCCESS
)
716 sz
= lstrlenW(szInstalled
) + 1;
719 sz
+= lstrlenW(szCommandLine
);
721 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
722 sz
+= lstrlenW(szInstallLevel
);
724 if (eInstallState
== INSTALLSTATE_ABSENT
)
725 sz
+= lstrlenW(szRemoveAll
);
727 if (context
== MSIINSTALLCONTEXT_MACHINE
)
728 sz
+= lstrlenW(szMachine
);
730 commandline
= msi_alloc(sz
* sizeof(WCHAR
));
733 r
= ERROR_OUTOFMEMORY
;
739 lstrcpyW(commandline
,szCommandLine
);
741 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
742 lstrcatW(commandline
, szInstallLevel
);
744 if (eInstallState
== INSTALLSTATE_ABSENT
)
745 lstrcatW(commandline
, szRemoveAll
);
747 if (context
== MSIINSTALLCONTEXT_MACHINE
)
748 lstrcatW(commandline
, szMachine
);
750 sz
= sizeof(sourcepath
);
751 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
752 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
754 sz
= sizeof(filename
);
755 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
756 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
758 strcatW(sourcepath
, filename
);
760 r
= MSI_InstallPackage( package
, sourcepath
, commandline
);
762 msi_free(commandline
);
765 msiobj_release( &package
->hdr
);
770 UINT WINAPI
MsiConfigureProductExA(LPCSTR szProduct
, int iInstallLevel
,
771 INSTALLSTATE eInstallState
, LPCSTR szCommandLine
)
773 LPWSTR szwProduct
= NULL
;
774 LPWSTR szwCommandLine
= NULL
;
775 UINT r
= ERROR_OUTOFMEMORY
;
779 szwProduct
= strdupAtoW( szProduct
);
786 szwCommandLine
= strdupAtoW( szCommandLine
);
791 r
= MsiConfigureProductExW( szwProduct
, iInstallLevel
, eInstallState
,
794 msi_free( szwProduct
);
795 msi_free( szwCommandLine
);
800 UINT WINAPI
MsiConfigureProductA(LPCSTR szProduct
, int iInstallLevel
,
801 INSTALLSTATE eInstallState
)
803 LPWSTR szwProduct
= NULL
;
806 TRACE("%s %d %d\n",debugstr_a(szProduct
), iInstallLevel
, eInstallState
);
810 szwProduct
= strdupAtoW( szProduct
);
812 return ERROR_OUTOFMEMORY
;
815 r
= MsiConfigureProductW( szwProduct
, iInstallLevel
, eInstallState
);
816 msi_free( szwProduct
);
821 UINT WINAPI
MsiConfigureProductW(LPCWSTR szProduct
, int iInstallLevel
,
822 INSTALLSTATE eInstallState
)
824 return MsiConfigureProductExW(szProduct
, iInstallLevel
, eInstallState
, NULL
);
827 UINT WINAPI
MsiGetProductCodeA(LPCSTR szComponent
, LPSTR szBuffer
)
829 LPWSTR szwComponent
= NULL
;
831 WCHAR szwBuffer
[GUID_SIZE
];
833 TRACE("%s %p\n", debugstr_a(szComponent
), szBuffer
);
837 szwComponent
= strdupAtoW( szComponent
);
839 return ERROR_OUTOFMEMORY
;
843 r
= MsiGetProductCodeW( szwComponent
, szwBuffer
);
846 WideCharToMultiByte(CP_ACP
, 0, szwBuffer
, -1, szBuffer
, GUID_SIZE
, NULL
, NULL
);
848 msi_free( szwComponent
);
853 UINT WINAPI
MsiGetProductCodeW(LPCWSTR szComponent
, LPWSTR szBuffer
)
856 HKEY compkey
, prodkey
;
857 WCHAR squished_comp
[GUID_SIZE
];
858 WCHAR squished_prod
[GUID_SIZE
];
859 DWORD sz
= GUID_SIZE
;
861 TRACE("%s %p\n", debugstr_w(szComponent
), szBuffer
);
863 if (!szComponent
|| !*szComponent
)
864 return ERROR_INVALID_PARAMETER
;
866 if (!squash_guid(szComponent
, squished_comp
))
867 return ERROR_INVALID_PARAMETER
;
869 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &compkey
, FALSE
) != ERROR_SUCCESS
&&
870 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &compkey
, FALSE
) != ERROR_SUCCESS
)
872 return ERROR_UNKNOWN_COMPONENT
;
875 rc
= RegEnumValueW(compkey
, 0, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
876 if (rc
!= ERROR_SUCCESS
)
878 RegCloseKey(compkey
);
879 return ERROR_UNKNOWN_COMPONENT
;
882 /* check simple case, only one product */
883 rc
= RegEnumValueW(compkey
, 1, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
884 if (rc
== ERROR_NO_MORE_ITEMS
)
891 while ((rc
= RegEnumValueW(compkey
, index
, squished_prod
, &sz
,
892 NULL
, NULL
, NULL
, NULL
)) != ERROR_NO_MORE_ITEMS
)
896 unsquash_guid(squished_prod
, szBuffer
);
898 if (MSIREG_OpenProductKey(szBuffer
, NULL
,
899 MSIINSTALLCONTEXT_USERMANAGED
,
900 &prodkey
, FALSE
) == ERROR_SUCCESS
||
901 MSIREG_OpenProductKey(szBuffer
, NULL
,
902 MSIINSTALLCONTEXT_USERUNMANAGED
,
903 &prodkey
, FALSE
) == ERROR_SUCCESS
||
904 MSIREG_OpenProductKey(szBuffer
, NULL
,
905 MSIINSTALLCONTEXT_MACHINE
,
906 &prodkey
, FALSE
) == ERROR_SUCCESS
)
908 RegCloseKey(prodkey
);
914 rc
= ERROR_INSTALL_FAILURE
;
917 RegCloseKey(compkey
);
918 unsquash_guid(squished_prod
, szBuffer
);
922 static LPWSTR
msi_reg_get_value(HKEY hkey
, LPCWSTR name
, DWORD
*type
)
928 static const WCHAR format
[] = {'%','d',0};
930 res
= RegQueryValueExW(hkey
, name
, NULL
, type
, NULL
, NULL
);
931 if (res
!= ERROR_SUCCESS
)
935 return msi_reg_get_val_str(hkey
, name
);
937 if (!msi_reg_get_val_dword(hkey
, name
, &dval
))
940 sprintfW(temp
, format
, dval
);
941 return strdupW(temp
);
944 static UINT
MSI_GetProductInfo(LPCWSTR szProduct
, LPCWSTR szAttribute
,
945 awstring
*szValue
, LPDWORD pcchValueBuf
)
947 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
948 UINT r
= ERROR_UNKNOWN_PROPERTY
;
949 HKEY prodkey
, userdata
, source
;
951 WCHAR squished_pc
[GUID_SIZE
];
952 WCHAR packagecode
[GUID_SIZE
];
953 BOOL badconfig
= FALSE
;
955 DWORD type
= REG_NONE
;
957 static WCHAR empty
[] = {0};
958 static const WCHAR sourcelist
[] = {
959 'S','o','u','r','c','e','L','i','s','t',0};
960 static const WCHAR display_name
[] = {
961 'D','i','s','p','l','a','y','N','a','m','e',0};
962 static const WCHAR display_version
[] = {
963 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
964 static const WCHAR assignment
[] = {
965 'A','s','s','i','g','n','m','e','n','t',0};
967 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
968 debugstr_w(szAttribute
), szValue
, pcchValueBuf
);
970 if ((szValue
->str
.w
&& !pcchValueBuf
) || !szProduct
|| !szAttribute
)
971 return ERROR_INVALID_PARAMETER
;
973 if (!squash_guid(szProduct
, squished_pc
))
974 return ERROR_INVALID_PARAMETER
;
976 if ((r
= MSIREG_OpenProductKey(szProduct
, NULL
,
977 MSIINSTALLCONTEXT_USERMANAGED
,
978 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
979 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
980 MSIINSTALLCONTEXT_USERUNMANAGED
,
981 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
982 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
983 MSIINSTALLCONTEXT_MACHINE
,
984 &prodkey
, FALSE
)) == ERROR_SUCCESS
)
986 context
= MSIINSTALLCONTEXT_MACHINE
;
989 MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
991 if (!strcmpW( szAttribute
, INSTALLPROPERTY_HELPLINKW
) ||
992 !strcmpW( szAttribute
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
993 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLDATEW
) ||
994 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
995 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
996 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
997 !strcmpW( szAttribute
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
998 !strcmpW( szAttribute
, INSTALLPROPERTY_PUBLISHERW
) ||
999 !strcmpW( szAttribute
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1000 !strcmpW( szAttribute
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1001 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMINORW
) ||
1002 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1003 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1004 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTIDW
) ||
1005 !strcmpW( szAttribute
, INSTALLPROPERTY_REGCOMPANYW
) ||
1006 !strcmpW( szAttribute
, INSTALLPROPERTY_REGOWNERW
))
1010 r
= ERROR_UNKNOWN_PRODUCT
;
1015 return ERROR_UNKNOWN_PROPERTY
;
1017 if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1018 szAttribute
= display_name
;
1019 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
))
1020 szAttribute
= display_version
;
1022 val
= msi_reg_get_value(userdata
, szAttribute
, &type
);
1026 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTANCETYPEW
) ||
1027 !strcmpW( szAttribute
, INSTALLPROPERTY_TRANSFORMSW
) ||
1028 !strcmpW( szAttribute
, INSTALLPROPERTY_LANGUAGEW
) ||
1029 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1030 !strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
) ||
1031 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
) ||
1032 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONW
) ||
1033 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTICONW
) ||
1034 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1035 !strcmpW( szAttribute
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1039 r
= ERROR_UNKNOWN_PRODUCT
;
1043 if (!strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1044 szAttribute
= assignment
;
1046 if (!strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
))
1048 res
= RegOpenKeyW(prodkey
, sourcelist
, &source
);
1049 if (res
!= ERROR_SUCCESS
)
1051 r
= ERROR_UNKNOWN_PRODUCT
;
1055 val
= msi_reg_get_value(source
, szAttribute
, &type
);
1059 RegCloseKey(source
);
1063 val
= msi_reg_get_value(prodkey
, szAttribute
, &type
);
1068 if (val
!= empty
&& type
!= REG_DWORD
&&
1069 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
))
1071 if (lstrlenW(val
) != SQUISH_GUID_SIZE
- 1)
1075 unsquash_guid(val
, packagecode
);
1077 val
= strdupW(packagecode
);
1084 r
= ERROR_UNKNOWN_PROPERTY
;
1090 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1091 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1092 * can't rely on its value.
1094 if (szValue
->str
.a
|| szValue
->str
.w
)
1096 DWORD size
= *pcchValueBuf
;
1097 if (strlenW(val
) < size
)
1098 r
= msi_strcpy_to_awstring(val
, szValue
, &size
);
1101 r
= ERROR_MORE_DATA
;
1106 *pcchValueBuf
= lstrlenW(val
);
1110 r
= ERROR_BAD_CONFIGURATION
;
1116 RegCloseKey(prodkey
);
1117 RegCloseKey(userdata
);
1121 UINT WINAPI
MsiGetProductInfoA(LPCSTR szProduct
, LPCSTR szAttribute
,
1122 LPSTR szBuffer
, LPDWORD pcchValueBuf
)
1124 LPWSTR szwProduct
, szwAttribute
= NULL
;
1125 UINT r
= ERROR_OUTOFMEMORY
;
1128 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szAttribute
),
1129 szBuffer
, pcchValueBuf
);
1131 szwProduct
= strdupAtoW( szProduct
);
1132 if( szProduct
&& !szwProduct
)
1135 szwAttribute
= strdupAtoW( szAttribute
);
1136 if( szAttribute
&& !szwAttribute
)
1139 buffer
.unicode
= FALSE
;
1140 buffer
.str
.a
= szBuffer
;
1142 r
= MSI_GetProductInfo( szwProduct
, szwAttribute
,
1143 &buffer
, pcchValueBuf
);
1146 msi_free( szwProduct
);
1147 msi_free( szwAttribute
);
1152 UINT WINAPI
MsiGetProductInfoW(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1153 LPWSTR szBuffer
, LPDWORD pcchValueBuf
)
1157 TRACE("%s %s %p %p\n", debugstr_w(szProduct
), debugstr_w(szAttribute
),
1158 szBuffer
, pcchValueBuf
);
1160 buffer
.unicode
= TRUE
;
1161 buffer
.str
.w
= szBuffer
;
1163 return MSI_GetProductInfo( szProduct
, szAttribute
,
1164 &buffer
, pcchValueBuf
);
1167 UINT WINAPI
MsiGetProductInfoExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1168 MSIINSTALLCONTEXT dwContext
, LPCSTR szProperty
,
1169 LPSTR szValue
, LPDWORD pcchValue
)
1171 LPWSTR product
= NULL
;
1172 LPWSTR usersid
= NULL
;
1173 LPWSTR property
= NULL
;
1174 LPWSTR value
= NULL
;
1178 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode
),
1179 debugstr_a(szUserSid
), dwContext
, debugstr_a(szProperty
),
1180 szValue
, pcchValue
);
1182 if (szValue
&& !pcchValue
)
1183 return ERROR_INVALID_PARAMETER
;
1185 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1186 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1187 if (szProperty
) property
= strdupAtoW(szProperty
);
1189 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1191 if (r
!= ERROR_SUCCESS
)
1194 value
= msi_alloc(++len
* sizeof(WCHAR
));
1197 r
= ERROR_OUTOFMEMORY
;
1201 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1203 if (r
!= ERROR_SUCCESS
)
1209 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
1210 if (*pcchValue
>= len
)
1211 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
1214 r
= ERROR_MORE_DATA
;
1219 if (*pcchValue
<= len
|| !szValue
)
1220 len
= len
* sizeof(WCHAR
) - 1;
1222 *pcchValue
= len
- 1;
1233 static UINT
msi_copy_outval(LPWSTR val
, LPWSTR out
, LPDWORD size
)
1235 UINT r
= ERROR_SUCCESS
;
1238 return ERROR_UNKNOWN_PROPERTY
;
1242 if (strlenW(val
) >= *size
)
1244 r
= ERROR_MORE_DATA
;
1253 *size
= lstrlenW(val
);
1258 UINT WINAPI
MsiGetProductInfoExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
1259 MSIINSTALLCONTEXT dwContext
, LPCWSTR szProperty
,
1260 LPWSTR szValue
, LPDWORD pcchValue
)
1262 WCHAR squished_pc
[GUID_SIZE
];
1264 LPCWSTR package
= NULL
;
1265 HKEY props
= NULL
, prod
;
1266 HKEY classes
= NULL
, managed
;
1269 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1271 static const WCHAR five
[] = {'5',0};
1272 static const WCHAR displayname
[] = {
1273 'D','i','s','p','l','a','y','N','a','m','e',0};
1274 static const WCHAR displayversion
[] = {
1275 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1276 static const WCHAR managed_local_package
[] = {
1277 'M','a','n','a','g','e','d','L','o','c','a','l',
1278 'P','a','c','k','a','g','e',0};
1280 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode
),
1281 debugstr_w(szUserSid
), dwContext
, debugstr_w(szProperty
),
1282 szValue
, pcchValue
);
1284 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1285 return ERROR_INVALID_PARAMETER
;
1287 if (szValue
&& !pcchValue
)
1288 return ERROR_INVALID_PARAMETER
;
1290 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1291 dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1292 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1293 return ERROR_INVALID_PARAMETER
;
1295 if (!szProperty
|| !*szProperty
)
1296 return ERROR_INVALID_PARAMETER
;
1298 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1299 return ERROR_INVALID_PARAMETER
;
1301 /* FIXME: dwContext is provided, no need to search for it */
1302 MSIREG_OpenProductKey(szProductCode
, NULL
,MSIINSTALLCONTEXT_USERMANAGED
,
1304 MSIREG_OpenProductKey(szProductCode
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1307 MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
, &props
, FALSE
);
1309 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1311 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1313 if (!props
&& !prod
)
1316 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1318 package
= managed_local_package
;
1320 if (!props
&& !managed
)
1323 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1325 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1326 MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
, &classes
, FALSE
);
1328 if (!props
&& !classes
)
1332 if (!strcmpW( szProperty
, INSTALLPROPERTY_HELPLINKW
) ||
1333 !strcmpW( szProperty
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1334 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
) ||
1335 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1336 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1337 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1338 !strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1339 !strcmpW( szProperty
, INSTALLPROPERTY_PUBLISHERW
) ||
1340 !strcmpW( szProperty
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1341 !strcmpW( szProperty
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1342 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMINORW
) ||
1343 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1344 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1345 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTIDW
) ||
1346 !strcmpW( szProperty
, INSTALLPROPERTY_REGCOMPANYW
) ||
1347 !strcmpW( szProperty
, INSTALLPROPERTY_REGOWNERW
) ||
1348 !strcmpW( szProperty
, INSTALLPROPERTY_INSTANCETYPEW
))
1350 val
= msi_reg_get_value(props
, package
, &type
);
1353 if (prod
|| classes
)
1354 r
= ERROR_UNKNOWN_PROPERTY
;
1361 if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1362 szProperty
= displayname
;
1363 else if (!strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
))
1364 szProperty
= displayversion
;
1366 val
= msi_reg_get_value(props
, szProperty
, &type
);
1368 val
= strdupW(szEmpty
);
1370 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1372 else if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
) ||
1373 !strcmpW( szProperty
, INSTALLPROPERTY_LANGUAGEW
) ||
1374 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1375 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGECODEW
) ||
1376 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONW
) ||
1377 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTICONW
) ||
1378 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1379 !strcmpW( szProperty
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1381 if (!prod
&& !classes
)
1384 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1386 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1388 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1391 val
= msi_reg_get_value(hkey
, szProperty
, &type
);
1393 val
= strdupW(szEmpty
);
1395 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1397 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTSTATEW
))
1399 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1403 val
= msi_reg_get_value(props
, package
, &type
);
1408 val
= strdupW(five
);
1411 val
= strdupW(szOne
);
1413 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1416 else if (props
&& (val
= msi_reg_get_value(props
, package
, &type
)))
1419 val
= strdupW(five
);
1420 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1424 if (prod
|| managed
)
1425 val
= strdupW(szOne
);
1429 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1431 else if (!strcmpW( szProperty
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1433 if (!prod
&& !classes
)
1437 val
= strdupW(szEmpty
);
1438 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1441 r
= ERROR_UNKNOWN_PROPERTY
;
1446 RegCloseKey(managed
);
1447 RegCloseKey(classes
);
1453 UINT WINAPI
MsiGetPatchInfoExA(LPCSTR szPatchCode
, LPCSTR szProductCode
,
1454 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1455 LPCSTR szProperty
, LPSTR lpValue
, DWORD
*pcchValue
)
1457 LPWSTR patch
= NULL
, product
= NULL
, usersid
= NULL
;
1458 LPWSTR property
= NULL
, val
= NULL
;
1462 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode
),
1463 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
,
1464 debugstr_a(szProperty
), lpValue
, pcchValue
);
1466 if (lpValue
&& !pcchValue
)
1467 return ERROR_INVALID_PARAMETER
;
1469 if (szPatchCode
) patch
= strdupAtoW(szPatchCode
);
1470 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1471 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1472 if (szProperty
) property
= strdupAtoW(szProperty
);
1475 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1477 if (r
!= ERROR_SUCCESS
)
1480 val
= msi_alloc(++len
* sizeof(WCHAR
));
1483 r
= ERROR_OUTOFMEMORY
;
1487 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1489 if (r
!= ERROR_SUCCESS
|| !pcchValue
)
1493 WideCharToMultiByte(CP_ACP
, 0, val
, -1, lpValue
,
1494 *pcchValue
- 1, NULL
, NULL
);
1496 len
= lstrlenW(val
);
1497 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1501 r
= ERROR_MORE_DATA
;
1502 lpValue
[*pcchValue
- 1] = '\0';
1505 *pcchValue
= len
* sizeof(WCHAR
);
1520 UINT WINAPI
MsiGetPatchInfoExW(LPCWSTR szPatchCode
, LPCWSTR szProductCode
,
1521 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1522 LPCWSTR szProperty
, LPWSTR lpValue
, DWORD
*pcchValue
)
1524 WCHAR squished_pc
[GUID_SIZE
];
1525 WCHAR squished_patch
[GUID_SIZE
];
1526 HKEY udprod
= 0, prod
= 0, props
= 0;
1527 HKEY patch
= 0, patches
= 0;
1528 HKEY udpatch
= 0, datakey
= 0;
1529 HKEY prodpatches
= 0;
1531 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1535 static const WCHAR szManagedPackage
[] = {'M','a','n','a','g','e','d',
1536 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1538 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode
),
1539 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
,
1540 debugstr_w(szProperty
), lpValue
, pcchValue
);
1542 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1543 return ERROR_INVALID_PARAMETER
;
1545 if (!szPatchCode
|| !squash_guid(szPatchCode
, squished_patch
))
1546 return ERROR_INVALID_PARAMETER
;
1549 return ERROR_INVALID_PARAMETER
;
1551 if (lpValue
&& !pcchValue
)
1552 return ERROR_INVALID_PARAMETER
;
1554 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1555 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1556 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1557 return ERROR_INVALID_PARAMETER
;
1559 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1560 return ERROR_INVALID_PARAMETER
;
1562 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
1563 return ERROR_INVALID_PARAMETER
;
1565 if (MSIREG_OpenUserDataProductKey(szProductCode
, dwContext
, NULL
,
1566 &udprod
, FALSE
) != ERROR_SUCCESS
)
1569 if (MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
,
1570 &props
, FALSE
) != ERROR_SUCCESS
)
1573 r
= ERROR_UNKNOWN_PATCH
;
1575 res
= RegOpenKeyExW(udprod
, szPatches
, 0, KEY_WOW64_64KEY
|KEY_READ
, &patches
);
1576 if (res
!= ERROR_SUCCESS
)
1579 res
= RegOpenKeyExW(patches
, squished_patch
, 0, KEY_WOW64_64KEY
|KEY_READ
, &patch
);
1580 if (res
!= ERROR_SUCCESS
)
1583 if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
))
1585 if (MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
,
1586 &prod
, FALSE
) != ERROR_SUCCESS
)
1589 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_WOW64_64KEY
|KEY_ALL_ACCESS
, &prodpatches
);
1590 if (res
!= ERROR_SUCCESS
)
1593 datakey
= prodpatches
;
1594 szProperty
= squished_patch
;
1598 if (MSIREG_OpenUserDataPatchKey(szPatchCode
, dwContext
,
1599 &udpatch
, FALSE
) != ERROR_SUCCESS
)
1602 if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1604 if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1605 szProperty
= szManagedPackage
;
1608 else if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
))
1611 szProperty
= szInstalled
;
1613 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1617 else if (!strcmpW( szProperty
, INSTALLPROPERTY_UNINSTALLABLEW
) ||
1618 !strcmpW( szProperty
, INSTALLPROPERTY_PATCHSTATEW
) ||
1619 !strcmpW( szProperty
, INSTALLPROPERTY_DISPLAYNAMEW
) ||
1620 !strcmpW( szProperty
, INSTALLPROPERTY_MOREINFOURLW
))
1626 r
= ERROR_UNKNOWN_PROPERTY
;
1631 val
= msi_reg_get_val_str(datakey
, szProperty
);
1633 val
= strdupW(szEmpty
);
1641 lstrcpynW(lpValue
, val
, *pcchValue
);
1643 len
= lstrlenW(val
);
1644 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1647 r
= ERROR_MORE_DATA
;
1649 *pcchValue
= len
* sizeof(WCHAR
);
1656 RegCloseKey(prodpatches
);
1659 RegCloseKey(patches
);
1660 RegCloseKey(udpatch
);
1662 RegCloseKey(udprod
);
1667 UINT WINAPI
MsiGetPatchInfoA( LPCSTR patch
, LPCSTR attr
, LPSTR buffer
, LPDWORD buflen
)
1669 UINT r
= ERROR_OUTOFMEMORY
;
1671 LPWSTR patchW
= NULL
, attrW
= NULL
, bufferW
= NULL
;
1673 TRACE("%s %s %p %p\n", debugstr_a(patch
), debugstr_a(attr
), buffer
, buflen
);
1675 if (!patch
|| !attr
)
1676 return ERROR_INVALID_PARAMETER
;
1678 if (!(patchW
= strdupAtoW( patch
)))
1681 if (!(attrW
= strdupAtoW( attr
)))
1685 r
= MsiGetPatchInfoW( patchW
, attrW
, NULL
, &size
);
1686 if (r
!= ERROR_SUCCESS
)
1690 if (!(bufferW
= msi_alloc( size
* sizeof(WCHAR
) )))
1692 r
= ERROR_OUTOFMEMORY
;
1696 r
= MsiGetPatchInfoW( patchW
, attrW
, bufferW
, &size
);
1697 if (r
== ERROR_SUCCESS
)
1699 int len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
1701 r
= ERROR_MORE_DATA
;
1703 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *buflen
, NULL
, NULL
);
1711 msi_free( bufferW
);
1715 UINT WINAPI
MsiGetPatchInfoW( LPCWSTR patch
, LPCWSTR attr
, LPWSTR buffer
, LPDWORD buflen
)
1718 WCHAR product
[GUID_SIZE
];
1721 TRACE("%s %s %p %p\n", debugstr_w(patch
), debugstr_w(attr
), buffer
, buflen
);
1723 if (!patch
|| !attr
)
1724 return ERROR_INVALID_PARAMETER
;
1726 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW
, attr
))
1727 return ERROR_UNKNOWN_PROPERTY
;
1732 r
= MsiEnumProductsW( index
, product
);
1733 if (r
!= ERROR_SUCCESS
)
1736 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, attr
, buffer
, buflen
);
1737 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1740 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, attr
, buffer
, buflen
);
1741 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1744 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_MACHINE
, attr
, buffer
, buflen
);
1745 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1751 return ERROR_UNKNOWN_PRODUCT
;
1754 UINT WINAPI
MsiEnableLogA(DWORD dwLogMode
, LPCSTR szLogFile
, DWORD attributes
)
1756 LPWSTR szwLogFile
= NULL
;
1759 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_a(szLogFile
), attributes
);
1763 szwLogFile
= strdupAtoW( szLogFile
);
1765 return ERROR_OUTOFMEMORY
;
1767 r
= MsiEnableLogW( dwLogMode
, szwLogFile
, attributes
);
1768 msi_free( szwLogFile
);
1772 UINT WINAPI
MsiEnableLogW(DWORD dwLogMode
, LPCWSTR szLogFile
, DWORD attributes
)
1774 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_w(szLogFile
), attributes
);
1776 msi_free(gszLogFile
);
1782 if (!(attributes
& INSTALLLOGATTRIBUTES_APPEND
))
1783 DeleteFileW(szLogFile
);
1784 file
= CreateFileW(szLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
,
1785 FILE_ATTRIBUTE_NORMAL
, NULL
);
1786 if (file
!= INVALID_HANDLE_VALUE
)
1788 gszLogFile
= strdupW(szLogFile
);
1792 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile
), GetLastError());
1795 return ERROR_SUCCESS
;
1798 UINT WINAPI
MsiEnumComponentCostsA( MSIHANDLE handle
, LPCSTR component
, DWORD index
,
1799 INSTALLSTATE state
, LPSTR drive
, DWORD
*buflen
,
1800 int *cost
, int *temp
)
1804 WCHAR
*driveW
, *componentW
= NULL
;
1806 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle
, debugstr_a(component
), index
,
1807 state
, drive
, buflen
, cost
, temp
);
1809 if (!drive
|| !buflen
) return ERROR_INVALID_PARAMETER
;
1810 if (component
&& !(componentW
= strdupAtoW( component
))) return ERROR_OUTOFMEMORY
;
1813 if (!(driveW
= msi_alloc( len
* sizeof(WCHAR
) )))
1815 msi_free( componentW
);
1816 return ERROR_OUTOFMEMORY
;
1818 r
= MsiEnumComponentCostsW( handle
, componentW
, index
, state
, driveW
, buflen
, cost
, temp
);
1821 WideCharToMultiByte( CP_ACP
, 0, driveW
, -1, drive
, len
, NULL
, NULL
);
1823 msi_free( componentW
);
1828 UINT WINAPI
MsiEnumComponentCostsW( MSIHANDLE handle
, LPCWSTR component
, DWORD index
,
1829 INSTALLSTATE state
, LPWSTR drive
, DWORD
*buflen
,
1830 int *cost
, int *temp
)
1832 UINT r
= ERROR_NO_MORE_ITEMS
;
1833 MSICOMPONENT
*comp
= NULL
;
1834 MSIPACKAGE
*package
;
1837 WCHAR path
[MAX_PATH
];
1839 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle
, debugstr_w(component
), index
,
1840 state
, drive
, buflen
, cost
, temp
);
1842 if (!drive
|| !buflen
|| !cost
|| !temp
) return ERROR_INVALID_PARAMETER
;
1843 if (!(package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
)))
1846 IWineMsiRemotePackage
*remote_package
;
1849 if (!(remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
)))
1850 return ERROR_INVALID_HANDLE
;
1852 bname
= SysAllocString( component
);
1855 IWineMsiRemotePackage_Release( remote_package
);
1856 return ERROR_OUTOFMEMORY
;
1858 hr
= IWineMsiRemotePackage_EnumComponentCosts( remote_package
, bname
, index
, state
, drive
, buflen
, cost
, temp
);
1859 IWineMsiRemotePackage_Release( remote_package
);
1860 SysFreeString( bname
);
1863 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
) return HRESULT_CODE(hr
);
1864 return ERROR_FUNCTION_FAILED
;
1866 return ERROR_SUCCESS
;
1869 if (!msi_get_property_int( package
->db
, szCostingComplete
, 0 ))
1871 msiobj_release( &package
->hdr
);
1872 return ERROR_FUNCTION_NOT_CALLED
;
1874 if (component
&& component
[0] && !(comp
= get_loaded_component( package
, component
)))
1876 msiobj_release( &package
->hdr
);
1877 return ERROR_UNKNOWN_COMPONENT
;
1882 msiobj_release( &package
->hdr
);
1883 return ERROR_MORE_DATA
;
1887 msiobj_release( &package
->hdr
);
1888 return ERROR_NO_MORE_ITEMS
;
1893 GetWindowsDirectoryW( path
, MAX_PATH
);
1894 if (component
&& component
[0])
1896 if (comp
->assembly
&& !comp
->assembly
->application
) *temp
= comp
->Cost
;
1897 if (!comp
->Enabled
|| !comp
->KeyPath
)
1906 else if ((file
= get_loaded_file( package
, comp
->KeyPath
)))
1908 *cost
= max( 8, comp
->Cost
/ 512 );
1909 drive
[0] = file
->TargetPath
[0];
1916 else if (IStorage_Stat( package
->db
->storage
, &stat
, STATFLAG_NONAME
) == S_OK
)
1918 *temp
= max( 8, stat
.cbSize
.QuadPart
/ 512 );
1925 msiobj_release( &package
->hdr
);
1929 UINT WINAPI
MsiQueryComponentStateA(LPCSTR szProductCode
,
1930 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1931 LPCSTR szComponent
, INSTALLSTATE
*pdwState
)
1933 LPWSTR prodcode
= NULL
, usersid
= NULL
, comp
= NULL
;
1936 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode
),
1937 debugstr_a(szUserSid
), dwContext
, debugstr_a(szComponent
), pdwState
);
1939 if (szProductCode
&& !(prodcode
= strdupAtoW(szProductCode
)))
1940 return ERROR_OUTOFMEMORY
;
1942 if (szUserSid
&& !(usersid
= strdupAtoW(szUserSid
)))
1943 return ERROR_OUTOFMEMORY
;
1945 if (szComponent
&& !(comp
= strdupAtoW(szComponent
)))
1946 return ERROR_OUTOFMEMORY
;
1948 r
= MsiQueryComponentStateW(prodcode
, usersid
, dwContext
, comp
, pdwState
);
1957 static BOOL
msi_comp_find_prod_key(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
1962 r
= MSIREG_OpenProductKey(prodcode
, NULL
, context
, &hkey
, FALSE
);
1964 return (r
== ERROR_SUCCESS
);
1967 static BOOL
msi_comp_find_package(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
1975 static const WCHAR local_package
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1976 static const WCHAR managed_local_package
[] = {
1977 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1980 r
= MSIREG_OpenInstallProps(prodcode
, context
, NULL
, &hkey
, FALSE
);
1981 if (r
!= ERROR_SUCCESS
)
1984 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
1985 package
= managed_local_package
;
1987 package
= local_package
;
1990 res
= RegQueryValueExW(hkey
, package
, NULL
, NULL
, NULL
, &sz
);
1993 return (res
== ERROR_SUCCESS
);
1996 static BOOL
msi_comp_find_prodcode(LPWSTR squished_pc
,
1997 MSIINSTALLCONTEXT context
,
1998 LPCWSTR comp
, LPWSTR val
, DWORD
*sz
)
2004 if (context
== MSIINSTALLCONTEXT_MACHINE
)
2005 r
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2007 r
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2009 if (r
!= ERROR_SUCCESS
)
2012 res
= RegQueryValueExW(hkey
, squished_pc
, NULL
, NULL
, (BYTE
*)val
, sz
);
2013 if (res
!= ERROR_SUCCESS
)
2020 UINT WINAPI
MsiQueryComponentStateW(LPCWSTR szProductCode
,
2021 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
2022 LPCWSTR szComponent
, INSTALLSTATE
*pdwState
)
2024 WCHAR squished_pc
[GUID_SIZE
];
2025 WCHAR val
[MAX_PATH
];
2029 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode
),
2030 debugstr_w(szUserSid
), dwContext
, debugstr_w(szComponent
), pdwState
);
2032 if (!pdwState
|| !szComponent
)
2033 return ERROR_INVALID_PARAMETER
;
2035 if (!szProductCode
|| !*szProductCode
|| lstrlenW(szProductCode
) != GUID_SIZE
- 1)
2036 return ERROR_INVALID_PARAMETER
;
2038 if (!squash_guid(szProductCode
, squished_pc
))
2039 return ERROR_INVALID_PARAMETER
;
2041 found
= msi_comp_find_prod_key(szProductCode
, dwContext
);
2043 if (!msi_comp_find_package(szProductCode
, dwContext
))
2047 *pdwState
= INSTALLSTATE_UNKNOWN
;
2048 return ERROR_UNKNOWN_COMPONENT
;
2051 return ERROR_UNKNOWN_PRODUCT
;
2054 *pdwState
= INSTALLSTATE_UNKNOWN
;
2057 if (!msi_comp_find_prodcode(squished_pc
, dwContext
, szComponent
, val
, &sz
))
2058 return ERROR_UNKNOWN_COMPONENT
;
2061 *pdwState
= INSTALLSTATE_NOTUSED
;
2064 if (lstrlenW(val
) > 2 &&
2065 val
[0] >= '0' && val
[0] <= '9' && val
[1] >= '0' && val
[1] <= '9')
2067 *pdwState
= INSTALLSTATE_SOURCE
;
2070 *pdwState
= INSTALLSTATE_LOCAL
;
2073 TRACE("-> %d\n", *pdwState
);
2074 return ERROR_SUCCESS
;
2077 INSTALLSTATE WINAPI
MsiQueryProductStateA(LPCSTR szProduct
)
2079 LPWSTR szwProduct
= NULL
;
2084 szwProduct
= strdupAtoW( szProduct
);
2086 return ERROR_OUTOFMEMORY
;
2088 r
= MsiQueryProductStateW( szwProduct
);
2089 msi_free( szwProduct
);
2093 INSTALLSTATE WINAPI
MsiQueryProductStateW(LPCWSTR szProduct
)
2095 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
2096 INSTALLSTATE state
= INSTALLSTATE_ADVERTISED
;
2097 HKEY prodkey
= 0, userdata
= 0;
2101 static const WCHAR szWindowsInstaller
[] = {
2102 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2104 TRACE("%s\n", debugstr_w(szProduct
));
2106 if (!szProduct
|| !*szProduct
)
2107 return INSTALLSTATE_INVALIDARG
;
2109 if (lstrlenW(szProduct
) != GUID_SIZE
- 1)
2110 return INSTALLSTATE_INVALIDARG
;
2112 if (szProduct
[0] != '{' || szProduct
[37] != '}')
2113 return INSTALLSTATE_UNKNOWN
;
2115 SetLastError( ERROR_SUCCESS
);
2117 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
2118 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2119 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2120 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2121 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2122 &prodkey
, FALSE
) == ERROR_SUCCESS
)
2124 context
= MSIINSTALLCONTEXT_MACHINE
;
2127 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
2128 if (r
!= ERROR_SUCCESS
)
2131 if (!msi_reg_get_val_dword(userdata
, szWindowsInstaller
, &val
))
2135 state
= INSTALLSTATE_DEFAULT
;
2137 state
= INSTALLSTATE_UNKNOWN
;
2142 state
= INSTALLSTATE_UNKNOWN
;
2145 state
= INSTALLSTATE_ABSENT
;
2148 RegCloseKey(prodkey
);
2149 RegCloseKey(userdata
);
2150 TRACE("-> %d\n", state
);
2154 INSTALLUILEVEL WINAPI
MsiSetInternalUI(INSTALLUILEVEL dwUILevel
, HWND
*phWnd
)
2156 INSTALLUILEVEL old
= gUILevel
;
2157 HWND oldwnd
= gUIhwnd
;
2159 TRACE("%08x %p\n", dwUILevel
, phWnd
);
2161 gUILevel
= dwUILevel
;
2170 INSTALLUI_HANDLERA WINAPI
MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler
,
2171 DWORD dwMessageFilter
, LPVOID pvContext
)
2173 INSTALLUI_HANDLERA prev
= gUIHandlerA
;
2175 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2177 gUIHandlerA
= puiHandler
;
2179 gUIFilter
= dwMessageFilter
;
2180 gUIContext
= pvContext
;
2185 INSTALLUI_HANDLERW WINAPI
MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler
,
2186 DWORD dwMessageFilter
, LPVOID pvContext
)
2188 INSTALLUI_HANDLERW prev
= gUIHandlerW
;
2190 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2193 gUIHandlerW
= puiHandler
;
2194 gUIFilter
= dwMessageFilter
;
2195 gUIContext
= pvContext
;
2200 /******************************************************************
2201 * MsiLoadStringW [MSI.@]
2203 * Loads a string from MSI's string resources.
2207 * handle [I] only -1 is handled currently
2208 * id [I] id of the string to be loaded
2209 * lpBuffer [O] buffer for the string to be written to
2210 * nBufferMax [I] maximum size of the buffer in characters
2211 * lang [I] the preferred language for the string
2215 * If successful, this function returns the language id of the string loaded
2216 * If the function fails, the function returns zero.
2220 * The type of the first parameter is unknown. LoadString's prototype
2221 * suggests that it might be a module handle. I have made it an MSI handle
2222 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2223 * handle. Maybe strings can be stored in an MSI database somehow.
2225 LANGID WINAPI
MsiLoadStringW( MSIHANDLE handle
, UINT id
, LPWSTR lpBuffer
,
2226 int nBufferMax
, LANGID lang
)
2233 TRACE("%d %u %p %d %d\n", handle
, id
, lpBuffer
, nBufferMax
, lang
);
2236 FIXME("don't know how to deal with handle = %08x\n", handle
);
2239 lang
= GetUserDefaultLangID();
2241 hres
= FindResourceExW( msi_hInstance
, (LPCWSTR
) RT_STRING
,
2245 hResData
= LoadResource( msi_hInstance
, hres
);
2248 p
= LockResource( hResData
);
2252 for (i
= 0; i
< (id
&0xf); i
++)
2256 if( nBufferMax
<= len
)
2259 memcpy( lpBuffer
, p
+1, len
* sizeof(WCHAR
));
2260 lpBuffer
[ len
] = 0;
2262 TRACE("found -> %s\n", debugstr_w(lpBuffer
));
2267 LANGID WINAPI
MsiLoadStringA( MSIHANDLE handle
, UINT id
, LPSTR lpBuffer
,
2268 int nBufferMax
, LANGID lang
)
2274 bufW
= msi_alloc(nBufferMax
*sizeof(WCHAR
));
2275 r
= MsiLoadStringW(handle
, id
, bufW
, nBufferMax
, lang
);
2278 len
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
2279 if( len
<= nBufferMax
)
2280 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1,
2281 lpBuffer
, nBufferMax
, NULL
, NULL
);
2289 INSTALLSTATE WINAPI
MsiLocateComponentA(LPCSTR szComponent
, LPSTR lpPathBuf
,
2292 char szProduct
[GUID_SIZE
];
2294 TRACE("%s %p %p\n", debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2296 if (!szComponent
|| !pcchBuf
)
2297 return INSTALLSTATE_INVALIDARG
;
2299 if (MsiGetProductCodeA( szComponent
, szProduct
) != ERROR_SUCCESS
)
2300 return INSTALLSTATE_UNKNOWN
;
2302 return MsiGetComponentPathA( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2305 INSTALLSTATE WINAPI
MsiLocateComponentW(LPCWSTR szComponent
, LPWSTR lpPathBuf
,
2308 WCHAR szProduct
[GUID_SIZE
];
2310 TRACE("%s %p %p\n", debugstr_w(szComponent
), lpPathBuf
, pcchBuf
);
2312 if (!szComponent
|| !pcchBuf
)
2313 return INSTALLSTATE_INVALIDARG
;
2315 if (MsiGetProductCodeW( szComponent
, szProduct
) != ERROR_SUCCESS
)
2316 return INSTALLSTATE_UNKNOWN
;
2318 return MsiGetComponentPathW( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2321 UINT WINAPI
MsiMessageBoxA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2322 WORD wLanguageId
, DWORD f
)
2324 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_a(lpText
), debugstr_a(lpCaption
),
2325 uType
, wLanguageId
, f
);
2326 return MessageBoxExA(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2329 UINT WINAPI
MsiMessageBoxW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2330 WORD wLanguageId
, DWORD f
)
2332 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_w(lpText
), debugstr_w(lpCaption
),
2333 uType
, wLanguageId
, f
);
2334 return MessageBoxExW(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2337 UINT WINAPI
MsiMessageBoxExA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2338 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2340 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_a(lpText
),
2341 debugstr_a(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2342 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2345 UINT WINAPI
MsiMessageBoxExW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2346 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2348 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_w(lpText
),
2349 debugstr_w(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2350 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2353 UINT WINAPI
MsiProvideAssemblyA( LPCSTR szAssemblyName
, LPCSTR szAppContext
,
2354 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPSTR lpPathBuf
,
2355 LPDWORD pcchPathBuf
)
2357 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName
),
2358 debugstr_a(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2360 return ERROR_CALL_NOT_IMPLEMENTED
;
2363 UINT WINAPI
MsiProvideAssemblyW( LPCWSTR szAssemblyName
, LPCWSTR szAppContext
,
2364 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPWSTR lpPathBuf
,
2365 LPDWORD pcchPathBuf
)
2367 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName
),
2368 debugstr_w(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2370 return ERROR_CALL_NOT_IMPLEMENTED
;
2373 UINT WINAPI
MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor
,
2374 LPSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2376 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2377 return ERROR_CALL_NOT_IMPLEMENTED
;
2380 UINT WINAPI
MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor
,
2381 LPWSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2383 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2384 return ERROR_CALL_NOT_IMPLEMENTED
;
2387 HRESULT WINAPI
MsiGetFileSignatureInformationA( LPCSTR path
, DWORD flags
, PCCERT_CONTEXT
*cert
,
2388 LPBYTE hash
, LPDWORD hashlen
)
2391 WCHAR
*pathW
= NULL
;
2393 TRACE("%s %08x %p %p %p\n", debugstr_a(path
), flags
, cert
, hash
, hashlen
);
2395 if (path
&& !(pathW
= strdupAtoW( path
))) return ERROR_OUTOFMEMORY
;
2396 r
= MsiGetFileSignatureInformationW( pathW
, flags
, cert
, hash
, hashlen
);
2401 HRESULT WINAPI
MsiGetFileSignatureInformationW( LPCWSTR path
, DWORD flags
, PCCERT_CONTEXT
*cert
,
2402 LPBYTE hash
, LPDWORD hashlen
)
2404 static GUID generic_verify_v2
= WINTRUST_ACTION_GENERIC_VERIFY_V2
;
2407 WINTRUST_FILE_INFO info
;
2408 CRYPT_PROVIDER_SGNR
*signer
;
2409 CRYPT_PROVIDER_CERT
*provider
;
2411 TRACE("%s %08x %p %p %p\n", debugstr_w(path
), flags
, cert
, hash
, hashlen
);
2413 if (!path
|| !cert
) return E_INVALIDARG
;
2415 info
.cbStruct
= sizeof(info
);
2416 info
.pcwszFilePath
= path
;
2418 info
.pgKnownSubject
= NULL
;
2420 data
.cbStruct
= sizeof(data
);
2421 data
.pPolicyCallbackData
= NULL
;
2422 data
.pSIPClientData
= NULL
;
2423 data
.dwUIChoice
= WTD_UI_NONE
;
2424 data
.fdwRevocationChecks
= WTD_REVOKE_WHOLECHAIN
;
2425 data
.dwUnionChoice
= WTD_CHOICE_FILE
;
2426 data
.u
.pFile
= &info
;
2427 data
.dwStateAction
= WTD_STATEACTION_VERIFY
;
2428 data
.hWVTStateData
= NULL
;
2429 data
.pwszURLReference
= NULL
;
2430 data
.dwProvFlags
= 0;
2431 data
.dwUIContext
= WTD_UICONTEXT_INSTALL
;
2432 hr
= WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2433 if (FAILED(hr
)) goto done
;
2435 if (!(signer
= WTHelperGetProvSignerFromChain( data
.hWVTStateData
, 0, FALSE
, 0 )))
2437 hr
= TRUST_E_NOSIGNATURE
;
2442 DWORD len
= signer
->psSigner
->EncryptedHash
.cbData
;
2446 hr
= HRESULT_FROM_WIN32(ERROR_MORE_DATA
);
2449 memcpy( hash
, signer
->psSigner
->EncryptedHash
.pbData
, len
);
2452 if (!(provider
= WTHelperGetProvCertFromChain( signer
, 0 )))
2454 hr
= TRUST_E_PROVIDER_UNKNOWN
;
2457 *cert
= CertDuplicateCertificateContext( provider
->pCert
);
2460 data
.dwStateAction
= WTD_STATEACTION_CLOSE
;
2461 WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2465 /******************************************************************
2466 * MsiGetProductPropertyA [MSI.@]
2468 UINT WINAPI
MsiGetProductPropertyA(MSIHANDLE hProduct
, LPCSTR szProperty
,
2469 LPSTR szValue
, LPDWORD pccbValue
)
2471 LPWSTR prop
= NULL
, val
= NULL
;
2475 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_a(szProperty
),
2476 szValue
, pccbValue
);
2478 if (szValue
&& !pccbValue
)
2479 return ERROR_INVALID_PARAMETER
;
2481 if (szProperty
) prop
= strdupAtoW(szProperty
);
2484 r
= MsiGetProductPropertyW(hProduct
, prop
, NULL
, &len
);
2485 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2488 if (r
== ERROR_SUCCESS
)
2490 if (szValue
) *szValue
= '\0';
2491 if (pccbValue
) *pccbValue
= 0;
2495 val
= msi_alloc(++len
* sizeof(WCHAR
));
2498 r
= ERROR_OUTOFMEMORY
;
2502 r
= MsiGetProductPropertyW(hProduct
, prop
, val
, &len
);
2503 if (r
!= ERROR_SUCCESS
)
2506 len
= WideCharToMultiByte(CP_ACP
, 0, val
, -1, NULL
, 0, NULL
, NULL
);
2509 WideCharToMultiByte(CP_ACP
, 0, val
, -1, szValue
,
2510 *pccbValue
, NULL
, NULL
);
2514 if (len
> *pccbValue
)
2515 r
= ERROR_MORE_DATA
;
2517 *pccbValue
= len
- 1;
2527 /******************************************************************
2528 * MsiGetProductPropertyW [MSI.@]
2530 UINT WINAPI
MsiGetProductPropertyW(MSIHANDLE hProduct
, LPCWSTR szProperty
,
2531 LPWSTR szValue
, LPDWORD pccbValue
)
2533 MSIPACKAGE
*package
;
2534 MSIQUERY
*view
= NULL
;
2535 MSIRECORD
*rec
= NULL
;
2539 static const WCHAR query
[] = {
2540 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2541 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2542 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2544 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_w(szProperty
),
2545 szValue
, pccbValue
);
2548 return ERROR_INVALID_PARAMETER
;
2550 if (szValue
&& !pccbValue
)
2551 return ERROR_INVALID_PARAMETER
;
2553 package
= msihandle2msiinfo(hProduct
, MSIHANDLETYPE_PACKAGE
);
2555 return ERROR_INVALID_HANDLE
;
2557 r
= MSI_OpenQuery(package
->db
, &view
, query
, szProperty
);
2558 if (r
!= ERROR_SUCCESS
)
2561 r
= MSI_ViewExecute(view
, 0);
2562 if (r
!= ERROR_SUCCESS
)
2565 r
= MSI_ViewFetch(view
, &rec
);
2566 if (r
!= ERROR_SUCCESS
)
2569 val
= MSI_RecordGetString(rec
, 2);
2573 if (lstrlenW(val
) >= *pccbValue
)
2575 lstrcpynW(szValue
, val
, *pccbValue
);
2576 *pccbValue
= lstrlenW(val
);
2577 r
= ERROR_MORE_DATA
;
2581 lstrcpyW(szValue
, val
);
2582 *pccbValue
= lstrlenW(val
);
2589 MSI_ViewClose(view
);
2590 msiobj_release(&view
->hdr
);
2591 if (rec
) msiobj_release(&rec
->hdr
);
2596 if (szValue
) *szValue
= '\0';
2597 if (pccbValue
) *pccbValue
= 0;
2601 msiobj_release(&package
->hdr
);
2605 UINT WINAPI
MsiVerifyPackageA( LPCSTR szPackage
)
2608 LPWSTR szPack
= NULL
;
2610 TRACE("%s\n", debugstr_a(szPackage
) );
2614 szPack
= strdupAtoW( szPackage
);
2616 return ERROR_OUTOFMEMORY
;
2619 r
= MsiVerifyPackageW( szPack
);
2626 UINT WINAPI
MsiVerifyPackageW( LPCWSTR szPackage
)
2631 TRACE("%s\n", debugstr_w(szPackage
) );
2633 r
= MsiOpenDatabaseW( szPackage
, MSIDBOPEN_READONLY
, &handle
);
2634 MsiCloseHandle( handle
);
2639 static INSTALLSTATE
MSI_GetComponentPath(LPCWSTR szProduct
, LPCWSTR szComponent
,
2640 awstring
* lpPathBuf
, LPDWORD pcchBuf
)
2642 WCHAR squished_pc
[GUID_SIZE
];
2643 WCHAR squished_comp
[GUID_SIZE
];
2649 static const WCHAR wininstaller
[] = {
2650 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2652 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
2653 debugstr_w(szComponent
), lpPathBuf
->str
.w
, pcchBuf
);
2655 if (!szProduct
|| !szComponent
)
2656 return INSTALLSTATE_INVALIDARG
;
2658 if (lpPathBuf
->str
.w
&& !pcchBuf
)
2659 return INSTALLSTATE_INVALIDARG
;
2661 if (!squash_guid(szProduct
, squished_pc
) ||
2662 !squash_guid(szComponent
, squished_comp
))
2663 return INSTALLSTATE_INVALIDARG
;
2665 state
= INSTALLSTATE_UNKNOWN
;
2667 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2668 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2670 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2673 state
= INSTALLSTATE_ABSENT
;
2675 if ((MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
, NULL
,
2676 &hkey
, FALSE
) == ERROR_SUCCESS
||
2677 MSIREG_OpenUserDataProductKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2678 NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
) &&
2679 msi_reg_get_val_dword(hkey
, wininstaller
, &version
) &&
2680 GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2683 state
= INSTALLSTATE_LOCAL
;
2687 if (state
!= INSTALLSTATE_LOCAL
&&
2688 (MSIREG_OpenProductKey(szProduct
, NULL
,
2689 MSIINSTALLCONTEXT_USERUNMANAGED
,
2690 &hkey
, FALSE
) == ERROR_SUCCESS
||
2691 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2692 &hkey
, FALSE
) == ERROR_SUCCESS
))
2696 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2697 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2700 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2703 state
= INSTALLSTATE_ABSENT
;
2705 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2706 state
= INSTALLSTATE_LOCAL
;
2711 return INSTALLSTATE_UNKNOWN
;
2713 if (state
== INSTALLSTATE_LOCAL
&& !*path
)
2714 state
= INSTALLSTATE_NOTUSED
;
2716 msi_strcpy_to_awstring(path
, lpPathBuf
, pcchBuf
);
2721 /******************************************************************
2722 * MsiGetComponentPathW [MSI.@]
2724 INSTALLSTATE WINAPI
MsiGetComponentPathW(LPCWSTR szProduct
, LPCWSTR szComponent
,
2725 LPWSTR lpPathBuf
, LPDWORD pcchBuf
)
2729 path
.unicode
= TRUE
;
2730 path
.str
.w
= lpPathBuf
;
2732 return MSI_GetComponentPath( szProduct
, szComponent
, &path
, pcchBuf
);
2735 /******************************************************************
2736 * MsiGetComponentPathA [MSI.@]
2738 INSTALLSTATE WINAPI
MsiGetComponentPathA(LPCSTR szProduct
, LPCSTR szComponent
,
2739 LPSTR lpPathBuf
, LPDWORD pcchBuf
)
2741 LPWSTR szwProduct
, szwComponent
= NULL
;
2742 INSTALLSTATE r
= INSTALLSTATE_UNKNOWN
;
2745 szwProduct
= strdupAtoW( szProduct
);
2746 if( szProduct
&& !szwProduct
)
2749 szwComponent
= strdupAtoW( szComponent
);
2750 if( szComponent
&& !szwComponent
)
2753 path
.unicode
= FALSE
;
2754 path
.str
.a
= lpPathBuf
;
2756 r
= MSI_GetComponentPath( szwProduct
, szwComponent
, &path
, pcchBuf
);
2759 msi_free( szwProduct
);
2760 msi_free( szwComponent
);
2765 /******************************************************************
2766 * MsiQueryFeatureStateA [MSI.@]
2768 INSTALLSTATE WINAPI
MsiQueryFeatureStateA(LPCSTR szProduct
, LPCSTR szFeature
)
2770 LPWSTR szwProduct
= NULL
, szwFeature
= NULL
;
2771 INSTALLSTATE rc
= INSTALLSTATE_UNKNOWN
;
2773 szwProduct
= strdupAtoW( szProduct
);
2774 if ( szProduct
&& !szwProduct
)
2777 szwFeature
= strdupAtoW( szFeature
);
2778 if ( szFeature
&& !szwFeature
)
2781 rc
= MsiQueryFeatureStateW(szwProduct
, szwFeature
);
2784 msi_free( szwProduct
);
2785 msi_free( szwFeature
);
2790 /******************************************************************
2791 * MsiQueryFeatureStateW [MSI.@]
2793 * Checks the state of a feature
2796 * szProduct [I] Product's GUID string
2797 * szFeature [I] Feature's GUID string
2800 * INSTALLSTATE_LOCAL Feature is installed and usable
2801 * INSTALLSTATE_ABSENT Feature is absent
2802 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2803 * INSTALLSTATE_UNKNOWN An error occurred
2804 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2807 INSTALLSTATE WINAPI
MsiQueryFeatureStateW(LPCWSTR szProduct
, LPCWSTR szFeature
)
2809 WCHAR squishProduct
[33], comp
[GUID_SIZE
];
2811 LPWSTR components
, p
, parent_feature
, path
;
2815 BOOL missing
= FALSE
;
2816 BOOL machine
= FALSE
;
2817 BOOL source
= FALSE
;
2819 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szFeature
));
2821 if (!szProduct
|| !szFeature
)
2822 return INSTALLSTATE_INVALIDARG
;
2824 if (!squash_guid( szProduct
, squishProduct
))
2825 return INSTALLSTATE_INVALIDARG
;
2827 SetLastError( ERROR_SUCCESS
);
2829 if (MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERMANAGED
,
2830 &hkey
, FALSE
) != ERROR_SUCCESS
&&
2831 MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2832 &hkey
, FALSE
) != ERROR_SUCCESS
)
2834 rc
= MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
2836 if (rc
!= ERROR_SUCCESS
)
2837 return INSTALLSTATE_UNKNOWN
;
2842 parent_feature
= msi_reg_get_val_str( hkey
, szFeature
);
2845 if (!parent_feature
)
2846 return INSTALLSTATE_UNKNOWN
;
2848 r
= (parent_feature
[0] == 6) ? INSTALLSTATE_ABSENT
: INSTALLSTATE_LOCAL
;
2849 msi_free(parent_feature
);
2850 if (r
== INSTALLSTATE_ABSENT
)
2854 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2855 MSIINSTALLCONTEXT_MACHINE
,
2858 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2859 MSIINSTALLCONTEXT_USERUNMANAGED
,
2862 if (rc
!= ERROR_SUCCESS
)
2863 return INSTALLSTATE_ADVERTISED
;
2865 components
= msi_reg_get_val_str( hkey
, szFeature
);
2868 TRACE("rc = %d buffer = %s\n", rc
, debugstr_w(components
));
2871 return INSTALLSTATE_ADVERTISED
;
2873 for( p
= components
; *p
&& *p
!= 2 ; p
+= 20)
2875 if (!decode_base85_guid( p
, &guid
))
2877 if (p
!= components
)
2880 msi_free(components
);
2881 return INSTALLSTATE_BADCONFIG
;
2884 StringFromGUID2(&guid
, comp
, GUID_SIZE
);
2887 rc
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2889 rc
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2891 if (rc
!= ERROR_SUCCESS
)
2893 msi_free(components
);
2894 return INSTALLSTATE_ADVERTISED
;
2897 path
= msi_reg_get_val_str(hkey
, squishProduct
);
2900 else if (lstrlenW(path
) > 2 &&
2901 path
[0] >= '0' && path
[0] <= '9' &&
2902 path
[1] >= '0' && path
[1] <= '9')
2909 msi_free(components
);
2912 r
= INSTALLSTATE_ADVERTISED
;
2914 r
= INSTALLSTATE_SOURCE
;
2916 r
= INSTALLSTATE_LOCAL
;
2918 TRACE("-> %d\n", r
);
2922 /******************************************************************
2923 * MsiGetFileVersionA [MSI.@]
2925 UINT WINAPI
MsiGetFileVersionA(LPCSTR szFilePath
, LPSTR lpVersionBuf
,
2926 LPDWORD pcchVersionBuf
, LPSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2928 LPWSTR szwFilePath
= NULL
, lpwVersionBuff
= NULL
, lpwLangBuff
= NULL
;
2929 UINT ret
= ERROR_OUTOFMEMORY
;
2931 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
2932 (lpLangBuf
&& !pcchLangBuf
))
2933 return ERROR_INVALID_PARAMETER
;
2937 szwFilePath
= strdupAtoW( szFilePath
);
2942 if( lpVersionBuf
&& pcchVersionBuf
&& *pcchVersionBuf
)
2944 lpwVersionBuff
= msi_alloc(*pcchVersionBuf
*sizeof(WCHAR
));
2945 if( !lpwVersionBuff
)
2949 if( lpLangBuf
&& pcchLangBuf
&& *pcchLangBuf
)
2951 lpwLangBuff
= msi_alloc(*pcchLangBuf
*sizeof(WCHAR
));
2956 ret
= MsiGetFileVersionW(szwFilePath
, lpwVersionBuff
, pcchVersionBuf
,
2957 lpwLangBuff
, pcchLangBuf
);
2959 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwVersionBuff
)
2960 WideCharToMultiByte(CP_ACP
, 0, lpwVersionBuff
, -1,
2961 lpVersionBuf
, *pcchVersionBuf
+ 1, NULL
, NULL
);
2962 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwLangBuff
)
2963 WideCharToMultiByte(CP_ACP
, 0, lpwLangBuff
, -1,
2964 lpLangBuf
, *pcchLangBuf
+ 1, NULL
, NULL
);
2967 msi_free(szwFilePath
);
2968 msi_free(lpwVersionBuff
);
2969 msi_free(lpwLangBuff
);
2974 /******************************************************************
2975 * MsiGetFileVersionW [MSI.@]
2977 UINT WINAPI
MsiGetFileVersionW(LPCWSTR szFilePath
, LPWSTR lpVersionBuf
,
2978 LPDWORD pcchVersionBuf
, LPWSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2980 static const WCHAR szVersionResource
[] = {'\\',0};
2981 static const WCHAR szVersionFormat
[] = {
2982 '%','d','.','%','d','.','%','d','.','%','d',0};
2983 static const WCHAR szLangResource
[] = {
2984 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2985 'T','r','a','n','s','l','a','t','i','o','n',0};
2986 static const WCHAR szLangFormat
[] = {'%','d',0};
2988 DWORD dwVerLen
, gle
;
2989 LPVOID lpVer
= NULL
;
2990 VS_FIXEDFILEINFO
*ffi
;
2995 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath
),
2996 lpVersionBuf
, pcchVersionBuf
?*pcchVersionBuf
:0,
2997 lpLangBuf
, pcchLangBuf
?*pcchLangBuf
:0);
2999 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
3000 (lpLangBuf
&& !pcchLangBuf
))
3001 return ERROR_INVALID_PARAMETER
;
3003 dwVerLen
= GetFileVersionInfoSizeW(szFilePath
, NULL
);
3006 gle
= GetLastError();
3007 if (gle
== ERROR_BAD_PATHNAME
)
3008 return ERROR_FILE_NOT_FOUND
;
3009 else if (gle
== ERROR_RESOURCE_DATA_NOT_FOUND
)
3010 return ERROR_FILE_INVALID
;
3015 lpVer
= msi_alloc(dwVerLen
);
3018 ret
= ERROR_OUTOFMEMORY
;
3022 if( !GetFileVersionInfoW(szFilePath
, 0, dwVerLen
, lpVer
) )
3024 ret
= GetLastError();
3030 if( VerQueryValueW(lpVer
, szVersionResource
, (LPVOID
*)&ffi
, &puLen
) &&
3033 wsprintfW(tmp
, szVersionFormat
,
3034 HIWORD(ffi
->dwFileVersionMS
), LOWORD(ffi
->dwFileVersionMS
),
3035 HIWORD(ffi
->dwFileVersionLS
), LOWORD(ffi
->dwFileVersionLS
));
3036 if (lpVersionBuf
) lstrcpynW(lpVersionBuf
, tmp
, *pcchVersionBuf
);
3038 if (strlenW(tmp
) >= *pcchVersionBuf
)
3039 ret
= ERROR_MORE_DATA
;
3041 *pcchVersionBuf
= lstrlenW(tmp
);
3045 if (lpVersionBuf
) *lpVersionBuf
= 0;
3046 *pcchVersionBuf
= 0;
3052 if (VerQueryValueW(lpVer
, szLangResource
, (LPVOID
*)&lang
, &puLen
) &&
3055 wsprintfW(tmp
, szLangFormat
, *lang
);
3056 if (lpLangBuf
) lstrcpynW(lpLangBuf
, tmp
, *pcchLangBuf
);
3058 if (strlenW(tmp
) >= *pcchLangBuf
)
3059 ret
= ERROR_MORE_DATA
;
3061 *pcchLangBuf
= lstrlenW(tmp
);
3065 if (lpLangBuf
) *lpLangBuf
= 0;
3075 /***********************************************************************
3076 * MsiGetFeatureUsageW [MSI.@]
3078 UINT WINAPI
MsiGetFeatureUsageW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3079 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
3081 FIXME("%s %s %p %p\n",debugstr_w(szProduct
), debugstr_w(szFeature
),
3082 pdwUseCount
, pwDateUsed
);
3083 return ERROR_CALL_NOT_IMPLEMENTED
;
3086 /***********************************************************************
3087 * MsiGetFeatureUsageA [MSI.@]
3089 UINT WINAPI
MsiGetFeatureUsageA( LPCSTR szProduct
, LPCSTR szFeature
,
3090 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
3092 LPWSTR prod
= NULL
, feat
= NULL
;
3093 UINT ret
= ERROR_OUTOFMEMORY
;
3095 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3096 pdwUseCount
, pwDateUsed
);
3098 prod
= strdupAtoW( szProduct
);
3099 if (szProduct
&& !prod
)
3102 feat
= strdupAtoW( szFeature
);
3103 if (szFeature
&& !feat
)
3106 ret
= MsiGetFeatureUsageW( prod
, feat
, pdwUseCount
, pwDateUsed
);
3115 /***********************************************************************
3116 * MsiUseFeatureExW [MSI.@]
3118 INSTALLSTATE WINAPI
MsiUseFeatureExW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3119 DWORD dwInstallMode
, DWORD dwReserved
)
3123 TRACE("%s %s %i %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
3124 dwInstallMode
, dwReserved
);
3126 state
= MsiQueryFeatureStateW( szProduct
, szFeature
);
3129 return INSTALLSTATE_INVALIDARG
;
3131 if (state
== INSTALLSTATE_LOCAL
&& dwInstallMode
!= INSTALLMODE_NODETECTION
)
3133 FIXME("mark product %s feature %s as used\n",
3134 debugstr_w(szProduct
), debugstr_w(szFeature
) );
3140 /***********************************************************************
3141 * MsiUseFeatureExA [MSI.@]
3143 INSTALLSTATE WINAPI
MsiUseFeatureExA( LPCSTR szProduct
, LPCSTR szFeature
,
3144 DWORD dwInstallMode
, DWORD dwReserved
)
3146 INSTALLSTATE ret
= INSTALLSTATE_UNKNOWN
;
3147 LPWSTR prod
= NULL
, feat
= NULL
;
3149 TRACE("%s %s %i %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3150 dwInstallMode
, dwReserved
);
3152 prod
= strdupAtoW( szProduct
);
3153 if (szProduct
&& !prod
)
3156 feat
= strdupAtoW( szFeature
);
3157 if (szFeature
&& !feat
)
3160 ret
= MsiUseFeatureExW( prod
, feat
, dwInstallMode
, dwReserved
);
3169 /***********************************************************************
3170 * MsiUseFeatureW [MSI.@]
3172 INSTALLSTATE WINAPI
MsiUseFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
)
3174 return MsiUseFeatureExW(szProduct
, szFeature
, 0, 0);
3177 /***********************************************************************
3178 * MsiUseFeatureA [MSI.@]
3180 INSTALLSTATE WINAPI
MsiUseFeatureA( LPCSTR szProduct
, LPCSTR szFeature
)
3182 return MsiUseFeatureExA(szProduct
, szFeature
, 0, 0);
3185 /***********************************************************************
3186 * MSI_ProvideQualifiedComponentEx [internal]
3188 static UINT
MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent
,
3189 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3190 DWORD Unused1
, DWORD Unused2
, awstring
*lpPathBuf
,
3191 LPDWORD pcchPathBuf
)
3193 WCHAR product
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1],
3194 feature
[MAX_FEATURE_CHARS
+1];
3200 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent
),
3201 debugstr_w(szQualifier
), dwInstallMode
, debugstr_w(szProduct
),
3202 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3204 rc
= MSIREG_OpenUserComponentsKey(szComponent
, &hkey
, FALSE
);
3205 if (rc
!= ERROR_SUCCESS
)
3206 return ERROR_INDEX_ABSENT
;
3208 info
= msi_reg_get_val_str( hkey
, szQualifier
);
3212 return ERROR_INDEX_ABSENT
;
3214 MsiDecomposeDescriptorW(info
, product
, feature
, component
, &sz
);
3217 rc
= MSI_GetComponentPath(product
, component
, lpPathBuf
, pcchPathBuf
);
3219 rc
= MSI_GetComponentPath(szProduct
, component
, lpPathBuf
, pcchPathBuf
);
3223 if (rc
!= INSTALLSTATE_LOCAL
)
3224 return ERROR_FILE_NOT_FOUND
;
3226 return ERROR_SUCCESS
;
3229 /***********************************************************************
3230 * MsiProvideQualifiedComponentExW [MSI.@]
3232 UINT WINAPI
MsiProvideQualifiedComponentExW(LPCWSTR szComponent
,
3233 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3234 DWORD Unused1
, DWORD Unused2
, LPWSTR lpPathBuf
,
3235 LPDWORD pcchPathBuf
)
3239 path
.unicode
= TRUE
;
3240 path
.str
.w
= lpPathBuf
;
3242 return MSI_ProvideQualifiedComponentEx(szComponent
, szQualifier
,
3243 dwInstallMode
, szProduct
, Unused1
, Unused2
, &path
, pcchPathBuf
);
3246 /***********************************************************************
3247 * MsiProvideQualifiedComponentExA [MSI.@]
3249 UINT WINAPI
MsiProvideQualifiedComponentExA(LPCSTR szComponent
,
3250 LPCSTR szQualifier
, DWORD dwInstallMode
, LPCSTR szProduct
,
3251 DWORD Unused1
, DWORD Unused2
, LPSTR lpPathBuf
,
3252 LPDWORD pcchPathBuf
)
3254 LPWSTR szwComponent
, szwQualifier
= NULL
, szwProduct
= NULL
;
3255 UINT r
= ERROR_OUTOFMEMORY
;
3258 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent
),
3259 debugstr_a(szQualifier
), dwInstallMode
, debugstr_a(szProduct
),
3260 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3262 szwComponent
= strdupAtoW( szComponent
);
3263 if (szComponent
&& !szwComponent
)
3266 szwQualifier
= strdupAtoW( szQualifier
);
3267 if (szQualifier
&& !szwQualifier
)
3270 szwProduct
= strdupAtoW( szProduct
);
3271 if (szProduct
&& !szwProduct
)
3274 path
.unicode
= FALSE
;
3275 path
.str
.a
= lpPathBuf
;
3277 r
= MSI_ProvideQualifiedComponentEx(szwComponent
, szwQualifier
,
3278 dwInstallMode
, szwProduct
, Unused1
,
3279 Unused2
, &path
, pcchPathBuf
);
3281 msi_free(szwProduct
);
3282 msi_free(szwComponent
);
3283 msi_free(szwQualifier
);
3288 /***********************************************************************
3289 * MsiProvideQualifiedComponentW [MSI.@]
3291 UINT WINAPI
MsiProvideQualifiedComponentW( LPCWSTR szComponent
,
3292 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPWSTR lpPathBuf
,
3293 LPDWORD pcchPathBuf
)
3295 return MsiProvideQualifiedComponentExW(szComponent
, szQualifier
,
3296 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3299 /***********************************************************************
3300 * MsiProvideQualifiedComponentA [MSI.@]
3302 UINT WINAPI
MsiProvideQualifiedComponentA( LPCSTR szComponent
,
3303 LPCSTR szQualifier
, DWORD dwInstallMode
, LPSTR lpPathBuf
,
3304 LPDWORD pcchPathBuf
)
3306 return MsiProvideQualifiedComponentExA(szComponent
, szQualifier
,
3307 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3310 /***********************************************************************
3311 * MSI_GetUserInfo [internal]
3313 static USERINFOSTATE
MSI_GetUserInfo(LPCWSTR szProduct
,
3314 awstring
*lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3315 awstring
*lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3316 awstring
*lpSerialBuf
, LPDWORD pcchSerialBuf
)
3318 WCHAR squished_pc
[SQUISH_GUID_SIZE
];
3319 LPWSTR user
, org
, serial
;
3320 USERINFOSTATE state
;
3325 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct
), lpUserNameBuf
,
3326 pcchUserNameBuf
, lpOrgNameBuf
, pcchOrgNameBuf
, lpSerialBuf
,
3329 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
3330 return USERINFOSTATE_INVALIDARG
;
3332 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
3333 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3334 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3335 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3336 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
3337 &hkey
, FALSE
) != ERROR_SUCCESS
)
3339 return USERINFOSTATE_UNKNOWN
;
3342 if (MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3343 NULL
, &props
, FALSE
) != ERROR_SUCCESS
&&
3344 MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
3345 NULL
, &props
, FALSE
) != ERROR_SUCCESS
)
3348 return USERINFOSTATE_ABSENT
;
3351 user
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGOWNERW
);
3352 org
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGCOMPANYW
);
3353 serial
= msi_reg_get_val_str(props
, INSTALLPROPERTY_PRODUCTIDW
);
3354 state
= USERINFOSTATE_ABSENT
;
3360 state
= USERINFOSTATE_PRESENT
;
3362 if (pcchUserNameBuf
)
3364 if (lpUserNameBuf
&& !user
)
3366 (*pcchUserNameBuf
)--;
3370 r
= msi_strcpy_to_awstring(user
, lpUserNameBuf
, pcchUserNameBuf
);
3371 if (r
== ERROR_MORE_DATA
)
3373 state
= USERINFOSTATE_MOREDATA
;
3381 if (!orgptr
) orgptr
= szEmpty
;
3383 r
= msi_strcpy_to_awstring(orgptr
, lpOrgNameBuf
, pcchOrgNameBuf
);
3384 if (r
== ERROR_MORE_DATA
)
3386 state
= USERINFOSTATE_MOREDATA
;
3399 r
= msi_strcpy_to_awstring(serial
, lpSerialBuf
, pcchSerialBuf
);
3400 if (r
== ERROR_MORE_DATA
)
3401 state
= USERINFOSTATE_MOREDATA
;
3412 /***********************************************************************
3413 * MsiGetUserInfoW [MSI.@]
3415 USERINFOSTATE WINAPI
MsiGetUserInfoW(LPCWSTR szProduct
,
3416 LPWSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3417 LPWSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3418 LPWSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3420 awstring user
, org
, serial
;
3422 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3423 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3424 (lpSerialBuf
&& !pcchSerialBuf
))
3425 return USERINFOSTATE_INVALIDARG
;
3427 user
.unicode
= TRUE
;
3428 user
.str
.w
= lpUserNameBuf
;
3430 org
.str
.w
= lpOrgNameBuf
;
3431 serial
.unicode
= TRUE
;
3432 serial
.str
.w
= lpSerialBuf
;
3434 return MSI_GetUserInfo( szProduct
, &user
, pcchUserNameBuf
,
3435 &org
, pcchOrgNameBuf
,
3436 &serial
, pcchSerialBuf
);
3439 USERINFOSTATE WINAPI
MsiGetUserInfoA(LPCSTR szProduct
,
3440 LPSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3441 LPSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3442 LPSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3444 awstring user
, org
, serial
;
3448 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3449 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3450 (lpSerialBuf
&& !pcchSerialBuf
))
3451 return USERINFOSTATE_INVALIDARG
;
3453 prod
= strdupAtoW( szProduct
);
3454 if (szProduct
&& !prod
)
3455 return ERROR_OUTOFMEMORY
;
3457 user
.unicode
= FALSE
;
3458 user
.str
.a
= lpUserNameBuf
;
3459 org
.unicode
= FALSE
;
3460 org
.str
.a
= lpOrgNameBuf
;
3461 serial
.unicode
= FALSE
;
3462 serial
.str
.a
= lpSerialBuf
;
3464 r
= MSI_GetUserInfo( prod
, &user
, pcchUserNameBuf
,
3465 &org
, pcchOrgNameBuf
,
3466 &serial
, pcchSerialBuf
);
3473 UINT WINAPI
MsiCollectUserInfoW(LPCWSTR szProduct
)
3477 MSIPACKAGE
*package
;
3478 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3480 TRACE("(%s)\n",debugstr_w(szProduct
));
3482 rc
= MsiOpenProductW(szProduct
,&handle
);
3483 if (rc
!= ERROR_SUCCESS
)
3484 return ERROR_INVALID_PARAMETER
;
3486 /* MsiCollectUserInfo cannot be called from a custom action. */
3487 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3489 return ERROR_CALL_NOT_IMPLEMENTED
;
3491 rc
= ACTION_PerformUIAction(package
, szFirstRun
, -1);
3492 msiobj_release( &package
->hdr
);
3494 MsiCloseHandle(handle
);
3499 UINT WINAPI
MsiCollectUserInfoA(LPCSTR szProduct
)
3503 MSIPACKAGE
*package
;
3504 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3506 TRACE("(%s)\n",debugstr_a(szProduct
));
3508 rc
= MsiOpenProductA(szProduct
,&handle
);
3509 if (rc
!= ERROR_SUCCESS
)
3510 return ERROR_INVALID_PARAMETER
;
3512 /* MsiCollectUserInfo cannot be called from a custom action. */
3513 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3515 return ERROR_CALL_NOT_IMPLEMENTED
;
3517 rc
= ACTION_PerformUIAction(package
, szFirstRun
, -1);
3518 msiobj_release( &package
->hdr
);
3520 MsiCloseHandle(handle
);
3525 /***********************************************************************
3526 * MsiConfigureFeatureA [MSI.@]
3528 UINT WINAPI
MsiConfigureFeatureA(LPCSTR szProduct
, LPCSTR szFeature
, INSTALLSTATE eInstallState
)
3530 LPWSTR prod
, feat
= NULL
;
3531 UINT r
= ERROR_OUTOFMEMORY
;
3533 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
), eInstallState
);
3535 prod
= strdupAtoW( szProduct
);
3536 if (szProduct
&& !prod
)
3539 feat
= strdupAtoW( szFeature
);
3540 if (szFeature
&& !feat
)
3543 r
= MsiConfigureFeatureW(prod
, feat
, eInstallState
);
3552 /***********************************************************************
3553 * MsiConfigureFeatureW [MSI.@]
3555 UINT WINAPI
MsiConfigureFeatureW(LPCWSTR szProduct
, LPCWSTR szFeature
, INSTALLSTATE eInstallState
)
3557 static const WCHAR szCostInit
[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3558 MSIPACKAGE
*package
= NULL
;
3560 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
3563 TRACE("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
), eInstallState
);
3565 if (!szProduct
|| !szFeature
)
3566 return ERROR_INVALID_PARAMETER
;
3568 switch (eInstallState
)
3570 case INSTALLSTATE_DEFAULT
:
3571 /* FIXME: how do we figure out the default location? */
3572 eInstallState
= INSTALLSTATE_LOCAL
;
3574 case INSTALLSTATE_LOCAL
:
3575 case INSTALLSTATE_SOURCE
:
3576 case INSTALLSTATE_ABSENT
:
3577 case INSTALLSTATE_ADVERTISED
:
3580 return ERROR_INVALID_PARAMETER
;
3583 r
= MSI_OpenProductW( szProduct
, &package
);
3584 if (r
!= ERROR_SUCCESS
)
3587 sz
= sizeof(sourcepath
);
3588 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3589 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3591 sz
= sizeof(filename
);
3592 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3593 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3595 lstrcatW( sourcepath
, filename
);
3597 MsiSetInternalUI( INSTALLUILEVEL_BASIC
, NULL
);
3599 r
= ACTION_PerformUIAction( package
, szCostInit
, -1 );
3600 if (r
!= ERROR_SUCCESS
)
3603 r
= MSI_SetFeatureStateW( package
, szFeature
, eInstallState
);
3604 if (r
!= ERROR_SUCCESS
)
3607 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3610 msiobj_release( &package
->hdr
);
3615 /***********************************************************************
3616 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3618 * Notes: undocumented
3620 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved
)
3622 WCHAR path
[MAX_PATH
];
3624 TRACE("%d\n", dwReserved
);
3628 FIXME("dwReserved=%d\n", dwReserved
);
3629 return ERROR_INVALID_PARAMETER
;
3632 if (!GetWindowsDirectoryW(path
, MAX_PATH
))
3633 return ERROR_FUNCTION_FAILED
;
3635 lstrcatW(path
, installerW
);
3637 if (!CreateDirectoryW(path
, NULL
))
3638 return ERROR_FUNCTION_FAILED
;
3640 return ERROR_SUCCESS
;
3643 /***********************************************************************
3644 * MsiGetShortcutTargetA [MSI.@]
3646 UINT WINAPI
MsiGetShortcutTargetA( LPCSTR szShortcutTarget
,
3647 LPSTR szProductCode
, LPSTR szFeatureId
,
3648 LPSTR szComponentCode
)
3651 const int len
= MAX_FEATURE_CHARS
+1;
3652 WCHAR product
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1];
3655 target
= strdupAtoW( szShortcutTarget
);
3656 if (szShortcutTarget
&& !target
)
3657 return ERROR_OUTOFMEMORY
;
3661 r
= MsiGetShortcutTargetW( target
, product
, feature
, component
);
3663 if (r
== ERROR_SUCCESS
)
3665 WideCharToMultiByte( CP_ACP
, 0, product
, -1, szProductCode
, len
, NULL
, NULL
);
3666 WideCharToMultiByte( CP_ACP
, 0, feature
, -1, szFeatureId
, len
, NULL
, NULL
);
3667 WideCharToMultiByte( CP_ACP
, 0, component
, -1, szComponentCode
, len
, NULL
, NULL
);
3672 /***********************************************************************
3673 * MsiGetShortcutTargetW [MSI.@]
3675 UINT WINAPI
MsiGetShortcutTargetW( LPCWSTR szShortcutTarget
,
3676 LPWSTR szProductCode
, LPWSTR szFeatureId
,
3677 LPWSTR szComponentCode
)
3679 IShellLinkDataList
*dl
= NULL
;
3680 IPersistFile
*pf
= NULL
;
3681 LPEXP_DARWIN_LINK darwin
= NULL
;
3684 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget
),
3685 szProductCode
, szFeatureId
, szComponentCode
);
3687 init
= CoInitialize(NULL
);
3689 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3690 &IID_IPersistFile
, (LPVOID
*) &pf
);
3691 if( SUCCEEDED( r
) )
3693 r
= IPersistFile_Load( pf
, szShortcutTarget
,
3694 STGM_READ
| STGM_SHARE_DENY_WRITE
);
3695 if( SUCCEEDED( r
) )
3697 r
= IPersistFile_QueryInterface( pf
, &IID_IShellLinkDataList
,
3699 if( SUCCEEDED( r
) )
3701 IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
,
3703 IShellLinkDataList_Release( dl
);
3706 IPersistFile_Release( pf
);
3709 if (SUCCEEDED(init
))
3712 TRACE("darwin = %p\n", darwin
);
3719 ret
= MsiDecomposeDescriptorW( darwin
->szwDarwinID
,
3720 szProductCode
, szFeatureId
, szComponentCode
, &sz
);
3721 LocalFree( darwin
);
3725 return ERROR_FUNCTION_FAILED
;
3728 UINT WINAPI
MsiReinstallFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3729 DWORD dwReinstallMode
)
3731 MSIPACKAGE
* package
= NULL
;
3733 WCHAR sourcepath
[MAX_PATH
];
3734 WCHAR filename
[MAX_PATH
];
3735 static const WCHAR szLogVerbose
[] = {
3736 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3737 WCHAR reinstallmode
[11];
3741 FIXME("%s %s 0x%08x\n",
3742 debugstr_w(szProduct
), debugstr_w(szFeature
), dwReinstallMode
);
3744 ptr
= reinstallmode
;
3746 if (dwReinstallMode
& REINSTALLMODE_FILEMISSING
)
3748 if (dwReinstallMode
& REINSTALLMODE_FILEOLDERVERSION
)
3750 if (dwReinstallMode
& REINSTALLMODE_FILEEQUALVERSION
)
3752 if (dwReinstallMode
& REINSTALLMODE_FILEEXACT
)
3754 if (dwReinstallMode
& REINSTALLMODE_FILEVERIFY
)
3756 if (dwReinstallMode
& REINSTALLMODE_FILEREPLACE
)
3758 if (dwReinstallMode
& REINSTALLMODE_USERDATA
)
3760 if (dwReinstallMode
& REINSTALLMODE_MACHINEDATA
)
3762 if (dwReinstallMode
& REINSTALLMODE_SHORTCUT
)
3764 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3768 sz
= sizeof(sourcepath
);
3769 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3770 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3772 sz
= sizeof(filename
);
3773 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3774 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3776 lstrcatW( sourcepath
, filename
);
3778 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3779 r
= MSI_OpenPackageW( sourcepath
, &package
);
3781 r
= MSI_OpenProductW( szProduct
, &package
);
3783 if (r
!= ERROR_SUCCESS
)
3786 msi_set_property( package
->db
, szReinstallMode
, reinstallmode
);
3787 msi_set_property( package
->db
, szInstalled
, szOne
);
3788 msi_set_property( package
->db
, szLogVerbose
, szOne
);
3789 msi_set_property( package
->db
, szReinstall
, szFeature
);
3791 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3793 msiobj_release( &package
->hdr
);
3798 UINT WINAPI
MsiReinstallFeatureA( LPCSTR szProduct
, LPCSTR szFeature
,
3799 DWORD dwReinstallMode
)
3805 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3808 wszProduct
= strdupAtoW(szProduct
);
3809 wszFeature
= strdupAtoW(szFeature
);
3811 rc
= MsiReinstallFeatureW(wszProduct
, wszFeature
, dwReinstallMode
);
3813 msi_free(wszProduct
);
3814 msi_free(wszFeature
);
3821 unsigned int buf
[4];
3822 unsigned char in
[64];
3823 unsigned char digest
[16];
3826 extern VOID WINAPI
MD5Init( MD5_CTX
*);
3827 extern VOID WINAPI
MD5Update( MD5_CTX
*, const unsigned char *, unsigned int );
3828 extern VOID WINAPI
MD5Final( MD5_CTX
*);
3830 /***********************************************************************
3831 * MsiGetFileHashW [MSI.@]
3833 UINT WINAPI
MsiGetFileHashW( LPCWSTR szFilePath
, DWORD dwOptions
,
3834 PMSIFILEHASHINFO pHash
)
3836 HANDLE handle
, mapping
;
3839 UINT r
= ERROR_FUNCTION_FAILED
;
3841 TRACE("%s %08x %p\n", debugstr_w(szFilePath
), dwOptions
, pHash
);
3844 return ERROR_INVALID_PARAMETER
;
3847 return ERROR_PATH_NOT_FOUND
;
3850 return ERROR_INVALID_PARAMETER
;
3852 return ERROR_INVALID_PARAMETER
;
3853 if (pHash
->dwFileHashInfoSize
< sizeof *pHash
)
3854 return ERROR_INVALID_PARAMETER
;
3856 handle
= CreateFileW( szFilePath
, GENERIC_READ
,
3857 FILE_SHARE_READ
| FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, 0, NULL
);
3858 if (handle
== INVALID_HANDLE_VALUE
)
3860 WARN("can't open file %u\n", GetLastError());
3861 return ERROR_FILE_NOT_FOUND
;
3863 length
= GetFileSize( handle
, NULL
);
3865 mapping
= CreateFileMappingW( handle
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
3868 p
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, length
);
3874 MD5Update( &ctx
, p
, length
);
3876 UnmapViewOfFile( p
);
3878 memcpy( pHash
->dwData
, ctx
.digest
, sizeof pHash
->dwData
);
3881 CloseHandle( mapping
);
3883 CloseHandle( handle
);
3888 /***********************************************************************
3889 * MsiGetFileHashA [MSI.@]
3891 UINT WINAPI
MsiGetFileHashA( LPCSTR szFilePath
, DWORD dwOptions
,
3892 PMSIFILEHASHINFO pHash
)
3897 TRACE("%s %08x %p\n", debugstr_a(szFilePath
), dwOptions
, pHash
);
3899 file
= strdupAtoW( szFilePath
);
3900 if (szFilePath
&& !file
)
3901 return ERROR_OUTOFMEMORY
;
3903 r
= MsiGetFileHashW( file
, dwOptions
, pHash
);
3908 /***********************************************************************
3909 * MsiAdvertiseScriptW [MSI.@]
3911 UINT WINAPI
MsiAdvertiseScriptW( LPCWSTR szScriptFile
, DWORD dwFlags
,
3912 PHKEY phRegData
, BOOL fRemoveItems
)
3914 FIXME("%s %08x %p %d\n",
3915 debugstr_w( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3916 return ERROR_CALL_NOT_IMPLEMENTED
;
3919 /***********************************************************************
3920 * MsiAdvertiseScriptA [MSI.@]
3922 UINT WINAPI
MsiAdvertiseScriptA( LPCSTR szScriptFile
, DWORD dwFlags
,
3923 PHKEY phRegData
, BOOL fRemoveItems
)
3925 FIXME("%s %08x %p %d\n",
3926 debugstr_a( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3927 return ERROR_CALL_NOT_IMPLEMENTED
;
3930 /***********************************************************************
3931 * MsiIsProductElevatedW [MSI.@]
3933 UINT WINAPI
MsiIsProductElevatedW( LPCWSTR szProduct
, BOOL
*pfElevated
)
3935 FIXME("%s %p - stub\n",
3936 debugstr_w( szProduct
), pfElevated
);
3938 return ERROR_SUCCESS
;
3941 /***********************************************************************
3942 * MsiIsProductElevatedA [MSI.@]
3944 UINT WINAPI
MsiIsProductElevatedA( LPCSTR szProduct
, BOOL
*pfElevated
)
3946 FIXME("%s %p - stub\n",
3947 debugstr_a( szProduct
), pfElevated
);
3949 return ERROR_SUCCESS
;
3952 /***********************************************************************
3953 * MsiSetExternalUIRecord [MSI.@]
3955 UINT WINAPI
MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler
,
3956 DWORD filter
, LPVOID context
,
3957 PINSTALLUI_HANDLER_RECORD prev
)
3959 TRACE("%p %08x %p %p\n", handler
, filter
, context
, prev
);
3962 *prev
= gUIHandlerRecord
;
3964 gUIHandlerRecord
= handler
;
3966 gUIContext
= context
;
3968 return ERROR_SUCCESS
;
3971 /***********************************************************************
3972 * MsiInstallMissingComponentA [MSI.@]
3974 UINT WINAPI
MsiInstallMissingComponentA( LPCSTR product
, LPCSTR component
, INSTALLSTATE state
)
3977 WCHAR
*productW
= NULL
, *componentW
= NULL
;
3979 TRACE("%s, %s, %d\n", debugstr_a(product
), debugstr_a(component
), state
);
3981 if (product
&& !(productW
= strdupAtoW( product
)))
3982 return ERROR_OUTOFMEMORY
;
3984 if (component
&& !(componentW
= strdupAtoW( component
)))
3986 msi_free( productW
);
3987 return ERROR_OUTOFMEMORY
;
3990 r
= MsiInstallMissingComponentW( productW
, componentW
, state
);
3991 msi_free( productW
);
3992 msi_free( componentW
);
3996 /***********************************************************************
3997 * MsiInstallMissingComponentW [MSI.@]
3999 UINT WINAPI
MsiInstallMissingComponentW(LPCWSTR szProduct
, LPCWSTR szComponent
, INSTALLSTATE eInstallState
)
4001 FIXME("(%s %s %d\n", debugstr_w(szProduct
), debugstr_w(szComponent
), eInstallState
);
4002 return ERROR_SUCCESS
;
4005 /***********************************************************************
4006 * MsiBeginTransactionA [MSI.@]
4008 UINT WINAPI
MsiBeginTransactionA( LPCSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
4013 FIXME("%s %u %p %p\n", debugstr_a(name
), attrs
, id
, event
);
4015 nameW
= strdupAtoW( name
);
4017 return ERROR_OUTOFMEMORY
;
4019 r
= MsiBeginTransactionW( nameW
, attrs
, id
, event
);
4024 /***********************************************************************
4025 * MsiBeginTransactionW [MSI.@]
4027 UINT WINAPI
MsiBeginTransactionW( LPCWSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
4029 FIXME("%s %u %p %p\n", debugstr_w(name
), attrs
, id
, event
);
4031 *id
= (MSIHANDLE
)0xdeadbeef;
4032 *event
= (HANDLE
)0xdeadbeef;
4034 return ERROR_SUCCESS
;
4037 /***********************************************************************
4038 * MsiEndTransaction [MSI.@]
4040 UINT WINAPI
MsiEndTransaction( DWORD state
)
4042 FIXME("%u\n", state
);
4043 return ERROR_SUCCESS
;