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
);
302 static UINT
get_patch_product_codes( LPCWSTR szPatchPackage
, WCHAR
**product_codes
)
304 MSIHANDLE patch
, info
= 0;
307 static WCHAR empty
[] = {0};
310 r
= MsiOpenDatabaseW( szPatchPackage
, MSIDBOPEN_READONLY
, &patch
);
311 if (r
!= ERROR_SUCCESS
)
314 r
= MsiGetSummaryInformationW( patch
, NULL
, 0, &info
);
315 if (r
!= ERROR_SUCCESS
)
319 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, empty
, &size
);
320 if (r
!= ERROR_MORE_DATA
|| !size
|| type
!= VT_LPSTR
)
322 ERR("Failed to read product codes from patch\n");
323 r
= ERROR_FUNCTION_FAILED
;
327 codes
= msi_alloc( ++size
* sizeof(WCHAR
) );
330 r
= ERROR_OUTOFMEMORY
;
334 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, codes
, &size
);
335 if (r
!= ERROR_SUCCESS
)
338 *product_codes
= codes
;
341 MsiCloseHandle( info
);
342 MsiCloseHandle( patch
);
346 static UINT
MSI_ApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szProductCode
, LPCWSTR szCommandLine
)
350 LPCWSTR cmd_ptr
= szCommandLine
;
351 LPWSTR beg
, end
, 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
);
380 while ((end
= strchrW(beg
, '}')))
383 r
= MsiConfigureProductExW(beg
, INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
384 if (r
== ERROR_SUCCESS
)
386 TRACE("patch applied\n");
401 UINT WINAPI
MsiApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szInstallPackage
,
402 INSTALLTYPE eInstallType
, LPCWSTR szCommandLine
)
404 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage
), debugstr_w(szInstallPackage
),
405 eInstallType
, debugstr_w(szCommandLine
));
407 if (szInstallPackage
|| eInstallType
== INSTALLTYPE_NETWORK_IMAGE
||
408 eInstallType
== INSTALLTYPE_SINGLE_INSTANCE
)
410 FIXME("Only reading target products from patch\n");
411 return ERROR_CALL_NOT_IMPLEMENTED
;
414 return MSI_ApplyPatchW(szPatchPackage
, NULL
, szCommandLine
);
417 UINT WINAPI
MsiApplyMultiplePatchesA(LPCSTR szPatchPackages
,
418 LPCSTR szProductCode
, LPCSTR szPropertiesList
)
420 LPWSTR patch_packages
= NULL
;
421 LPWSTR product_code
= NULL
;
422 LPWSTR properties_list
= NULL
;
423 UINT r
= ERROR_OUTOFMEMORY
;
425 TRACE("%s %s %s\n", debugstr_a(szPatchPackages
), debugstr_a(szProductCode
),
426 debugstr_a(szPropertiesList
));
428 if (!szPatchPackages
|| !szPatchPackages
[0])
429 return ERROR_INVALID_PARAMETER
;
431 if (!(patch_packages
= strdupAtoW(szPatchPackages
)))
432 return ERROR_OUTOFMEMORY
;
434 if (szProductCode
&& !(product_code
= strdupAtoW(szProductCode
)))
437 if (szPropertiesList
&& !(properties_list
= strdupAtoW(szPropertiesList
)))
440 r
= MsiApplyMultiplePatchesW(patch_packages
, product_code
, properties_list
);
443 msi_free(patch_packages
);
444 msi_free(product_code
);
445 msi_free(properties_list
);
450 UINT WINAPI
MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages
,
451 LPCWSTR szProductCode
, LPCWSTR szPropertiesList
)
453 UINT r
= ERROR_SUCCESS
;
456 TRACE("%s %s %s\n", debugstr_w(szPatchPackages
), debugstr_w(szProductCode
),
457 debugstr_w(szPropertiesList
));
459 if (!szPatchPackages
|| !szPatchPackages
[0])
460 return ERROR_INVALID_PARAMETER
;
462 beg
= end
= szPatchPackages
;
468 while (*beg
== ' ') beg
++;
469 while (*end
&& *end
!= ';') end
++;
472 while (len
&& beg
[len
- 1] == ' ') len
--;
474 if (!len
) return ERROR_INVALID_NAME
;
476 patch
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
478 return ERROR_OUTOFMEMORY
;
480 memcpy(patch
, beg
, len
* sizeof(WCHAR
));
483 r
= MSI_ApplyPatchW(patch
, szProductCode
, szPropertiesList
);
486 if (r
!= ERROR_SUCCESS
)
494 UINT WINAPI
MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath
,
495 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
498 WCHAR
*package_path
= NULL
;
499 MSIPATCHSEQUENCEINFOW
*psi
;
501 TRACE("(%s, %d, %p)\n", debugstr_a(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
503 if (szProductPackagePath
&& !(package_path
= strdupAtoW( szProductPackagePath
)))
504 return ERROR_OUTOFMEMORY
;
506 psi
= msi_alloc( cPatchInfo
* sizeof(*psi
) );
509 msi_free( package_path
);
510 return ERROR_OUTOFMEMORY
;
513 for (i
= 0; i
< cPatchInfo
; i
++)
515 psi
[i
].szPatchData
= strdupAtoW( pPatchInfo
[i
].szPatchData
);
516 psi
[i
].ePatchDataType
= pPatchInfo
[i
].ePatchDataType
;
519 r
= MsiDetermineApplicablePatchesW( package_path
, cPatchInfo
, psi
);
520 if (r
== ERROR_SUCCESS
)
522 for (i
= 0; i
< cPatchInfo
; i
++)
524 pPatchInfo
[i
].dwOrder
= psi
[i
].dwOrder
;
525 pPatchInfo
[i
].uStatus
= psi
[i
].uStatus
;
529 msi_free( package_path
);
530 for (i
= 0; i
< cPatchInfo
; i
++)
531 msi_free( (WCHAR
*)psi
[i
].szPatchData
);
536 static UINT
MSI_ApplicablePatchW( MSIPACKAGE
*package
, LPCWSTR patch
)
539 MSIDATABASE
*patch_db
;
540 UINT r
= ERROR_SUCCESS
;
542 r
= MSI_OpenDatabaseW( patch
, MSIDBOPEN_READONLY
, &patch_db
);
543 if (r
!= ERROR_SUCCESS
)
545 WARN("failed to open patch file %s\n", debugstr_w(patch
));
549 si
= MSI_GetSummaryInformationW( patch_db
->storage
, 0 );
552 msiobj_release( &patch_db
->hdr
);
553 return ERROR_FUNCTION_FAILED
;
556 r
= msi_check_patch_applicable( package
, si
);
557 if (r
!= ERROR_SUCCESS
)
558 TRACE("patch not applicable\n");
560 msiobj_release( &patch_db
->hdr
);
561 msiobj_release( &si
->hdr
);
565 UINT WINAPI
MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath
,
566 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
568 UINT i
, r
, ret
= ERROR_FUNCTION_FAILED
;
571 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
573 r
= MSI_OpenPackageW( szProductPackagePath
, &package
);
574 if (r
!= ERROR_SUCCESS
)
576 ERR("failed to open package %u\n", r
);
580 for (i
= 0; i
< cPatchInfo
; i
++)
582 switch (pPatchInfo
[i
].ePatchDataType
)
584 case MSIPATCH_DATATYPE_PATCHFILE
:
586 FIXME("patch ordering not supported\n");
587 r
= MSI_ApplicablePatchW( package
, pPatchInfo
[i
].szPatchData
);
588 if (r
!= ERROR_SUCCESS
)
590 pPatchInfo
[i
].dwOrder
= ~0u;
591 pPatchInfo
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
595 pPatchInfo
[i
].dwOrder
= i
;
596 pPatchInfo
[i
].uStatus
= ret
= ERROR_SUCCESS
;
602 FIXME("patch data type %u not supported\n", pPatchInfo
[i
].ePatchDataType
);
603 pPatchInfo
[i
].dwOrder
= ~0u;
604 pPatchInfo
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
609 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo
[i
].szPatchData
));
610 TRACE("ePatchDataType: %u\n", pPatchInfo
[i
].ePatchDataType
);
611 TRACE(" dwOrder: %u\n", pPatchInfo
[i
].dwOrder
);
612 TRACE(" uStatus: %u\n", pPatchInfo
[i
].uStatus
);
617 UINT WINAPI
MsiDeterminePatchSequenceA(LPCSTR szProductCode
, LPCSTR szUserSid
,
618 MSIINSTALLCONTEXT dwContext
, DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
620 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode
),
621 debugstr_a(szUserSid
), dwContext
, cPatchInfo
, pPatchInfo
);
623 return ERROR_CALL_NOT_IMPLEMENTED
;
626 UINT WINAPI
MsiDeterminePatchSequenceW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
627 MSIINSTALLCONTEXT dwContext
, DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
629 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode
),
630 debugstr_w(szUserSid
), dwContext
, cPatchInfo
, pPatchInfo
);
632 return ERROR_CALL_NOT_IMPLEMENTED
;
635 static UINT
msi_open_package(LPCWSTR product
, MSIINSTALLCONTEXT context
,
636 MSIPACKAGE
**package
)
642 WCHAR sourcepath
[MAX_PATH
];
643 WCHAR filename
[MAX_PATH
];
645 r
= MSIREG_OpenInstallProps(product
, context
, NULL
, &props
, FALSE
);
646 if (r
!= ERROR_SUCCESS
)
647 return ERROR_BAD_CONFIGURATION
;
649 localpack
= msi_reg_get_val_str(props
, szLocalPackage
);
652 lstrcpyW(sourcepath
, localpack
);
656 if (!localpack
|| GetFileAttributesW(sourcepath
) == INVALID_FILE_ATTRIBUTES
)
658 sz
= sizeof(sourcepath
);
659 MsiSourceListGetInfoW(product
, NULL
, context
, MSICODE_PRODUCT
,
660 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
662 sz
= sizeof(filename
);
663 MsiSourceListGetInfoW(product
, NULL
, context
, MSICODE_PRODUCT
,
664 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
666 lstrcatW(sourcepath
, filename
);
669 if (GetFileAttributesW(sourcepath
) == INVALID_FILE_ATTRIBUTES
)
670 return ERROR_INSTALL_SOURCE_ABSENT
;
672 return MSI_OpenPackageW(sourcepath
, package
);
675 UINT WINAPI
MsiConfigureProductExW(LPCWSTR szProduct
, int iInstallLevel
,
676 INSTALLSTATE eInstallState
, LPCWSTR szCommandLine
)
678 MSIPACKAGE
* package
= NULL
;
679 MSIINSTALLCONTEXT context
;
682 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
685 static const WCHAR szInstalled
[] = {
686 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
687 static const WCHAR szRemoveAll
[] = {
688 ' ','R','E','M','O','V','E','=','A','L','L',0};
689 static const WCHAR szMachine
[] = {
690 ' ','A','L','L','U','S','E','R','S','=','1',0};
692 TRACE("%s %d %d %s\n",debugstr_w(szProduct
), iInstallLevel
, eInstallState
,
693 debugstr_w(szCommandLine
));
695 if (!szProduct
|| lstrlenW(szProduct
) != GUID_SIZE
- 1)
696 return ERROR_INVALID_PARAMETER
;
698 if (eInstallState
== INSTALLSTATE_ADVERTISED
||
699 eInstallState
== INSTALLSTATE_SOURCE
)
701 FIXME("State %d not implemented\n", eInstallState
);
702 return ERROR_CALL_NOT_IMPLEMENTED
;
705 r
= msi_locate_product(szProduct
, &context
);
706 if (r
!= ERROR_SUCCESS
)
709 r
= msi_open_package(szProduct
, context
, &package
);
710 if (r
!= ERROR_SUCCESS
)
713 sz
= lstrlenW(szInstalled
) + 1;
716 sz
+= lstrlenW(szCommandLine
);
718 if (eInstallState
== INSTALLSTATE_ABSENT
)
719 sz
+= lstrlenW(szRemoveAll
);
721 if (context
== MSIINSTALLCONTEXT_MACHINE
)
722 sz
+= lstrlenW(szMachine
);
724 commandline
= msi_alloc(sz
* sizeof(WCHAR
));
727 r
= ERROR_OUTOFMEMORY
;
733 lstrcpyW(commandline
,szCommandLine
);
735 if (eInstallState
== INSTALLSTATE_ABSENT
)
736 lstrcatW(commandline
, szRemoveAll
);
738 if (context
== MSIINSTALLCONTEXT_MACHINE
)
739 lstrcatW(commandline
, szMachine
);
741 sz
= sizeof(sourcepath
);
742 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
743 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
745 sz
= sizeof(filename
);
746 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
747 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
749 strcatW(sourcepath
, filename
);
751 r
= MSI_InstallPackage( package
, sourcepath
, commandline
);
753 msi_free(commandline
);
756 msiobj_release( &package
->hdr
);
761 UINT WINAPI
MsiConfigureProductExA(LPCSTR szProduct
, int iInstallLevel
,
762 INSTALLSTATE eInstallState
, LPCSTR szCommandLine
)
764 LPWSTR szwProduct
= NULL
;
765 LPWSTR szwCommandLine
= NULL
;
766 UINT r
= ERROR_OUTOFMEMORY
;
770 szwProduct
= strdupAtoW( szProduct
);
777 szwCommandLine
= strdupAtoW( szCommandLine
);
782 r
= MsiConfigureProductExW( szwProduct
, iInstallLevel
, eInstallState
,
785 msi_free( szwProduct
);
786 msi_free( szwCommandLine
);
791 UINT WINAPI
MsiConfigureProductA(LPCSTR szProduct
, int iInstallLevel
,
792 INSTALLSTATE eInstallState
)
794 LPWSTR szwProduct
= NULL
;
797 TRACE("%s %d %d\n",debugstr_a(szProduct
), iInstallLevel
, eInstallState
);
801 szwProduct
= strdupAtoW( szProduct
);
803 return ERROR_OUTOFMEMORY
;
806 r
= MsiConfigureProductW( szwProduct
, iInstallLevel
, eInstallState
);
807 msi_free( szwProduct
);
812 UINT WINAPI
MsiConfigureProductW(LPCWSTR szProduct
, int iInstallLevel
,
813 INSTALLSTATE eInstallState
)
815 return MsiConfigureProductExW(szProduct
, iInstallLevel
, eInstallState
, NULL
);
818 UINT WINAPI
MsiGetProductCodeA(LPCSTR szComponent
, LPSTR szBuffer
)
820 LPWSTR szwComponent
= NULL
;
822 WCHAR szwBuffer
[GUID_SIZE
];
824 TRACE("%s %p\n", debugstr_a(szComponent
), szBuffer
);
828 szwComponent
= strdupAtoW( szComponent
);
830 return ERROR_OUTOFMEMORY
;
834 r
= MsiGetProductCodeW( szwComponent
, szwBuffer
);
837 WideCharToMultiByte(CP_ACP
, 0, szwBuffer
, -1, szBuffer
, GUID_SIZE
, NULL
, NULL
);
839 msi_free( szwComponent
);
844 UINT WINAPI
MsiGetProductCodeW(LPCWSTR szComponent
, LPWSTR szBuffer
)
847 HKEY compkey
, prodkey
;
848 WCHAR squished_comp
[GUID_SIZE
];
849 WCHAR squished_prod
[GUID_SIZE
];
850 DWORD sz
= GUID_SIZE
;
852 TRACE("%s %p\n", debugstr_w(szComponent
), szBuffer
);
854 if (!szComponent
|| !*szComponent
)
855 return ERROR_INVALID_PARAMETER
;
857 if (!squash_guid(szComponent
, squished_comp
))
858 return ERROR_INVALID_PARAMETER
;
860 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &compkey
, FALSE
) != ERROR_SUCCESS
&&
861 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &compkey
, FALSE
) != ERROR_SUCCESS
)
863 return ERROR_UNKNOWN_COMPONENT
;
866 rc
= RegEnumValueW(compkey
, 0, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
867 if (rc
!= ERROR_SUCCESS
)
869 RegCloseKey(compkey
);
870 return ERROR_UNKNOWN_COMPONENT
;
873 /* check simple case, only one product */
874 rc
= RegEnumValueW(compkey
, 1, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
875 if (rc
== ERROR_NO_MORE_ITEMS
)
882 while ((rc
= RegEnumValueW(compkey
, index
, squished_prod
, &sz
,
883 NULL
, NULL
, NULL
, NULL
)) != ERROR_NO_MORE_ITEMS
)
887 unsquash_guid(squished_prod
, szBuffer
);
889 if (MSIREG_OpenProductKey(szBuffer
, NULL
,
890 MSIINSTALLCONTEXT_USERMANAGED
,
891 &prodkey
, FALSE
) == ERROR_SUCCESS
||
892 MSIREG_OpenProductKey(szBuffer
, NULL
,
893 MSIINSTALLCONTEXT_USERUNMANAGED
,
894 &prodkey
, FALSE
) == ERROR_SUCCESS
||
895 MSIREG_OpenProductKey(szBuffer
, NULL
,
896 MSIINSTALLCONTEXT_MACHINE
,
897 &prodkey
, FALSE
) == ERROR_SUCCESS
)
899 RegCloseKey(prodkey
);
905 rc
= ERROR_INSTALL_FAILURE
;
908 RegCloseKey(compkey
);
909 unsquash_guid(squished_prod
, szBuffer
);
913 static LPWSTR
msi_reg_get_value(HKEY hkey
, LPCWSTR name
, DWORD
*type
)
919 static const WCHAR format
[] = {'%','d',0};
921 res
= RegQueryValueExW(hkey
, name
, NULL
, type
, NULL
, NULL
);
922 if (res
!= ERROR_SUCCESS
)
926 return msi_reg_get_val_str(hkey
, name
);
928 if (!msi_reg_get_val_dword(hkey
, name
, &dval
))
931 sprintfW(temp
, format
, dval
);
932 return strdupW(temp
);
935 static UINT
MSI_GetProductInfo(LPCWSTR szProduct
, LPCWSTR szAttribute
,
936 awstring
*szValue
, LPDWORD pcchValueBuf
)
938 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
939 UINT r
= ERROR_UNKNOWN_PROPERTY
;
940 HKEY prodkey
, userdata
, source
;
942 WCHAR squished_pc
[GUID_SIZE
];
943 WCHAR packagecode
[GUID_SIZE
];
944 BOOL badconfig
= FALSE
;
946 DWORD type
= REG_NONE
;
948 static WCHAR empty
[] = {0};
949 static const WCHAR sourcelist
[] = {
950 'S','o','u','r','c','e','L','i','s','t',0};
951 static const WCHAR display_name
[] = {
952 'D','i','s','p','l','a','y','N','a','m','e',0};
953 static const WCHAR display_version
[] = {
954 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
955 static const WCHAR assignment
[] = {
956 'A','s','s','i','g','n','m','e','n','t',0};
958 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
959 debugstr_w(szAttribute
), szValue
, pcchValueBuf
);
961 if ((szValue
->str
.w
&& !pcchValueBuf
) || !szProduct
|| !szAttribute
)
962 return ERROR_INVALID_PARAMETER
;
964 if (!squash_guid(szProduct
, squished_pc
))
965 return ERROR_INVALID_PARAMETER
;
967 if ((r
= MSIREG_OpenProductKey(szProduct
, NULL
,
968 MSIINSTALLCONTEXT_USERMANAGED
,
969 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
970 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
971 MSIINSTALLCONTEXT_USERUNMANAGED
,
972 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
973 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
974 MSIINSTALLCONTEXT_MACHINE
,
975 &prodkey
, FALSE
)) == ERROR_SUCCESS
)
977 context
= MSIINSTALLCONTEXT_MACHINE
;
980 MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
982 if (!strcmpW( szAttribute
, INSTALLPROPERTY_HELPLINKW
) ||
983 !strcmpW( szAttribute
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
984 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLDATEW
) ||
985 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
986 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
987 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
988 !strcmpW( szAttribute
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
989 !strcmpW( szAttribute
, INSTALLPROPERTY_PUBLISHERW
) ||
990 !strcmpW( szAttribute
, INSTALLPROPERTY_URLINFOABOUTW
) ||
991 !strcmpW( szAttribute
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
992 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMINORW
) ||
993 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMAJORW
) ||
994 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
995 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTIDW
) ||
996 !strcmpW( szAttribute
, INSTALLPROPERTY_REGCOMPANYW
) ||
997 !strcmpW( szAttribute
, INSTALLPROPERTY_REGOWNERW
))
1001 r
= ERROR_UNKNOWN_PRODUCT
;
1006 return ERROR_UNKNOWN_PROPERTY
;
1008 if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1009 szAttribute
= display_name
;
1010 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
))
1011 szAttribute
= display_version
;
1013 val
= msi_reg_get_value(userdata
, szAttribute
, &type
);
1017 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTANCETYPEW
) ||
1018 !strcmpW( szAttribute
, INSTALLPROPERTY_TRANSFORMSW
) ||
1019 !strcmpW( szAttribute
, INSTALLPROPERTY_LANGUAGEW
) ||
1020 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1021 !strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
) ||
1022 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
) ||
1023 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONW
) ||
1024 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTICONW
) ||
1025 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1026 !strcmpW( szAttribute
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1030 r
= ERROR_UNKNOWN_PRODUCT
;
1034 if (!strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1035 szAttribute
= assignment
;
1037 if (!strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
))
1039 res
= RegOpenKeyW(prodkey
, sourcelist
, &source
);
1040 if (res
!= ERROR_SUCCESS
)
1042 r
= ERROR_UNKNOWN_PRODUCT
;
1046 val
= msi_reg_get_value(source
, szAttribute
, &type
);
1050 RegCloseKey(source
);
1054 val
= msi_reg_get_value(prodkey
, szAttribute
, &type
);
1059 if (val
!= empty
&& type
!= REG_DWORD
&&
1060 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
))
1062 if (lstrlenW(val
) != SQUISH_GUID_SIZE
- 1)
1066 unsquash_guid(val
, packagecode
);
1068 val
= strdupW(packagecode
);
1075 r
= ERROR_UNKNOWN_PROPERTY
;
1081 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1082 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1083 * can't rely on its value.
1085 if (szValue
->str
.a
|| szValue
->str
.w
)
1087 DWORD size
= *pcchValueBuf
;
1088 if (strlenW(val
) < size
)
1089 r
= msi_strcpy_to_awstring(val
, szValue
, &size
);
1092 r
= ERROR_MORE_DATA
;
1097 *pcchValueBuf
= lstrlenW(val
);
1101 r
= ERROR_BAD_CONFIGURATION
;
1107 RegCloseKey(prodkey
);
1108 RegCloseKey(userdata
);
1112 UINT WINAPI
MsiGetProductInfoA(LPCSTR szProduct
, LPCSTR szAttribute
,
1113 LPSTR szBuffer
, LPDWORD pcchValueBuf
)
1115 LPWSTR szwProduct
, szwAttribute
= NULL
;
1116 UINT r
= ERROR_OUTOFMEMORY
;
1119 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szAttribute
),
1120 szBuffer
, pcchValueBuf
);
1122 szwProduct
= strdupAtoW( szProduct
);
1123 if( szProduct
&& !szwProduct
)
1126 szwAttribute
= strdupAtoW( szAttribute
);
1127 if( szAttribute
&& !szwAttribute
)
1130 buffer
.unicode
= FALSE
;
1131 buffer
.str
.a
= szBuffer
;
1133 r
= MSI_GetProductInfo( szwProduct
, szwAttribute
,
1134 &buffer
, pcchValueBuf
);
1137 msi_free( szwProduct
);
1138 msi_free( szwAttribute
);
1143 UINT WINAPI
MsiGetProductInfoW(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1144 LPWSTR szBuffer
, LPDWORD pcchValueBuf
)
1148 TRACE("%s %s %p %p\n", debugstr_w(szProduct
), debugstr_w(szAttribute
),
1149 szBuffer
, pcchValueBuf
);
1151 buffer
.unicode
= TRUE
;
1152 buffer
.str
.w
= szBuffer
;
1154 return MSI_GetProductInfo( szProduct
, szAttribute
,
1155 &buffer
, pcchValueBuf
);
1158 UINT WINAPI
MsiGetProductInfoExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1159 MSIINSTALLCONTEXT dwContext
, LPCSTR szProperty
,
1160 LPSTR szValue
, LPDWORD pcchValue
)
1162 LPWSTR product
= NULL
;
1163 LPWSTR usersid
= NULL
;
1164 LPWSTR property
= NULL
;
1165 LPWSTR value
= NULL
;
1169 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode
),
1170 debugstr_a(szUserSid
), dwContext
, debugstr_a(szProperty
),
1171 szValue
, pcchValue
);
1173 if (szValue
&& !pcchValue
)
1174 return ERROR_INVALID_PARAMETER
;
1176 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1177 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1178 if (szProperty
) property
= strdupAtoW(szProperty
);
1180 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1182 if (r
!= ERROR_SUCCESS
)
1185 value
= msi_alloc(++len
* sizeof(WCHAR
));
1188 r
= ERROR_OUTOFMEMORY
;
1192 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1194 if (r
!= ERROR_SUCCESS
)
1200 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
1201 if (*pcchValue
>= len
)
1202 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
1205 r
= ERROR_MORE_DATA
;
1210 if (*pcchValue
<= len
|| !szValue
)
1211 len
= len
* sizeof(WCHAR
) - 1;
1213 *pcchValue
= len
- 1;
1224 static UINT
msi_copy_outval(LPWSTR val
, LPWSTR out
, LPDWORD size
)
1226 UINT r
= ERROR_SUCCESS
;
1229 return ERROR_UNKNOWN_PROPERTY
;
1233 if (strlenW(val
) >= *size
)
1235 r
= ERROR_MORE_DATA
;
1244 *size
= lstrlenW(val
);
1249 UINT WINAPI
MsiGetProductInfoExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
1250 MSIINSTALLCONTEXT dwContext
, LPCWSTR szProperty
,
1251 LPWSTR szValue
, LPDWORD pcchValue
)
1253 WCHAR squished_pc
[GUID_SIZE
];
1255 LPCWSTR package
= NULL
;
1256 HKEY props
= NULL
, prod
;
1257 HKEY classes
= NULL
, managed
;
1260 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1262 static const WCHAR five
[] = {'5',0};
1263 static const WCHAR displayname
[] = {
1264 'D','i','s','p','l','a','y','N','a','m','e',0};
1265 static const WCHAR displayversion
[] = {
1266 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1267 static const WCHAR managed_local_package
[] = {
1268 'M','a','n','a','g','e','d','L','o','c','a','l',
1269 'P','a','c','k','a','g','e',0};
1271 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode
),
1272 debugstr_w(szUserSid
), dwContext
, debugstr_w(szProperty
),
1273 szValue
, pcchValue
);
1275 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1276 return ERROR_INVALID_PARAMETER
;
1278 if (szValue
&& !pcchValue
)
1279 return ERROR_INVALID_PARAMETER
;
1281 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1282 dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1283 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1284 return ERROR_INVALID_PARAMETER
;
1286 if (!szProperty
|| !*szProperty
)
1287 return ERROR_INVALID_PARAMETER
;
1289 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1290 return ERROR_INVALID_PARAMETER
;
1292 /* FIXME: dwContext is provided, no need to search for it */
1293 MSIREG_OpenProductKey(szProductCode
, NULL
,MSIINSTALLCONTEXT_USERMANAGED
,
1295 MSIREG_OpenProductKey(szProductCode
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1298 MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
, &props
, FALSE
);
1300 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1302 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1304 if (!props
&& !prod
)
1307 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1309 package
= managed_local_package
;
1311 if (!props
&& !managed
)
1314 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1316 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1317 MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
, &classes
, FALSE
);
1319 if (!props
&& !classes
)
1323 if (!strcmpW( szProperty
, INSTALLPROPERTY_HELPLINKW
) ||
1324 !strcmpW( szProperty
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1325 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
) ||
1326 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1327 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1328 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1329 !strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1330 !strcmpW( szProperty
, INSTALLPROPERTY_PUBLISHERW
) ||
1331 !strcmpW( szProperty
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1332 !strcmpW( szProperty
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1333 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMINORW
) ||
1334 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1335 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1336 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTIDW
) ||
1337 !strcmpW( szProperty
, INSTALLPROPERTY_REGCOMPANYW
) ||
1338 !strcmpW( szProperty
, INSTALLPROPERTY_REGOWNERW
) ||
1339 !strcmpW( szProperty
, INSTALLPROPERTY_INSTANCETYPEW
))
1341 val
= msi_reg_get_value(props
, package
, &type
);
1344 if (prod
|| classes
)
1345 r
= ERROR_UNKNOWN_PROPERTY
;
1352 if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1353 szProperty
= displayname
;
1354 else if (!strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
))
1355 szProperty
= displayversion
;
1357 val
= msi_reg_get_value(props
, szProperty
, &type
);
1359 val
= strdupW(szEmpty
);
1361 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1363 else if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
) ||
1364 !strcmpW( szProperty
, INSTALLPROPERTY_LANGUAGEW
) ||
1365 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1366 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGECODEW
) ||
1367 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONW
) ||
1368 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTICONW
) ||
1369 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1370 !strcmpW( szProperty
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1372 if (!prod
&& !classes
)
1375 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1377 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1379 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1382 val
= msi_reg_get_value(hkey
, szProperty
, &type
);
1384 val
= strdupW(szEmpty
);
1386 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1388 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTSTATEW
))
1390 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1394 val
= msi_reg_get_value(props
, package
, &type
);
1399 val
= strdupW(five
);
1402 val
= strdupW(szOne
);
1404 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1407 else if (props
&& (val
= msi_reg_get_value(props
, package
, &type
)))
1410 val
= strdupW(five
);
1411 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1415 if (prod
|| managed
)
1416 val
= strdupW(szOne
);
1420 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1422 else if (!strcmpW( szProperty
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1424 if (!prod
&& !classes
)
1428 val
= strdupW(szEmpty
);
1429 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1432 r
= ERROR_UNKNOWN_PROPERTY
;
1437 RegCloseKey(managed
);
1438 RegCloseKey(classes
);
1444 UINT WINAPI
MsiGetPatchInfoExA(LPCSTR szPatchCode
, LPCSTR szProductCode
,
1445 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1446 LPCSTR szProperty
, LPSTR lpValue
, DWORD
*pcchValue
)
1448 LPWSTR patch
= NULL
, product
= NULL
, usersid
= NULL
;
1449 LPWSTR property
= NULL
, val
= NULL
;
1453 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode
),
1454 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
,
1455 debugstr_a(szProperty
), lpValue
, pcchValue
);
1457 if (lpValue
&& !pcchValue
)
1458 return ERROR_INVALID_PARAMETER
;
1460 if (szPatchCode
) patch
= strdupAtoW(szPatchCode
);
1461 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1462 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1463 if (szProperty
) property
= strdupAtoW(szProperty
);
1466 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1468 if (r
!= ERROR_SUCCESS
)
1471 val
= msi_alloc(++len
* sizeof(WCHAR
));
1474 r
= ERROR_OUTOFMEMORY
;
1478 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1480 if (r
!= ERROR_SUCCESS
|| !pcchValue
)
1484 WideCharToMultiByte(CP_ACP
, 0, val
, -1, lpValue
,
1485 *pcchValue
- 1, NULL
, NULL
);
1487 len
= lstrlenW(val
);
1488 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1492 r
= ERROR_MORE_DATA
;
1493 lpValue
[*pcchValue
- 1] = '\0';
1496 *pcchValue
= len
* sizeof(WCHAR
);
1511 UINT WINAPI
MsiGetPatchInfoExW(LPCWSTR szPatchCode
, LPCWSTR szProductCode
,
1512 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1513 LPCWSTR szProperty
, LPWSTR lpValue
, DWORD
*pcchValue
)
1515 WCHAR squished_pc
[GUID_SIZE
];
1516 WCHAR squished_patch
[GUID_SIZE
];
1517 HKEY udprod
= 0, prod
= 0, props
= 0;
1518 HKEY patch
= 0, patches
= 0;
1519 HKEY udpatch
= 0, datakey
= 0;
1520 HKEY prodpatches
= 0;
1522 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1526 static const WCHAR szManagedPackage
[] = {'M','a','n','a','g','e','d',
1527 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1529 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode
),
1530 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
,
1531 debugstr_w(szProperty
), lpValue
, pcchValue
);
1533 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1534 return ERROR_INVALID_PARAMETER
;
1536 if (!szPatchCode
|| !squash_guid(szPatchCode
, squished_patch
))
1537 return ERROR_INVALID_PARAMETER
;
1540 return ERROR_INVALID_PARAMETER
;
1542 if (lpValue
&& !pcchValue
)
1543 return ERROR_INVALID_PARAMETER
;
1545 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1546 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1547 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1548 return ERROR_INVALID_PARAMETER
;
1550 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1551 return ERROR_INVALID_PARAMETER
;
1553 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
1554 return ERROR_INVALID_PARAMETER
;
1556 if (MSIREG_OpenUserDataProductKey(szProductCode
, dwContext
, NULL
,
1557 &udprod
, FALSE
) != ERROR_SUCCESS
)
1560 if (MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
,
1561 &props
, FALSE
) != ERROR_SUCCESS
)
1564 r
= ERROR_UNKNOWN_PATCH
;
1566 res
= RegOpenKeyExW(udprod
, szPatches
, 0, KEY_READ
, &patches
);
1567 if (res
!= ERROR_SUCCESS
)
1570 res
= RegOpenKeyExW(patches
, squished_patch
, 0, KEY_READ
, &patch
);
1571 if (res
!= ERROR_SUCCESS
)
1574 if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
))
1576 if (MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
,
1577 &prod
, FALSE
) != ERROR_SUCCESS
)
1580 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_ALL_ACCESS
, &prodpatches
);
1581 if (res
!= ERROR_SUCCESS
)
1584 datakey
= prodpatches
;
1585 szProperty
= squished_patch
;
1589 if (MSIREG_OpenUserDataPatchKey(szPatchCode
, dwContext
,
1590 &udpatch
, FALSE
) != ERROR_SUCCESS
)
1593 if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1595 if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1596 szProperty
= szManagedPackage
;
1599 else if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
))
1602 szProperty
= szInstalled
;
1604 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1608 else if (!strcmpW( szProperty
, INSTALLPROPERTY_UNINSTALLABLEW
) ||
1609 !strcmpW( szProperty
, INSTALLPROPERTY_PATCHSTATEW
) ||
1610 !strcmpW( szProperty
, INSTALLPROPERTY_DISPLAYNAMEW
) ||
1611 !strcmpW( szProperty
, INSTALLPROPERTY_MOREINFOURLW
))
1617 r
= ERROR_UNKNOWN_PROPERTY
;
1622 val
= msi_reg_get_val_str(datakey
, szProperty
);
1624 val
= strdupW(szEmpty
);
1632 lstrcpynW(lpValue
, val
, *pcchValue
);
1634 len
= lstrlenW(val
);
1635 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1638 r
= ERROR_MORE_DATA
;
1640 *pcchValue
= len
* sizeof(WCHAR
);
1647 RegCloseKey(prodpatches
);
1650 RegCloseKey(patches
);
1651 RegCloseKey(udpatch
);
1653 RegCloseKey(udprod
);
1658 UINT WINAPI
MsiGetPatchInfoA( LPCSTR patch
, LPCSTR attr
, LPSTR buffer
, LPDWORD buflen
)
1660 UINT r
= ERROR_OUTOFMEMORY
;
1662 LPWSTR patchW
= NULL
, attrW
= NULL
, bufferW
= NULL
;
1664 TRACE("%s %s %p %p\n", debugstr_a(patch
), debugstr_a(attr
), buffer
, buflen
);
1666 if (!patch
|| !attr
)
1667 return ERROR_INVALID_PARAMETER
;
1669 if (!(patchW
= strdupAtoW( patch
)))
1672 if (!(attrW
= strdupAtoW( attr
)))
1676 r
= MsiGetPatchInfoW( patchW
, attrW
, NULL
, &size
);
1677 if (r
!= ERROR_SUCCESS
)
1681 if (!(bufferW
= msi_alloc( size
* sizeof(WCHAR
) )))
1683 r
= ERROR_OUTOFMEMORY
;
1687 r
= MsiGetPatchInfoW( patchW
, attrW
, bufferW
, &size
);
1688 if (r
== ERROR_SUCCESS
)
1690 int len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
1692 r
= ERROR_MORE_DATA
;
1694 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *buflen
, NULL
, NULL
);
1702 msi_free( bufferW
);
1706 UINT WINAPI
MsiGetPatchInfoW( LPCWSTR patch
, LPCWSTR attr
, LPWSTR buffer
, LPDWORD buflen
)
1709 WCHAR product
[GUID_SIZE
];
1712 TRACE("%s %s %p %p\n", debugstr_w(patch
), debugstr_w(attr
), buffer
, buflen
);
1714 if (!patch
|| !attr
)
1715 return ERROR_INVALID_PARAMETER
;
1717 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW
, attr
))
1718 return ERROR_UNKNOWN_PROPERTY
;
1723 r
= MsiEnumProductsW( index
, product
);
1724 if (r
!= ERROR_SUCCESS
)
1727 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, attr
, buffer
, buflen
);
1728 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1731 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, attr
, buffer
, buflen
);
1732 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1735 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_MACHINE
, attr
, buffer
, buflen
);
1736 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1742 return ERROR_UNKNOWN_PRODUCT
;
1745 UINT WINAPI
MsiEnableLogA(DWORD dwLogMode
, LPCSTR szLogFile
, DWORD attributes
)
1747 LPWSTR szwLogFile
= NULL
;
1750 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_a(szLogFile
), attributes
);
1754 szwLogFile
= strdupAtoW( szLogFile
);
1756 return ERROR_OUTOFMEMORY
;
1758 r
= MsiEnableLogW( dwLogMode
, szwLogFile
, attributes
);
1759 msi_free( szwLogFile
);
1763 UINT WINAPI
MsiEnableLogW(DWORD dwLogMode
, LPCWSTR szLogFile
, DWORD attributes
)
1765 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_w(szLogFile
), attributes
);
1767 msi_free(gszLogFile
);
1773 if (!(attributes
& INSTALLLOGATTRIBUTES_APPEND
))
1774 DeleteFileW(szLogFile
);
1775 file
= CreateFileW(szLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
,
1776 FILE_ATTRIBUTE_NORMAL
, NULL
);
1777 if (file
!= INVALID_HANDLE_VALUE
)
1779 gszLogFile
= strdupW(szLogFile
);
1783 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile
), GetLastError());
1786 return ERROR_SUCCESS
;
1789 UINT WINAPI
MsiEnumComponentCostsW(MSIHANDLE hInstall
, LPCWSTR szComponent
,
1790 DWORD dwIndex
, INSTALLSTATE iState
,
1791 LPWSTR lpDriveBuf
, DWORD
*pcchDriveBuf
,
1792 int *piCost
, int *pTempCost
)
1794 FIXME("(%d, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall
,
1795 debugstr_w(szComponent
), dwIndex
, iState
, lpDriveBuf
,
1796 pcchDriveBuf
, piCost
, pTempCost
);
1798 return ERROR_NO_MORE_ITEMS
;
1801 UINT WINAPI
MsiQueryComponentStateA(LPCSTR szProductCode
,
1802 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1803 LPCSTR szComponent
, INSTALLSTATE
*pdwState
)
1805 LPWSTR prodcode
= NULL
, usersid
= NULL
, comp
= NULL
;
1808 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode
),
1809 debugstr_a(szUserSid
), dwContext
, debugstr_a(szComponent
), pdwState
);
1811 if (szProductCode
&& !(prodcode
= strdupAtoW(szProductCode
)))
1812 return ERROR_OUTOFMEMORY
;
1814 if (szUserSid
&& !(usersid
= strdupAtoW(szUserSid
)))
1815 return ERROR_OUTOFMEMORY
;
1817 if (szComponent
&& !(comp
= strdupAtoW(szComponent
)))
1818 return ERROR_OUTOFMEMORY
;
1820 r
= MsiQueryComponentStateW(prodcode
, usersid
, dwContext
, comp
, pdwState
);
1829 static BOOL
msi_comp_find_prod_key(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
1834 r
= MSIREG_OpenProductKey(prodcode
, NULL
, context
, &hkey
, FALSE
);
1836 return (r
== ERROR_SUCCESS
);
1839 static BOOL
msi_comp_find_package(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
1847 static const WCHAR local_package
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1848 static const WCHAR managed_local_package
[] = {
1849 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1852 r
= MSIREG_OpenInstallProps(prodcode
, context
, NULL
, &hkey
, FALSE
);
1853 if (r
!= ERROR_SUCCESS
)
1856 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
1857 package
= managed_local_package
;
1859 package
= local_package
;
1862 res
= RegQueryValueExW(hkey
, package
, NULL
, NULL
, NULL
, &sz
);
1865 return (res
== ERROR_SUCCESS
);
1868 static BOOL
msi_comp_find_prodcode(LPWSTR squished_pc
,
1869 MSIINSTALLCONTEXT context
,
1870 LPCWSTR comp
, LPWSTR val
, DWORD
*sz
)
1876 if (context
== MSIINSTALLCONTEXT_MACHINE
)
1877 r
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
1879 r
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
1881 if (r
!= ERROR_SUCCESS
)
1884 res
= RegQueryValueExW(hkey
, squished_pc
, NULL
, NULL
, (BYTE
*)val
, sz
);
1885 if (res
!= ERROR_SUCCESS
)
1892 UINT WINAPI
MsiQueryComponentStateW(LPCWSTR szProductCode
,
1893 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1894 LPCWSTR szComponent
, INSTALLSTATE
*pdwState
)
1896 WCHAR squished_pc
[GUID_SIZE
];
1897 WCHAR val
[MAX_PATH
];
1901 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode
),
1902 debugstr_w(szUserSid
), dwContext
, debugstr_w(szComponent
), pdwState
);
1904 if (!pdwState
|| !szComponent
)
1905 return ERROR_INVALID_PARAMETER
;
1907 if (!szProductCode
|| !*szProductCode
|| lstrlenW(szProductCode
) != GUID_SIZE
- 1)
1908 return ERROR_INVALID_PARAMETER
;
1910 if (!squash_guid(szProductCode
, squished_pc
))
1911 return ERROR_INVALID_PARAMETER
;
1913 found
= msi_comp_find_prod_key(szProductCode
, dwContext
);
1915 if (!msi_comp_find_package(szProductCode
, dwContext
))
1919 *pdwState
= INSTALLSTATE_UNKNOWN
;
1920 return ERROR_UNKNOWN_COMPONENT
;
1923 return ERROR_UNKNOWN_PRODUCT
;
1926 *pdwState
= INSTALLSTATE_UNKNOWN
;
1929 if (!msi_comp_find_prodcode(squished_pc
, dwContext
, szComponent
, val
, &sz
))
1930 return ERROR_UNKNOWN_COMPONENT
;
1933 *pdwState
= INSTALLSTATE_NOTUSED
;
1936 if (lstrlenW(val
) > 2 &&
1937 val
[0] >= '0' && val
[0] <= '9' && val
[1] >= '0' && val
[1] <= '9')
1939 *pdwState
= INSTALLSTATE_SOURCE
;
1942 *pdwState
= INSTALLSTATE_LOCAL
;
1945 return ERROR_SUCCESS
;
1948 INSTALLSTATE WINAPI
MsiQueryProductStateA(LPCSTR szProduct
)
1950 LPWSTR szwProduct
= NULL
;
1955 szwProduct
= strdupAtoW( szProduct
);
1957 return ERROR_OUTOFMEMORY
;
1959 r
= MsiQueryProductStateW( szwProduct
);
1960 msi_free( szwProduct
);
1964 INSTALLSTATE WINAPI
MsiQueryProductStateW(LPCWSTR szProduct
)
1966 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
1967 INSTALLSTATE state
= INSTALLSTATE_ADVERTISED
;
1968 HKEY prodkey
= 0, userdata
= 0;
1972 static const WCHAR szWindowsInstaller
[] = {
1973 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1975 TRACE("%s\n", debugstr_w(szProduct
));
1977 if (!szProduct
|| !*szProduct
)
1978 return INSTALLSTATE_INVALIDARG
;
1980 if (lstrlenW(szProduct
) != GUID_SIZE
- 1)
1981 return INSTALLSTATE_INVALIDARG
;
1983 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
1984 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
1985 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1986 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
1987 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
1988 &prodkey
, FALSE
) == ERROR_SUCCESS
)
1990 context
= MSIINSTALLCONTEXT_MACHINE
;
1993 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
1994 if (r
!= ERROR_SUCCESS
)
1997 if (!msi_reg_get_val_dword(userdata
, szWindowsInstaller
, &val
))
2001 state
= INSTALLSTATE_DEFAULT
;
2003 state
= INSTALLSTATE_UNKNOWN
;
2008 state
= INSTALLSTATE_UNKNOWN
;
2011 state
= INSTALLSTATE_ABSENT
;
2014 RegCloseKey(prodkey
);
2015 RegCloseKey(userdata
);
2019 INSTALLUILEVEL WINAPI
MsiSetInternalUI(INSTALLUILEVEL dwUILevel
, HWND
*phWnd
)
2021 INSTALLUILEVEL old
= gUILevel
;
2022 HWND oldwnd
= gUIhwnd
;
2024 TRACE("%08x %p\n", dwUILevel
, phWnd
);
2026 gUILevel
= dwUILevel
;
2035 INSTALLUI_HANDLERA WINAPI
MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler
,
2036 DWORD dwMessageFilter
, LPVOID pvContext
)
2038 INSTALLUI_HANDLERA prev
= gUIHandlerA
;
2040 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2042 gUIHandlerA
= puiHandler
;
2044 gUIFilter
= dwMessageFilter
;
2045 gUIContext
= pvContext
;
2050 INSTALLUI_HANDLERW WINAPI
MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler
,
2051 DWORD dwMessageFilter
, LPVOID pvContext
)
2053 INSTALLUI_HANDLERW prev
= gUIHandlerW
;
2055 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2058 gUIHandlerW
= puiHandler
;
2059 gUIFilter
= dwMessageFilter
;
2060 gUIContext
= pvContext
;
2065 /******************************************************************
2066 * MsiLoadStringW [MSI.@]
2068 * Loads a string from MSI's string resources.
2072 * handle [I] only -1 is handled currently
2073 * id [I] id of the string to be loaded
2074 * lpBuffer [O] buffer for the string to be written to
2075 * nBufferMax [I] maximum size of the buffer in characters
2076 * lang [I] the preferred language for the string
2080 * If successful, this function returns the language id of the string loaded
2081 * If the function fails, the function returns zero.
2085 * The type of the first parameter is unknown. LoadString's prototype
2086 * suggests that it might be a module handle. I have made it an MSI handle
2087 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2088 * handle. Maybe strings can be stored in an MSI database somehow.
2090 LANGID WINAPI
MsiLoadStringW( MSIHANDLE handle
, UINT id
, LPWSTR lpBuffer
,
2091 int nBufferMax
, LANGID lang
)
2098 TRACE("%d %u %p %d %d\n", handle
, id
, lpBuffer
, nBufferMax
, lang
);
2101 FIXME("don't know how to deal with handle = %08x\n", handle
);
2104 lang
= GetUserDefaultLangID();
2106 hres
= FindResourceExW( msi_hInstance
, (LPCWSTR
) RT_STRING
,
2110 hResData
= LoadResource( msi_hInstance
, hres
);
2113 p
= LockResource( hResData
);
2117 for (i
= 0; i
< (id
&0xf); i
++)
2121 if( nBufferMax
<= len
)
2124 memcpy( lpBuffer
, p
+1, len
* sizeof(WCHAR
));
2125 lpBuffer
[ len
] = 0;
2127 TRACE("found -> %s\n", debugstr_w(lpBuffer
));
2132 LANGID WINAPI
MsiLoadStringA( MSIHANDLE handle
, UINT id
, LPSTR lpBuffer
,
2133 int nBufferMax
, LANGID lang
)
2139 bufW
= msi_alloc(nBufferMax
*sizeof(WCHAR
));
2140 r
= MsiLoadStringW(handle
, id
, bufW
, nBufferMax
, lang
);
2143 len
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
2144 if( len
<= nBufferMax
)
2145 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1,
2146 lpBuffer
, nBufferMax
, NULL
, NULL
);
2154 INSTALLSTATE WINAPI
MsiLocateComponentA(LPCSTR szComponent
, LPSTR lpPathBuf
,
2157 char szProduct
[GUID_SIZE
];
2159 TRACE("%s %p %p\n", debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2161 if (!szComponent
|| !pcchBuf
)
2162 return INSTALLSTATE_INVALIDARG
;
2164 if (MsiGetProductCodeA( szComponent
, szProduct
) != ERROR_SUCCESS
)
2165 return INSTALLSTATE_UNKNOWN
;
2167 return MsiGetComponentPathA( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2170 INSTALLSTATE WINAPI
MsiLocateComponentW(LPCWSTR szComponent
, LPWSTR lpPathBuf
,
2173 WCHAR szProduct
[GUID_SIZE
];
2175 TRACE("%s %p %p\n", debugstr_w(szComponent
), lpPathBuf
, pcchBuf
);
2177 if (!szComponent
|| !pcchBuf
)
2178 return INSTALLSTATE_INVALIDARG
;
2180 if (MsiGetProductCodeW( szComponent
, szProduct
) != ERROR_SUCCESS
)
2181 return INSTALLSTATE_UNKNOWN
;
2183 return MsiGetComponentPathW( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2186 UINT WINAPI
MsiMessageBoxA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2187 WORD wLanguageId
, DWORD f
)
2189 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_a(lpText
), debugstr_a(lpCaption
),
2190 uType
, wLanguageId
, f
);
2191 return MessageBoxExA(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2194 UINT WINAPI
MsiMessageBoxW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2195 WORD wLanguageId
, DWORD f
)
2197 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_w(lpText
), debugstr_w(lpCaption
),
2198 uType
, wLanguageId
, f
);
2199 return MessageBoxExW(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2202 UINT WINAPI
MsiMessageBoxExA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2203 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2205 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_a(lpText
),
2206 debugstr_a(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2207 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2210 UINT WINAPI
MsiMessageBoxExW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2211 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2213 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_w(lpText
),
2214 debugstr_w(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2215 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2218 UINT WINAPI
MsiProvideAssemblyA( LPCSTR szAssemblyName
, LPCSTR szAppContext
,
2219 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPSTR lpPathBuf
,
2220 LPDWORD pcchPathBuf
)
2222 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName
),
2223 debugstr_a(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2225 return ERROR_CALL_NOT_IMPLEMENTED
;
2228 UINT WINAPI
MsiProvideAssemblyW( LPCWSTR szAssemblyName
, LPCWSTR szAppContext
,
2229 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPWSTR lpPathBuf
,
2230 LPDWORD pcchPathBuf
)
2232 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName
),
2233 debugstr_w(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2235 return ERROR_CALL_NOT_IMPLEMENTED
;
2238 UINT WINAPI
MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor
,
2239 LPSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2241 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2242 return ERROR_CALL_NOT_IMPLEMENTED
;
2245 UINT WINAPI
MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor
,
2246 LPWSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2248 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2249 return ERROR_CALL_NOT_IMPLEMENTED
;
2252 HRESULT WINAPI
MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath
,
2253 DWORD dwFlags
, PCCERT_CONTEXT
* ppcCertContext
, LPBYTE pbHashData
,
2254 LPDWORD pcbHashData
)
2256 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath
), dwFlags
,
2257 ppcCertContext
, pbHashData
, pcbHashData
);
2258 return ERROR_CALL_NOT_IMPLEMENTED
;
2261 HRESULT WINAPI
MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath
,
2262 DWORD dwFlags
, PCCERT_CONTEXT
* ppcCertContext
, LPBYTE pbHashData
,
2263 LPDWORD pcbHashData
)
2265 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath
), dwFlags
,
2266 ppcCertContext
, pbHashData
, pcbHashData
);
2267 return ERROR_CALL_NOT_IMPLEMENTED
;
2270 /******************************************************************
2271 * MsiGetProductPropertyA [MSI.@]
2273 UINT WINAPI
MsiGetProductPropertyA(MSIHANDLE hProduct
, LPCSTR szProperty
,
2274 LPSTR szValue
, LPDWORD pccbValue
)
2276 LPWSTR prop
= NULL
, val
= NULL
;
2280 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_a(szProperty
),
2281 szValue
, pccbValue
);
2283 if (szValue
&& !pccbValue
)
2284 return ERROR_INVALID_PARAMETER
;
2286 if (szProperty
) prop
= strdupAtoW(szProperty
);
2289 r
= MsiGetProductPropertyW(hProduct
, prop
, NULL
, &len
);
2290 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2293 if (r
== ERROR_SUCCESS
)
2295 if (szValue
) *szValue
= '\0';
2296 if (pccbValue
) *pccbValue
= 0;
2300 val
= msi_alloc(++len
* sizeof(WCHAR
));
2303 r
= ERROR_OUTOFMEMORY
;
2307 r
= MsiGetProductPropertyW(hProduct
, prop
, val
, &len
);
2308 if (r
!= ERROR_SUCCESS
)
2311 len
= WideCharToMultiByte(CP_ACP
, 0, val
, -1, NULL
, 0, NULL
, NULL
);
2314 WideCharToMultiByte(CP_ACP
, 0, val
, -1, szValue
,
2315 *pccbValue
, NULL
, NULL
);
2319 if (len
> *pccbValue
)
2320 r
= ERROR_MORE_DATA
;
2322 *pccbValue
= len
- 1;
2332 /******************************************************************
2333 * MsiGetProductPropertyW [MSI.@]
2335 UINT WINAPI
MsiGetProductPropertyW(MSIHANDLE hProduct
, LPCWSTR szProperty
,
2336 LPWSTR szValue
, LPDWORD pccbValue
)
2338 MSIPACKAGE
*package
;
2339 MSIQUERY
*view
= NULL
;
2340 MSIRECORD
*rec
= NULL
;
2344 static const WCHAR query
[] = {
2345 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2346 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2347 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2349 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_w(szProperty
),
2350 szValue
, pccbValue
);
2353 return ERROR_INVALID_PARAMETER
;
2355 if (szValue
&& !pccbValue
)
2356 return ERROR_INVALID_PARAMETER
;
2358 package
= msihandle2msiinfo(hProduct
, MSIHANDLETYPE_PACKAGE
);
2360 return ERROR_INVALID_HANDLE
;
2362 r
= MSI_OpenQuery(package
->db
, &view
, query
, szProperty
);
2363 if (r
!= ERROR_SUCCESS
)
2366 r
= MSI_ViewExecute(view
, 0);
2367 if (r
!= ERROR_SUCCESS
)
2370 r
= MSI_ViewFetch(view
, &rec
);
2371 if (r
!= ERROR_SUCCESS
)
2374 val
= MSI_RecordGetString(rec
, 2);
2378 if (lstrlenW(val
) >= *pccbValue
)
2380 lstrcpynW(szValue
, val
, *pccbValue
);
2381 *pccbValue
= lstrlenW(val
);
2382 r
= ERROR_MORE_DATA
;
2386 lstrcpyW(szValue
, val
);
2387 *pccbValue
= lstrlenW(val
);
2394 MSI_ViewClose(view
);
2395 msiobj_release(&view
->hdr
);
2396 if (rec
) msiobj_release(&rec
->hdr
);
2401 if (szValue
) *szValue
= '\0';
2402 if (pccbValue
) *pccbValue
= 0;
2406 msiobj_release(&package
->hdr
);
2410 UINT WINAPI
MsiVerifyPackageA( LPCSTR szPackage
)
2413 LPWSTR szPack
= NULL
;
2415 TRACE("%s\n", debugstr_a(szPackage
) );
2419 szPack
= strdupAtoW( szPackage
);
2421 return ERROR_OUTOFMEMORY
;
2424 r
= MsiVerifyPackageW( szPack
);
2431 UINT WINAPI
MsiVerifyPackageW( LPCWSTR szPackage
)
2436 TRACE("%s\n", debugstr_w(szPackage
) );
2438 r
= MsiOpenDatabaseW( szPackage
, MSIDBOPEN_READONLY
, &handle
);
2439 MsiCloseHandle( handle
);
2444 static INSTALLSTATE
MSI_GetComponentPath(LPCWSTR szProduct
, LPCWSTR szComponent
,
2445 awstring
* lpPathBuf
, LPDWORD pcchBuf
)
2447 WCHAR squished_pc
[GUID_SIZE
];
2448 WCHAR squished_comp
[GUID_SIZE
];
2454 static const WCHAR wininstaller
[] = {
2455 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2457 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
2458 debugstr_w(szComponent
), lpPathBuf
->str
.w
, pcchBuf
);
2460 if (!szProduct
|| !szComponent
)
2461 return INSTALLSTATE_INVALIDARG
;
2463 if (lpPathBuf
->str
.w
&& !pcchBuf
)
2464 return INSTALLSTATE_INVALIDARG
;
2466 if (!squash_guid(szProduct
, squished_pc
) ||
2467 !squash_guid(szComponent
, squished_comp
))
2468 return INSTALLSTATE_INVALIDARG
;
2470 state
= INSTALLSTATE_UNKNOWN
;
2472 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2473 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2475 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2478 state
= INSTALLSTATE_ABSENT
;
2480 if ((MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
, NULL
,
2481 &hkey
, FALSE
) == ERROR_SUCCESS
||
2482 MSIREG_OpenUserDataProductKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2483 NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
) &&
2484 msi_reg_get_val_dword(hkey
, wininstaller
, &version
) &&
2485 GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2488 state
= INSTALLSTATE_LOCAL
;
2492 if (state
!= INSTALLSTATE_LOCAL
&&
2493 (MSIREG_OpenProductKey(szProduct
, NULL
,
2494 MSIINSTALLCONTEXT_USERUNMANAGED
,
2495 &hkey
, FALSE
) == ERROR_SUCCESS
||
2496 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2497 &hkey
, FALSE
) == ERROR_SUCCESS
))
2501 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2502 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2505 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2508 state
= INSTALLSTATE_ABSENT
;
2510 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2511 state
= INSTALLSTATE_LOCAL
;
2516 return INSTALLSTATE_UNKNOWN
;
2518 if (state
== INSTALLSTATE_LOCAL
&& !*path
)
2519 state
= INSTALLSTATE_NOTUSED
;
2521 msi_strcpy_to_awstring(path
, lpPathBuf
, pcchBuf
);
2526 /******************************************************************
2527 * MsiGetComponentPathW [MSI.@]
2529 INSTALLSTATE WINAPI
MsiGetComponentPathW(LPCWSTR szProduct
, LPCWSTR szComponent
,
2530 LPWSTR lpPathBuf
, LPDWORD pcchBuf
)
2534 path
.unicode
= TRUE
;
2535 path
.str
.w
= lpPathBuf
;
2537 return MSI_GetComponentPath( szProduct
, szComponent
, &path
, pcchBuf
);
2540 /******************************************************************
2541 * MsiGetComponentPathA [MSI.@]
2543 INSTALLSTATE WINAPI
MsiGetComponentPathA(LPCSTR szProduct
, LPCSTR szComponent
,
2544 LPSTR lpPathBuf
, LPDWORD pcchBuf
)
2546 LPWSTR szwProduct
, szwComponent
= NULL
;
2547 INSTALLSTATE r
= INSTALLSTATE_UNKNOWN
;
2550 szwProduct
= strdupAtoW( szProduct
);
2551 if( szProduct
&& !szwProduct
)
2554 szwComponent
= strdupAtoW( szComponent
);
2555 if( szComponent
&& !szwComponent
)
2558 path
.unicode
= FALSE
;
2559 path
.str
.a
= lpPathBuf
;
2561 r
= MSI_GetComponentPath( szwProduct
, szwComponent
, &path
, pcchBuf
);
2564 msi_free( szwProduct
);
2565 msi_free( szwComponent
);
2570 /******************************************************************
2571 * MsiQueryFeatureStateA [MSI.@]
2573 INSTALLSTATE WINAPI
MsiQueryFeatureStateA(LPCSTR szProduct
, LPCSTR szFeature
)
2575 LPWSTR szwProduct
= NULL
, szwFeature
= NULL
;
2576 INSTALLSTATE rc
= INSTALLSTATE_UNKNOWN
;
2578 szwProduct
= strdupAtoW( szProduct
);
2579 if ( szProduct
&& !szwProduct
)
2582 szwFeature
= strdupAtoW( szFeature
);
2583 if ( szFeature
&& !szwFeature
)
2586 rc
= MsiQueryFeatureStateW(szwProduct
, szwFeature
);
2589 msi_free( szwProduct
);
2590 msi_free( szwFeature
);
2595 /******************************************************************
2596 * MsiQueryFeatureStateW [MSI.@]
2598 * Checks the state of a feature
2601 * szProduct [I] Product's GUID string
2602 * szFeature [I] Feature's GUID string
2605 * INSTALLSTATE_LOCAL Feature is installed and usable
2606 * INSTALLSTATE_ABSENT Feature is absent
2607 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2608 * INSTALLSTATE_UNKNOWN An error occurred
2609 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2612 INSTALLSTATE WINAPI
MsiQueryFeatureStateW(LPCWSTR szProduct
, LPCWSTR szFeature
)
2614 WCHAR squishProduct
[33], comp
[GUID_SIZE
];
2616 LPWSTR components
, p
, parent_feature
, path
;
2620 BOOL missing
= FALSE
;
2621 BOOL machine
= FALSE
;
2622 BOOL source
= FALSE
;
2624 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szFeature
));
2626 if (!szProduct
|| !szFeature
)
2627 return INSTALLSTATE_INVALIDARG
;
2629 if (!squash_guid( szProduct
, squishProduct
))
2630 return INSTALLSTATE_INVALIDARG
;
2632 if (MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERMANAGED
,
2633 &hkey
, FALSE
) != ERROR_SUCCESS
&&
2634 MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2635 &hkey
, FALSE
) != ERROR_SUCCESS
)
2637 rc
= MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
2639 if (rc
!= ERROR_SUCCESS
)
2640 return INSTALLSTATE_UNKNOWN
;
2645 parent_feature
= msi_reg_get_val_str( hkey
, szFeature
);
2648 if (!parent_feature
)
2649 return INSTALLSTATE_UNKNOWN
;
2651 r
= (parent_feature
[0] == 6) ? INSTALLSTATE_ABSENT
: INSTALLSTATE_LOCAL
;
2652 msi_free(parent_feature
);
2653 if (r
== INSTALLSTATE_ABSENT
)
2657 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2658 MSIINSTALLCONTEXT_MACHINE
,
2661 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2662 MSIINSTALLCONTEXT_USERUNMANAGED
,
2665 if (rc
!= ERROR_SUCCESS
)
2666 return INSTALLSTATE_ADVERTISED
;
2668 components
= msi_reg_get_val_str( hkey
, szFeature
);
2671 TRACE("rc = %d buffer = %s\n", rc
, debugstr_w(components
));
2674 return INSTALLSTATE_ADVERTISED
;
2676 for( p
= components
; *p
&& *p
!= 2 ; p
+= 20)
2678 if (!decode_base85_guid( p
, &guid
))
2680 if (p
!= components
)
2683 msi_free(components
);
2684 return INSTALLSTATE_BADCONFIG
;
2687 StringFromGUID2(&guid
, comp
, GUID_SIZE
);
2690 rc
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2692 rc
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2694 if (rc
!= ERROR_SUCCESS
)
2696 msi_free(components
);
2697 return INSTALLSTATE_ADVERTISED
;
2700 path
= msi_reg_get_val_str(hkey
, squishProduct
);
2703 else if (lstrlenW(path
) > 2 &&
2704 path
[0] >= '0' && path
[0] <= '9' &&
2705 path
[1] >= '0' && path
[1] <= '9')
2713 TRACE("%s %s -> %d\n", debugstr_w(szProduct
), debugstr_w(szFeature
), r
);
2714 msi_free(components
);
2717 return INSTALLSTATE_ADVERTISED
;
2720 return INSTALLSTATE_SOURCE
;
2722 return INSTALLSTATE_LOCAL
;
2725 /******************************************************************
2726 * MsiGetFileVersionA [MSI.@]
2728 UINT WINAPI
MsiGetFileVersionA(LPCSTR szFilePath
, LPSTR lpVersionBuf
,
2729 LPDWORD pcchVersionBuf
, LPSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2731 LPWSTR szwFilePath
= NULL
, lpwVersionBuff
= NULL
, lpwLangBuff
= NULL
;
2732 UINT ret
= ERROR_OUTOFMEMORY
;
2734 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
2735 (lpLangBuf
&& !pcchLangBuf
))
2736 return ERROR_INVALID_PARAMETER
;
2740 szwFilePath
= strdupAtoW( szFilePath
);
2745 if( lpVersionBuf
&& pcchVersionBuf
&& *pcchVersionBuf
)
2747 lpwVersionBuff
= msi_alloc(*pcchVersionBuf
*sizeof(WCHAR
));
2748 if( !lpwVersionBuff
)
2752 if( lpLangBuf
&& pcchLangBuf
&& *pcchLangBuf
)
2754 lpwLangBuff
= msi_alloc(*pcchLangBuf
*sizeof(WCHAR
));
2759 ret
= MsiGetFileVersionW(szwFilePath
, lpwVersionBuff
, pcchVersionBuf
,
2760 lpwLangBuff
, pcchLangBuf
);
2762 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwVersionBuff
)
2763 WideCharToMultiByte(CP_ACP
, 0, lpwVersionBuff
, -1,
2764 lpVersionBuf
, *pcchVersionBuf
+ 1, NULL
, NULL
);
2765 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwLangBuff
)
2766 WideCharToMultiByte(CP_ACP
, 0, lpwLangBuff
, -1,
2767 lpLangBuf
, *pcchLangBuf
+ 1, NULL
, NULL
);
2770 msi_free(szwFilePath
);
2771 msi_free(lpwVersionBuff
);
2772 msi_free(lpwLangBuff
);
2777 /******************************************************************
2778 * MsiGetFileVersionW [MSI.@]
2780 UINT WINAPI
MsiGetFileVersionW(LPCWSTR szFilePath
, LPWSTR lpVersionBuf
,
2781 LPDWORD pcchVersionBuf
, LPWSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2783 static const WCHAR szVersionResource
[] = {'\\',0};
2784 static const WCHAR szVersionFormat
[] = {
2785 '%','d','.','%','d','.','%','d','.','%','d',0};
2786 static const WCHAR szLangResource
[] = {
2787 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2788 'T','r','a','n','s','l','a','t','i','o','n',0};
2789 static const WCHAR szLangFormat
[] = {'%','d',0};
2791 DWORD dwVerLen
, gle
;
2792 LPVOID lpVer
= NULL
;
2793 VS_FIXEDFILEINFO
*ffi
;
2798 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath
),
2799 lpVersionBuf
, pcchVersionBuf
?*pcchVersionBuf
:0,
2800 lpLangBuf
, pcchLangBuf
?*pcchLangBuf
:0);
2802 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
2803 (lpLangBuf
&& !pcchLangBuf
))
2804 return ERROR_INVALID_PARAMETER
;
2806 dwVerLen
= GetFileVersionInfoSizeW(szFilePath
, NULL
);
2809 gle
= GetLastError();
2810 if (gle
== ERROR_BAD_PATHNAME
)
2811 return ERROR_FILE_NOT_FOUND
;
2812 else if (gle
== ERROR_RESOURCE_DATA_NOT_FOUND
)
2813 return ERROR_FILE_INVALID
;
2818 lpVer
= msi_alloc(dwVerLen
);
2821 ret
= ERROR_OUTOFMEMORY
;
2825 if( !GetFileVersionInfoW(szFilePath
, 0, dwVerLen
, lpVer
) )
2827 ret
= GetLastError();
2833 if( VerQueryValueW(lpVer
, szVersionResource
, (LPVOID
*)&ffi
, &puLen
) &&
2836 wsprintfW(tmp
, szVersionFormat
,
2837 HIWORD(ffi
->dwFileVersionMS
), LOWORD(ffi
->dwFileVersionMS
),
2838 HIWORD(ffi
->dwFileVersionLS
), LOWORD(ffi
->dwFileVersionLS
));
2839 if (lpVersionBuf
) lstrcpynW(lpVersionBuf
, tmp
, *pcchVersionBuf
);
2841 if (strlenW(tmp
) >= *pcchVersionBuf
)
2842 ret
= ERROR_MORE_DATA
;
2844 *pcchVersionBuf
= lstrlenW(tmp
);
2848 if (lpVersionBuf
) *lpVersionBuf
= 0;
2849 *pcchVersionBuf
= 0;
2855 if (VerQueryValueW(lpVer
, szLangResource
, (LPVOID
*)&lang
, &puLen
) &&
2858 wsprintfW(tmp
, szLangFormat
, *lang
);
2859 if (lpLangBuf
) lstrcpynW(lpLangBuf
, tmp
, *pcchLangBuf
);
2861 if (strlenW(tmp
) >= *pcchLangBuf
)
2862 ret
= ERROR_MORE_DATA
;
2864 *pcchLangBuf
= lstrlenW(tmp
);
2868 if (lpLangBuf
) *lpLangBuf
= 0;
2878 /***********************************************************************
2879 * MsiGetFeatureUsageW [MSI.@]
2881 UINT WINAPI
MsiGetFeatureUsageW( LPCWSTR szProduct
, LPCWSTR szFeature
,
2882 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
2884 FIXME("%s %s %p %p\n",debugstr_w(szProduct
), debugstr_w(szFeature
),
2885 pdwUseCount
, pwDateUsed
);
2886 return ERROR_CALL_NOT_IMPLEMENTED
;
2889 /***********************************************************************
2890 * MsiGetFeatureUsageA [MSI.@]
2892 UINT WINAPI
MsiGetFeatureUsageA( LPCSTR szProduct
, LPCSTR szFeature
,
2893 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
2895 LPWSTR prod
= NULL
, feat
= NULL
;
2896 UINT ret
= ERROR_OUTOFMEMORY
;
2898 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
2899 pdwUseCount
, pwDateUsed
);
2901 prod
= strdupAtoW( szProduct
);
2902 if (szProduct
&& !prod
)
2905 feat
= strdupAtoW( szFeature
);
2906 if (szFeature
&& !feat
)
2909 ret
= MsiGetFeatureUsageW( prod
, feat
, pdwUseCount
, pwDateUsed
);
2918 /***********************************************************************
2919 * MsiUseFeatureExW [MSI.@]
2921 INSTALLSTATE WINAPI
MsiUseFeatureExW( LPCWSTR szProduct
, LPCWSTR szFeature
,
2922 DWORD dwInstallMode
, DWORD dwReserved
)
2926 TRACE("%s %s %i %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
2927 dwInstallMode
, dwReserved
);
2929 state
= MsiQueryFeatureStateW( szProduct
, szFeature
);
2932 return INSTALLSTATE_INVALIDARG
;
2934 if (state
== INSTALLSTATE_LOCAL
&& dwInstallMode
!= INSTALLMODE_NODETECTION
)
2936 FIXME("mark product %s feature %s as used\n",
2937 debugstr_w(szProduct
), debugstr_w(szFeature
) );
2943 /***********************************************************************
2944 * MsiUseFeatureExA [MSI.@]
2946 INSTALLSTATE WINAPI
MsiUseFeatureExA( LPCSTR szProduct
, LPCSTR szFeature
,
2947 DWORD dwInstallMode
, DWORD dwReserved
)
2949 INSTALLSTATE ret
= INSTALLSTATE_UNKNOWN
;
2950 LPWSTR prod
= NULL
, feat
= NULL
;
2952 TRACE("%s %s %i %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
2953 dwInstallMode
, dwReserved
);
2955 prod
= strdupAtoW( szProduct
);
2956 if (szProduct
&& !prod
)
2959 feat
= strdupAtoW( szFeature
);
2960 if (szFeature
&& !feat
)
2963 ret
= MsiUseFeatureExW( prod
, feat
, dwInstallMode
, dwReserved
);
2972 /***********************************************************************
2973 * MsiUseFeatureW [MSI.@]
2975 INSTALLSTATE WINAPI
MsiUseFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
)
2977 return MsiUseFeatureExW(szProduct
, szFeature
, 0, 0);
2980 /***********************************************************************
2981 * MsiUseFeatureA [MSI.@]
2983 INSTALLSTATE WINAPI
MsiUseFeatureA( LPCSTR szProduct
, LPCSTR szFeature
)
2985 return MsiUseFeatureExA(szProduct
, szFeature
, 0, 0);
2988 /***********************************************************************
2989 * MSI_ProvideQualifiedComponentEx [internal]
2991 static UINT
MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent
,
2992 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
2993 DWORD Unused1
, DWORD Unused2
, awstring
*lpPathBuf
,
2994 LPDWORD pcchPathBuf
)
2996 WCHAR product
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1],
2997 feature
[MAX_FEATURE_CHARS
+1];
3003 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent
),
3004 debugstr_w(szQualifier
), dwInstallMode
, debugstr_w(szProduct
),
3005 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3007 rc
= MSIREG_OpenUserComponentsKey(szComponent
, &hkey
, FALSE
);
3008 if (rc
!= ERROR_SUCCESS
)
3009 return ERROR_INDEX_ABSENT
;
3011 info
= msi_reg_get_val_str( hkey
, szQualifier
);
3015 return ERROR_INDEX_ABSENT
;
3017 MsiDecomposeDescriptorW(info
, product
, feature
, component
, &sz
);
3020 rc
= MSI_GetComponentPath(product
, component
, lpPathBuf
, pcchPathBuf
);
3022 rc
= MSI_GetComponentPath(szProduct
, component
, lpPathBuf
, pcchPathBuf
);
3026 if (rc
!= INSTALLSTATE_LOCAL
)
3027 return ERROR_FILE_NOT_FOUND
;
3029 return ERROR_SUCCESS
;
3032 /***********************************************************************
3033 * MsiProvideQualifiedComponentExW [MSI.@]
3035 UINT WINAPI
MsiProvideQualifiedComponentExW(LPCWSTR szComponent
,
3036 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3037 DWORD Unused1
, DWORD Unused2
, LPWSTR lpPathBuf
,
3038 LPDWORD pcchPathBuf
)
3042 path
.unicode
= TRUE
;
3043 path
.str
.w
= lpPathBuf
;
3045 return MSI_ProvideQualifiedComponentEx(szComponent
, szQualifier
,
3046 dwInstallMode
, szProduct
, Unused1
, Unused2
, &path
, pcchPathBuf
);
3049 /***********************************************************************
3050 * MsiProvideQualifiedComponentExA [MSI.@]
3052 UINT WINAPI
MsiProvideQualifiedComponentExA(LPCSTR szComponent
,
3053 LPCSTR szQualifier
, DWORD dwInstallMode
, LPCSTR szProduct
,
3054 DWORD Unused1
, DWORD Unused2
, LPSTR lpPathBuf
,
3055 LPDWORD pcchPathBuf
)
3057 LPWSTR szwComponent
, szwQualifier
= NULL
, szwProduct
= NULL
;
3058 UINT r
= ERROR_OUTOFMEMORY
;
3061 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent
),
3062 debugstr_a(szQualifier
), dwInstallMode
, debugstr_a(szProduct
),
3063 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3065 szwComponent
= strdupAtoW( szComponent
);
3066 if (szComponent
&& !szwComponent
)
3069 szwQualifier
= strdupAtoW( szQualifier
);
3070 if (szQualifier
&& !szwQualifier
)
3073 szwProduct
= strdupAtoW( szProduct
);
3074 if (szProduct
&& !szwProduct
)
3077 path
.unicode
= FALSE
;
3078 path
.str
.a
= lpPathBuf
;
3080 r
= MSI_ProvideQualifiedComponentEx(szwComponent
, szwQualifier
,
3081 dwInstallMode
, szwProduct
, Unused1
,
3082 Unused2
, &path
, pcchPathBuf
);
3084 msi_free(szwProduct
);
3085 msi_free(szwComponent
);
3086 msi_free(szwQualifier
);
3091 /***********************************************************************
3092 * MsiProvideQualifiedComponentW [MSI.@]
3094 UINT WINAPI
MsiProvideQualifiedComponentW( LPCWSTR szComponent
,
3095 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPWSTR lpPathBuf
,
3096 LPDWORD pcchPathBuf
)
3098 return MsiProvideQualifiedComponentExW(szComponent
, szQualifier
,
3099 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3102 /***********************************************************************
3103 * MsiProvideQualifiedComponentA [MSI.@]
3105 UINT WINAPI
MsiProvideQualifiedComponentA( LPCSTR szComponent
,
3106 LPCSTR szQualifier
, DWORD dwInstallMode
, LPSTR lpPathBuf
,
3107 LPDWORD pcchPathBuf
)
3109 return MsiProvideQualifiedComponentExA(szComponent
, szQualifier
,
3110 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3113 /***********************************************************************
3114 * MSI_GetUserInfo [internal]
3116 static USERINFOSTATE
MSI_GetUserInfo(LPCWSTR szProduct
,
3117 awstring
*lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3118 awstring
*lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3119 awstring
*lpSerialBuf
, LPDWORD pcchSerialBuf
)
3121 WCHAR squished_pc
[SQUISH_GUID_SIZE
];
3122 LPWSTR user
, org
, serial
;
3123 USERINFOSTATE state
;
3128 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct
), lpUserNameBuf
,
3129 pcchUserNameBuf
, lpOrgNameBuf
, pcchOrgNameBuf
, lpSerialBuf
,
3132 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
3133 return USERINFOSTATE_INVALIDARG
;
3135 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
3136 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3137 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3138 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3139 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
3140 &hkey
, FALSE
) != ERROR_SUCCESS
)
3142 return USERINFOSTATE_UNKNOWN
;
3145 if (MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3146 NULL
, &props
, FALSE
) != ERROR_SUCCESS
&&
3147 MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
3148 NULL
, &props
, FALSE
) != ERROR_SUCCESS
)
3151 return USERINFOSTATE_ABSENT
;
3154 user
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGOWNERW
);
3155 org
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGCOMPANYW
);
3156 serial
= msi_reg_get_val_str(props
, INSTALLPROPERTY_PRODUCTIDW
);
3157 state
= USERINFOSTATE_ABSENT
;
3163 state
= USERINFOSTATE_PRESENT
;
3165 if (pcchUserNameBuf
)
3167 if (lpUserNameBuf
&& !user
)
3169 (*pcchUserNameBuf
)--;
3173 r
= msi_strcpy_to_awstring(user
, lpUserNameBuf
, pcchUserNameBuf
);
3174 if (r
== ERROR_MORE_DATA
)
3176 state
= USERINFOSTATE_MOREDATA
;
3184 if (!orgptr
) orgptr
= szEmpty
;
3186 r
= msi_strcpy_to_awstring(orgptr
, lpOrgNameBuf
, pcchOrgNameBuf
);
3187 if (r
== ERROR_MORE_DATA
)
3189 state
= USERINFOSTATE_MOREDATA
;
3202 r
= msi_strcpy_to_awstring(serial
, lpSerialBuf
, pcchSerialBuf
);
3203 if (r
== ERROR_MORE_DATA
)
3204 state
= USERINFOSTATE_MOREDATA
;
3215 /***********************************************************************
3216 * MsiGetUserInfoW [MSI.@]
3218 USERINFOSTATE WINAPI
MsiGetUserInfoW(LPCWSTR szProduct
,
3219 LPWSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3220 LPWSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3221 LPWSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3223 awstring user
, org
, serial
;
3225 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3226 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3227 (lpSerialBuf
&& !pcchSerialBuf
))
3228 return USERINFOSTATE_INVALIDARG
;
3230 user
.unicode
= TRUE
;
3231 user
.str
.w
= lpUserNameBuf
;
3233 org
.str
.w
= lpOrgNameBuf
;
3234 serial
.unicode
= TRUE
;
3235 serial
.str
.w
= lpSerialBuf
;
3237 return MSI_GetUserInfo( szProduct
, &user
, pcchUserNameBuf
,
3238 &org
, pcchOrgNameBuf
,
3239 &serial
, pcchSerialBuf
);
3242 USERINFOSTATE WINAPI
MsiGetUserInfoA(LPCSTR szProduct
,
3243 LPSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3244 LPSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3245 LPSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3247 awstring user
, org
, serial
;
3251 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3252 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3253 (lpSerialBuf
&& !pcchSerialBuf
))
3254 return USERINFOSTATE_INVALIDARG
;
3256 prod
= strdupAtoW( szProduct
);
3257 if (szProduct
&& !prod
)
3258 return ERROR_OUTOFMEMORY
;
3260 user
.unicode
= FALSE
;
3261 user
.str
.a
= lpUserNameBuf
;
3262 org
.unicode
= FALSE
;
3263 org
.str
.a
= lpOrgNameBuf
;
3264 serial
.unicode
= FALSE
;
3265 serial
.str
.a
= lpSerialBuf
;
3267 r
= MSI_GetUserInfo( prod
, &user
, pcchUserNameBuf
,
3268 &org
, pcchOrgNameBuf
,
3269 &serial
, pcchSerialBuf
);
3276 UINT WINAPI
MsiCollectUserInfoW(LPCWSTR szProduct
)
3280 MSIPACKAGE
*package
;
3281 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3283 TRACE("(%s)\n",debugstr_w(szProduct
));
3285 rc
= MsiOpenProductW(szProduct
,&handle
);
3286 if (rc
!= ERROR_SUCCESS
)
3287 return ERROR_INVALID_PARAMETER
;
3289 /* MsiCollectUserInfo cannot be called from a custom action. */
3290 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3292 return ERROR_CALL_NOT_IMPLEMENTED
;
3294 rc
= ACTION_PerformUIAction(package
, szFirstRun
, -1);
3295 msiobj_release( &package
->hdr
);
3297 MsiCloseHandle(handle
);
3302 UINT WINAPI
MsiCollectUserInfoA(LPCSTR szProduct
)
3306 MSIPACKAGE
*package
;
3307 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3309 TRACE("(%s)\n",debugstr_a(szProduct
));
3311 rc
= MsiOpenProductA(szProduct
,&handle
);
3312 if (rc
!= ERROR_SUCCESS
)
3313 return ERROR_INVALID_PARAMETER
;
3315 /* MsiCollectUserInfo cannot be called from a custom action. */
3316 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3318 return ERROR_CALL_NOT_IMPLEMENTED
;
3320 rc
= ACTION_PerformUIAction(package
, szFirstRun
, -1);
3321 msiobj_release( &package
->hdr
);
3323 MsiCloseHandle(handle
);
3328 /***********************************************************************
3329 * MsiConfigureFeatureA [MSI.@]
3331 UINT WINAPI
MsiConfigureFeatureA(LPCSTR szProduct
, LPCSTR szFeature
, INSTALLSTATE eInstallState
)
3333 LPWSTR prod
, feat
= NULL
;
3334 UINT r
= ERROR_OUTOFMEMORY
;
3336 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
), eInstallState
);
3338 prod
= strdupAtoW( szProduct
);
3339 if (szProduct
&& !prod
)
3342 feat
= strdupAtoW( szFeature
);
3343 if (szFeature
&& !feat
)
3346 r
= MsiConfigureFeatureW(prod
, feat
, eInstallState
);
3355 /***********************************************************************
3356 * MsiConfigureFeatureW [MSI.@]
3358 UINT WINAPI
MsiConfigureFeatureW(LPCWSTR szProduct
, LPCWSTR szFeature
, INSTALLSTATE eInstallState
)
3360 static const WCHAR szCostInit
[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3361 MSIPACKAGE
*package
= NULL
;
3363 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
3366 TRACE("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
), eInstallState
);
3368 if (!szProduct
|| !szFeature
)
3369 return ERROR_INVALID_PARAMETER
;
3371 switch (eInstallState
)
3373 case INSTALLSTATE_DEFAULT
:
3374 /* FIXME: how do we figure out the default location? */
3375 eInstallState
= INSTALLSTATE_LOCAL
;
3377 case INSTALLSTATE_LOCAL
:
3378 case INSTALLSTATE_SOURCE
:
3379 case INSTALLSTATE_ABSENT
:
3380 case INSTALLSTATE_ADVERTISED
:
3383 return ERROR_INVALID_PARAMETER
;
3386 r
= MSI_OpenProductW( szProduct
, &package
);
3387 if (r
!= ERROR_SUCCESS
)
3390 sz
= sizeof(sourcepath
);
3391 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3392 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3394 sz
= sizeof(filename
);
3395 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3396 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3398 lstrcatW( sourcepath
, filename
);
3400 MsiSetInternalUI( INSTALLUILEVEL_BASIC
, NULL
);
3402 r
= ACTION_PerformUIAction( package
, szCostInit
, -1 );
3403 if (r
!= ERROR_SUCCESS
)
3406 r
= MSI_SetFeatureStateW( package
, szFeature
, eInstallState
);
3407 if (r
!= ERROR_SUCCESS
)
3410 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3413 msiobj_release( &package
->hdr
);
3418 /***********************************************************************
3419 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3421 * Notes: undocumented
3423 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved
)
3425 WCHAR path
[MAX_PATH
];
3427 TRACE("%d\n", dwReserved
);
3431 FIXME("dwReserved=%d\n", dwReserved
);
3432 return ERROR_INVALID_PARAMETER
;
3435 if (!GetWindowsDirectoryW(path
, MAX_PATH
))
3436 return ERROR_FUNCTION_FAILED
;
3438 lstrcatW(path
, installerW
);
3440 if (!CreateDirectoryW(path
, NULL
))
3441 return ERROR_FUNCTION_FAILED
;
3443 return ERROR_SUCCESS
;
3446 /***********************************************************************
3447 * MsiGetShortcutTargetA [MSI.@]
3449 UINT WINAPI
MsiGetShortcutTargetA( LPCSTR szShortcutTarget
,
3450 LPSTR szProductCode
, LPSTR szFeatureId
,
3451 LPSTR szComponentCode
)
3454 const int len
= MAX_FEATURE_CHARS
+1;
3455 WCHAR product
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1];
3458 target
= strdupAtoW( szShortcutTarget
);
3459 if (szShortcutTarget
&& !target
)
3460 return ERROR_OUTOFMEMORY
;
3464 r
= MsiGetShortcutTargetW( target
, product
, feature
, component
);
3466 if (r
== ERROR_SUCCESS
)
3468 WideCharToMultiByte( CP_ACP
, 0, product
, -1, szProductCode
, len
, NULL
, NULL
);
3469 WideCharToMultiByte( CP_ACP
, 0, feature
, -1, szFeatureId
, len
, NULL
, NULL
);
3470 WideCharToMultiByte( CP_ACP
, 0, component
, -1, szComponentCode
, len
, NULL
, NULL
);
3475 /***********************************************************************
3476 * MsiGetShortcutTargetW [MSI.@]
3478 UINT WINAPI
MsiGetShortcutTargetW( LPCWSTR szShortcutTarget
,
3479 LPWSTR szProductCode
, LPWSTR szFeatureId
,
3480 LPWSTR szComponentCode
)
3482 IShellLinkDataList
*dl
= NULL
;
3483 IPersistFile
*pf
= NULL
;
3484 LPEXP_DARWIN_LINK darwin
= NULL
;
3487 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget
),
3488 szProductCode
, szFeatureId
, szComponentCode
);
3490 init
= CoInitialize(NULL
);
3492 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3493 &IID_IPersistFile
, (LPVOID
*) &pf
);
3494 if( SUCCEEDED( r
) )
3496 r
= IPersistFile_Load( pf
, szShortcutTarget
,
3497 STGM_READ
| STGM_SHARE_DENY_WRITE
);
3498 if( SUCCEEDED( r
) )
3500 r
= IPersistFile_QueryInterface( pf
, &IID_IShellLinkDataList
,
3502 if( SUCCEEDED( r
) )
3504 IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
,
3506 IShellLinkDataList_Release( dl
);
3509 IPersistFile_Release( pf
);
3512 if (SUCCEEDED(init
))
3515 TRACE("darwin = %p\n", darwin
);
3522 ret
= MsiDecomposeDescriptorW( darwin
->szwDarwinID
,
3523 szProductCode
, szFeatureId
, szComponentCode
, &sz
);
3524 LocalFree( darwin
);
3528 return ERROR_FUNCTION_FAILED
;
3531 UINT WINAPI
MsiReinstallFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3532 DWORD dwReinstallMode
)
3534 MSIPACKAGE
* package
= NULL
;
3536 WCHAR sourcepath
[MAX_PATH
];
3537 WCHAR filename
[MAX_PATH
];
3538 static const WCHAR szLogVerbose
[] = {
3539 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3540 WCHAR reinstallmode
[11];
3544 FIXME("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
3547 ptr
= reinstallmode
;
3549 if (dwReinstallMode
& REINSTALLMODE_FILEMISSING
)
3551 if (dwReinstallMode
& REINSTALLMODE_FILEOLDERVERSION
)
3553 if (dwReinstallMode
& REINSTALLMODE_FILEEQUALVERSION
)
3555 if (dwReinstallMode
& REINSTALLMODE_FILEEXACT
)
3557 if (dwReinstallMode
& REINSTALLMODE_FILEVERIFY
)
3559 if (dwReinstallMode
& REINSTALLMODE_FILEREPLACE
)
3561 if (dwReinstallMode
& REINSTALLMODE_USERDATA
)
3563 if (dwReinstallMode
& REINSTALLMODE_MACHINEDATA
)
3565 if (dwReinstallMode
& REINSTALLMODE_SHORTCUT
)
3567 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3571 sz
= sizeof(sourcepath
);
3572 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3573 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3575 sz
= sizeof(filename
);
3576 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3577 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3579 lstrcatW( sourcepath
, filename
);
3581 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3582 r
= MSI_OpenPackageW( sourcepath
, &package
);
3584 r
= MSI_OpenProductW( szProduct
, &package
);
3586 if (r
!= ERROR_SUCCESS
)
3589 msi_set_property( package
->db
, szReinstallMode
, reinstallmode
);
3590 msi_set_property( package
->db
, szInstalled
, szOne
);
3591 msi_set_property( package
->db
, szLogVerbose
, szOne
);
3592 msi_set_property( package
->db
, szReinstall
, szFeature
);
3594 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3596 msiobj_release( &package
->hdr
);
3601 UINT WINAPI
MsiReinstallFeatureA( LPCSTR szProduct
, LPCSTR szFeature
,
3602 DWORD dwReinstallMode
)
3608 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3611 wszProduct
= strdupAtoW(szProduct
);
3612 wszFeature
= strdupAtoW(szFeature
);
3614 rc
= MsiReinstallFeatureW(wszProduct
, wszFeature
, dwReinstallMode
);
3616 msi_free(wszProduct
);
3617 msi_free(wszFeature
);
3624 unsigned int buf
[4];
3625 unsigned char in
[64];
3626 unsigned char digest
[16];
3629 extern VOID WINAPI
MD5Init( MD5_CTX
*);
3630 extern VOID WINAPI
MD5Update( MD5_CTX
*, const unsigned char *, unsigned int );
3631 extern VOID WINAPI
MD5Final( MD5_CTX
*);
3633 /***********************************************************************
3634 * MsiGetFileHashW [MSI.@]
3636 UINT WINAPI
MsiGetFileHashW( LPCWSTR szFilePath
, DWORD dwOptions
,
3637 PMSIFILEHASHINFO pHash
)
3639 HANDLE handle
, mapping
;
3642 UINT r
= ERROR_FUNCTION_FAILED
;
3644 TRACE("%s %08x %p\n", debugstr_w(szFilePath
), dwOptions
, pHash
);
3647 return ERROR_INVALID_PARAMETER
;
3650 return ERROR_PATH_NOT_FOUND
;
3653 return ERROR_INVALID_PARAMETER
;
3655 return ERROR_INVALID_PARAMETER
;
3656 if (pHash
->dwFileHashInfoSize
< sizeof *pHash
)
3657 return ERROR_INVALID_PARAMETER
;
3659 handle
= CreateFileW( szFilePath
, GENERIC_READ
,
3660 FILE_SHARE_READ
| FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, 0, NULL
);
3661 if (handle
== INVALID_HANDLE_VALUE
)
3662 return ERROR_FILE_NOT_FOUND
;
3664 length
= GetFileSize( handle
, NULL
);
3666 mapping
= CreateFileMappingW( handle
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
3669 p
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, length
);
3675 MD5Update( &ctx
, p
, length
);
3677 UnmapViewOfFile( p
);
3679 memcpy( pHash
->dwData
, ctx
.digest
, sizeof pHash
->dwData
);
3682 CloseHandle( mapping
);
3684 CloseHandle( handle
);
3689 /***********************************************************************
3690 * MsiGetFileHashA [MSI.@]
3692 UINT WINAPI
MsiGetFileHashA( LPCSTR szFilePath
, DWORD dwOptions
,
3693 PMSIFILEHASHINFO pHash
)
3698 TRACE("%s %08x %p\n", debugstr_a(szFilePath
), dwOptions
, pHash
);
3700 file
= strdupAtoW( szFilePath
);
3701 if (szFilePath
&& !file
)
3702 return ERROR_OUTOFMEMORY
;
3704 r
= MsiGetFileHashW( file
, dwOptions
, pHash
);
3709 /***********************************************************************
3710 * MsiAdvertiseScriptW [MSI.@]
3712 UINT WINAPI
MsiAdvertiseScriptW( LPCWSTR szScriptFile
, DWORD dwFlags
,
3713 PHKEY phRegData
, BOOL fRemoveItems
)
3715 FIXME("%s %08x %p %d\n",
3716 debugstr_w( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3717 return ERROR_CALL_NOT_IMPLEMENTED
;
3720 /***********************************************************************
3721 * MsiAdvertiseScriptA [MSI.@]
3723 UINT WINAPI
MsiAdvertiseScriptA( LPCSTR szScriptFile
, DWORD dwFlags
,
3724 PHKEY phRegData
, BOOL fRemoveItems
)
3726 FIXME("%s %08x %p %d\n",
3727 debugstr_a( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3728 return ERROR_CALL_NOT_IMPLEMENTED
;
3731 /***********************************************************************
3732 * MsiIsProductElevatedW [MSI.@]
3734 UINT WINAPI
MsiIsProductElevatedW( LPCWSTR szProduct
, BOOL
*pfElevated
)
3736 FIXME("%s %p - stub\n",
3737 debugstr_w( szProduct
), pfElevated
);
3739 return ERROR_SUCCESS
;
3742 /***********************************************************************
3743 * MsiIsProductElevatedA [MSI.@]
3745 UINT WINAPI
MsiIsProductElevatedA( LPCSTR szProduct
, BOOL
*pfElevated
)
3747 FIXME("%s %p - stub\n",
3748 debugstr_a( szProduct
), pfElevated
);
3750 return ERROR_SUCCESS
;
3753 /***********************************************************************
3754 * MsiSetExternalUIRecord [MSI.@]
3756 UINT WINAPI
MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler
,
3757 DWORD filter
, LPVOID context
,
3758 PINSTALLUI_HANDLER_RECORD prev
)
3760 TRACE("%p %08x %p %p\n", handler
, filter
, context
, prev
);
3763 *prev
= gUIHandlerRecord
;
3765 gUIHandlerRecord
= handler
;
3767 gUIContext
= context
;
3769 return ERROR_SUCCESS
;
3772 /***********************************************************************
3773 * MsiInstallMissingComponentW [MSI.@]
3775 UINT WINAPI
MsiInstallMissingComponentW(LPCWSTR szProduct
, LPCWSTR szComponent
, INSTALLSTATE eInstallState
)
3777 FIXME("(%s %s %d\n", debugstr_w(szProduct
), debugstr_w(szComponent
), eInstallState
);
3778 return ERROR_SUCCESS
;
3781 /***********************************************************************
3782 * MsiBeginTransactionA [MSI.@]
3784 UINT WINAPI
MsiBeginTransactionA( LPCSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
3789 FIXME("%s %u %p %p\n", debugstr_a(name
), attrs
, id
, event
);
3791 nameW
= strdupAtoW( name
);
3793 return ERROR_OUTOFMEMORY
;
3795 r
= MsiBeginTransactionW( nameW
, attrs
, id
, event
);
3800 /***********************************************************************
3801 * MsiBeginTransactionW [MSI.@]
3803 UINT WINAPI
MsiBeginTransactionW( LPCWSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
3805 FIXME("%s %u %p %p\n", debugstr_w(name
), attrs
, id
, event
);
3807 *id
= (MSIHANDLE
)0xdeadbeef;
3808 *event
= (HANDLE
)0xdeadbeef;
3810 return ERROR_SUCCESS
;
3813 /***********************************************************************
3814 * MsiEndTransaction [MSI.@]
3816 UINT WINAPI
MsiEndTransaction( DWORD state
)
3818 FIXME("%u\n", state
);
3819 return ERROR_SUCCESS
;