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
31 #include "wine/debug.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
46 static const WCHAR installerW
[] = {'\\','I','n','s','t','a','l','l','e','r',0};
48 static UINT
msi_locate_product(LPCWSTR szProduct
, MSIINSTALLCONTEXT
*context
)
52 *context
= MSIINSTALLCONTEXT_NONE
;
54 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
55 &hkey
, FALSE
) == ERROR_SUCCESS
)
56 *context
= MSIINSTALLCONTEXT_USERMANAGED
;
57 else if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
58 &hkey
, FALSE
) == ERROR_SUCCESS
)
59 *context
= MSIINSTALLCONTEXT_MACHINE
;
60 else if (MSIREG_OpenProductKey(szProduct
, NULL
,
61 MSIINSTALLCONTEXT_USERUNMANAGED
,
62 &hkey
, FALSE
) == ERROR_SUCCESS
)
63 *context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
67 if (*context
== MSIINSTALLCONTEXT_NONE
)
68 return ERROR_UNKNOWN_PRODUCT
;
73 UINT WINAPI
MsiOpenProductA(LPCSTR szProduct
, MSIHANDLE
*phProduct
)
76 LPWSTR szwProd
= NULL
;
78 TRACE("%s %p\n",debugstr_a(szProduct
), phProduct
);
82 szwProd
= strdupAtoW( szProduct
);
84 return ERROR_OUTOFMEMORY
;
87 r
= MsiOpenProductW( szwProd
, phProduct
);
94 static UINT
MSI_OpenProductW(LPCWSTR szProduct
, MSIPACKAGE
**package
)
99 MSIINSTALLCONTEXT context
;
101 static const WCHAR managed
[] = {
102 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
103 static const WCHAR local
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
105 TRACE("%s %p\n", debugstr_w(szProduct
), package
);
107 r
= msi_locate_product(szProduct
, &context
);
108 if (r
!= ERROR_SUCCESS
)
111 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &props
, FALSE
);
112 if (r
!= ERROR_SUCCESS
)
113 return ERROR_UNKNOWN_PRODUCT
;
115 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
116 path
= msi_reg_get_val_str(props
, managed
);
118 path
= msi_reg_get_val_str(props
, local
);
120 r
= ERROR_UNKNOWN_PRODUCT
;
122 if (!path
|| GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
125 if (PathIsRelativeW(path
))
127 r
= ERROR_INSTALL_PACKAGE_OPEN_FAILED
;
131 r
= MSI_OpenPackageW(path
, package
);
139 UINT WINAPI
MsiOpenProductW(LPCWSTR szProduct
, MSIHANDLE
*phProduct
)
141 MSIPACKAGE
*package
= NULL
;
142 WCHAR squished_pc
[GUID_SIZE
];
145 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
146 return ERROR_INVALID_PARAMETER
;
149 return ERROR_INVALID_PARAMETER
;
151 r
= MSI_OpenProductW(szProduct
, &package
);
152 if (r
!= ERROR_SUCCESS
)
155 *phProduct
= alloc_msihandle(&package
->hdr
);
157 r
= ERROR_NOT_ENOUGH_MEMORY
;
159 msiobj_release(&package
->hdr
);
163 UINT WINAPI
MsiAdvertiseProductA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
164 LPCSTR szTransforms
, LANGID lgidLanguage
)
166 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath
),
167 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
), lgidLanguage
);
168 return ERROR_CALL_NOT_IMPLEMENTED
;
171 UINT WINAPI
MsiAdvertiseProductW(LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
172 LPCWSTR szTransforms
, LANGID lgidLanguage
)
174 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath
),
175 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
), lgidLanguage
);
176 return ERROR_CALL_NOT_IMPLEMENTED
;
179 UINT WINAPI
MsiAdvertiseProductExA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
180 LPCSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
182 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath
),
183 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
),
184 lgidLanguage
, dwPlatform
, dwOptions
);
185 return ERROR_CALL_NOT_IMPLEMENTED
;
188 UINT WINAPI
MsiAdvertiseProductExW( LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
189 LPCWSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
191 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath
),
192 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
),
193 lgidLanguage
, dwPlatform
, dwOptions
);
194 return ERROR_CALL_NOT_IMPLEMENTED
;
197 UINT WINAPI
MsiInstallProductA(LPCSTR szPackagePath
, LPCSTR szCommandLine
)
199 LPWSTR szwPath
= NULL
, szwCommand
= NULL
;
200 UINT r
= ERROR_OUTOFMEMORY
;
202 TRACE("%s %s\n",debugstr_a(szPackagePath
), debugstr_a(szCommandLine
));
206 szwPath
= strdupAtoW( szPackagePath
);
213 szwCommand
= strdupAtoW( szCommandLine
);
218 r
= MsiInstallProductW( szwPath
, szwCommand
);
222 msi_free( szwCommand
);
227 UINT WINAPI
MsiInstallProductW(LPCWSTR szPackagePath
, LPCWSTR szCommandLine
)
229 MSIPACKAGE
*package
= NULL
;
232 TRACE("%s %s\n",debugstr_w(szPackagePath
), debugstr_w(szCommandLine
));
235 return ERROR_INVALID_PARAMETER
;
238 return ERROR_PATH_NOT_FOUND
;
240 r
= MSI_OpenPackageW( szPackagePath
, &package
);
241 if (r
== ERROR_SUCCESS
)
243 r
= MSI_InstallPackage( package
, szPackagePath
, szCommandLine
);
244 msiobj_release( &package
->hdr
);
250 UINT WINAPI
MsiReinstallProductA(LPCSTR szProduct
, DWORD dwReinstallMode
)
255 TRACE("%s %08x\n", debugstr_a(szProduct
), dwReinstallMode
);
257 wszProduct
= strdupAtoW(szProduct
);
259 rc
= MsiReinstallProductW(wszProduct
, dwReinstallMode
);
261 msi_free(wszProduct
);
265 UINT WINAPI
MsiReinstallProductW(LPCWSTR szProduct
, DWORD dwReinstallMode
)
267 TRACE("%s %08x\n", debugstr_w(szProduct
), dwReinstallMode
);
269 return MsiReinstallFeatureW(szProduct
, szAll
, dwReinstallMode
);
272 UINT WINAPI
MsiApplyPatchA(LPCSTR szPatchPackage
, LPCSTR szInstallPackage
,
273 INSTALLTYPE eInstallType
, LPCSTR szCommandLine
)
275 LPWSTR patch_package
= NULL
;
276 LPWSTR install_package
= NULL
;
277 LPWSTR command_line
= NULL
;
278 UINT r
= ERROR_OUTOFMEMORY
;
280 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage
), debugstr_a(szInstallPackage
),
281 eInstallType
, debugstr_a(szCommandLine
));
283 if (szPatchPackage
&& !(patch_package
= strdupAtoW(szPatchPackage
)))
286 if (szInstallPackage
&& !(install_package
= strdupAtoW(szInstallPackage
)))
289 if (szCommandLine
&& !(command_line
= strdupAtoW(szCommandLine
)))
292 r
= MsiApplyPatchW(patch_package
, install_package
, eInstallType
, command_line
);
295 msi_free(patch_package
);
296 msi_free(install_package
);
297 msi_free(command_line
);
303 static UINT
get_patch_product_codes( LPCWSTR szPatchPackage
, WCHAR
***product_codes
)
305 MSIHANDLE patch
, info
= 0;
308 static WCHAR empty
[] = {0};
311 r
= MsiOpenDatabaseW( szPatchPackage
, MSIDBOPEN_READONLY
, &patch
);
312 if (r
!= ERROR_SUCCESS
)
315 r
= MsiGetSummaryInformationW( patch
, NULL
, 0, &info
);
316 if (r
!= ERROR_SUCCESS
)
320 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, empty
, &size
);
321 if (r
!= ERROR_MORE_DATA
|| !size
|| type
!= VT_LPSTR
)
323 ERR("Failed to read product codes from patch\n");
324 r
= ERROR_FUNCTION_FAILED
;
328 codes
= msi_alloc( ++size
* sizeof(WCHAR
) );
331 r
= ERROR_OUTOFMEMORY
;
335 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, codes
, &size
);
336 if (r
== ERROR_SUCCESS
)
337 *product_codes
= msi_split_string( codes
, ';' );
340 MsiCloseHandle( info
);
341 MsiCloseHandle( patch
);
346 static UINT
MSI_ApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szProductCode
, LPCWSTR szCommandLine
)
350 LPCWSTR cmd_ptr
= szCommandLine
;
351 LPWSTR cmd
, *codes
= NULL
;
352 BOOL succeeded
= FALSE
;
354 static const WCHAR fmt
[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
355 static WCHAR empty
[] = {0};
357 if (!szPatchPackage
|| !szPatchPackage
[0])
358 return ERROR_INVALID_PARAMETER
;
360 if (!szProductCode
&& (r
= get_patch_product_codes( szPatchPackage
, &codes
)))
366 size
= strlenW(cmd_ptr
) + strlenW(fmt
) + strlenW(szPatchPackage
) + 1;
367 cmd
= msi_alloc(size
* sizeof(WCHAR
));
371 return ERROR_OUTOFMEMORY
;
373 sprintfW(cmd
, fmt
, cmd_ptr
, szPatchPackage
);
376 r
= MsiConfigureProductExW(szProductCode
, INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
379 for (i
= 0; codes
[i
]; i
++)
381 r
= MsiConfigureProductExW(codes
[i
], INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
382 if (r
== ERROR_SUCCESS
)
384 TRACE("patch applied\n");
398 UINT WINAPI
MsiApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szInstallPackage
,
399 INSTALLTYPE eInstallType
, LPCWSTR szCommandLine
)
401 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage
), debugstr_w(szInstallPackage
),
402 eInstallType
, debugstr_w(szCommandLine
));
404 if (szInstallPackage
|| eInstallType
== INSTALLTYPE_NETWORK_IMAGE
||
405 eInstallType
== INSTALLTYPE_SINGLE_INSTANCE
)
407 FIXME("Only reading target products from patch\n");
408 return ERROR_CALL_NOT_IMPLEMENTED
;
411 return MSI_ApplyPatchW(szPatchPackage
, NULL
, szCommandLine
);
414 UINT WINAPI
MsiApplyMultiplePatchesA(LPCSTR szPatchPackages
,
415 LPCSTR szProductCode
, LPCSTR szPropertiesList
)
417 LPWSTR patch_packages
= NULL
;
418 LPWSTR product_code
= NULL
;
419 LPWSTR properties_list
= NULL
;
420 UINT r
= ERROR_OUTOFMEMORY
;
422 TRACE("%s %s %s\n", debugstr_a(szPatchPackages
), debugstr_a(szProductCode
),
423 debugstr_a(szPropertiesList
));
425 if (!szPatchPackages
|| !szPatchPackages
[0])
426 return ERROR_INVALID_PARAMETER
;
428 if (!(patch_packages
= strdupAtoW(szPatchPackages
)))
429 return ERROR_OUTOFMEMORY
;
431 if (szProductCode
&& !(product_code
= strdupAtoW(szProductCode
)))
434 if (szPropertiesList
&& !(properties_list
= strdupAtoW(szPropertiesList
)))
437 r
= MsiApplyMultiplePatchesW(patch_packages
, product_code
, properties_list
);
440 msi_free(patch_packages
);
441 msi_free(product_code
);
442 msi_free(properties_list
);
447 UINT WINAPI
MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages
,
448 LPCWSTR szProductCode
, LPCWSTR szPropertiesList
)
450 UINT r
= ERROR_SUCCESS
;
453 TRACE("%s %s %s\n", debugstr_w(szPatchPackages
), debugstr_w(szProductCode
),
454 debugstr_w(szPropertiesList
));
456 if (!szPatchPackages
|| !szPatchPackages
[0])
457 return ERROR_INVALID_PARAMETER
;
459 beg
= end
= szPatchPackages
;
465 while (*beg
== ' ') beg
++;
466 while (*end
&& *end
!= ';') end
++;
469 while (len
&& beg
[len
- 1] == ' ') len
--;
471 if (!len
) return ERROR_INVALID_NAME
;
473 patch
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
475 return ERROR_OUTOFMEMORY
;
477 memcpy(patch
, beg
, len
* sizeof(WCHAR
));
480 r
= MSI_ApplyPatchW(patch
, szProductCode
, szPropertiesList
);
483 if (r
!= ERROR_SUCCESS
)
491 UINT WINAPI
MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath
,
492 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
495 WCHAR
*package_path
= NULL
;
496 MSIPATCHSEQUENCEINFOW
*psi
;
498 TRACE("(%s, %d, %p)\n", debugstr_a(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
500 if (szProductPackagePath
&& !(package_path
= strdupAtoW( szProductPackagePath
)))
501 return ERROR_OUTOFMEMORY
;
503 psi
= msi_alloc( cPatchInfo
* sizeof(*psi
) );
506 msi_free( package_path
);
507 return ERROR_OUTOFMEMORY
;
510 for (i
= 0; i
< cPatchInfo
; i
++)
512 psi
[i
].szPatchData
= strdupAtoW( pPatchInfo
[i
].szPatchData
);
513 psi
[i
].ePatchDataType
= pPatchInfo
[i
].ePatchDataType
;
516 r
= MsiDetermineApplicablePatchesW( package_path
, cPatchInfo
, psi
);
517 if (r
== ERROR_SUCCESS
)
519 for (i
= 0; i
< cPatchInfo
; i
++)
521 pPatchInfo
[i
].dwOrder
= psi
[i
].dwOrder
;
522 pPatchInfo
[i
].uStatus
= psi
[i
].uStatus
;
526 msi_free( package_path
);
527 for (i
= 0; i
< cPatchInfo
; i
++)
528 msi_free( (WCHAR
*)psi
[i
].szPatchData
);
533 static UINT
MSI_ApplicablePatchW( MSIPACKAGE
*package
, LPCWSTR patch
)
536 MSIDATABASE
*patch_db
;
537 UINT r
= ERROR_SUCCESS
;
539 r
= MSI_OpenDatabaseW( patch
, MSIDBOPEN_READONLY
, &patch_db
);
540 if (r
!= ERROR_SUCCESS
)
542 WARN("failed to open patch file %s\n", debugstr_w(patch
));
546 si
= MSI_GetSummaryInformationW( patch_db
->storage
, 0 );
549 msiobj_release( &patch_db
->hdr
);
550 return ERROR_FUNCTION_FAILED
;
553 r
= msi_check_patch_applicable( package
, si
);
554 if (r
!= ERROR_SUCCESS
)
555 TRACE("patch not applicable\n");
557 msiobj_release( &patch_db
->hdr
);
558 msiobj_release( &si
->hdr
);
562 UINT WINAPI
MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath
,
563 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
565 UINT i
, r
, ret
= ERROR_FUNCTION_FAILED
;
568 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
570 r
= MSI_OpenPackageW( szProductPackagePath
, &package
);
571 if (r
!= ERROR_SUCCESS
)
573 ERR("failed to open package %u\n", r
);
577 for (i
= 0; i
< cPatchInfo
; i
++)
579 switch (pPatchInfo
[i
].ePatchDataType
)
581 case MSIPATCH_DATATYPE_PATCHFILE
:
583 FIXME("patch ordering not supported\n");
584 r
= MSI_ApplicablePatchW( package
, pPatchInfo
[i
].szPatchData
);
585 if (r
!= ERROR_SUCCESS
)
587 pPatchInfo
[i
].dwOrder
= ~0u;
588 pPatchInfo
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
592 pPatchInfo
[i
].dwOrder
= i
;
593 pPatchInfo
[i
].uStatus
= ret
= ERROR_SUCCESS
;
599 FIXME("patch data type %u not supported\n", pPatchInfo
[i
].ePatchDataType
);
600 pPatchInfo
[i
].dwOrder
= ~0u;
601 pPatchInfo
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
606 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo
[i
].szPatchData
));
607 TRACE("ePatchDataType: %u\n", pPatchInfo
[i
].ePatchDataType
);
608 TRACE(" dwOrder: %u\n", pPatchInfo
[i
].dwOrder
);
609 TRACE(" uStatus: %u\n", pPatchInfo
[i
].uStatus
);
614 UINT WINAPI
MsiDeterminePatchSequenceA(LPCSTR szProductCode
, LPCSTR szUserSid
,
615 MSIINSTALLCONTEXT dwContext
, DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
617 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode
),
618 debugstr_a(szUserSid
), dwContext
, cPatchInfo
, pPatchInfo
);
620 return ERROR_CALL_NOT_IMPLEMENTED
;
623 UINT WINAPI
MsiDeterminePatchSequenceW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
624 MSIINSTALLCONTEXT dwContext
, DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
626 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode
),
627 debugstr_w(szUserSid
), dwContext
, cPatchInfo
, pPatchInfo
);
629 return ERROR_CALL_NOT_IMPLEMENTED
;
632 static UINT
msi_open_package(LPCWSTR product
, MSIINSTALLCONTEXT context
,
633 MSIPACKAGE
**package
)
639 WCHAR sourcepath
[MAX_PATH
];
640 WCHAR filename
[MAX_PATH
];
642 r
= MSIREG_OpenInstallProps(product
, context
, NULL
, &props
, FALSE
);
643 if (r
!= ERROR_SUCCESS
)
644 return ERROR_BAD_CONFIGURATION
;
646 localpack
= msi_reg_get_val_str(props
, szLocalPackage
);
649 lstrcpyW(sourcepath
, localpack
);
653 if (!localpack
|| GetFileAttributesW(sourcepath
) == INVALID_FILE_ATTRIBUTES
)
655 sz
= sizeof(sourcepath
);
656 MsiSourceListGetInfoW(product
, NULL
, context
, MSICODE_PRODUCT
,
657 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
659 sz
= sizeof(filename
);
660 MsiSourceListGetInfoW(product
, NULL
, context
, MSICODE_PRODUCT
,
661 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
663 lstrcatW(sourcepath
, filename
);
666 if (GetFileAttributesW(sourcepath
) == INVALID_FILE_ATTRIBUTES
)
667 return ERROR_INSTALL_SOURCE_ABSENT
;
669 return MSI_OpenPackageW(sourcepath
, package
);
672 UINT WINAPI
MsiConfigureProductExW(LPCWSTR szProduct
, int iInstallLevel
,
673 INSTALLSTATE eInstallState
, LPCWSTR szCommandLine
)
675 MSIPACKAGE
* package
= NULL
;
676 MSIINSTALLCONTEXT context
;
679 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
682 static const WCHAR szInstalled
[] = {
683 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
684 static const WCHAR szInstallLevel
[] = {
685 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
686 static const WCHAR szRemoveAll
[] = {
687 ' ','R','E','M','O','V','E','=','A','L','L',0};
688 static const WCHAR szMachine
[] = {
689 ' ','A','L','L','U','S','E','R','S','=','1',0};
691 TRACE("%s %d %d %s\n",debugstr_w(szProduct
), iInstallLevel
, eInstallState
,
692 debugstr_w(szCommandLine
));
694 if (!szProduct
|| lstrlenW(szProduct
) != GUID_SIZE
- 1)
695 return ERROR_INVALID_PARAMETER
;
697 if (eInstallState
== INSTALLSTATE_ADVERTISED
||
698 eInstallState
== INSTALLSTATE_SOURCE
)
700 FIXME("State %d not implemented\n", eInstallState
);
701 return ERROR_CALL_NOT_IMPLEMENTED
;
704 r
= msi_locate_product(szProduct
, &context
);
705 if (r
!= ERROR_SUCCESS
)
708 r
= msi_open_package(szProduct
, context
, &package
);
709 if (r
!= ERROR_SUCCESS
)
712 sz
= lstrlenW(szInstalled
) + 1;
715 sz
+= lstrlenW(szCommandLine
);
717 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
718 sz
+= lstrlenW(szInstallLevel
);
720 if (eInstallState
== INSTALLSTATE_ABSENT
)
721 sz
+= lstrlenW(szRemoveAll
);
723 if (context
== MSIINSTALLCONTEXT_MACHINE
)
724 sz
+= lstrlenW(szMachine
);
726 commandline
= msi_alloc(sz
* sizeof(WCHAR
));
729 r
= ERROR_OUTOFMEMORY
;
735 lstrcpyW(commandline
,szCommandLine
);
737 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
738 lstrcatW(commandline
, szInstallLevel
);
740 if (eInstallState
== INSTALLSTATE_ABSENT
)
741 lstrcatW(commandline
, szRemoveAll
);
743 if (context
== MSIINSTALLCONTEXT_MACHINE
)
744 lstrcatW(commandline
, szMachine
);
746 sz
= sizeof(sourcepath
);
747 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
748 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
750 sz
= sizeof(filename
);
751 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
752 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
754 strcatW(sourcepath
, filename
);
756 r
= MSI_InstallPackage( package
, sourcepath
, commandline
);
758 msi_free(commandline
);
761 msiobj_release( &package
->hdr
);
766 UINT WINAPI
MsiConfigureProductExA(LPCSTR szProduct
, int iInstallLevel
,
767 INSTALLSTATE eInstallState
, LPCSTR szCommandLine
)
769 LPWSTR szwProduct
= NULL
;
770 LPWSTR szwCommandLine
= NULL
;
771 UINT r
= ERROR_OUTOFMEMORY
;
775 szwProduct
= strdupAtoW( szProduct
);
782 szwCommandLine
= strdupAtoW( szCommandLine
);
787 r
= MsiConfigureProductExW( szwProduct
, iInstallLevel
, eInstallState
,
790 msi_free( szwProduct
);
791 msi_free( szwCommandLine
);
796 UINT WINAPI
MsiConfigureProductA(LPCSTR szProduct
, int iInstallLevel
,
797 INSTALLSTATE eInstallState
)
799 LPWSTR szwProduct
= NULL
;
802 TRACE("%s %d %d\n",debugstr_a(szProduct
), iInstallLevel
, eInstallState
);
806 szwProduct
= strdupAtoW( szProduct
);
808 return ERROR_OUTOFMEMORY
;
811 r
= MsiConfigureProductW( szwProduct
, iInstallLevel
, eInstallState
);
812 msi_free( szwProduct
);
817 UINT WINAPI
MsiConfigureProductW(LPCWSTR szProduct
, int iInstallLevel
,
818 INSTALLSTATE eInstallState
)
820 return MsiConfigureProductExW(szProduct
, iInstallLevel
, eInstallState
, NULL
);
823 UINT WINAPI
MsiGetProductCodeA(LPCSTR szComponent
, LPSTR szBuffer
)
825 LPWSTR szwComponent
= NULL
;
827 WCHAR szwBuffer
[GUID_SIZE
];
829 TRACE("%s %p\n", debugstr_a(szComponent
), szBuffer
);
833 szwComponent
= strdupAtoW( szComponent
);
835 return ERROR_OUTOFMEMORY
;
839 r
= MsiGetProductCodeW( szwComponent
, szwBuffer
);
842 WideCharToMultiByte(CP_ACP
, 0, szwBuffer
, -1, szBuffer
, GUID_SIZE
, NULL
, NULL
);
844 msi_free( szwComponent
);
849 UINT WINAPI
MsiGetProductCodeW(LPCWSTR szComponent
, LPWSTR szBuffer
)
852 HKEY compkey
, prodkey
;
853 WCHAR squished_comp
[GUID_SIZE
];
854 WCHAR squished_prod
[GUID_SIZE
];
855 DWORD sz
= GUID_SIZE
;
857 TRACE("%s %p\n", debugstr_w(szComponent
), szBuffer
);
859 if (!szComponent
|| !*szComponent
)
860 return ERROR_INVALID_PARAMETER
;
862 if (!squash_guid(szComponent
, squished_comp
))
863 return ERROR_INVALID_PARAMETER
;
865 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &compkey
, FALSE
) != ERROR_SUCCESS
&&
866 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &compkey
, FALSE
) != ERROR_SUCCESS
)
868 return ERROR_UNKNOWN_COMPONENT
;
871 rc
= RegEnumValueW(compkey
, 0, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
872 if (rc
!= ERROR_SUCCESS
)
874 RegCloseKey(compkey
);
875 return ERROR_UNKNOWN_COMPONENT
;
878 /* check simple case, only one product */
879 rc
= RegEnumValueW(compkey
, 1, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
880 if (rc
== ERROR_NO_MORE_ITEMS
)
887 while ((rc
= RegEnumValueW(compkey
, index
, squished_prod
, &sz
,
888 NULL
, NULL
, NULL
, NULL
)) != ERROR_NO_MORE_ITEMS
)
892 unsquash_guid(squished_prod
, szBuffer
);
894 if (MSIREG_OpenProductKey(szBuffer
, NULL
,
895 MSIINSTALLCONTEXT_USERMANAGED
,
896 &prodkey
, FALSE
) == ERROR_SUCCESS
||
897 MSIREG_OpenProductKey(szBuffer
, NULL
,
898 MSIINSTALLCONTEXT_USERUNMANAGED
,
899 &prodkey
, FALSE
) == ERROR_SUCCESS
||
900 MSIREG_OpenProductKey(szBuffer
, NULL
,
901 MSIINSTALLCONTEXT_MACHINE
,
902 &prodkey
, FALSE
) == ERROR_SUCCESS
)
904 RegCloseKey(prodkey
);
910 rc
= ERROR_INSTALL_FAILURE
;
913 RegCloseKey(compkey
);
914 unsquash_guid(squished_prod
, szBuffer
);
918 static LPWSTR
msi_reg_get_value(HKEY hkey
, LPCWSTR name
, DWORD
*type
)
924 static const WCHAR format
[] = {'%','d',0};
926 res
= RegQueryValueExW(hkey
, name
, NULL
, type
, NULL
, NULL
);
927 if (res
!= ERROR_SUCCESS
)
931 return msi_reg_get_val_str(hkey
, name
);
933 if (!msi_reg_get_val_dword(hkey
, name
, &dval
))
936 sprintfW(temp
, format
, dval
);
937 return strdupW(temp
);
940 static UINT
MSI_GetProductInfo(LPCWSTR szProduct
, LPCWSTR szAttribute
,
941 awstring
*szValue
, LPDWORD pcchValueBuf
)
943 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
944 UINT r
= ERROR_UNKNOWN_PROPERTY
;
945 HKEY prodkey
, userdata
, source
;
947 WCHAR squished_pc
[GUID_SIZE
];
948 WCHAR packagecode
[GUID_SIZE
];
949 BOOL badconfig
= FALSE
;
951 DWORD type
= REG_NONE
;
953 static WCHAR empty
[] = {0};
954 static const WCHAR sourcelist
[] = {
955 'S','o','u','r','c','e','L','i','s','t',0};
956 static const WCHAR display_name
[] = {
957 'D','i','s','p','l','a','y','N','a','m','e',0};
958 static const WCHAR display_version
[] = {
959 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
960 static const WCHAR assignment
[] = {
961 'A','s','s','i','g','n','m','e','n','t',0};
963 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
964 debugstr_w(szAttribute
), szValue
, pcchValueBuf
);
966 if ((szValue
->str
.w
&& !pcchValueBuf
) || !szProduct
|| !szAttribute
)
967 return ERROR_INVALID_PARAMETER
;
969 if (!squash_guid(szProduct
, squished_pc
))
970 return ERROR_INVALID_PARAMETER
;
972 if ((r
= MSIREG_OpenProductKey(szProduct
, NULL
,
973 MSIINSTALLCONTEXT_USERMANAGED
,
974 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
975 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
976 MSIINSTALLCONTEXT_USERUNMANAGED
,
977 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
978 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
979 MSIINSTALLCONTEXT_MACHINE
,
980 &prodkey
, FALSE
)) == ERROR_SUCCESS
)
982 context
= MSIINSTALLCONTEXT_MACHINE
;
985 MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
987 if (!strcmpW( szAttribute
, INSTALLPROPERTY_HELPLINKW
) ||
988 !strcmpW( szAttribute
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
989 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLDATEW
) ||
990 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
991 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
992 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
993 !strcmpW( szAttribute
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
994 !strcmpW( szAttribute
, INSTALLPROPERTY_PUBLISHERW
) ||
995 !strcmpW( szAttribute
, INSTALLPROPERTY_URLINFOABOUTW
) ||
996 !strcmpW( szAttribute
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
997 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMINORW
) ||
998 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMAJORW
) ||
999 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1000 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTIDW
) ||
1001 !strcmpW( szAttribute
, INSTALLPROPERTY_REGCOMPANYW
) ||
1002 !strcmpW( szAttribute
, INSTALLPROPERTY_REGOWNERW
))
1006 r
= ERROR_UNKNOWN_PRODUCT
;
1011 return ERROR_UNKNOWN_PROPERTY
;
1013 if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1014 szAttribute
= display_name
;
1015 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
))
1016 szAttribute
= display_version
;
1018 val
= msi_reg_get_value(userdata
, szAttribute
, &type
);
1022 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTANCETYPEW
) ||
1023 !strcmpW( szAttribute
, INSTALLPROPERTY_TRANSFORMSW
) ||
1024 !strcmpW( szAttribute
, INSTALLPROPERTY_LANGUAGEW
) ||
1025 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1026 !strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
) ||
1027 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
) ||
1028 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONW
) ||
1029 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTICONW
) ||
1030 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1031 !strcmpW( szAttribute
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1035 r
= ERROR_UNKNOWN_PRODUCT
;
1039 if (!strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1040 szAttribute
= assignment
;
1042 if (!strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
))
1044 res
= RegOpenKeyW(prodkey
, sourcelist
, &source
);
1045 if (res
!= ERROR_SUCCESS
)
1047 r
= ERROR_UNKNOWN_PRODUCT
;
1051 val
= msi_reg_get_value(source
, szAttribute
, &type
);
1055 RegCloseKey(source
);
1059 val
= msi_reg_get_value(prodkey
, szAttribute
, &type
);
1064 if (val
!= empty
&& type
!= REG_DWORD
&&
1065 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
))
1067 if (lstrlenW(val
) != SQUISH_GUID_SIZE
- 1)
1071 unsquash_guid(val
, packagecode
);
1073 val
= strdupW(packagecode
);
1080 r
= ERROR_UNKNOWN_PROPERTY
;
1086 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1087 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1088 * can't rely on its value.
1090 if (szValue
->str
.a
|| szValue
->str
.w
)
1092 DWORD size
= *pcchValueBuf
;
1093 if (strlenW(val
) < size
)
1094 r
= msi_strcpy_to_awstring(val
, szValue
, &size
);
1097 r
= ERROR_MORE_DATA
;
1102 *pcchValueBuf
= lstrlenW(val
);
1106 r
= ERROR_BAD_CONFIGURATION
;
1112 RegCloseKey(prodkey
);
1113 RegCloseKey(userdata
);
1117 UINT WINAPI
MsiGetProductInfoA(LPCSTR szProduct
, LPCSTR szAttribute
,
1118 LPSTR szBuffer
, LPDWORD pcchValueBuf
)
1120 LPWSTR szwProduct
, szwAttribute
= NULL
;
1121 UINT r
= ERROR_OUTOFMEMORY
;
1124 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szAttribute
),
1125 szBuffer
, pcchValueBuf
);
1127 szwProduct
= strdupAtoW( szProduct
);
1128 if( szProduct
&& !szwProduct
)
1131 szwAttribute
= strdupAtoW( szAttribute
);
1132 if( szAttribute
&& !szwAttribute
)
1135 buffer
.unicode
= FALSE
;
1136 buffer
.str
.a
= szBuffer
;
1138 r
= MSI_GetProductInfo( szwProduct
, szwAttribute
,
1139 &buffer
, pcchValueBuf
);
1142 msi_free( szwProduct
);
1143 msi_free( szwAttribute
);
1148 UINT WINAPI
MsiGetProductInfoW(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1149 LPWSTR szBuffer
, LPDWORD pcchValueBuf
)
1153 TRACE("%s %s %p %p\n", debugstr_w(szProduct
), debugstr_w(szAttribute
),
1154 szBuffer
, pcchValueBuf
);
1156 buffer
.unicode
= TRUE
;
1157 buffer
.str
.w
= szBuffer
;
1159 return MSI_GetProductInfo( szProduct
, szAttribute
,
1160 &buffer
, pcchValueBuf
);
1163 UINT WINAPI
MsiGetProductInfoExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1164 MSIINSTALLCONTEXT dwContext
, LPCSTR szProperty
,
1165 LPSTR szValue
, LPDWORD pcchValue
)
1167 LPWSTR product
= NULL
;
1168 LPWSTR usersid
= NULL
;
1169 LPWSTR property
= NULL
;
1170 LPWSTR value
= NULL
;
1174 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode
),
1175 debugstr_a(szUserSid
), dwContext
, debugstr_a(szProperty
),
1176 szValue
, pcchValue
);
1178 if (szValue
&& !pcchValue
)
1179 return ERROR_INVALID_PARAMETER
;
1181 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1182 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1183 if (szProperty
) property
= strdupAtoW(szProperty
);
1185 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1187 if (r
!= ERROR_SUCCESS
)
1190 value
= msi_alloc(++len
* sizeof(WCHAR
));
1193 r
= ERROR_OUTOFMEMORY
;
1197 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1199 if (r
!= ERROR_SUCCESS
)
1205 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
1206 if (*pcchValue
>= len
)
1207 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
1210 r
= ERROR_MORE_DATA
;
1215 if (*pcchValue
<= len
|| !szValue
)
1216 len
= len
* sizeof(WCHAR
) - 1;
1218 *pcchValue
= len
- 1;
1229 static UINT
msi_copy_outval(LPWSTR val
, LPWSTR out
, LPDWORD size
)
1231 UINT r
= ERROR_SUCCESS
;
1234 return ERROR_UNKNOWN_PROPERTY
;
1238 if (strlenW(val
) >= *size
)
1240 r
= ERROR_MORE_DATA
;
1249 *size
= lstrlenW(val
);
1254 UINT WINAPI
MsiGetProductInfoExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
1255 MSIINSTALLCONTEXT dwContext
, LPCWSTR szProperty
,
1256 LPWSTR szValue
, LPDWORD pcchValue
)
1258 WCHAR squished_pc
[GUID_SIZE
];
1260 LPCWSTR package
= NULL
;
1261 HKEY props
= NULL
, prod
;
1262 HKEY classes
= NULL
, managed
;
1265 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1267 static const WCHAR five
[] = {'5',0};
1268 static const WCHAR displayname
[] = {
1269 'D','i','s','p','l','a','y','N','a','m','e',0};
1270 static const WCHAR displayversion
[] = {
1271 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1272 static const WCHAR managed_local_package
[] = {
1273 'M','a','n','a','g','e','d','L','o','c','a','l',
1274 'P','a','c','k','a','g','e',0};
1276 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode
),
1277 debugstr_w(szUserSid
), dwContext
, debugstr_w(szProperty
),
1278 szValue
, pcchValue
);
1280 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1281 return ERROR_INVALID_PARAMETER
;
1283 if (szValue
&& !pcchValue
)
1284 return ERROR_INVALID_PARAMETER
;
1286 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1287 dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1288 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1289 return ERROR_INVALID_PARAMETER
;
1291 if (!szProperty
|| !*szProperty
)
1292 return ERROR_INVALID_PARAMETER
;
1294 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1295 return ERROR_INVALID_PARAMETER
;
1297 /* FIXME: dwContext is provided, no need to search for it */
1298 MSIREG_OpenProductKey(szProductCode
, NULL
,MSIINSTALLCONTEXT_USERMANAGED
,
1300 MSIREG_OpenProductKey(szProductCode
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1303 MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
, &props
, FALSE
);
1305 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1307 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1309 if (!props
&& !prod
)
1312 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1314 package
= managed_local_package
;
1316 if (!props
&& !managed
)
1319 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1321 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1322 MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
, &classes
, FALSE
);
1324 if (!props
&& !classes
)
1328 if (!strcmpW( szProperty
, INSTALLPROPERTY_HELPLINKW
) ||
1329 !strcmpW( szProperty
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1330 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
) ||
1331 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1332 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1333 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1334 !strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1335 !strcmpW( szProperty
, INSTALLPROPERTY_PUBLISHERW
) ||
1336 !strcmpW( szProperty
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1337 !strcmpW( szProperty
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1338 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMINORW
) ||
1339 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1340 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1341 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTIDW
) ||
1342 !strcmpW( szProperty
, INSTALLPROPERTY_REGCOMPANYW
) ||
1343 !strcmpW( szProperty
, INSTALLPROPERTY_REGOWNERW
) ||
1344 !strcmpW( szProperty
, INSTALLPROPERTY_INSTANCETYPEW
))
1346 val
= msi_reg_get_value(props
, package
, &type
);
1349 if (prod
|| classes
)
1350 r
= ERROR_UNKNOWN_PROPERTY
;
1357 if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1358 szProperty
= displayname
;
1359 else if (!strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
))
1360 szProperty
= displayversion
;
1362 val
= msi_reg_get_value(props
, szProperty
, &type
);
1364 val
= strdupW(szEmpty
);
1366 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1368 else if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
) ||
1369 !strcmpW( szProperty
, INSTALLPROPERTY_LANGUAGEW
) ||
1370 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1371 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGECODEW
) ||
1372 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONW
) ||
1373 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTICONW
) ||
1374 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1375 !strcmpW( szProperty
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1377 if (!prod
&& !classes
)
1380 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1382 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1384 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1387 val
= msi_reg_get_value(hkey
, szProperty
, &type
);
1389 val
= strdupW(szEmpty
);
1391 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1393 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTSTATEW
))
1395 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1399 val
= msi_reg_get_value(props
, package
, &type
);
1404 val
= strdupW(five
);
1407 val
= strdupW(szOne
);
1409 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1412 else if (props
&& (val
= msi_reg_get_value(props
, package
, &type
)))
1415 val
= strdupW(five
);
1416 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1420 if (prod
|| managed
)
1421 val
= strdupW(szOne
);
1425 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1427 else if (!strcmpW( szProperty
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1429 if (!prod
&& !classes
)
1433 val
= strdupW(szEmpty
);
1434 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1437 r
= ERROR_UNKNOWN_PROPERTY
;
1442 RegCloseKey(managed
);
1443 RegCloseKey(classes
);
1449 UINT WINAPI
MsiGetPatchInfoExA(LPCSTR szPatchCode
, LPCSTR szProductCode
,
1450 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1451 LPCSTR szProperty
, LPSTR lpValue
, DWORD
*pcchValue
)
1453 LPWSTR patch
= NULL
, product
= NULL
, usersid
= NULL
;
1454 LPWSTR property
= NULL
, val
= NULL
;
1458 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode
),
1459 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
,
1460 debugstr_a(szProperty
), lpValue
, pcchValue
);
1462 if (lpValue
&& !pcchValue
)
1463 return ERROR_INVALID_PARAMETER
;
1465 if (szPatchCode
) patch
= strdupAtoW(szPatchCode
);
1466 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1467 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1468 if (szProperty
) property
= strdupAtoW(szProperty
);
1471 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1473 if (r
!= ERROR_SUCCESS
)
1476 val
= msi_alloc(++len
* sizeof(WCHAR
));
1479 r
= ERROR_OUTOFMEMORY
;
1483 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1485 if (r
!= ERROR_SUCCESS
|| !pcchValue
)
1489 WideCharToMultiByte(CP_ACP
, 0, val
, -1, lpValue
,
1490 *pcchValue
- 1, NULL
, NULL
);
1492 len
= lstrlenW(val
);
1493 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1497 r
= ERROR_MORE_DATA
;
1498 lpValue
[*pcchValue
- 1] = '\0';
1501 *pcchValue
= len
* sizeof(WCHAR
);
1516 UINT WINAPI
MsiGetPatchInfoExW(LPCWSTR szPatchCode
, LPCWSTR szProductCode
,
1517 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1518 LPCWSTR szProperty
, LPWSTR lpValue
, DWORD
*pcchValue
)
1520 WCHAR squished_pc
[GUID_SIZE
];
1521 WCHAR squished_patch
[GUID_SIZE
];
1522 HKEY udprod
= 0, prod
= 0, props
= 0;
1523 HKEY patch
= 0, patches
= 0;
1524 HKEY udpatch
= 0, datakey
= 0;
1525 HKEY prodpatches
= 0;
1527 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1531 static const WCHAR szManagedPackage
[] = {'M','a','n','a','g','e','d',
1532 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1534 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode
),
1535 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
,
1536 debugstr_w(szProperty
), lpValue
, pcchValue
);
1538 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1539 return ERROR_INVALID_PARAMETER
;
1541 if (!szPatchCode
|| !squash_guid(szPatchCode
, squished_patch
))
1542 return ERROR_INVALID_PARAMETER
;
1545 return ERROR_INVALID_PARAMETER
;
1547 if (lpValue
&& !pcchValue
)
1548 return ERROR_INVALID_PARAMETER
;
1550 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1551 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1552 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1553 return ERROR_INVALID_PARAMETER
;
1555 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1556 return ERROR_INVALID_PARAMETER
;
1558 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
1559 return ERROR_INVALID_PARAMETER
;
1561 if (MSIREG_OpenUserDataProductKey(szProductCode
, dwContext
, NULL
,
1562 &udprod
, FALSE
) != ERROR_SUCCESS
)
1565 if (MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
,
1566 &props
, FALSE
) != ERROR_SUCCESS
)
1569 r
= ERROR_UNKNOWN_PATCH
;
1571 res
= RegOpenKeyExW(udprod
, szPatches
, 0, KEY_READ
, &patches
);
1572 if (res
!= ERROR_SUCCESS
)
1575 res
= RegOpenKeyExW(patches
, squished_patch
, 0, KEY_READ
, &patch
);
1576 if (res
!= ERROR_SUCCESS
)
1579 if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
))
1581 if (MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
,
1582 &prod
, FALSE
) != ERROR_SUCCESS
)
1585 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_ALL_ACCESS
, &prodpatches
);
1586 if (res
!= ERROR_SUCCESS
)
1589 datakey
= prodpatches
;
1590 szProperty
= squished_patch
;
1594 if (MSIREG_OpenUserDataPatchKey(szPatchCode
, dwContext
,
1595 &udpatch
, FALSE
) != ERROR_SUCCESS
)
1598 if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1600 if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1601 szProperty
= szManagedPackage
;
1604 else if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
))
1607 szProperty
= szInstalled
;
1609 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1613 else if (!strcmpW( szProperty
, INSTALLPROPERTY_UNINSTALLABLEW
) ||
1614 !strcmpW( szProperty
, INSTALLPROPERTY_PATCHSTATEW
) ||
1615 !strcmpW( szProperty
, INSTALLPROPERTY_DISPLAYNAMEW
) ||
1616 !strcmpW( szProperty
, INSTALLPROPERTY_MOREINFOURLW
))
1622 r
= ERROR_UNKNOWN_PROPERTY
;
1627 val
= msi_reg_get_val_str(datakey
, szProperty
);
1629 val
= strdupW(szEmpty
);
1637 lstrcpynW(lpValue
, val
, *pcchValue
);
1639 len
= lstrlenW(val
);
1640 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1643 r
= ERROR_MORE_DATA
;
1645 *pcchValue
= len
* sizeof(WCHAR
);
1652 RegCloseKey(prodpatches
);
1655 RegCloseKey(patches
);
1656 RegCloseKey(udpatch
);
1658 RegCloseKey(udprod
);
1663 UINT WINAPI
MsiGetPatchInfoA( LPCSTR patch
, LPCSTR attr
, LPSTR buffer
, LPDWORD buflen
)
1665 UINT r
= ERROR_OUTOFMEMORY
;
1667 LPWSTR patchW
= NULL
, attrW
= NULL
, bufferW
= NULL
;
1669 TRACE("%s %s %p %p\n", debugstr_a(patch
), debugstr_a(attr
), buffer
, buflen
);
1671 if (!patch
|| !attr
)
1672 return ERROR_INVALID_PARAMETER
;
1674 if (!(patchW
= strdupAtoW( patch
)))
1677 if (!(attrW
= strdupAtoW( attr
)))
1681 r
= MsiGetPatchInfoW( patchW
, attrW
, NULL
, &size
);
1682 if (r
!= ERROR_SUCCESS
)
1686 if (!(bufferW
= msi_alloc( size
* sizeof(WCHAR
) )))
1688 r
= ERROR_OUTOFMEMORY
;
1692 r
= MsiGetPatchInfoW( patchW
, attrW
, bufferW
, &size
);
1693 if (r
== ERROR_SUCCESS
)
1695 int len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
1697 r
= ERROR_MORE_DATA
;
1699 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *buflen
, NULL
, NULL
);
1707 msi_free( bufferW
);
1711 UINT WINAPI
MsiGetPatchInfoW( LPCWSTR patch
, LPCWSTR attr
, LPWSTR buffer
, LPDWORD buflen
)
1714 WCHAR product
[GUID_SIZE
];
1717 TRACE("%s %s %p %p\n", debugstr_w(patch
), debugstr_w(attr
), buffer
, buflen
);
1719 if (!patch
|| !attr
)
1720 return ERROR_INVALID_PARAMETER
;
1722 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW
, attr
))
1723 return ERROR_UNKNOWN_PROPERTY
;
1728 r
= MsiEnumProductsW( index
, product
);
1729 if (r
!= ERROR_SUCCESS
)
1732 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, attr
, buffer
, buflen
);
1733 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1736 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, attr
, buffer
, buflen
);
1737 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1740 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_MACHINE
, attr
, buffer
, buflen
);
1741 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1747 return ERROR_UNKNOWN_PRODUCT
;
1750 UINT WINAPI
MsiEnableLogA(DWORD dwLogMode
, LPCSTR szLogFile
, DWORD attributes
)
1752 LPWSTR szwLogFile
= NULL
;
1755 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_a(szLogFile
), attributes
);
1759 szwLogFile
= strdupAtoW( szLogFile
);
1761 return ERROR_OUTOFMEMORY
;
1763 r
= MsiEnableLogW( dwLogMode
, szwLogFile
, attributes
);
1764 msi_free( szwLogFile
);
1768 UINT WINAPI
MsiEnableLogW(DWORD dwLogMode
, LPCWSTR szLogFile
, DWORD attributes
)
1770 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_w(szLogFile
), attributes
);
1772 msi_free(gszLogFile
);
1778 if (!(attributes
& INSTALLLOGATTRIBUTES_APPEND
))
1779 DeleteFileW(szLogFile
);
1780 file
= CreateFileW(szLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
,
1781 FILE_ATTRIBUTE_NORMAL
, NULL
);
1782 if (file
!= INVALID_HANDLE_VALUE
)
1784 gszLogFile
= strdupW(szLogFile
);
1788 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile
), GetLastError());
1791 return ERROR_SUCCESS
;
1794 UINT WINAPI
MsiEnumComponentCostsW(MSIHANDLE hInstall
, LPCWSTR szComponent
,
1795 DWORD dwIndex
, INSTALLSTATE iState
,
1796 LPWSTR lpDriveBuf
, DWORD
*pcchDriveBuf
,
1797 int *piCost
, int *pTempCost
)
1799 FIXME("(%d, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall
,
1800 debugstr_w(szComponent
), dwIndex
, iState
, lpDriveBuf
,
1801 pcchDriveBuf
, piCost
, pTempCost
);
1803 return ERROR_NO_MORE_ITEMS
;
1806 UINT WINAPI
MsiQueryComponentStateA(LPCSTR szProductCode
,
1807 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1808 LPCSTR szComponent
, INSTALLSTATE
*pdwState
)
1810 LPWSTR prodcode
= NULL
, usersid
= NULL
, comp
= NULL
;
1813 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode
),
1814 debugstr_a(szUserSid
), dwContext
, debugstr_a(szComponent
), pdwState
);
1816 if (szProductCode
&& !(prodcode
= strdupAtoW(szProductCode
)))
1817 return ERROR_OUTOFMEMORY
;
1819 if (szUserSid
&& !(usersid
= strdupAtoW(szUserSid
)))
1820 return ERROR_OUTOFMEMORY
;
1822 if (szComponent
&& !(comp
= strdupAtoW(szComponent
)))
1823 return ERROR_OUTOFMEMORY
;
1825 r
= MsiQueryComponentStateW(prodcode
, usersid
, dwContext
, comp
, pdwState
);
1834 static BOOL
msi_comp_find_prod_key(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
1839 r
= MSIREG_OpenProductKey(prodcode
, NULL
, context
, &hkey
, FALSE
);
1841 return (r
== ERROR_SUCCESS
);
1844 static BOOL
msi_comp_find_package(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
1852 static const WCHAR local_package
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1853 static const WCHAR managed_local_package
[] = {
1854 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1857 r
= MSIREG_OpenInstallProps(prodcode
, context
, NULL
, &hkey
, FALSE
);
1858 if (r
!= ERROR_SUCCESS
)
1861 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
1862 package
= managed_local_package
;
1864 package
= local_package
;
1867 res
= RegQueryValueExW(hkey
, package
, NULL
, NULL
, NULL
, &sz
);
1870 return (res
== ERROR_SUCCESS
);
1873 static BOOL
msi_comp_find_prodcode(LPWSTR squished_pc
,
1874 MSIINSTALLCONTEXT context
,
1875 LPCWSTR comp
, LPWSTR val
, DWORD
*sz
)
1881 if (context
== MSIINSTALLCONTEXT_MACHINE
)
1882 r
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
1884 r
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
1886 if (r
!= ERROR_SUCCESS
)
1889 res
= RegQueryValueExW(hkey
, squished_pc
, NULL
, NULL
, (BYTE
*)val
, sz
);
1890 if (res
!= ERROR_SUCCESS
)
1897 UINT WINAPI
MsiQueryComponentStateW(LPCWSTR szProductCode
,
1898 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1899 LPCWSTR szComponent
, INSTALLSTATE
*pdwState
)
1901 WCHAR squished_pc
[GUID_SIZE
];
1902 WCHAR val
[MAX_PATH
];
1906 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode
),
1907 debugstr_w(szUserSid
), dwContext
, debugstr_w(szComponent
), pdwState
);
1909 if (!pdwState
|| !szComponent
)
1910 return ERROR_INVALID_PARAMETER
;
1912 if (!szProductCode
|| !*szProductCode
|| lstrlenW(szProductCode
) != GUID_SIZE
- 1)
1913 return ERROR_INVALID_PARAMETER
;
1915 if (!squash_guid(szProductCode
, squished_pc
))
1916 return ERROR_INVALID_PARAMETER
;
1918 found
= msi_comp_find_prod_key(szProductCode
, dwContext
);
1920 if (!msi_comp_find_package(szProductCode
, dwContext
))
1924 *pdwState
= INSTALLSTATE_UNKNOWN
;
1925 return ERROR_UNKNOWN_COMPONENT
;
1928 return ERROR_UNKNOWN_PRODUCT
;
1931 *pdwState
= INSTALLSTATE_UNKNOWN
;
1934 if (!msi_comp_find_prodcode(squished_pc
, dwContext
, szComponent
, val
, &sz
))
1935 return ERROR_UNKNOWN_COMPONENT
;
1938 *pdwState
= INSTALLSTATE_NOTUSED
;
1941 if (lstrlenW(val
) > 2 &&
1942 val
[0] >= '0' && val
[0] <= '9' && val
[1] >= '0' && val
[1] <= '9')
1944 *pdwState
= INSTALLSTATE_SOURCE
;
1947 *pdwState
= INSTALLSTATE_LOCAL
;
1950 TRACE("-> %d\n", *pdwState
);
1951 return ERROR_SUCCESS
;
1954 INSTALLSTATE WINAPI
MsiQueryProductStateA(LPCSTR szProduct
)
1956 LPWSTR szwProduct
= NULL
;
1961 szwProduct
= strdupAtoW( szProduct
);
1963 return ERROR_OUTOFMEMORY
;
1965 r
= MsiQueryProductStateW( szwProduct
);
1966 msi_free( szwProduct
);
1970 INSTALLSTATE WINAPI
MsiQueryProductStateW(LPCWSTR szProduct
)
1972 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
1973 INSTALLSTATE state
= INSTALLSTATE_ADVERTISED
;
1974 HKEY prodkey
= 0, userdata
= 0;
1978 static const WCHAR szWindowsInstaller
[] = {
1979 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1981 TRACE("%s\n", debugstr_w(szProduct
));
1983 if (!szProduct
|| !*szProduct
)
1984 return INSTALLSTATE_INVALIDARG
;
1986 if (lstrlenW(szProduct
) != GUID_SIZE
- 1)
1987 return INSTALLSTATE_INVALIDARG
;
1989 if (szProduct
[0] != '{' || szProduct
[37] != '}')
1990 return INSTALLSTATE_UNKNOWN
;
1992 SetLastError( ERROR_SUCCESS
);
1994 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
1995 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
1996 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1997 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
1998 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
1999 &prodkey
, FALSE
) == ERROR_SUCCESS
)
2001 context
= MSIINSTALLCONTEXT_MACHINE
;
2004 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
2005 if (r
!= ERROR_SUCCESS
)
2008 if (!msi_reg_get_val_dword(userdata
, szWindowsInstaller
, &val
))
2012 state
= INSTALLSTATE_DEFAULT
;
2014 state
= INSTALLSTATE_UNKNOWN
;
2019 state
= INSTALLSTATE_UNKNOWN
;
2022 state
= INSTALLSTATE_ABSENT
;
2025 RegCloseKey(prodkey
);
2026 RegCloseKey(userdata
);
2027 TRACE("-> %d\n", state
);
2031 INSTALLUILEVEL WINAPI
MsiSetInternalUI(INSTALLUILEVEL dwUILevel
, HWND
*phWnd
)
2033 INSTALLUILEVEL old
= gUILevel
;
2034 HWND oldwnd
= gUIhwnd
;
2036 TRACE("%08x %p\n", dwUILevel
, phWnd
);
2038 gUILevel
= dwUILevel
;
2047 INSTALLUI_HANDLERA WINAPI
MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler
,
2048 DWORD dwMessageFilter
, LPVOID pvContext
)
2050 INSTALLUI_HANDLERA prev
= gUIHandlerA
;
2052 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2054 gUIHandlerA
= puiHandler
;
2056 gUIFilter
= dwMessageFilter
;
2057 gUIContext
= pvContext
;
2062 INSTALLUI_HANDLERW WINAPI
MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler
,
2063 DWORD dwMessageFilter
, LPVOID pvContext
)
2065 INSTALLUI_HANDLERW prev
= gUIHandlerW
;
2067 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2070 gUIHandlerW
= puiHandler
;
2071 gUIFilter
= dwMessageFilter
;
2072 gUIContext
= pvContext
;
2077 /******************************************************************
2078 * MsiLoadStringW [MSI.@]
2080 * Loads a string from MSI's string resources.
2084 * handle [I] only -1 is handled currently
2085 * id [I] id of the string to be loaded
2086 * lpBuffer [O] buffer for the string to be written to
2087 * nBufferMax [I] maximum size of the buffer in characters
2088 * lang [I] the preferred language for the string
2092 * If successful, this function returns the language id of the string loaded
2093 * If the function fails, the function returns zero.
2097 * The type of the first parameter is unknown. LoadString's prototype
2098 * suggests that it might be a module handle. I have made it an MSI handle
2099 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2100 * handle. Maybe strings can be stored in an MSI database somehow.
2102 LANGID WINAPI
MsiLoadStringW( MSIHANDLE handle
, UINT id
, LPWSTR lpBuffer
,
2103 int nBufferMax
, LANGID lang
)
2110 TRACE("%d %u %p %d %d\n", handle
, id
, lpBuffer
, nBufferMax
, lang
);
2113 FIXME("don't know how to deal with handle = %08x\n", handle
);
2116 lang
= GetUserDefaultLangID();
2118 hres
= FindResourceExW( msi_hInstance
, (LPCWSTR
) RT_STRING
,
2122 hResData
= LoadResource( msi_hInstance
, hres
);
2125 p
= LockResource( hResData
);
2129 for (i
= 0; i
< (id
&0xf); i
++)
2133 if( nBufferMax
<= len
)
2136 memcpy( lpBuffer
, p
+1, len
* sizeof(WCHAR
));
2137 lpBuffer
[ len
] = 0;
2139 TRACE("found -> %s\n", debugstr_w(lpBuffer
));
2144 LANGID WINAPI
MsiLoadStringA( MSIHANDLE handle
, UINT id
, LPSTR lpBuffer
,
2145 int nBufferMax
, LANGID lang
)
2151 bufW
= msi_alloc(nBufferMax
*sizeof(WCHAR
));
2152 r
= MsiLoadStringW(handle
, id
, bufW
, nBufferMax
, lang
);
2155 len
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
2156 if( len
<= nBufferMax
)
2157 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1,
2158 lpBuffer
, nBufferMax
, NULL
, NULL
);
2166 INSTALLSTATE WINAPI
MsiLocateComponentA(LPCSTR szComponent
, LPSTR lpPathBuf
,
2169 char szProduct
[GUID_SIZE
];
2171 TRACE("%s %p %p\n", debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2173 if (!szComponent
|| !pcchBuf
)
2174 return INSTALLSTATE_INVALIDARG
;
2176 if (MsiGetProductCodeA( szComponent
, szProduct
) != ERROR_SUCCESS
)
2177 return INSTALLSTATE_UNKNOWN
;
2179 return MsiGetComponentPathA( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2182 INSTALLSTATE WINAPI
MsiLocateComponentW(LPCWSTR szComponent
, LPWSTR lpPathBuf
,
2185 WCHAR szProduct
[GUID_SIZE
];
2187 TRACE("%s %p %p\n", debugstr_w(szComponent
), lpPathBuf
, pcchBuf
);
2189 if (!szComponent
|| !pcchBuf
)
2190 return INSTALLSTATE_INVALIDARG
;
2192 if (MsiGetProductCodeW( szComponent
, szProduct
) != ERROR_SUCCESS
)
2193 return INSTALLSTATE_UNKNOWN
;
2195 return MsiGetComponentPathW( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2198 UINT WINAPI
MsiMessageBoxA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2199 WORD wLanguageId
, DWORD f
)
2201 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_a(lpText
), debugstr_a(lpCaption
),
2202 uType
, wLanguageId
, f
);
2203 return MessageBoxExA(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2206 UINT WINAPI
MsiMessageBoxW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2207 WORD wLanguageId
, DWORD f
)
2209 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_w(lpText
), debugstr_w(lpCaption
),
2210 uType
, wLanguageId
, f
);
2211 return MessageBoxExW(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2214 UINT WINAPI
MsiMessageBoxExA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2215 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2217 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_a(lpText
),
2218 debugstr_a(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2219 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2222 UINT WINAPI
MsiMessageBoxExW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2223 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2225 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_w(lpText
),
2226 debugstr_w(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2227 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2230 UINT WINAPI
MsiProvideAssemblyA( LPCSTR szAssemblyName
, LPCSTR szAppContext
,
2231 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPSTR lpPathBuf
,
2232 LPDWORD pcchPathBuf
)
2234 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName
),
2235 debugstr_a(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2237 return ERROR_CALL_NOT_IMPLEMENTED
;
2240 UINT WINAPI
MsiProvideAssemblyW( LPCWSTR szAssemblyName
, LPCWSTR szAppContext
,
2241 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPWSTR lpPathBuf
,
2242 LPDWORD pcchPathBuf
)
2244 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName
),
2245 debugstr_w(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2247 return ERROR_CALL_NOT_IMPLEMENTED
;
2250 UINT WINAPI
MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor
,
2251 LPSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2253 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2254 return ERROR_CALL_NOT_IMPLEMENTED
;
2257 UINT WINAPI
MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor
,
2258 LPWSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2260 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2261 return ERROR_CALL_NOT_IMPLEMENTED
;
2264 HRESULT WINAPI
MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath
,
2265 DWORD dwFlags
, PCCERT_CONTEXT
* ppcCertContext
, LPBYTE pbHashData
,
2266 LPDWORD pcbHashData
)
2268 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath
), dwFlags
,
2269 ppcCertContext
, pbHashData
, pcbHashData
);
2270 return ERROR_CALL_NOT_IMPLEMENTED
;
2273 HRESULT WINAPI
MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath
,
2274 DWORD dwFlags
, PCCERT_CONTEXT
* ppcCertContext
, LPBYTE pbHashData
,
2275 LPDWORD pcbHashData
)
2277 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath
), dwFlags
,
2278 ppcCertContext
, pbHashData
, pcbHashData
);
2279 return ERROR_CALL_NOT_IMPLEMENTED
;
2282 /******************************************************************
2283 * MsiGetProductPropertyA [MSI.@]
2285 UINT WINAPI
MsiGetProductPropertyA(MSIHANDLE hProduct
, LPCSTR szProperty
,
2286 LPSTR szValue
, LPDWORD pccbValue
)
2288 LPWSTR prop
= NULL
, val
= NULL
;
2292 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_a(szProperty
),
2293 szValue
, pccbValue
);
2295 if (szValue
&& !pccbValue
)
2296 return ERROR_INVALID_PARAMETER
;
2298 if (szProperty
) prop
= strdupAtoW(szProperty
);
2301 r
= MsiGetProductPropertyW(hProduct
, prop
, NULL
, &len
);
2302 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2305 if (r
== ERROR_SUCCESS
)
2307 if (szValue
) *szValue
= '\0';
2308 if (pccbValue
) *pccbValue
= 0;
2312 val
= msi_alloc(++len
* sizeof(WCHAR
));
2315 r
= ERROR_OUTOFMEMORY
;
2319 r
= MsiGetProductPropertyW(hProduct
, prop
, val
, &len
);
2320 if (r
!= ERROR_SUCCESS
)
2323 len
= WideCharToMultiByte(CP_ACP
, 0, val
, -1, NULL
, 0, NULL
, NULL
);
2326 WideCharToMultiByte(CP_ACP
, 0, val
, -1, szValue
,
2327 *pccbValue
, NULL
, NULL
);
2331 if (len
> *pccbValue
)
2332 r
= ERROR_MORE_DATA
;
2334 *pccbValue
= len
- 1;
2344 /******************************************************************
2345 * MsiGetProductPropertyW [MSI.@]
2347 UINT WINAPI
MsiGetProductPropertyW(MSIHANDLE hProduct
, LPCWSTR szProperty
,
2348 LPWSTR szValue
, LPDWORD pccbValue
)
2350 MSIPACKAGE
*package
;
2351 MSIQUERY
*view
= NULL
;
2352 MSIRECORD
*rec
= NULL
;
2356 static const WCHAR query
[] = {
2357 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2358 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2359 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2361 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_w(szProperty
),
2362 szValue
, pccbValue
);
2365 return ERROR_INVALID_PARAMETER
;
2367 if (szValue
&& !pccbValue
)
2368 return ERROR_INVALID_PARAMETER
;
2370 package
= msihandle2msiinfo(hProduct
, MSIHANDLETYPE_PACKAGE
);
2372 return ERROR_INVALID_HANDLE
;
2374 r
= MSI_OpenQuery(package
->db
, &view
, query
, szProperty
);
2375 if (r
!= ERROR_SUCCESS
)
2378 r
= MSI_ViewExecute(view
, 0);
2379 if (r
!= ERROR_SUCCESS
)
2382 r
= MSI_ViewFetch(view
, &rec
);
2383 if (r
!= ERROR_SUCCESS
)
2386 val
= MSI_RecordGetString(rec
, 2);
2390 if (lstrlenW(val
) >= *pccbValue
)
2392 lstrcpynW(szValue
, val
, *pccbValue
);
2393 *pccbValue
= lstrlenW(val
);
2394 r
= ERROR_MORE_DATA
;
2398 lstrcpyW(szValue
, val
);
2399 *pccbValue
= lstrlenW(val
);
2406 MSI_ViewClose(view
);
2407 msiobj_release(&view
->hdr
);
2408 if (rec
) msiobj_release(&rec
->hdr
);
2413 if (szValue
) *szValue
= '\0';
2414 if (pccbValue
) *pccbValue
= 0;
2418 msiobj_release(&package
->hdr
);
2422 UINT WINAPI
MsiVerifyPackageA( LPCSTR szPackage
)
2425 LPWSTR szPack
= NULL
;
2427 TRACE("%s\n", debugstr_a(szPackage
) );
2431 szPack
= strdupAtoW( szPackage
);
2433 return ERROR_OUTOFMEMORY
;
2436 r
= MsiVerifyPackageW( szPack
);
2443 UINT WINAPI
MsiVerifyPackageW( LPCWSTR szPackage
)
2448 TRACE("%s\n", debugstr_w(szPackage
) );
2450 r
= MsiOpenDatabaseW( szPackage
, MSIDBOPEN_READONLY
, &handle
);
2451 MsiCloseHandle( handle
);
2456 static INSTALLSTATE
MSI_GetComponentPath(LPCWSTR szProduct
, LPCWSTR szComponent
,
2457 awstring
* lpPathBuf
, LPDWORD pcchBuf
)
2459 WCHAR squished_pc
[GUID_SIZE
];
2460 WCHAR squished_comp
[GUID_SIZE
];
2466 static const WCHAR wininstaller
[] = {
2467 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2469 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
2470 debugstr_w(szComponent
), lpPathBuf
->str
.w
, pcchBuf
);
2472 if (!szProduct
|| !szComponent
)
2473 return INSTALLSTATE_INVALIDARG
;
2475 if (lpPathBuf
->str
.w
&& !pcchBuf
)
2476 return INSTALLSTATE_INVALIDARG
;
2478 if (!squash_guid(szProduct
, squished_pc
) ||
2479 !squash_guid(szComponent
, squished_comp
))
2480 return INSTALLSTATE_INVALIDARG
;
2482 state
= INSTALLSTATE_UNKNOWN
;
2484 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2485 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2487 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2490 state
= INSTALLSTATE_ABSENT
;
2492 if ((MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
, NULL
,
2493 &hkey
, FALSE
) == ERROR_SUCCESS
||
2494 MSIREG_OpenUserDataProductKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2495 NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
) &&
2496 msi_reg_get_val_dword(hkey
, wininstaller
, &version
) &&
2497 GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2500 state
= INSTALLSTATE_LOCAL
;
2504 if (state
!= INSTALLSTATE_LOCAL
&&
2505 (MSIREG_OpenProductKey(szProduct
, NULL
,
2506 MSIINSTALLCONTEXT_USERUNMANAGED
,
2507 &hkey
, FALSE
) == ERROR_SUCCESS
||
2508 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2509 &hkey
, FALSE
) == ERROR_SUCCESS
))
2513 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2514 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2517 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2520 state
= INSTALLSTATE_ABSENT
;
2522 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2523 state
= INSTALLSTATE_LOCAL
;
2528 return INSTALLSTATE_UNKNOWN
;
2530 if (state
== INSTALLSTATE_LOCAL
&& !*path
)
2531 state
= INSTALLSTATE_NOTUSED
;
2533 msi_strcpy_to_awstring(path
, lpPathBuf
, pcchBuf
);
2538 /******************************************************************
2539 * MsiGetComponentPathW [MSI.@]
2541 INSTALLSTATE WINAPI
MsiGetComponentPathW(LPCWSTR szProduct
, LPCWSTR szComponent
,
2542 LPWSTR lpPathBuf
, LPDWORD pcchBuf
)
2546 path
.unicode
= TRUE
;
2547 path
.str
.w
= lpPathBuf
;
2549 return MSI_GetComponentPath( szProduct
, szComponent
, &path
, pcchBuf
);
2552 /******************************************************************
2553 * MsiGetComponentPathA [MSI.@]
2555 INSTALLSTATE WINAPI
MsiGetComponentPathA(LPCSTR szProduct
, LPCSTR szComponent
,
2556 LPSTR lpPathBuf
, LPDWORD pcchBuf
)
2558 LPWSTR szwProduct
, szwComponent
= NULL
;
2559 INSTALLSTATE r
= INSTALLSTATE_UNKNOWN
;
2562 szwProduct
= strdupAtoW( szProduct
);
2563 if( szProduct
&& !szwProduct
)
2566 szwComponent
= strdupAtoW( szComponent
);
2567 if( szComponent
&& !szwComponent
)
2570 path
.unicode
= FALSE
;
2571 path
.str
.a
= lpPathBuf
;
2573 r
= MSI_GetComponentPath( szwProduct
, szwComponent
, &path
, pcchBuf
);
2576 msi_free( szwProduct
);
2577 msi_free( szwComponent
);
2582 /******************************************************************
2583 * MsiQueryFeatureStateA [MSI.@]
2585 INSTALLSTATE WINAPI
MsiQueryFeatureStateA(LPCSTR szProduct
, LPCSTR szFeature
)
2587 LPWSTR szwProduct
= NULL
, szwFeature
= NULL
;
2588 INSTALLSTATE rc
= INSTALLSTATE_UNKNOWN
;
2590 szwProduct
= strdupAtoW( szProduct
);
2591 if ( szProduct
&& !szwProduct
)
2594 szwFeature
= strdupAtoW( szFeature
);
2595 if ( szFeature
&& !szwFeature
)
2598 rc
= MsiQueryFeatureStateW(szwProduct
, szwFeature
);
2601 msi_free( szwProduct
);
2602 msi_free( szwFeature
);
2607 /******************************************************************
2608 * MsiQueryFeatureStateW [MSI.@]
2610 * Checks the state of a feature
2613 * szProduct [I] Product's GUID string
2614 * szFeature [I] Feature's GUID string
2617 * INSTALLSTATE_LOCAL Feature is installed and usable
2618 * INSTALLSTATE_ABSENT Feature is absent
2619 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2620 * INSTALLSTATE_UNKNOWN An error occurred
2621 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2624 INSTALLSTATE WINAPI
MsiQueryFeatureStateW(LPCWSTR szProduct
, LPCWSTR szFeature
)
2626 WCHAR squishProduct
[33], comp
[GUID_SIZE
];
2628 LPWSTR components
, p
, parent_feature
, path
;
2632 BOOL missing
= FALSE
;
2633 BOOL machine
= FALSE
;
2634 BOOL source
= FALSE
;
2636 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szFeature
));
2638 if (!szProduct
|| !szFeature
)
2639 return INSTALLSTATE_INVALIDARG
;
2641 if (!squash_guid( szProduct
, squishProduct
))
2642 return INSTALLSTATE_INVALIDARG
;
2644 SetLastError( ERROR_SUCCESS
);
2646 if (MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERMANAGED
,
2647 &hkey
, FALSE
) != ERROR_SUCCESS
&&
2648 MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2649 &hkey
, FALSE
) != ERROR_SUCCESS
)
2651 rc
= MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
2653 if (rc
!= ERROR_SUCCESS
)
2654 return INSTALLSTATE_UNKNOWN
;
2659 parent_feature
= msi_reg_get_val_str( hkey
, szFeature
);
2662 if (!parent_feature
)
2663 return INSTALLSTATE_UNKNOWN
;
2665 r
= (parent_feature
[0] == 6) ? INSTALLSTATE_ABSENT
: INSTALLSTATE_LOCAL
;
2666 msi_free(parent_feature
);
2667 if (r
== INSTALLSTATE_ABSENT
)
2671 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2672 MSIINSTALLCONTEXT_MACHINE
,
2675 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2676 MSIINSTALLCONTEXT_USERUNMANAGED
,
2679 if (rc
!= ERROR_SUCCESS
)
2680 return INSTALLSTATE_ADVERTISED
;
2682 components
= msi_reg_get_val_str( hkey
, szFeature
);
2685 TRACE("rc = %d buffer = %s\n", rc
, debugstr_w(components
));
2688 return INSTALLSTATE_ADVERTISED
;
2690 for( p
= components
; *p
&& *p
!= 2 ; p
+= 20)
2692 if (!decode_base85_guid( p
, &guid
))
2694 if (p
!= components
)
2697 msi_free(components
);
2698 return INSTALLSTATE_BADCONFIG
;
2701 StringFromGUID2(&guid
, comp
, GUID_SIZE
);
2704 rc
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2706 rc
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2708 if (rc
!= ERROR_SUCCESS
)
2710 msi_free(components
);
2711 return INSTALLSTATE_ADVERTISED
;
2714 path
= msi_reg_get_val_str(hkey
, squishProduct
);
2717 else if (lstrlenW(path
) > 2 &&
2718 path
[0] >= '0' && path
[0] <= '9' &&
2719 path
[1] >= '0' && path
[1] <= '9')
2726 msi_free(components
);
2729 r
= INSTALLSTATE_ADVERTISED
;
2731 r
= INSTALLSTATE_SOURCE
;
2733 r
= INSTALLSTATE_LOCAL
;
2735 TRACE("-> %d\n", r
);
2739 /******************************************************************
2740 * MsiGetFileVersionA [MSI.@]
2742 UINT WINAPI
MsiGetFileVersionA(LPCSTR szFilePath
, LPSTR lpVersionBuf
,
2743 LPDWORD pcchVersionBuf
, LPSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2745 LPWSTR szwFilePath
= NULL
, lpwVersionBuff
= NULL
, lpwLangBuff
= NULL
;
2746 UINT ret
= ERROR_OUTOFMEMORY
;
2748 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
2749 (lpLangBuf
&& !pcchLangBuf
))
2750 return ERROR_INVALID_PARAMETER
;
2754 szwFilePath
= strdupAtoW( szFilePath
);
2759 if( lpVersionBuf
&& pcchVersionBuf
&& *pcchVersionBuf
)
2761 lpwVersionBuff
= msi_alloc(*pcchVersionBuf
*sizeof(WCHAR
));
2762 if( !lpwVersionBuff
)
2766 if( lpLangBuf
&& pcchLangBuf
&& *pcchLangBuf
)
2768 lpwLangBuff
= msi_alloc(*pcchLangBuf
*sizeof(WCHAR
));
2773 ret
= MsiGetFileVersionW(szwFilePath
, lpwVersionBuff
, pcchVersionBuf
,
2774 lpwLangBuff
, pcchLangBuf
);
2776 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwVersionBuff
)
2777 WideCharToMultiByte(CP_ACP
, 0, lpwVersionBuff
, -1,
2778 lpVersionBuf
, *pcchVersionBuf
+ 1, NULL
, NULL
);
2779 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwLangBuff
)
2780 WideCharToMultiByte(CP_ACP
, 0, lpwLangBuff
, -1,
2781 lpLangBuf
, *pcchLangBuf
+ 1, NULL
, NULL
);
2784 msi_free(szwFilePath
);
2785 msi_free(lpwVersionBuff
);
2786 msi_free(lpwLangBuff
);
2791 /******************************************************************
2792 * MsiGetFileVersionW [MSI.@]
2794 UINT WINAPI
MsiGetFileVersionW(LPCWSTR szFilePath
, LPWSTR lpVersionBuf
,
2795 LPDWORD pcchVersionBuf
, LPWSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2797 static const WCHAR szVersionResource
[] = {'\\',0};
2798 static const WCHAR szVersionFormat
[] = {
2799 '%','d','.','%','d','.','%','d','.','%','d',0};
2800 static const WCHAR szLangResource
[] = {
2801 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2802 'T','r','a','n','s','l','a','t','i','o','n',0};
2803 static const WCHAR szLangFormat
[] = {'%','d',0};
2805 DWORD dwVerLen
, gle
;
2806 LPVOID lpVer
= NULL
;
2807 VS_FIXEDFILEINFO
*ffi
;
2812 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath
),
2813 lpVersionBuf
, pcchVersionBuf
?*pcchVersionBuf
:0,
2814 lpLangBuf
, pcchLangBuf
?*pcchLangBuf
:0);
2816 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
2817 (lpLangBuf
&& !pcchLangBuf
))
2818 return ERROR_INVALID_PARAMETER
;
2820 dwVerLen
= GetFileVersionInfoSizeW(szFilePath
, NULL
);
2823 gle
= GetLastError();
2824 if (gle
== ERROR_BAD_PATHNAME
)
2825 return ERROR_FILE_NOT_FOUND
;
2826 else if (gle
== ERROR_RESOURCE_DATA_NOT_FOUND
)
2827 return ERROR_FILE_INVALID
;
2832 lpVer
= msi_alloc(dwVerLen
);
2835 ret
= ERROR_OUTOFMEMORY
;
2839 if( !GetFileVersionInfoW(szFilePath
, 0, dwVerLen
, lpVer
) )
2841 ret
= GetLastError();
2847 if( VerQueryValueW(lpVer
, szVersionResource
, (LPVOID
*)&ffi
, &puLen
) &&
2850 wsprintfW(tmp
, szVersionFormat
,
2851 HIWORD(ffi
->dwFileVersionMS
), LOWORD(ffi
->dwFileVersionMS
),
2852 HIWORD(ffi
->dwFileVersionLS
), LOWORD(ffi
->dwFileVersionLS
));
2853 if (lpVersionBuf
) lstrcpynW(lpVersionBuf
, tmp
, *pcchVersionBuf
);
2855 if (strlenW(tmp
) >= *pcchVersionBuf
)
2856 ret
= ERROR_MORE_DATA
;
2858 *pcchVersionBuf
= lstrlenW(tmp
);
2862 if (lpVersionBuf
) *lpVersionBuf
= 0;
2863 *pcchVersionBuf
= 0;
2869 if (VerQueryValueW(lpVer
, szLangResource
, (LPVOID
*)&lang
, &puLen
) &&
2872 wsprintfW(tmp
, szLangFormat
, *lang
);
2873 if (lpLangBuf
) lstrcpynW(lpLangBuf
, tmp
, *pcchLangBuf
);
2875 if (strlenW(tmp
) >= *pcchLangBuf
)
2876 ret
= ERROR_MORE_DATA
;
2878 *pcchLangBuf
= lstrlenW(tmp
);
2882 if (lpLangBuf
) *lpLangBuf
= 0;
2892 /***********************************************************************
2893 * MsiGetFeatureUsageW [MSI.@]
2895 UINT WINAPI
MsiGetFeatureUsageW( LPCWSTR szProduct
, LPCWSTR szFeature
,
2896 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
2898 FIXME("%s %s %p %p\n",debugstr_w(szProduct
), debugstr_w(szFeature
),
2899 pdwUseCount
, pwDateUsed
);
2900 return ERROR_CALL_NOT_IMPLEMENTED
;
2903 /***********************************************************************
2904 * MsiGetFeatureUsageA [MSI.@]
2906 UINT WINAPI
MsiGetFeatureUsageA( LPCSTR szProduct
, LPCSTR szFeature
,
2907 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
2909 LPWSTR prod
= NULL
, feat
= NULL
;
2910 UINT ret
= ERROR_OUTOFMEMORY
;
2912 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
2913 pdwUseCount
, pwDateUsed
);
2915 prod
= strdupAtoW( szProduct
);
2916 if (szProduct
&& !prod
)
2919 feat
= strdupAtoW( szFeature
);
2920 if (szFeature
&& !feat
)
2923 ret
= MsiGetFeatureUsageW( prod
, feat
, pdwUseCount
, pwDateUsed
);
2932 /***********************************************************************
2933 * MsiUseFeatureExW [MSI.@]
2935 INSTALLSTATE WINAPI
MsiUseFeatureExW( LPCWSTR szProduct
, LPCWSTR szFeature
,
2936 DWORD dwInstallMode
, DWORD dwReserved
)
2940 TRACE("%s %s %i %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
2941 dwInstallMode
, dwReserved
);
2943 state
= MsiQueryFeatureStateW( szProduct
, szFeature
);
2946 return INSTALLSTATE_INVALIDARG
;
2948 if (state
== INSTALLSTATE_LOCAL
&& dwInstallMode
!= INSTALLMODE_NODETECTION
)
2950 FIXME("mark product %s feature %s as used\n",
2951 debugstr_w(szProduct
), debugstr_w(szFeature
) );
2957 /***********************************************************************
2958 * MsiUseFeatureExA [MSI.@]
2960 INSTALLSTATE WINAPI
MsiUseFeatureExA( LPCSTR szProduct
, LPCSTR szFeature
,
2961 DWORD dwInstallMode
, DWORD dwReserved
)
2963 INSTALLSTATE ret
= INSTALLSTATE_UNKNOWN
;
2964 LPWSTR prod
= NULL
, feat
= NULL
;
2966 TRACE("%s %s %i %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
2967 dwInstallMode
, dwReserved
);
2969 prod
= strdupAtoW( szProduct
);
2970 if (szProduct
&& !prod
)
2973 feat
= strdupAtoW( szFeature
);
2974 if (szFeature
&& !feat
)
2977 ret
= MsiUseFeatureExW( prod
, feat
, dwInstallMode
, dwReserved
);
2986 /***********************************************************************
2987 * MsiUseFeatureW [MSI.@]
2989 INSTALLSTATE WINAPI
MsiUseFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
)
2991 return MsiUseFeatureExW(szProduct
, szFeature
, 0, 0);
2994 /***********************************************************************
2995 * MsiUseFeatureA [MSI.@]
2997 INSTALLSTATE WINAPI
MsiUseFeatureA( LPCSTR szProduct
, LPCSTR szFeature
)
2999 return MsiUseFeatureExA(szProduct
, szFeature
, 0, 0);
3002 /***********************************************************************
3003 * MSI_ProvideQualifiedComponentEx [internal]
3005 static UINT
MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent
,
3006 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3007 DWORD Unused1
, DWORD Unused2
, awstring
*lpPathBuf
,
3008 LPDWORD pcchPathBuf
)
3010 WCHAR product
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1],
3011 feature
[MAX_FEATURE_CHARS
+1];
3017 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent
),
3018 debugstr_w(szQualifier
), dwInstallMode
, debugstr_w(szProduct
),
3019 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3021 rc
= MSIREG_OpenUserComponentsKey(szComponent
, &hkey
, FALSE
);
3022 if (rc
!= ERROR_SUCCESS
)
3023 return ERROR_INDEX_ABSENT
;
3025 info
= msi_reg_get_val_str( hkey
, szQualifier
);
3029 return ERROR_INDEX_ABSENT
;
3031 MsiDecomposeDescriptorW(info
, product
, feature
, component
, &sz
);
3034 rc
= MSI_GetComponentPath(product
, component
, lpPathBuf
, pcchPathBuf
);
3036 rc
= MSI_GetComponentPath(szProduct
, component
, lpPathBuf
, pcchPathBuf
);
3040 if (rc
!= INSTALLSTATE_LOCAL
)
3041 return ERROR_FILE_NOT_FOUND
;
3043 return ERROR_SUCCESS
;
3046 /***********************************************************************
3047 * MsiProvideQualifiedComponentExW [MSI.@]
3049 UINT WINAPI
MsiProvideQualifiedComponentExW(LPCWSTR szComponent
,
3050 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3051 DWORD Unused1
, DWORD Unused2
, LPWSTR lpPathBuf
,
3052 LPDWORD pcchPathBuf
)
3056 path
.unicode
= TRUE
;
3057 path
.str
.w
= lpPathBuf
;
3059 return MSI_ProvideQualifiedComponentEx(szComponent
, szQualifier
,
3060 dwInstallMode
, szProduct
, Unused1
, Unused2
, &path
, pcchPathBuf
);
3063 /***********************************************************************
3064 * MsiProvideQualifiedComponentExA [MSI.@]
3066 UINT WINAPI
MsiProvideQualifiedComponentExA(LPCSTR szComponent
,
3067 LPCSTR szQualifier
, DWORD dwInstallMode
, LPCSTR szProduct
,
3068 DWORD Unused1
, DWORD Unused2
, LPSTR lpPathBuf
,
3069 LPDWORD pcchPathBuf
)
3071 LPWSTR szwComponent
, szwQualifier
= NULL
, szwProduct
= NULL
;
3072 UINT r
= ERROR_OUTOFMEMORY
;
3075 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent
),
3076 debugstr_a(szQualifier
), dwInstallMode
, debugstr_a(szProduct
),
3077 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3079 szwComponent
= strdupAtoW( szComponent
);
3080 if (szComponent
&& !szwComponent
)
3083 szwQualifier
= strdupAtoW( szQualifier
);
3084 if (szQualifier
&& !szwQualifier
)
3087 szwProduct
= strdupAtoW( szProduct
);
3088 if (szProduct
&& !szwProduct
)
3091 path
.unicode
= FALSE
;
3092 path
.str
.a
= lpPathBuf
;
3094 r
= MSI_ProvideQualifiedComponentEx(szwComponent
, szwQualifier
,
3095 dwInstallMode
, szwProduct
, Unused1
,
3096 Unused2
, &path
, pcchPathBuf
);
3098 msi_free(szwProduct
);
3099 msi_free(szwComponent
);
3100 msi_free(szwQualifier
);
3105 /***********************************************************************
3106 * MsiProvideQualifiedComponentW [MSI.@]
3108 UINT WINAPI
MsiProvideQualifiedComponentW( LPCWSTR szComponent
,
3109 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPWSTR lpPathBuf
,
3110 LPDWORD pcchPathBuf
)
3112 return MsiProvideQualifiedComponentExW(szComponent
, szQualifier
,
3113 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3116 /***********************************************************************
3117 * MsiProvideQualifiedComponentA [MSI.@]
3119 UINT WINAPI
MsiProvideQualifiedComponentA( LPCSTR szComponent
,
3120 LPCSTR szQualifier
, DWORD dwInstallMode
, LPSTR lpPathBuf
,
3121 LPDWORD pcchPathBuf
)
3123 return MsiProvideQualifiedComponentExA(szComponent
, szQualifier
,
3124 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3127 /***********************************************************************
3128 * MSI_GetUserInfo [internal]
3130 static USERINFOSTATE
MSI_GetUserInfo(LPCWSTR szProduct
,
3131 awstring
*lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3132 awstring
*lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3133 awstring
*lpSerialBuf
, LPDWORD pcchSerialBuf
)
3135 WCHAR squished_pc
[SQUISH_GUID_SIZE
];
3136 LPWSTR user
, org
, serial
;
3137 USERINFOSTATE state
;
3142 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct
), lpUserNameBuf
,
3143 pcchUserNameBuf
, lpOrgNameBuf
, pcchOrgNameBuf
, lpSerialBuf
,
3146 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
3147 return USERINFOSTATE_INVALIDARG
;
3149 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
3150 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3151 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3152 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3153 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
3154 &hkey
, FALSE
) != ERROR_SUCCESS
)
3156 return USERINFOSTATE_UNKNOWN
;
3159 if (MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3160 NULL
, &props
, FALSE
) != ERROR_SUCCESS
&&
3161 MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
3162 NULL
, &props
, FALSE
) != ERROR_SUCCESS
)
3165 return USERINFOSTATE_ABSENT
;
3168 user
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGOWNERW
);
3169 org
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGCOMPANYW
);
3170 serial
= msi_reg_get_val_str(props
, INSTALLPROPERTY_PRODUCTIDW
);
3171 state
= USERINFOSTATE_ABSENT
;
3177 state
= USERINFOSTATE_PRESENT
;
3179 if (pcchUserNameBuf
)
3181 if (lpUserNameBuf
&& !user
)
3183 (*pcchUserNameBuf
)--;
3187 r
= msi_strcpy_to_awstring(user
, lpUserNameBuf
, pcchUserNameBuf
);
3188 if (r
== ERROR_MORE_DATA
)
3190 state
= USERINFOSTATE_MOREDATA
;
3198 if (!orgptr
) orgptr
= szEmpty
;
3200 r
= msi_strcpy_to_awstring(orgptr
, lpOrgNameBuf
, pcchOrgNameBuf
);
3201 if (r
== ERROR_MORE_DATA
)
3203 state
= USERINFOSTATE_MOREDATA
;
3216 r
= msi_strcpy_to_awstring(serial
, lpSerialBuf
, pcchSerialBuf
);
3217 if (r
== ERROR_MORE_DATA
)
3218 state
= USERINFOSTATE_MOREDATA
;
3229 /***********************************************************************
3230 * MsiGetUserInfoW [MSI.@]
3232 USERINFOSTATE WINAPI
MsiGetUserInfoW(LPCWSTR szProduct
,
3233 LPWSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3234 LPWSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3235 LPWSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3237 awstring user
, org
, serial
;
3239 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3240 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3241 (lpSerialBuf
&& !pcchSerialBuf
))
3242 return USERINFOSTATE_INVALIDARG
;
3244 user
.unicode
= TRUE
;
3245 user
.str
.w
= lpUserNameBuf
;
3247 org
.str
.w
= lpOrgNameBuf
;
3248 serial
.unicode
= TRUE
;
3249 serial
.str
.w
= lpSerialBuf
;
3251 return MSI_GetUserInfo( szProduct
, &user
, pcchUserNameBuf
,
3252 &org
, pcchOrgNameBuf
,
3253 &serial
, pcchSerialBuf
);
3256 USERINFOSTATE WINAPI
MsiGetUserInfoA(LPCSTR szProduct
,
3257 LPSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3258 LPSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3259 LPSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3261 awstring user
, org
, serial
;
3265 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3266 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3267 (lpSerialBuf
&& !pcchSerialBuf
))
3268 return USERINFOSTATE_INVALIDARG
;
3270 prod
= strdupAtoW( szProduct
);
3271 if (szProduct
&& !prod
)
3272 return ERROR_OUTOFMEMORY
;
3274 user
.unicode
= FALSE
;
3275 user
.str
.a
= lpUserNameBuf
;
3276 org
.unicode
= FALSE
;
3277 org
.str
.a
= lpOrgNameBuf
;
3278 serial
.unicode
= FALSE
;
3279 serial
.str
.a
= lpSerialBuf
;
3281 r
= MSI_GetUserInfo( prod
, &user
, pcchUserNameBuf
,
3282 &org
, pcchOrgNameBuf
,
3283 &serial
, pcchSerialBuf
);
3290 UINT WINAPI
MsiCollectUserInfoW(LPCWSTR szProduct
)
3294 MSIPACKAGE
*package
;
3295 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3297 TRACE("(%s)\n",debugstr_w(szProduct
));
3299 rc
= MsiOpenProductW(szProduct
,&handle
);
3300 if (rc
!= ERROR_SUCCESS
)
3301 return ERROR_INVALID_PARAMETER
;
3303 /* MsiCollectUserInfo cannot be called from a custom action. */
3304 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3306 return ERROR_CALL_NOT_IMPLEMENTED
;
3308 rc
= ACTION_PerformUIAction(package
, szFirstRun
, -1);
3309 msiobj_release( &package
->hdr
);
3311 MsiCloseHandle(handle
);
3316 UINT WINAPI
MsiCollectUserInfoA(LPCSTR szProduct
)
3320 MSIPACKAGE
*package
;
3321 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3323 TRACE("(%s)\n",debugstr_a(szProduct
));
3325 rc
= MsiOpenProductA(szProduct
,&handle
);
3326 if (rc
!= ERROR_SUCCESS
)
3327 return ERROR_INVALID_PARAMETER
;
3329 /* MsiCollectUserInfo cannot be called from a custom action. */
3330 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3332 return ERROR_CALL_NOT_IMPLEMENTED
;
3334 rc
= ACTION_PerformUIAction(package
, szFirstRun
, -1);
3335 msiobj_release( &package
->hdr
);
3337 MsiCloseHandle(handle
);
3342 /***********************************************************************
3343 * MsiConfigureFeatureA [MSI.@]
3345 UINT WINAPI
MsiConfigureFeatureA(LPCSTR szProduct
, LPCSTR szFeature
, INSTALLSTATE eInstallState
)
3347 LPWSTR prod
, feat
= NULL
;
3348 UINT r
= ERROR_OUTOFMEMORY
;
3350 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
), eInstallState
);
3352 prod
= strdupAtoW( szProduct
);
3353 if (szProduct
&& !prod
)
3356 feat
= strdupAtoW( szFeature
);
3357 if (szFeature
&& !feat
)
3360 r
= MsiConfigureFeatureW(prod
, feat
, eInstallState
);
3369 /***********************************************************************
3370 * MsiConfigureFeatureW [MSI.@]
3372 UINT WINAPI
MsiConfigureFeatureW(LPCWSTR szProduct
, LPCWSTR szFeature
, INSTALLSTATE eInstallState
)
3374 static const WCHAR szCostInit
[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3375 MSIPACKAGE
*package
= NULL
;
3377 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
3380 TRACE("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
), eInstallState
);
3382 if (!szProduct
|| !szFeature
)
3383 return ERROR_INVALID_PARAMETER
;
3385 switch (eInstallState
)
3387 case INSTALLSTATE_DEFAULT
:
3388 /* FIXME: how do we figure out the default location? */
3389 eInstallState
= INSTALLSTATE_LOCAL
;
3391 case INSTALLSTATE_LOCAL
:
3392 case INSTALLSTATE_SOURCE
:
3393 case INSTALLSTATE_ABSENT
:
3394 case INSTALLSTATE_ADVERTISED
:
3397 return ERROR_INVALID_PARAMETER
;
3400 r
= MSI_OpenProductW( szProduct
, &package
);
3401 if (r
!= ERROR_SUCCESS
)
3404 sz
= sizeof(sourcepath
);
3405 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3406 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3408 sz
= sizeof(filename
);
3409 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3410 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3412 lstrcatW( sourcepath
, filename
);
3414 MsiSetInternalUI( INSTALLUILEVEL_BASIC
, NULL
);
3416 r
= ACTION_PerformUIAction( package
, szCostInit
, -1 );
3417 if (r
!= ERROR_SUCCESS
)
3420 r
= MSI_SetFeatureStateW( package
, szFeature
, eInstallState
);
3421 if (r
!= ERROR_SUCCESS
)
3424 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3427 msiobj_release( &package
->hdr
);
3432 /***********************************************************************
3433 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3435 * Notes: undocumented
3437 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved
)
3439 WCHAR path
[MAX_PATH
];
3441 TRACE("%d\n", dwReserved
);
3445 FIXME("dwReserved=%d\n", dwReserved
);
3446 return ERROR_INVALID_PARAMETER
;
3449 if (!GetWindowsDirectoryW(path
, MAX_PATH
))
3450 return ERROR_FUNCTION_FAILED
;
3452 lstrcatW(path
, installerW
);
3454 if (!CreateDirectoryW(path
, NULL
))
3455 return ERROR_FUNCTION_FAILED
;
3457 return ERROR_SUCCESS
;
3460 /***********************************************************************
3461 * MsiGetShortcutTargetA [MSI.@]
3463 UINT WINAPI
MsiGetShortcutTargetA( LPCSTR szShortcutTarget
,
3464 LPSTR szProductCode
, LPSTR szFeatureId
,
3465 LPSTR szComponentCode
)
3468 const int len
= MAX_FEATURE_CHARS
+1;
3469 WCHAR product
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1];
3472 target
= strdupAtoW( szShortcutTarget
);
3473 if (szShortcutTarget
&& !target
)
3474 return ERROR_OUTOFMEMORY
;
3478 r
= MsiGetShortcutTargetW( target
, product
, feature
, component
);
3480 if (r
== ERROR_SUCCESS
)
3482 WideCharToMultiByte( CP_ACP
, 0, product
, -1, szProductCode
, len
, NULL
, NULL
);
3483 WideCharToMultiByte( CP_ACP
, 0, feature
, -1, szFeatureId
, len
, NULL
, NULL
);
3484 WideCharToMultiByte( CP_ACP
, 0, component
, -1, szComponentCode
, len
, NULL
, NULL
);
3489 /***********************************************************************
3490 * MsiGetShortcutTargetW [MSI.@]
3492 UINT WINAPI
MsiGetShortcutTargetW( LPCWSTR szShortcutTarget
,
3493 LPWSTR szProductCode
, LPWSTR szFeatureId
,
3494 LPWSTR szComponentCode
)
3496 IShellLinkDataList
*dl
= NULL
;
3497 IPersistFile
*pf
= NULL
;
3498 LPEXP_DARWIN_LINK darwin
= NULL
;
3501 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget
),
3502 szProductCode
, szFeatureId
, szComponentCode
);
3504 init
= CoInitialize(NULL
);
3506 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3507 &IID_IPersistFile
, (LPVOID
*) &pf
);
3508 if( SUCCEEDED( r
) )
3510 r
= IPersistFile_Load( pf
, szShortcutTarget
,
3511 STGM_READ
| STGM_SHARE_DENY_WRITE
);
3512 if( SUCCEEDED( r
) )
3514 r
= IPersistFile_QueryInterface( pf
, &IID_IShellLinkDataList
,
3516 if( SUCCEEDED( r
) )
3518 IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
,
3520 IShellLinkDataList_Release( dl
);
3523 IPersistFile_Release( pf
);
3526 if (SUCCEEDED(init
))
3529 TRACE("darwin = %p\n", darwin
);
3536 ret
= MsiDecomposeDescriptorW( darwin
->szwDarwinID
,
3537 szProductCode
, szFeatureId
, szComponentCode
, &sz
);
3538 LocalFree( darwin
);
3542 return ERROR_FUNCTION_FAILED
;
3545 UINT WINAPI
MsiReinstallFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3546 DWORD dwReinstallMode
)
3548 MSIPACKAGE
* package
= NULL
;
3550 WCHAR sourcepath
[MAX_PATH
];
3551 WCHAR filename
[MAX_PATH
];
3552 static const WCHAR szLogVerbose
[] = {
3553 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3554 WCHAR reinstallmode
[11];
3558 FIXME("%s %s 0x%08x\n",
3559 debugstr_w(szProduct
), debugstr_w(szFeature
), dwReinstallMode
);
3561 ptr
= reinstallmode
;
3563 if (dwReinstallMode
& REINSTALLMODE_FILEMISSING
)
3565 if (dwReinstallMode
& REINSTALLMODE_FILEOLDERVERSION
)
3567 if (dwReinstallMode
& REINSTALLMODE_FILEEQUALVERSION
)
3569 if (dwReinstallMode
& REINSTALLMODE_FILEEXACT
)
3571 if (dwReinstallMode
& REINSTALLMODE_FILEVERIFY
)
3573 if (dwReinstallMode
& REINSTALLMODE_FILEREPLACE
)
3575 if (dwReinstallMode
& REINSTALLMODE_USERDATA
)
3577 if (dwReinstallMode
& REINSTALLMODE_MACHINEDATA
)
3579 if (dwReinstallMode
& REINSTALLMODE_SHORTCUT
)
3581 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3585 sz
= sizeof(sourcepath
);
3586 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3587 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3589 sz
= sizeof(filename
);
3590 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3591 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3593 lstrcatW( sourcepath
, filename
);
3595 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3596 r
= MSI_OpenPackageW( sourcepath
, &package
);
3598 r
= MSI_OpenProductW( szProduct
, &package
);
3600 if (r
!= ERROR_SUCCESS
)
3603 msi_set_property( package
->db
, szReinstallMode
, reinstallmode
);
3604 msi_set_property( package
->db
, szInstalled
, szOne
);
3605 msi_set_property( package
->db
, szLogVerbose
, szOne
);
3606 msi_set_property( package
->db
, szReinstall
, szFeature
);
3608 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3610 msiobj_release( &package
->hdr
);
3615 UINT WINAPI
MsiReinstallFeatureA( LPCSTR szProduct
, LPCSTR szFeature
,
3616 DWORD dwReinstallMode
)
3622 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3625 wszProduct
= strdupAtoW(szProduct
);
3626 wszFeature
= strdupAtoW(szFeature
);
3628 rc
= MsiReinstallFeatureW(wszProduct
, wszFeature
, dwReinstallMode
);
3630 msi_free(wszProduct
);
3631 msi_free(wszFeature
);
3638 unsigned int buf
[4];
3639 unsigned char in
[64];
3640 unsigned char digest
[16];
3643 extern VOID WINAPI
MD5Init( MD5_CTX
*);
3644 extern VOID WINAPI
MD5Update( MD5_CTX
*, const unsigned char *, unsigned int );
3645 extern VOID WINAPI
MD5Final( MD5_CTX
*);
3647 /***********************************************************************
3648 * MsiGetFileHashW [MSI.@]
3650 UINT WINAPI
MsiGetFileHashW( LPCWSTR szFilePath
, DWORD dwOptions
,
3651 PMSIFILEHASHINFO pHash
)
3653 HANDLE handle
, mapping
;
3656 UINT r
= ERROR_FUNCTION_FAILED
;
3658 TRACE("%s %08x %p\n", debugstr_w(szFilePath
), dwOptions
, pHash
);
3661 return ERROR_INVALID_PARAMETER
;
3664 return ERROR_PATH_NOT_FOUND
;
3667 return ERROR_INVALID_PARAMETER
;
3669 return ERROR_INVALID_PARAMETER
;
3670 if (pHash
->dwFileHashInfoSize
< sizeof *pHash
)
3671 return ERROR_INVALID_PARAMETER
;
3673 handle
= CreateFileW( szFilePath
, GENERIC_READ
,
3674 FILE_SHARE_READ
| FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, 0, NULL
);
3675 if (handle
== INVALID_HANDLE_VALUE
)
3677 WARN("can't open file %u\n", GetLastError());
3678 return ERROR_FILE_NOT_FOUND
;
3680 length
= GetFileSize( handle
, NULL
);
3682 mapping
= CreateFileMappingW( handle
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
3685 p
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, length
);
3691 MD5Update( &ctx
, p
, length
);
3693 UnmapViewOfFile( p
);
3695 memcpy( pHash
->dwData
, ctx
.digest
, sizeof pHash
->dwData
);
3698 CloseHandle( mapping
);
3700 CloseHandle( handle
);
3705 /***********************************************************************
3706 * MsiGetFileHashA [MSI.@]
3708 UINT WINAPI
MsiGetFileHashA( LPCSTR szFilePath
, DWORD dwOptions
,
3709 PMSIFILEHASHINFO pHash
)
3714 TRACE("%s %08x %p\n", debugstr_a(szFilePath
), dwOptions
, pHash
);
3716 file
= strdupAtoW( szFilePath
);
3717 if (szFilePath
&& !file
)
3718 return ERROR_OUTOFMEMORY
;
3720 r
= MsiGetFileHashW( file
, dwOptions
, pHash
);
3725 /***********************************************************************
3726 * MsiAdvertiseScriptW [MSI.@]
3728 UINT WINAPI
MsiAdvertiseScriptW( LPCWSTR szScriptFile
, DWORD dwFlags
,
3729 PHKEY phRegData
, BOOL fRemoveItems
)
3731 FIXME("%s %08x %p %d\n",
3732 debugstr_w( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3733 return ERROR_CALL_NOT_IMPLEMENTED
;
3736 /***********************************************************************
3737 * MsiAdvertiseScriptA [MSI.@]
3739 UINT WINAPI
MsiAdvertiseScriptA( LPCSTR szScriptFile
, DWORD dwFlags
,
3740 PHKEY phRegData
, BOOL fRemoveItems
)
3742 FIXME("%s %08x %p %d\n",
3743 debugstr_a( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3744 return ERROR_CALL_NOT_IMPLEMENTED
;
3747 /***********************************************************************
3748 * MsiIsProductElevatedW [MSI.@]
3750 UINT WINAPI
MsiIsProductElevatedW( LPCWSTR szProduct
, BOOL
*pfElevated
)
3752 FIXME("%s %p - stub\n",
3753 debugstr_w( szProduct
), pfElevated
);
3755 return ERROR_SUCCESS
;
3758 /***********************************************************************
3759 * MsiIsProductElevatedA [MSI.@]
3761 UINT WINAPI
MsiIsProductElevatedA( LPCSTR szProduct
, BOOL
*pfElevated
)
3763 FIXME("%s %p - stub\n",
3764 debugstr_a( szProduct
), pfElevated
);
3766 return ERROR_SUCCESS
;
3769 /***********************************************************************
3770 * MsiSetExternalUIRecord [MSI.@]
3772 UINT WINAPI
MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler
,
3773 DWORD filter
, LPVOID context
,
3774 PINSTALLUI_HANDLER_RECORD prev
)
3776 TRACE("%p %08x %p %p\n", handler
, filter
, context
, prev
);
3779 *prev
= gUIHandlerRecord
;
3781 gUIHandlerRecord
= handler
;
3783 gUIContext
= context
;
3785 return ERROR_SUCCESS
;
3788 /***********************************************************************
3789 * MsiInstallMissingComponentA [MSI.@]
3791 UINT WINAPI
MsiInstallMissingComponentA( LPCSTR product
, LPCSTR component
, INSTALLSTATE state
)
3794 WCHAR
*productW
= NULL
, *componentW
= NULL
;
3796 TRACE("%s, %s, %d\n", debugstr_a(product
), debugstr_a(component
), state
);
3798 if (product
&& !(productW
= strdupAtoW( product
)))
3799 return ERROR_OUTOFMEMORY
;
3801 if (component
&& !(componentW
= strdupAtoW( component
)))
3803 msi_free( productW
);
3804 return ERROR_OUTOFMEMORY
;
3807 r
= MsiInstallMissingComponentW( productW
, componentW
, state
);
3808 msi_free( productW
);
3809 msi_free( componentW
);
3813 /***********************************************************************
3814 * MsiInstallMissingComponentW [MSI.@]
3816 UINT WINAPI
MsiInstallMissingComponentW(LPCWSTR szProduct
, LPCWSTR szComponent
, INSTALLSTATE eInstallState
)
3818 FIXME("(%s %s %d\n", debugstr_w(szProduct
), debugstr_w(szComponent
), eInstallState
);
3819 return ERROR_SUCCESS
;
3822 /***********************************************************************
3823 * MsiBeginTransactionA [MSI.@]
3825 UINT WINAPI
MsiBeginTransactionA( LPCSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
3830 FIXME("%s %u %p %p\n", debugstr_a(name
), attrs
, id
, event
);
3832 nameW
= strdupAtoW( name
);
3834 return ERROR_OUTOFMEMORY
;
3836 r
= MsiBeginTransactionW( nameW
, attrs
, id
, event
);
3841 /***********************************************************************
3842 * MsiBeginTransactionW [MSI.@]
3844 UINT WINAPI
MsiBeginTransactionW( LPCWSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
3846 FIXME("%s %u %p %p\n", debugstr_w(name
), attrs
, id
, event
);
3848 *id
= (MSIHANDLE
)0xdeadbeef;
3849 *event
= (HANDLE
)0xdeadbeef;
3851 return ERROR_SUCCESS
;
3854 /***********************************************************************
3855 * MsiEndTransaction [MSI.@]
3857 UINT WINAPI
MsiEndTransaction( DWORD state
)
3859 FIXME("%u\n", state
);
3860 return ERROR_SUCCESS
;