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 szInstallLevel
[] = {
688 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
689 static const WCHAR szRemoveAll
[] = {
690 ' ','R','E','M','O','V','E','=','A','L','L',0};
691 static const WCHAR szMachine
[] = {
692 ' ','A','L','L','U','S','E','R','S','=','1',0};
694 TRACE("%s %d %d %s\n",debugstr_w(szProduct
), iInstallLevel
, eInstallState
,
695 debugstr_w(szCommandLine
));
697 if (!szProduct
|| lstrlenW(szProduct
) != GUID_SIZE
- 1)
698 return ERROR_INVALID_PARAMETER
;
700 if (eInstallState
== INSTALLSTATE_ADVERTISED
||
701 eInstallState
== INSTALLSTATE_SOURCE
)
703 FIXME("State %d not implemented\n", eInstallState
);
704 return ERROR_CALL_NOT_IMPLEMENTED
;
707 r
= msi_locate_product(szProduct
, &context
);
708 if (r
!= ERROR_SUCCESS
)
711 r
= msi_open_package(szProduct
, context
, &package
);
712 if (r
!= ERROR_SUCCESS
)
715 sz
= lstrlenW(szInstalled
) + 1;
718 sz
+= lstrlenW(szCommandLine
);
720 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
721 sz
+= lstrlenW(szInstallLevel
);
723 if (eInstallState
== INSTALLSTATE_ABSENT
)
724 sz
+= lstrlenW(szRemoveAll
);
726 if (context
== MSIINSTALLCONTEXT_MACHINE
)
727 sz
+= lstrlenW(szMachine
);
729 commandline
= msi_alloc(sz
* sizeof(WCHAR
));
732 r
= ERROR_OUTOFMEMORY
;
738 lstrcpyW(commandline
,szCommandLine
);
740 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
741 lstrcatW(commandline
, szInstallLevel
);
743 if (eInstallState
== INSTALLSTATE_ABSENT
)
744 lstrcatW(commandline
, szRemoveAll
);
746 if (context
== MSIINSTALLCONTEXT_MACHINE
)
747 lstrcatW(commandline
, szMachine
);
749 sz
= sizeof(sourcepath
);
750 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
751 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
753 sz
= sizeof(filename
);
754 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
755 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
757 strcatW(sourcepath
, filename
);
759 r
= MSI_InstallPackage( package
, sourcepath
, commandline
);
761 msi_free(commandline
);
764 msiobj_release( &package
->hdr
);
769 UINT WINAPI
MsiConfigureProductExA(LPCSTR szProduct
, int iInstallLevel
,
770 INSTALLSTATE eInstallState
, LPCSTR szCommandLine
)
772 LPWSTR szwProduct
= NULL
;
773 LPWSTR szwCommandLine
= NULL
;
774 UINT r
= ERROR_OUTOFMEMORY
;
778 szwProduct
= strdupAtoW( szProduct
);
785 szwCommandLine
= strdupAtoW( szCommandLine
);
790 r
= MsiConfigureProductExW( szwProduct
, iInstallLevel
, eInstallState
,
793 msi_free( szwProduct
);
794 msi_free( szwCommandLine
);
799 UINT WINAPI
MsiConfigureProductA(LPCSTR szProduct
, int iInstallLevel
,
800 INSTALLSTATE eInstallState
)
802 LPWSTR szwProduct
= NULL
;
805 TRACE("%s %d %d\n",debugstr_a(szProduct
), iInstallLevel
, eInstallState
);
809 szwProduct
= strdupAtoW( szProduct
);
811 return ERROR_OUTOFMEMORY
;
814 r
= MsiConfigureProductW( szwProduct
, iInstallLevel
, eInstallState
);
815 msi_free( szwProduct
);
820 UINT WINAPI
MsiConfigureProductW(LPCWSTR szProduct
, int iInstallLevel
,
821 INSTALLSTATE eInstallState
)
823 return MsiConfigureProductExW(szProduct
, iInstallLevel
, eInstallState
, NULL
);
826 UINT WINAPI
MsiGetProductCodeA(LPCSTR szComponent
, LPSTR szBuffer
)
828 LPWSTR szwComponent
= NULL
;
830 WCHAR szwBuffer
[GUID_SIZE
];
832 TRACE("%s %p\n", debugstr_a(szComponent
), szBuffer
);
836 szwComponent
= strdupAtoW( szComponent
);
838 return ERROR_OUTOFMEMORY
;
842 r
= MsiGetProductCodeW( szwComponent
, szwBuffer
);
845 WideCharToMultiByte(CP_ACP
, 0, szwBuffer
, -1, szBuffer
, GUID_SIZE
, NULL
, NULL
);
847 msi_free( szwComponent
);
852 UINT WINAPI
MsiGetProductCodeW(LPCWSTR szComponent
, LPWSTR szBuffer
)
855 HKEY compkey
, prodkey
;
856 WCHAR squished_comp
[GUID_SIZE
];
857 WCHAR squished_prod
[GUID_SIZE
];
858 DWORD sz
= GUID_SIZE
;
860 TRACE("%s %p\n", debugstr_w(szComponent
), szBuffer
);
862 if (!szComponent
|| !*szComponent
)
863 return ERROR_INVALID_PARAMETER
;
865 if (!squash_guid(szComponent
, squished_comp
))
866 return ERROR_INVALID_PARAMETER
;
868 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &compkey
, FALSE
) != ERROR_SUCCESS
&&
869 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &compkey
, FALSE
) != ERROR_SUCCESS
)
871 return ERROR_UNKNOWN_COMPONENT
;
874 rc
= RegEnumValueW(compkey
, 0, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
875 if (rc
!= ERROR_SUCCESS
)
877 RegCloseKey(compkey
);
878 return ERROR_UNKNOWN_COMPONENT
;
881 /* check simple case, only one product */
882 rc
= RegEnumValueW(compkey
, 1, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
883 if (rc
== ERROR_NO_MORE_ITEMS
)
890 while ((rc
= RegEnumValueW(compkey
, index
, squished_prod
, &sz
,
891 NULL
, NULL
, NULL
, NULL
)) != ERROR_NO_MORE_ITEMS
)
895 unsquash_guid(squished_prod
, szBuffer
);
897 if (MSIREG_OpenProductKey(szBuffer
, NULL
,
898 MSIINSTALLCONTEXT_USERMANAGED
,
899 &prodkey
, FALSE
) == ERROR_SUCCESS
||
900 MSIREG_OpenProductKey(szBuffer
, NULL
,
901 MSIINSTALLCONTEXT_USERUNMANAGED
,
902 &prodkey
, FALSE
) == ERROR_SUCCESS
||
903 MSIREG_OpenProductKey(szBuffer
, NULL
,
904 MSIINSTALLCONTEXT_MACHINE
,
905 &prodkey
, FALSE
) == ERROR_SUCCESS
)
907 RegCloseKey(prodkey
);
913 rc
= ERROR_INSTALL_FAILURE
;
916 RegCloseKey(compkey
);
917 unsquash_guid(squished_prod
, szBuffer
);
921 static LPWSTR
msi_reg_get_value(HKEY hkey
, LPCWSTR name
, DWORD
*type
)
927 static const WCHAR format
[] = {'%','d',0};
929 res
= RegQueryValueExW(hkey
, name
, NULL
, type
, NULL
, NULL
);
930 if (res
!= ERROR_SUCCESS
)
934 return msi_reg_get_val_str(hkey
, name
);
936 if (!msi_reg_get_val_dword(hkey
, name
, &dval
))
939 sprintfW(temp
, format
, dval
);
940 return strdupW(temp
);
943 static UINT
MSI_GetProductInfo(LPCWSTR szProduct
, LPCWSTR szAttribute
,
944 awstring
*szValue
, LPDWORD pcchValueBuf
)
946 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
947 UINT r
= ERROR_UNKNOWN_PROPERTY
;
948 HKEY prodkey
, userdata
, source
;
950 WCHAR squished_pc
[GUID_SIZE
];
951 WCHAR packagecode
[GUID_SIZE
];
952 BOOL badconfig
= FALSE
;
954 DWORD type
= REG_NONE
;
956 static WCHAR empty
[] = {0};
957 static const WCHAR sourcelist
[] = {
958 'S','o','u','r','c','e','L','i','s','t',0};
959 static const WCHAR display_name
[] = {
960 'D','i','s','p','l','a','y','N','a','m','e',0};
961 static const WCHAR display_version
[] = {
962 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
963 static const WCHAR assignment
[] = {
964 'A','s','s','i','g','n','m','e','n','t',0};
966 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
967 debugstr_w(szAttribute
), szValue
, pcchValueBuf
);
969 if ((szValue
->str
.w
&& !pcchValueBuf
) || !szProduct
|| !szAttribute
)
970 return ERROR_INVALID_PARAMETER
;
972 if (!squash_guid(szProduct
, squished_pc
))
973 return ERROR_INVALID_PARAMETER
;
975 if ((r
= MSIREG_OpenProductKey(szProduct
, NULL
,
976 MSIINSTALLCONTEXT_USERMANAGED
,
977 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
978 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
979 MSIINSTALLCONTEXT_USERUNMANAGED
,
980 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
981 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
982 MSIINSTALLCONTEXT_MACHINE
,
983 &prodkey
, FALSE
)) == ERROR_SUCCESS
)
985 context
= MSIINSTALLCONTEXT_MACHINE
;
988 MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
990 if (!strcmpW( szAttribute
, INSTALLPROPERTY_HELPLINKW
) ||
991 !strcmpW( szAttribute
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
992 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLDATEW
) ||
993 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
994 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
995 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
996 !strcmpW( szAttribute
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
997 !strcmpW( szAttribute
, INSTALLPROPERTY_PUBLISHERW
) ||
998 !strcmpW( szAttribute
, INSTALLPROPERTY_URLINFOABOUTW
) ||
999 !strcmpW( szAttribute
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1000 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMINORW
) ||
1001 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1002 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1003 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTIDW
) ||
1004 !strcmpW( szAttribute
, INSTALLPROPERTY_REGCOMPANYW
) ||
1005 !strcmpW( szAttribute
, INSTALLPROPERTY_REGOWNERW
))
1009 r
= ERROR_UNKNOWN_PRODUCT
;
1014 return ERROR_UNKNOWN_PROPERTY
;
1016 if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1017 szAttribute
= display_name
;
1018 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
))
1019 szAttribute
= display_version
;
1021 val
= msi_reg_get_value(userdata
, szAttribute
, &type
);
1025 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTANCETYPEW
) ||
1026 !strcmpW( szAttribute
, INSTALLPROPERTY_TRANSFORMSW
) ||
1027 !strcmpW( szAttribute
, INSTALLPROPERTY_LANGUAGEW
) ||
1028 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1029 !strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
) ||
1030 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
) ||
1031 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONW
) ||
1032 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTICONW
) ||
1033 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1034 !strcmpW( szAttribute
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1038 r
= ERROR_UNKNOWN_PRODUCT
;
1042 if (!strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1043 szAttribute
= assignment
;
1045 if (!strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
))
1047 res
= RegOpenKeyW(prodkey
, sourcelist
, &source
);
1048 if (res
!= ERROR_SUCCESS
)
1050 r
= ERROR_UNKNOWN_PRODUCT
;
1054 val
= msi_reg_get_value(source
, szAttribute
, &type
);
1058 RegCloseKey(source
);
1062 val
= msi_reg_get_value(prodkey
, szAttribute
, &type
);
1067 if (val
!= empty
&& type
!= REG_DWORD
&&
1068 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
))
1070 if (lstrlenW(val
) != SQUISH_GUID_SIZE
- 1)
1074 unsquash_guid(val
, packagecode
);
1076 val
= strdupW(packagecode
);
1083 r
= ERROR_UNKNOWN_PROPERTY
;
1089 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1090 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1091 * can't rely on its value.
1093 if (szValue
->str
.a
|| szValue
->str
.w
)
1095 DWORD size
= *pcchValueBuf
;
1096 if (strlenW(val
) < size
)
1097 r
= msi_strcpy_to_awstring(val
, szValue
, &size
);
1100 r
= ERROR_MORE_DATA
;
1105 *pcchValueBuf
= lstrlenW(val
);
1109 r
= ERROR_BAD_CONFIGURATION
;
1115 RegCloseKey(prodkey
);
1116 RegCloseKey(userdata
);
1120 UINT WINAPI
MsiGetProductInfoA(LPCSTR szProduct
, LPCSTR szAttribute
,
1121 LPSTR szBuffer
, LPDWORD pcchValueBuf
)
1123 LPWSTR szwProduct
, szwAttribute
= NULL
;
1124 UINT r
= ERROR_OUTOFMEMORY
;
1127 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szAttribute
),
1128 szBuffer
, pcchValueBuf
);
1130 szwProduct
= strdupAtoW( szProduct
);
1131 if( szProduct
&& !szwProduct
)
1134 szwAttribute
= strdupAtoW( szAttribute
);
1135 if( szAttribute
&& !szwAttribute
)
1138 buffer
.unicode
= FALSE
;
1139 buffer
.str
.a
= szBuffer
;
1141 r
= MSI_GetProductInfo( szwProduct
, szwAttribute
,
1142 &buffer
, pcchValueBuf
);
1145 msi_free( szwProduct
);
1146 msi_free( szwAttribute
);
1151 UINT WINAPI
MsiGetProductInfoW(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1152 LPWSTR szBuffer
, LPDWORD pcchValueBuf
)
1156 TRACE("%s %s %p %p\n", debugstr_w(szProduct
), debugstr_w(szAttribute
),
1157 szBuffer
, pcchValueBuf
);
1159 buffer
.unicode
= TRUE
;
1160 buffer
.str
.w
= szBuffer
;
1162 return MSI_GetProductInfo( szProduct
, szAttribute
,
1163 &buffer
, pcchValueBuf
);
1166 UINT WINAPI
MsiGetProductInfoExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1167 MSIINSTALLCONTEXT dwContext
, LPCSTR szProperty
,
1168 LPSTR szValue
, LPDWORD pcchValue
)
1170 LPWSTR product
= NULL
;
1171 LPWSTR usersid
= NULL
;
1172 LPWSTR property
= NULL
;
1173 LPWSTR value
= NULL
;
1177 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode
),
1178 debugstr_a(szUserSid
), dwContext
, debugstr_a(szProperty
),
1179 szValue
, pcchValue
);
1181 if (szValue
&& !pcchValue
)
1182 return ERROR_INVALID_PARAMETER
;
1184 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1185 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1186 if (szProperty
) property
= strdupAtoW(szProperty
);
1188 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1190 if (r
!= ERROR_SUCCESS
)
1193 value
= msi_alloc(++len
* sizeof(WCHAR
));
1196 r
= ERROR_OUTOFMEMORY
;
1200 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1202 if (r
!= ERROR_SUCCESS
)
1208 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
1209 if (*pcchValue
>= len
)
1210 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
1213 r
= ERROR_MORE_DATA
;
1218 if (*pcchValue
<= len
|| !szValue
)
1219 len
= len
* sizeof(WCHAR
) - 1;
1221 *pcchValue
= len
- 1;
1232 static UINT
msi_copy_outval(LPWSTR val
, LPWSTR out
, LPDWORD size
)
1234 UINT r
= ERROR_SUCCESS
;
1237 return ERROR_UNKNOWN_PROPERTY
;
1241 if (strlenW(val
) >= *size
)
1243 r
= ERROR_MORE_DATA
;
1252 *size
= lstrlenW(val
);
1257 UINT WINAPI
MsiGetProductInfoExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
1258 MSIINSTALLCONTEXT dwContext
, LPCWSTR szProperty
,
1259 LPWSTR szValue
, LPDWORD pcchValue
)
1261 WCHAR squished_pc
[GUID_SIZE
];
1263 LPCWSTR package
= NULL
;
1264 HKEY props
= NULL
, prod
;
1265 HKEY classes
= NULL
, managed
;
1268 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1270 static const WCHAR five
[] = {'5',0};
1271 static const WCHAR displayname
[] = {
1272 'D','i','s','p','l','a','y','N','a','m','e',0};
1273 static const WCHAR displayversion
[] = {
1274 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1275 static const WCHAR managed_local_package
[] = {
1276 'M','a','n','a','g','e','d','L','o','c','a','l',
1277 'P','a','c','k','a','g','e',0};
1279 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode
),
1280 debugstr_w(szUserSid
), dwContext
, debugstr_w(szProperty
),
1281 szValue
, pcchValue
);
1283 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1284 return ERROR_INVALID_PARAMETER
;
1286 if (szValue
&& !pcchValue
)
1287 return ERROR_INVALID_PARAMETER
;
1289 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1290 dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1291 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1292 return ERROR_INVALID_PARAMETER
;
1294 if (!szProperty
|| !*szProperty
)
1295 return ERROR_INVALID_PARAMETER
;
1297 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1298 return ERROR_INVALID_PARAMETER
;
1300 /* FIXME: dwContext is provided, no need to search for it */
1301 MSIREG_OpenProductKey(szProductCode
, NULL
,MSIINSTALLCONTEXT_USERMANAGED
,
1303 MSIREG_OpenProductKey(szProductCode
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1306 MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
, &props
, FALSE
);
1308 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1310 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1312 if (!props
&& !prod
)
1315 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1317 package
= managed_local_package
;
1319 if (!props
&& !managed
)
1322 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1324 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1325 MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
, &classes
, FALSE
);
1327 if (!props
&& !classes
)
1331 if (!strcmpW( szProperty
, INSTALLPROPERTY_HELPLINKW
) ||
1332 !strcmpW( szProperty
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1333 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
) ||
1334 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1335 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1336 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1337 !strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1338 !strcmpW( szProperty
, INSTALLPROPERTY_PUBLISHERW
) ||
1339 !strcmpW( szProperty
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1340 !strcmpW( szProperty
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1341 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMINORW
) ||
1342 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1343 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1344 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTIDW
) ||
1345 !strcmpW( szProperty
, INSTALLPROPERTY_REGCOMPANYW
) ||
1346 !strcmpW( szProperty
, INSTALLPROPERTY_REGOWNERW
) ||
1347 !strcmpW( szProperty
, INSTALLPROPERTY_INSTANCETYPEW
))
1349 val
= msi_reg_get_value(props
, package
, &type
);
1352 if (prod
|| classes
)
1353 r
= ERROR_UNKNOWN_PROPERTY
;
1360 if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1361 szProperty
= displayname
;
1362 else if (!strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
))
1363 szProperty
= displayversion
;
1365 val
= msi_reg_get_value(props
, szProperty
, &type
);
1367 val
= strdupW(szEmpty
);
1369 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1371 else if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
) ||
1372 !strcmpW( szProperty
, INSTALLPROPERTY_LANGUAGEW
) ||
1373 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1374 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGECODEW
) ||
1375 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONW
) ||
1376 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTICONW
) ||
1377 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1378 !strcmpW( szProperty
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1380 if (!prod
&& !classes
)
1383 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1385 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1387 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1390 val
= msi_reg_get_value(hkey
, szProperty
, &type
);
1392 val
= strdupW(szEmpty
);
1394 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1396 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTSTATEW
))
1398 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1402 val
= msi_reg_get_value(props
, package
, &type
);
1407 val
= strdupW(five
);
1410 val
= strdupW(szOne
);
1412 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1415 else if (props
&& (val
= msi_reg_get_value(props
, package
, &type
)))
1418 val
= strdupW(five
);
1419 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1423 if (prod
|| managed
)
1424 val
= strdupW(szOne
);
1428 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1430 else if (!strcmpW( szProperty
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1432 if (!prod
&& !classes
)
1436 val
= strdupW(szEmpty
);
1437 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1440 r
= ERROR_UNKNOWN_PROPERTY
;
1445 RegCloseKey(managed
);
1446 RegCloseKey(classes
);
1452 UINT WINAPI
MsiGetPatchInfoExA(LPCSTR szPatchCode
, LPCSTR szProductCode
,
1453 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1454 LPCSTR szProperty
, LPSTR lpValue
, DWORD
*pcchValue
)
1456 LPWSTR patch
= NULL
, product
= NULL
, usersid
= NULL
;
1457 LPWSTR property
= NULL
, val
= NULL
;
1461 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode
),
1462 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
,
1463 debugstr_a(szProperty
), lpValue
, pcchValue
);
1465 if (lpValue
&& !pcchValue
)
1466 return ERROR_INVALID_PARAMETER
;
1468 if (szPatchCode
) patch
= strdupAtoW(szPatchCode
);
1469 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1470 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1471 if (szProperty
) property
= strdupAtoW(szProperty
);
1474 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1476 if (r
!= ERROR_SUCCESS
)
1479 val
= msi_alloc(++len
* sizeof(WCHAR
));
1482 r
= ERROR_OUTOFMEMORY
;
1486 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1488 if (r
!= ERROR_SUCCESS
|| !pcchValue
)
1492 WideCharToMultiByte(CP_ACP
, 0, val
, -1, lpValue
,
1493 *pcchValue
- 1, NULL
, NULL
);
1495 len
= lstrlenW(val
);
1496 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1500 r
= ERROR_MORE_DATA
;
1501 lpValue
[*pcchValue
- 1] = '\0';
1504 *pcchValue
= len
* sizeof(WCHAR
);
1519 UINT WINAPI
MsiGetPatchInfoExW(LPCWSTR szPatchCode
, LPCWSTR szProductCode
,
1520 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1521 LPCWSTR szProperty
, LPWSTR lpValue
, DWORD
*pcchValue
)
1523 WCHAR squished_pc
[GUID_SIZE
];
1524 WCHAR squished_patch
[GUID_SIZE
];
1525 HKEY udprod
= 0, prod
= 0, props
= 0;
1526 HKEY patch
= 0, patches
= 0;
1527 HKEY udpatch
= 0, datakey
= 0;
1528 HKEY prodpatches
= 0;
1530 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1534 static const WCHAR szManagedPackage
[] = {'M','a','n','a','g','e','d',
1535 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1537 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode
),
1538 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
,
1539 debugstr_w(szProperty
), lpValue
, pcchValue
);
1541 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1542 return ERROR_INVALID_PARAMETER
;
1544 if (!szPatchCode
|| !squash_guid(szPatchCode
, squished_patch
))
1545 return ERROR_INVALID_PARAMETER
;
1548 return ERROR_INVALID_PARAMETER
;
1550 if (lpValue
&& !pcchValue
)
1551 return ERROR_INVALID_PARAMETER
;
1553 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1554 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1555 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1556 return ERROR_INVALID_PARAMETER
;
1558 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1559 return ERROR_INVALID_PARAMETER
;
1561 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
1562 return ERROR_INVALID_PARAMETER
;
1564 if (MSIREG_OpenUserDataProductKey(szProductCode
, dwContext
, NULL
,
1565 &udprod
, FALSE
) != ERROR_SUCCESS
)
1568 if (MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
,
1569 &props
, FALSE
) != ERROR_SUCCESS
)
1572 r
= ERROR_UNKNOWN_PATCH
;
1574 res
= RegOpenKeyExW(udprod
, szPatches
, 0, KEY_READ
, &patches
);
1575 if (res
!= ERROR_SUCCESS
)
1578 res
= RegOpenKeyExW(patches
, squished_patch
, 0, KEY_READ
, &patch
);
1579 if (res
!= ERROR_SUCCESS
)
1582 if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
))
1584 if (MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
,
1585 &prod
, FALSE
) != ERROR_SUCCESS
)
1588 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_ALL_ACCESS
, &prodpatches
);
1589 if (res
!= ERROR_SUCCESS
)
1592 datakey
= prodpatches
;
1593 szProperty
= squished_patch
;
1597 if (MSIREG_OpenUserDataPatchKey(szPatchCode
, dwContext
,
1598 &udpatch
, FALSE
) != ERROR_SUCCESS
)
1601 if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1603 if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1604 szProperty
= szManagedPackage
;
1607 else if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
))
1610 szProperty
= szInstalled
;
1612 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1616 else if (!strcmpW( szProperty
, INSTALLPROPERTY_UNINSTALLABLEW
) ||
1617 !strcmpW( szProperty
, INSTALLPROPERTY_PATCHSTATEW
) ||
1618 !strcmpW( szProperty
, INSTALLPROPERTY_DISPLAYNAMEW
) ||
1619 !strcmpW( szProperty
, INSTALLPROPERTY_MOREINFOURLW
))
1625 r
= ERROR_UNKNOWN_PROPERTY
;
1630 val
= msi_reg_get_val_str(datakey
, szProperty
);
1632 val
= strdupW(szEmpty
);
1640 lstrcpynW(lpValue
, val
, *pcchValue
);
1642 len
= lstrlenW(val
);
1643 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1646 r
= ERROR_MORE_DATA
;
1648 *pcchValue
= len
* sizeof(WCHAR
);
1655 RegCloseKey(prodpatches
);
1658 RegCloseKey(patches
);
1659 RegCloseKey(udpatch
);
1661 RegCloseKey(udprod
);
1666 UINT WINAPI
MsiGetPatchInfoA( LPCSTR patch
, LPCSTR attr
, LPSTR buffer
, LPDWORD buflen
)
1668 UINT r
= ERROR_OUTOFMEMORY
;
1670 LPWSTR patchW
= NULL
, attrW
= NULL
, bufferW
= NULL
;
1672 TRACE("%s %s %p %p\n", debugstr_a(patch
), debugstr_a(attr
), buffer
, buflen
);
1674 if (!patch
|| !attr
)
1675 return ERROR_INVALID_PARAMETER
;
1677 if (!(patchW
= strdupAtoW( patch
)))
1680 if (!(attrW
= strdupAtoW( attr
)))
1684 r
= MsiGetPatchInfoW( patchW
, attrW
, NULL
, &size
);
1685 if (r
!= ERROR_SUCCESS
)
1689 if (!(bufferW
= msi_alloc( size
* sizeof(WCHAR
) )))
1691 r
= ERROR_OUTOFMEMORY
;
1695 r
= MsiGetPatchInfoW( patchW
, attrW
, bufferW
, &size
);
1696 if (r
== ERROR_SUCCESS
)
1698 int len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
1700 r
= ERROR_MORE_DATA
;
1702 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *buflen
, NULL
, NULL
);
1710 msi_free( bufferW
);
1714 UINT WINAPI
MsiGetPatchInfoW( LPCWSTR patch
, LPCWSTR attr
, LPWSTR buffer
, LPDWORD buflen
)
1717 WCHAR product
[GUID_SIZE
];
1720 TRACE("%s %s %p %p\n", debugstr_w(patch
), debugstr_w(attr
), buffer
, buflen
);
1722 if (!patch
|| !attr
)
1723 return ERROR_INVALID_PARAMETER
;
1725 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW
, attr
))
1726 return ERROR_UNKNOWN_PROPERTY
;
1731 r
= MsiEnumProductsW( index
, product
);
1732 if (r
!= ERROR_SUCCESS
)
1735 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, attr
, buffer
, buflen
);
1736 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1739 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, attr
, buffer
, buflen
);
1740 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1743 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_MACHINE
, attr
, buffer
, buflen
);
1744 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1750 return ERROR_UNKNOWN_PRODUCT
;
1753 UINT WINAPI
MsiEnableLogA(DWORD dwLogMode
, LPCSTR szLogFile
, DWORD attributes
)
1755 LPWSTR szwLogFile
= NULL
;
1758 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_a(szLogFile
), attributes
);
1762 szwLogFile
= strdupAtoW( szLogFile
);
1764 return ERROR_OUTOFMEMORY
;
1766 r
= MsiEnableLogW( dwLogMode
, szwLogFile
, attributes
);
1767 msi_free( szwLogFile
);
1771 UINT WINAPI
MsiEnableLogW(DWORD dwLogMode
, LPCWSTR szLogFile
, DWORD attributes
)
1773 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_w(szLogFile
), attributes
);
1775 msi_free(gszLogFile
);
1781 if (!(attributes
& INSTALLLOGATTRIBUTES_APPEND
))
1782 DeleteFileW(szLogFile
);
1783 file
= CreateFileW(szLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
,
1784 FILE_ATTRIBUTE_NORMAL
, NULL
);
1785 if (file
!= INVALID_HANDLE_VALUE
)
1787 gszLogFile
= strdupW(szLogFile
);
1791 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile
), GetLastError());
1794 return ERROR_SUCCESS
;
1797 UINT WINAPI
MsiEnumComponentCostsW(MSIHANDLE hInstall
, LPCWSTR szComponent
,
1798 DWORD dwIndex
, INSTALLSTATE iState
,
1799 LPWSTR lpDriveBuf
, DWORD
*pcchDriveBuf
,
1800 int *piCost
, int *pTempCost
)
1802 FIXME("(%d, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall
,
1803 debugstr_w(szComponent
), dwIndex
, iState
, lpDriveBuf
,
1804 pcchDriveBuf
, piCost
, pTempCost
);
1806 return ERROR_NO_MORE_ITEMS
;
1809 UINT WINAPI
MsiQueryComponentStateA(LPCSTR szProductCode
,
1810 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1811 LPCSTR szComponent
, INSTALLSTATE
*pdwState
)
1813 LPWSTR prodcode
= NULL
, usersid
= NULL
, comp
= NULL
;
1816 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode
),
1817 debugstr_a(szUserSid
), dwContext
, debugstr_a(szComponent
), pdwState
);
1819 if (szProductCode
&& !(prodcode
= strdupAtoW(szProductCode
)))
1820 return ERROR_OUTOFMEMORY
;
1822 if (szUserSid
&& !(usersid
= strdupAtoW(szUserSid
)))
1823 return ERROR_OUTOFMEMORY
;
1825 if (szComponent
&& !(comp
= strdupAtoW(szComponent
)))
1826 return ERROR_OUTOFMEMORY
;
1828 r
= MsiQueryComponentStateW(prodcode
, usersid
, dwContext
, comp
, pdwState
);
1837 static BOOL
msi_comp_find_prod_key(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
1842 r
= MSIREG_OpenProductKey(prodcode
, NULL
, context
, &hkey
, FALSE
);
1844 return (r
== ERROR_SUCCESS
);
1847 static BOOL
msi_comp_find_package(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
1855 static const WCHAR local_package
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1856 static const WCHAR managed_local_package
[] = {
1857 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1860 r
= MSIREG_OpenInstallProps(prodcode
, context
, NULL
, &hkey
, FALSE
);
1861 if (r
!= ERROR_SUCCESS
)
1864 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
1865 package
= managed_local_package
;
1867 package
= local_package
;
1870 res
= RegQueryValueExW(hkey
, package
, NULL
, NULL
, NULL
, &sz
);
1873 return (res
== ERROR_SUCCESS
);
1876 static BOOL
msi_comp_find_prodcode(LPWSTR squished_pc
,
1877 MSIINSTALLCONTEXT context
,
1878 LPCWSTR comp
, LPWSTR val
, DWORD
*sz
)
1884 if (context
== MSIINSTALLCONTEXT_MACHINE
)
1885 r
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
1887 r
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
1889 if (r
!= ERROR_SUCCESS
)
1892 res
= RegQueryValueExW(hkey
, squished_pc
, NULL
, NULL
, (BYTE
*)val
, sz
);
1893 if (res
!= ERROR_SUCCESS
)
1900 UINT WINAPI
MsiQueryComponentStateW(LPCWSTR szProductCode
,
1901 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1902 LPCWSTR szComponent
, INSTALLSTATE
*pdwState
)
1904 WCHAR squished_pc
[GUID_SIZE
];
1905 WCHAR val
[MAX_PATH
];
1909 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode
),
1910 debugstr_w(szUserSid
), dwContext
, debugstr_w(szComponent
), pdwState
);
1912 if (!pdwState
|| !szComponent
)
1913 return ERROR_INVALID_PARAMETER
;
1915 if (!szProductCode
|| !*szProductCode
|| lstrlenW(szProductCode
) != GUID_SIZE
- 1)
1916 return ERROR_INVALID_PARAMETER
;
1918 if (!squash_guid(szProductCode
, squished_pc
))
1919 return ERROR_INVALID_PARAMETER
;
1921 found
= msi_comp_find_prod_key(szProductCode
, dwContext
);
1923 if (!msi_comp_find_package(szProductCode
, dwContext
))
1927 *pdwState
= INSTALLSTATE_UNKNOWN
;
1928 return ERROR_UNKNOWN_COMPONENT
;
1931 return ERROR_UNKNOWN_PRODUCT
;
1934 *pdwState
= INSTALLSTATE_UNKNOWN
;
1937 if (!msi_comp_find_prodcode(squished_pc
, dwContext
, szComponent
, val
, &sz
))
1938 return ERROR_UNKNOWN_COMPONENT
;
1941 *pdwState
= INSTALLSTATE_NOTUSED
;
1944 if (lstrlenW(val
) > 2 &&
1945 val
[0] >= '0' && val
[0] <= '9' && val
[1] >= '0' && val
[1] <= '9')
1947 *pdwState
= INSTALLSTATE_SOURCE
;
1950 *pdwState
= INSTALLSTATE_LOCAL
;
1953 TRACE("-> %d\n", *pdwState
);
1954 return ERROR_SUCCESS
;
1957 INSTALLSTATE WINAPI
MsiQueryProductStateA(LPCSTR szProduct
)
1959 LPWSTR szwProduct
= NULL
;
1964 szwProduct
= strdupAtoW( szProduct
);
1966 return ERROR_OUTOFMEMORY
;
1968 r
= MsiQueryProductStateW( szwProduct
);
1969 msi_free( szwProduct
);
1973 INSTALLSTATE WINAPI
MsiQueryProductStateW(LPCWSTR szProduct
)
1975 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
1976 INSTALLSTATE state
= INSTALLSTATE_ADVERTISED
;
1977 HKEY prodkey
= 0, userdata
= 0;
1981 static const WCHAR szWindowsInstaller
[] = {
1982 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1984 TRACE("%s\n", debugstr_w(szProduct
));
1986 if (!szProduct
|| !*szProduct
)
1987 return INSTALLSTATE_INVALIDARG
;
1989 if (lstrlenW(szProduct
) != GUID_SIZE
- 1)
1990 return INSTALLSTATE_INVALIDARG
;
1992 if (szProduct
[0] != '{' || szProduct
[37] != '}')
1993 return INSTALLSTATE_UNKNOWN
;
1995 SetLastError( ERROR_SUCCESS
);
1997 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
1998 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
1999 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2000 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2001 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2002 &prodkey
, FALSE
) == ERROR_SUCCESS
)
2004 context
= MSIINSTALLCONTEXT_MACHINE
;
2007 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
2008 if (r
!= ERROR_SUCCESS
)
2011 if (!msi_reg_get_val_dword(userdata
, szWindowsInstaller
, &val
))
2015 state
= INSTALLSTATE_DEFAULT
;
2017 state
= INSTALLSTATE_UNKNOWN
;
2022 state
= INSTALLSTATE_UNKNOWN
;
2025 state
= INSTALLSTATE_ABSENT
;
2028 RegCloseKey(prodkey
);
2029 RegCloseKey(userdata
);
2030 TRACE("-> %d\n", state
);
2034 INSTALLUILEVEL WINAPI
MsiSetInternalUI(INSTALLUILEVEL dwUILevel
, HWND
*phWnd
)
2036 INSTALLUILEVEL old
= gUILevel
;
2037 HWND oldwnd
= gUIhwnd
;
2039 TRACE("%08x %p\n", dwUILevel
, phWnd
);
2041 gUILevel
= dwUILevel
;
2050 INSTALLUI_HANDLERA WINAPI
MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler
,
2051 DWORD dwMessageFilter
, LPVOID pvContext
)
2053 INSTALLUI_HANDLERA prev
= gUIHandlerA
;
2055 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2057 gUIHandlerA
= puiHandler
;
2059 gUIFilter
= dwMessageFilter
;
2060 gUIContext
= pvContext
;
2065 INSTALLUI_HANDLERW WINAPI
MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler
,
2066 DWORD dwMessageFilter
, LPVOID pvContext
)
2068 INSTALLUI_HANDLERW prev
= gUIHandlerW
;
2070 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2073 gUIHandlerW
= puiHandler
;
2074 gUIFilter
= dwMessageFilter
;
2075 gUIContext
= pvContext
;
2080 /******************************************************************
2081 * MsiLoadStringW [MSI.@]
2083 * Loads a string from MSI's string resources.
2087 * handle [I] only -1 is handled currently
2088 * id [I] id of the string to be loaded
2089 * lpBuffer [O] buffer for the string to be written to
2090 * nBufferMax [I] maximum size of the buffer in characters
2091 * lang [I] the preferred language for the string
2095 * If successful, this function returns the language id of the string loaded
2096 * If the function fails, the function returns zero.
2100 * The type of the first parameter is unknown. LoadString's prototype
2101 * suggests that it might be a module handle. I have made it an MSI handle
2102 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2103 * handle. Maybe strings can be stored in an MSI database somehow.
2105 LANGID WINAPI
MsiLoadStringW( MSIHANDLE handle
, UINT id
, LPWSTR lpBuffer
,
2106 int nBufferMax
, LANGID lang
)
2113 TRACE("%d %u %p %d %d\n", handle
, id
, lpBuffer
, nBufferMax
, lang
);
2116 FIXME("don't know how to deal with handle = %08x\n", handle
);
2119 lang
= GetUserDefaultLangID();
2121 hres
= FindResourceExW( msi_hInstance
, (LPCWSTR
) RT_STRING
,
2125 hResData
= LoadResource( msi_hInstance
, hres
);
2128 p
= LockResource( hResData
);
2132 for (i
= 0; i
< (id
&0xf); i
++)
2136 if( nBufferMax
<= len
)
2139 memcpy( lpBuffer
, p
+1, len
* sizeof(WCHAR
));
2140 lpBuffer
[ len
] = 0;
2142 TRACE("found -> %s\n", debugstr_w(lpBuffer
));
2147 LANGID WINAPI
MsiLoadStringA( MSIHANDLE handle
, UINT id
, LPSTR lpBuffer
,
2148 int nBufferMax
, LANGID lang
)
2154 bufW
= msi_alloc(nBufferMax
*sizeof(WCHAR
));
2155 r
= MsiLoadStringW(handle
, id
, bufW
, nBufferMax
, lang
);
2158 len
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
2159 if( len
<= nBufferMax
)
2160 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1,
2161 lpBuffer
, nBufferMax
, NULL
, NULL
);
2169 INSTALLSTATE WINAPI
MsiLocateComponentA(LPCSTR szComponent
, LPSTR lpPathBuf
,
2172 char szProduct
[GUID_SIZE
];
2174 TRACE("%s %p %p\n", debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2176 if (!szComponent
|| !pcchBuf
)
2177 return INSTALLSTATE_INVALIDARG
;
2179 if (MsiGetProductCodeA( szComponent
, szProduct
) != ERROR_SUCCESS
)
2180 return INSTALLSTATE_UNKNOWN
;
2182 return MsiGetComponentPathA( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2185 INSTALLSTATE WINAPI
MsiLocateComponentW(LPCWSTR szComponent
, LPWSTR lpPathBuf
,
2188 WCHAR szProduct
[GUID_SIZE
];
2190 TRACE("%s %p %p\n", debugstr_w(szComponent
), lpPathBuf
, pcchBuf
);
2192 if (!szComponent
|| !pcchBuf
)
2193 return INSTALLSTATE_INVALIDARG
;
2195 if (MsiGetProductCodeW( szComponent
, szProduct
) != ERROR_SUCCESS
)
2196 return INSTALLSTATE_UNKNOWN
;
2198 return MsiGetComponentPathW( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2201 UINT WINAPI
MsiMessageBoxA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2202 WORD wLanguageId
, DWORD f
)
2204 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_a(lpText
), debugstr_a(lpCaption
),
2205 uType
, wLanguageId
, f
);
2206 return MessageBoxExA(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2209 UINT WINAPI
MsiMessageBoxW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2210 WORD wLanguageId
, DWORD f
)
2212 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_w(lpText
), debugstr_w(lpCaption
),
2213 uType
, wLanguageId
, f
);
2214 return MessageBoxExW(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2217 UINT WINAPI
MsiMessageBoxExA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2218 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2220 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_a(lpText
),
2221 debugstr_a(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2222 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2225 UINT WINAPI
MsiMessageBoxExW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2226 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2228 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_w(lpText
),
2229 debugstr_w(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2230 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2233 UINT WINAPI
MsiProvideAssemblyA( LPCSTR szAssemblyName
, LPCSTR szAppContext
,
2234 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPSTR lpPathBuf
,
2235 LPDWORD pcchPathBuf
)
2237 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName
),
2238 debugstr_a(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2240 return ERROR_CALL_NOT_IMPLEMENTED
;
2243 UINT WINAPI
MsiProvideAssemblyW( LPCWSTR szAssemblyName
, LPCWSTR szAppContext
,
2244 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPWSTR lpPathBuf
,
2245 LPDWORD pcchPathBuf
)
2247 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName
),
2248 debugstr_w(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2250 return ERROR_CALL_NOT_IMPLEMENTED
;
2253 UINT WINAPI
MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor
,
2254 LPSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2256 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2257 return ERROR_CALL_NOT_IMPLEMENTED
;
2260 UINT WINAPI
MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor
,
2261 LPWSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2263 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2264 return ERROR_CALL_NOT_IMPLEMENTED
;
2267 HRESULT WINAPI
MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath
,
2268 DWORD dwFlags
, PCCERT_CONTEXT
* ppcCertContext
, LPBYTE pbHashData
,
2269 LPDWORD pcbHashData
)
2271 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath
), dwFlags
,
2272 ppcCertContext
, pbHashData
, pcbHashData
);
2273 return ERROR_CALL_NOT_IMPLEMENTED
;
2276 HRESULT WINAPI
MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath
,
2277 DWORD dwFlags
, PCCERT_CONTEXT
* ppcCertContext
, LPBYTE pbHashData
,
2278 LPDWORD pcbHashData
)
2280 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath
), dwFlags
,
2281 ppcCertContext
, pbHashData
, pcbHashData
);
2282 return ERROR_CALL_NOT_IMPLEMENTED
;
2285 /******************************************************************
2286 * MsiGetProductPropertyA [MSI.@]
2288 UINT WINAPI
MsiGetProductPropertyA(MSIHANDLE hProduct
, LPCSTR szProperty
,
2289 LPSTR szValue
, LPDWORD pccbValue
)
2291 LPWSTR prop
= NULL
, val
= NULL
;
2295 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_a(szProperty
),
2296 szValue
, pccbValue
);
2298 if (szValue
&& !pccbValue
)
2299 return ERROR_INVALID_PARAMETER
;
2301 if (szProperty
) prop
= strdupAtoW(szProperty
);
2304 r
= MsiGetProductPropertyW(hProduct
, prop
, NULL
, &len
);
2305 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2308 if (r
== ERROR_SUCCESS
)
2310 if (szValue
) *szValue
= '\0';
2311 if (pccbValue
) *pccbValue
= 0;
2315 val
= msi_alloc(++len
* sizeof(WCHAR
));
2318 r
= ERROR_OUTOFMEMORY
;
2322 r
= MsiGetProductPropertyW(hProduct
, prop
, val
, &len
);
2323 if (r
!= ERROR_SUCCESS
)
2326 len
= WideCharToMultiByte(CP_ACP
, 0, val
, -1, NULL
, 0, NULL
, NULL
);
2329 WideCharToMultiByte(CP_ACP
, 0, val
, -1, szValue
,
2330 *pccbValue
, NULL
, NULL
);
2334 if (len
> *pccbValue
)
2335 r
= ERROR_MORE_DATA
;
2337 *pccbValue
= len
- 1;
2347 /******************************************************************
2348 * MsiGetProductPropertyW [MSI.@]
2350 UINT WINAPI
MsiGetProductPropertyW(MSIHANDLE hProduct
, LPCWSTR szProperty
,
2351 LPWSTR szValue
, LPDWORD pccbValue
)
2353 MSIPACKAGE
*package
;
2354 MSIQUERY
*view
= NULL
;
2355 MSIRECORD
*rec
= NULL
;
2359 static const WCHAR query
[] = {
2360 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2361 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2362 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2364 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_w(szProperty
),
2365 szValue
, pccbValue
);
2368 return ERROR_INVALID_PARAMETER
;
2370 if (szValue
&& !pccbValue
)
2371 return ERROR_INVALID_PARAMETER
;
2373 package
= msihandle2msiinfo(hProduct
, MSIHANDLETYPE_PACKAGE
);
2375 return ERROR_INVALID_HANDLE
;
2377 r
= MSI_OpenQuery(package
->db
, &view
, query
, szProperty
);
2378 if (r
!= ERROR_SUCCESS
)
2381 r
= MSI_ViewExecute(view
, 0);
2382 if (r
!= ERROR_SUCCESS
)
2385 r
= MSI_ViewFetch(view
, &rec
);
2386 if (r
!= ERROR_SUCCESS
)
2389 val
= MSI_RecordGetString(rec
, 2);
2393 if (lstrlenW(val
) >= *pccbValue
)
2395 lstrcpynW(szValue
, val
, *pccbValue
);
2396 *pccbValue
= lstrlenW(val
);
2397 r
= ERROR_MORE_DATA
;
2401 lstrcpyW(szValue
, val
);
2402 *pccbValue
= lstrlenW(val
);
2409 MSI_ViewClose(view
);
2410 msiobj_release(&view
->hdr
);
2411 if (rec
) msiobj_release(&rec
->hdr
);
2416 if (szValue
) *szValue
= '\0';
2417 if (pccbValue
) *pccbValue
= 0;
2421 msiobj_release(&package
->hdr
);
2425 UINT WINAPI
MsiVerifyPackageA( LPCSTR szPackage
)
2428 LPWSTR szPack
= NULL
;
2430 TRACE("%s\n", debugstr_a(szPackage
) );
2434 szPack
= strdupAtoW( szPackage
);
2436 return ERROR_OUTOFMEMORY
;
2439 r
= MsiVerifyPackageW( szPack
);
2446 UINT WINAPI
MsiVerifyPackageW( LPCWSTR szPackage
)
2451 TRACE("%s\n", debugstr_w(szPackage
) );
2453 r
= MsiOpenDatabaseW( szPackage
, MSIDBOPEN_READONLY
, &handle
);
2454 MsiCloseHandle( handle
);
2459 static INSTALLSTATE
MSI_GetComponentPath(LPCWSTR szProduct
, LPCWSTR szComponent
,
2460 awstring
* lpPathBuf
, LPDWORD pcchBuf
)
2462 WCHAR squished_pc
[GUID_SIZE
];
2463 WCHAR squished_comp
[GUID_SIZE
];
2469 static const WCHAR wininstaller
[] = {
2470 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2472 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
2473 debugstr_w(szComponent
), lpPathBuf
->str
.w
, pcchBuf
);
2475 if (!szProduct
|| !szComponent
)
2476 return INSTALLSTATE_INVALIDARG
;
2478 if (lpPathBuf
->str
.w
&& !pcchBuf
)
2479 return INSTALLSTATE_INVALIDARG
;
2481 if (!squash_guid(szProduct
, squished_pc
) ||
2482 !squash_guid(szComponent
, squished_comp
))
2483 return INSTALLSTATE_INVALIDARG
;
2485 state
= INSTALLSTATE_UNKNOWN
;
2487 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2488 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2490 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2493 state
= INSTALLSTATE_ABSENT
;
2495 if ((MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
, NULL
,
2496 &hkey
, FALSE
) == ERROR_SUCCESS
||
2497 MSIREG_OpenUserDataProductKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2498 NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
) &&
2499 msi_reg_get_val_dword(hkey
, wininstaller
, &version
) &&
2500 GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2503 state
= INSTALLSTATE_LOCAL
;
2507 if (state
!= INSTALLSTATE_LOCAL
&&
2508 (MSIREG_OpenProductKey(szProduct
, NULL
,
2509 MSIINSTALLCONTEXT_USERUNMANAGED
,
2510 &hkey
, FALSE
) == ERROR_SUCCESS
||
2511 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2512 &hkey
, FALSE
) == ERROR_SUCCESS
))
2516 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2517 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2520 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2523 state
= INSTALLSTATE_ABSENT
;
2525 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2526 state
= INSTALLSTATE_LOCAL
;
2531 return INSTALLSTATE_UNKNOWN
;
2533 if (state
== INSTALLSTATE_LOCAL
&& !*path
)
2534 state
= INSTALLSTATE_NOTUSED
;
2536 msi_strcpy_to_awstring(path
, lpPathBuf
, pcchBuf
);
2541 /******************************************************************
2542 * MsiGetComponentPathW [MSI.@]
2544 INSTALLSTATE WINAPI
MsiGetComponentPathW(LPCWSTR szProduct
, LPCWSTR szComponent
,
2545 LPWSTR lpPathBuf
, LPDWORD pcchBuf
)
2549 path
.unicode
= TRUE
;
2550 path
.str
.w
= lpPathBuf
;
2552 return MSI_GetComponentPath( szProduct
, szComponent
, &path
, pcchBuf
);
2555 /******************************************************************
2556 * MsiGetComponentPathA [MSI.@]
2558 INSTALLSTATE WINAPI
MsiGetComponentPathA(LPCSTR szProduct
, LPCSTR szComponent
,
2559 LPSTR lpPathBuf
, LPDWORD pcchBuf
)
2561 LPWSTR szwProduct
, szwComponent
= NULL
;
2562 INSTALLSTATE r
= INSTALLSTATE_UNKNOWN
;
2565 szwProduct
= strdupAtoW( szProduct
);
2566 if( szProduct
&& !szwProduct
)
2569 szwComponent
= strdupAtoW( szComponent
);
2570 if( szComponent
&& !szwComponent
)
2573 path
.unicode
= FALSE
;
2574 path
.str
.a
= lpPathBuf
;
2576 r
= MSI_GetComponentPath( szwProduct
, szwComponent
, &path
, pcchBuf
);
2579 msi_free( szwProduct
);
2580 msi_free( szwComponent
);
2585 /******************************************************************
2586 * MsiQueryFeatureStateA [MSI.@]
2588 INSTALLSTATE WINAPI
MsiQueryFeatureStateA(LPCSTR szProduct
, LPCSTR szFeature
)
2590 LPWSTR szwProduct
= NULL
, szwFeature
= NULL
;
2591 INSTALLSTATE rc
= INSTALLSTATE_UNKNOWN
;
2593 szwProduct
= strdupAtoW( szProduct
);
2594 if ( szProduct
&& !szwProduct
)
2597 szwFeature
= strdupAtoW( szFeature
);
2598 if ( szFeature
&& !szwFeature
)
2601 rc
= MsiQueryFeatureStateW(szwProduct
, szwFeature
);
2604 msi_free( szwProduct
);
2605 msi_free( szwFeature
);
2610 /******************************************************************
2611 * MsiQueryFeatureStateW [MSI.@]
2613 * Checks the state of a feature
2616 * szProduct [I] Product's GUID string
2617 * szFeature [I] Feature's GUID string
2620 * INSTALLSTATE_LOCAL Feature is installed and usable
2621 * INSTALLSTATE_ABSENT Feature is absent
2622 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2623 * INSTALLSTATE_UNKNOWN An error occurred
2624 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2627 INSTALLSTATE WINAPI
MsiQueryFeatureStateW(LPCWSTR szProduct
, LPCWSTR szFeature
)
2629 WCHAR squishProduct
[33], comp
[GUID_SIZE
];
2631 LPWSTR components
, p
, parent_feature
, path
;
2635 BOOL missing
= FALSE
;
2636 BOOL machine
= FALSE
;
2637 BOOL source
= FALSE
;
2639 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szFeature
));
2641 if (!szProduct
|| !szFeature
)
2642 return INSTALLSTATE_INVALIDARG
;
2644 if (!squash_guid( szProduct
, squishProduct
))
2645 return INSTALLSTATE_INVALIDARG
;
2647 SetLastError( ERROR_SUCCESS
);
2649 if (MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERMANAGED
,
2650 &hkey
, FALSE
) != ERROR_SUCCESS
&&
2651 MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2652 &hkey
, FALSE
) != ERROR_SUCCESS
)
2654 rc
= MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
2656 if (rc
!= ERROR_SUCCESS
)
2657 return INSTALLSTATE_UNKNOWN
;
2662 parent_feature
= msi_reg_get_val_str( hkey
, szFeature
);
2665 if (!parent_feature
)
2666 return INSTALLSTATE_UNKNOWN
;
2668 r
= (parent_feature
[0] == 6) ? INSTALLSTATE_ABSENT
: INSTALLSTATE_LOCAL
;
2669 msi_free(parent_feature
);
2670 if (r
== INSTALLSTATE_ABSENT
)
2674 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2675 MSIINSTALLCONTEXT_MACHINE
,
2678 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2679 MSIINSTALLCONTEXT_USERUNMANAGED
,
2682 if (rc
!= ERROR_SUCCESS
)
2683 return INSTALLSTATE_ADVERTISED
;
2685 components
= msi_reg_get_val_str( hkey
, szFeature
);
2688 TRACE("rc = %d buffer = %s\n", rc
, debugstr_w(components
));
2691 return INSTALLSTATE_ADVERTISED
;
2693 for( p
= components
; *p
&& *p
!= 2 ; p
+= 20)
2695 if (!decode_base85_guid( p
, &guid
))
2697 if (p
!= components
)
2700 msi_free(components
);
2701 return INSTALLSTATE_BADCONFIG
;
2704 StringFromGUID2(&guid
, comp
, GUID_SIZE
);
2707 rc
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2709 rc
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2711 if (rc
!= ERROR_SUCCESS
)
2713 msi_free(components
);
2714 return INSTALLSTATE_ADVERTISED
;
2717 path
= msi_reg_get_val_str(hkey
, squishProduct
);
2720 else if (lstrlenW(path
) > 2 &&
2721 path
[0] >= '0' && path
[0] <= '9' &&
2722 path
[1] >= '0' && path
[1] <= '9')
2729 msi_free(components
);
2732 r
= INSTALLSTATE_ADVERTISED
;
2734 r
= INSTALLSTATE_SOURCE
;
2736 r
= INSTALLSTATE_LOCAL
;
2738 TRACE("-> %d\n", r
);
2742 /******************************************************************
2743 * MsiGetFileVersionA [MSI.@]
2745 UINT WINAPI
MsiGetFileVersionA(LPCSTR szFilePath
, LPSTR lpVersionBuf
,
2746 LPDWORD pcchVersionBuf
, LPSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2748 LPWSTR szwFilePath
= NULL
, lpwVersionBuff
= NULL
, lpwLangBuff
= NULL
;
2749 UINT ret
= ERROR_OUTOFMEMORY
;
2751 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
2752 (lpLangBuf
&& !pcchLangBuf
))
2753 return ERROR_INVALID_PARAMETER
;
2757 szwFilePath
= strdupAtoW( szFilePath
);
2762 if( lpVersionBuf
&& pcchVersionBuf
&& *pcchVersionBuf
)
2764 lpwVersionBuff
= msi_alloc(*pcchVersionBuf
*sizeof(WCHAR
));
2765 if( !lpwVersionBuff
)
2769 if( lpLangBuf
&& pcchLangBuf
&& *pcchLangBuf
)
2771 lpwLangBuff
= msi_alloc(*pcchLangBuf
*sizeof(WCHAR
));
2776 ret
= MsiGetFileVersionW(szwFilePath
, lpwVersionBuff
, pcchVersionBuf
,
2777 lpwLangBuff
, pcchLangBuf
);
2779 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwVersionBuff
)
2780 WideCharToMultiByte(CP_ACP
, 0, lpwVersionBuff
, -1,
2781 lpVersionBuf
, *pcchVersionBuf
+ 1, NULL
, NULL
);
2782 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwLangBuff
)
2783 WideCharToMultiByte(CP_ACP
, 0, lpwLangBuff
, -1,
2784 lpLangBuf
, *pcchLangBuf
+ 1, NULL
, NULL
);
2787 msi_free(szwFilePath
);
2788 msi_free(lpwVersionBuff
);
2789 msi_free(lpwLangBuff
);
2794 /******************************************************************
2795 * MsiGetFileVersionW [MSI.@]
2797 UINT WINAPI
MsiGetFileVersionW(LPCWSTR szFilePath
, LPWSTR lpVersionBuf
,
2798 LPDWORD pcchVersionBuf
, LPWSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2800 static const WCHAR szVersionResource
[] = {'\\',0};
2801 static const WCHAR szVersionFormat
[] = {
2802 '%','d','.','%','d','.','%','d','.','%','d',0};
2803 static const WCHAR szLangResource
[] = {
2804 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2805 'T','r','a','n','s','l','a','t','i','o','n',0};
2806 static const WCHAR szLangFormat
[] = {'%','d',0};
2808 DWORD dwVerLen
, gle
;
2809 LPVOID lpVer
= NULL
;
2810 VS_FIXEDFILEINFO
*ffi
;
2815 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath
),
2816 lpVersionBuf
, pcchVersionBuf
?*pcchVersionBuf
:0,
2817 lpLangBuf
, pcchLangBuf
?*pcchLangBuf
:0);
2819 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
2820 (lpLangBuf
&& !pcchLangBuf
))
2821 return ERROR_INVALID_PARAMETER
;
2823 dwVerLen
= GetFileVersionInfoSizeW(szFilePath
, NULL
);
2826 gle
= GetLastError();
2827 if (gle
== ERROR_BAD_PATHNAME
)
2828 return ERROR_FILE_NOT_FOUND
;
2829 else if (gle
== ERROR_RESOURCE_DATA_NOT_FOUND
)
2830 return ERROR_FILE_INVALID
;
2835 lpVer
= msi_alloc(dwVerLen
);
2838 ret
= ERROR_OUTOFMEMORY
;
2842 if( !GetFileVersionInfoW(szFilePath
, 0, dwVerLen
, lpVer
) )
2844 ret
= GetLastError();
2850 if( VerQueryValueW(lpVer
, szVersionResource
, (LPVOID
*)&ffi
, &puLen
) &&
2853 wsprintfW(tmp
, szVersionFormat
,
2854 HIWORD(ffi
->dwFileVersionMS
), LOWORD(ffi
->dwFileVersionMS
),
2855 HIWORD(ffi
->dwFileVersionLS
), LOWORD(ffi
->dwFileVersionLS
));
2856 if (lpVersionBuf
) lstrcpynW(lpVersionBuf
, tmp
, *pcchVersionBuf
);
2858 if (strlenW(tmp
) >= *pcchVersionBuf
)
2859 ret
= ERROR_MORE_DATA
;
2861 *pcchVersionBuf
= lstrlenW(tmp
);
2865 if (lpVersionBuf
) *lpVersionBuf
= 0;
2866 *pcchVersionBuf
= 0;
2872 if (VerQueryValueW(lpVer
, szLangResource
, (LPVOID
*)&lang
, &puLen
) &&
2875 wsprintfW(tmp
, szLangFormat
, *lang
);
2876 if (lpLangBuf
) lstrcpynW(lpLangBuf
, tmp
, *pcchLangBuf
);
2878 if (strlenW(tmp
) >= *pcchLangBuf
)
2879 ret
= ERROR_MORE_DATA
;
2881 *pcchLangBuf
= lstrlenW(tmp
);
2885 if (lpLangBuf
) *lpLangBuf
= 0;
2895 /***********************************************************************
2896 * MsiGetFeatureUsageW [MSI.@]
2898 UINT WINAPI
MsiGetFeatureUsageW( LPCWSTR szProduct
, LPCWSTR szFeature
,
2899 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
2901 FIXME("%s %s %p %p\n",debugstr_w(szProduct
), debugstr_w(szFeature
),
2902 pdwUseCount
, pwDateUsed
);
2903 return ERROR_CALL_NOT_IMPLEMENTED
;
2906 /***********************************************************************
2907 * MsiGetFeatureUsageA [MSI.@]
2909 UINT WINAPI
MsiGetFeatureUsageA( LPCSTR szProduct
, LPCSTR szFeature
,
2910 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
2912 LPWSTR prod
= NULL
, feat
= NULL
;
2913 UINT ret
= ERROR_OUTOFMEMORY
;
2915 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
2916 pdwUseCount
, pwDateUsed
);
2918 prod
= strdupAtoW( szProduct
);
2919 if (szProduct
&& !prod
)
2922 feat
= strdupAtoW( szFeature
);
2923 if (szFeature
&& !feat
)
2926 ret
= MsiGetFeatureUsageW( prod
, feat
, pdwUseCount
, pwDateUsed
);
2935 /***********************************************************************
2936 * MsiUseFeatureExW [MSI.@]
2938 INSTALLSTATE WINAPI
MsiUseFeatureExW( LPCWSTR szProduct
, LPCWSTR szFeature
,
2939 DWORD dwInstallMode
, DWORD dwReserved
)
2943 TRACE("%s %s %i %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
2944 dwInstallMode
, dwReserved
);
2946 state
= MsiQueryFeatureStateW( szProduct
, szFeature
);
2949 return INSTALLSTATE_INVALIDARG
;
2951 if (state
== INSTALLSTATE_LOCAL
&& dwInstallMode
!= INSTALLMODE_NODETECTION
)
2953 FIXME("mark product %s feature %s as used\n",
2954 debugstr_w(szProduct
), debugstr_w(szFeature
) );
2960 /***********************************************************************
2961 * MsiUseFeatureExA [MSI.@]
2963 INSTALLSTATE WINAPI
MsiUseFeatureExA( LPCSTR szProduct
, LPCSTR szFeature
,
2964 DWORD dwInstallMode
, DWORD dwReserved
)
2966 INSTALLSTATE ret
= INSTALLSTATE_UNKNOWN
;
2967 LPWSTR prod
= NULL
, feat
= NULL
;
2969 TRACE("%s %s %i %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
2970 dwInstallMode
, dwReserved
);
2972 prod
= strdupAtoW( szProduct
);
2973 if (szProduct
&& !prod
)
2976 feat
= strdupAtoW( szFeature
);
2977 if (szFeature
&& !feat
)
2980 ret
= MsiUseFeatureExW( prod
, feat
, dwInstallMode
, dwReserved
);
2989 /***********************************************************************
2990 * MsiUseFeatureW [MSI.@]
2992 INSTALLSTATE WINAPI
MsiUseFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
)
2994 return MsiUseFeatureExW(szProduct
, szFeature
, 0, 0);
2997 /***********************************************************************
2998 * MsiUseFeatureA [MSI.@]
3000 INSTALLSTATE WINAPI
MsiUseFeatureA( LPCSTR szProduct
, LPCSTR szFeature
)
3002 return MsiUseFeatureExA(szProduct
, szFeature
, 0, 0);
3005 /***********************************************************************
3006 * MSI_ProvideQualifiedComponentEx [internal]
3008 static UINT
MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent
,
3009 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3010 DWORD Unused1
, DWORD Unused2
, awstring
*lpPathBuf
,
3011 LPDWORD pcchPathBuf
)
3013 WCHAR product
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1],
3014 feature
[MAX_FEATURE_CHARS
+1];
3020 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent
),
3021 debugstr_w(szQualifier
), dwInstallMode
, debugstr_w(szProduct
),
3022 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3024 rc
= MSIREG_OpenUserComponentsKey(szComponent
, &hkey
, FALSE
);
3025 if (rc
!= ERROR_SUCCESS
)
3026 return ERROR_INDEX_ABSENT
;
3028 info
= msi_reg_get_val_str( hkey
, szQualifier
);
3032 return ERROR_INDEX_ABSENT
;
3034 MsiDecomposeDescriptorW(info
, product
, feature
, component
, &sz
);
3037 rc
= MSI_GetComponentPath(product
, component
, lpPathBuf
, pcchPathBuf
);
3039 rc
= MSI_GetComponentPath(szProduct
, component
, lpPathBuf
, pcchPathBuf
);
3043 if (rc
!= INSTALLSTATE_LOCAL
)
3044 return ERROR_FILE_NOT_FOUND
;
3046 return ERROR_SUCCESS
;
3049 /***********************************************************************
3050 * MsiProvideQualifiedComponentExW [MSI.@]
3052 UINT WINAPI
MsiProvideQualifiedComponentExW(LPCWSTR szComponent
,
3053 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3054 DWORD Unused1
, DWORD Unused2
, LPWSTR lpPathBuf
,
3055 LPDWORD pcchPathBuf
)
3059 path
.unicode
= TRUE
;
3060 path
.str
.w
= lpPathBuf
;
3062 return MSI_ProvideQualifiedComponentEx(szComponent
, szQualifier
,
3063 dwInstallMode
, szProduct
, Unused1
, Unused2
, &path
, pcchPathBuf
);
3066 /***********************************************************************
3067 * MsiProvideQualifiedComponentExA [MSI.@]
3069 UINT WINAPI
MsiProvideQualifiedComponentExA(LPCSTR szComponent
,
3070 LPCSTR szQualifier
, DWORD dwInstallMode
, LPCSTR szProduct
,
3071 DWORD Unused1
, DWORD Unused2
, LPSTR lpPathBuf
,
3072 LPDWORD pcchPathBuf
)
3074 LPWSTR szwComponent
, szwQualifier
= NULL
, szwProduct
= NULL
;
3075 UINT r
= ERROR_OUTOFMEMORY
;
3078 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent
),
3079 debugstr_a(szQualifier
), dwInstallMode
, debugstr_a(szProduct
),
3080 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3082 szwComponent
= strdupAtoW( szComponent
);
3083 if (szComponent
&& !szwComponent
)
3086 szwQualifier
= strdupAtoW( szQualifier
);
3087 if (szQualifier
&& !szwQualifier
)
3090 szwProduct
= strdupAtoW( szProduct
);
3091 if (szProduct
&& !szwProduct
)
3094 path
.unicode
= FALSE
;
3095 path
.str
.a
= lpPathBuf
;
3097 r
= MSI_ProvideQualifiedComponentEx(szwComponent
, szwQualifier
,
3098 dwInstallMode
, szwProduct
, Unused1
,
3099 Unused2
, &path
, pcchPathBuf
);
3101 msi_free(szwProduct
);
3102 msi_free(szwComponent
);
3103 msi_free(szwQualifier
);
3108 /***********************************************************************
3109 * MsiProvideQualifiedComponentW [MSI.@]
3111 UINT WINAPI
MsiProvideQualifiedComponentW( LPCWSTR szComponent
,
3112 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPWSTR lpPathBuf
,
3113 LPDWORD pcchPathBuf
)
3115 return MsiProvideQualifiedComponentExW(szComponent
, szQualifier
,
3116 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3119 /***********************************************************************
3120 * MsiProvideQualifiedComponentA [MSI.@]
3122 UINT WINAPI
MsiProvideQualifiedComponentA( LPCSTR szComponent
,
3123 LPCSTR szQualifier
, DWORD dwInstallMode
, LPSTR lpPathBuf
,
3124 LPDWORD pcchPathBuf
)
3126 return MsiProvideQualifiedComponentExA(szComponent
, szQualifier
,
3127 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3130 /***********************************************************************
3131 * MSI_GetUserInfo [internal]
3133 static USERINFOSTATE
MSI_GetUserInfo(LPCWSTR szProduct
,
3134 awstring
*lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3135 awstring
*lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3136 awstring
*lpSerialBuf
, LPDWORD pcchSerialBuf
)
3138 WCHAR squished_pc
[SQUISH_GUID_SIZE
];
3139 LPWSTR user
, org
, serial
;
3140 USERINFOSTATE state
;
3145 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct
), lpUserNameBuf
,
3146 pcchUserNameBuf
, lpOrgNameBuf
, pcchOrgNameBuf
, lpSerialBuf
,
3149 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
3150 return USERINFOSTATE_INVALIDARG
;
3152 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
3153 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3154 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3155 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3156 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
3157 &hkey
, FALSE
) != ERROR_SUCCESS
)
3159 return USERINFOSTATE_UNKNOWN
;
3162 if (MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3163 NULL
, &props
, FALSE
) != ERROR_SUCCESS
&&
3164 MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
3165 NULL
, &props
, FALSE
) != ERROR_SUCCESS
)
3168 return USERINFOSTATE_ABSENT
;
3171 user
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGOWNERW
);
3172 org
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGCOMPANYW
);
3173 serial
= msi_reg_get_val_str(props
, INSTALLPROPERTY_PRODUCTIDW
);
3174 state
= USERINFOSTATE_ABSENT
;
3180 state
= USERINFOSTATE_PRESENT
;
3182 if (pcchUserNameBuf
)
3184 if (lpUserNameBuf
&& !user
)
3186 (*pcchUserNameBuf
)--;
3190 r
= msi_strcpy_to_awstring(user
, lpUserNameBuf
, pcchUserNameBuf
);
3191 if (r
== ERROR_MORE_DATA
)
3193 state
= USERINFOSTATE_MOREDATA
;
3201 if (!orgptr
) orgptr
= szEmpty
;
3203 r
= msi_strcpy_to_awstring(orgptr
, lpOrgNameBuf
, pcchOrgNameBuf
);
3204 if (r
== ERROR_MORE_DATA
)
3206 state
= USERINFOSTATE_MOREDATA
;
3219 r
= msi_strcpy_to_awstring(serial
, lpSerialBuf
, pcchSerialBuf
);
3220 if (r
== ERROR_MORE_DATA
)
3221 state
= USERINFOSTATE_MOREDATA
;
3232 /***********************************************************************
3233 * MsiGetUserInfoW [MSI.@]
3235 USERINFOSTATE WINAPI
MsiGetUserInfoW(LPCWSTR szProduct
,
3236 LPWSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3237 LPWSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3238 LPWSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3240 awstring user
, org
, serial
;
3242 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3243 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3244 (lpSerialBuf
&& !pcchSerialBuf
))
3245 return USERINFOSTATE_INVALIDARG
;
3247 user
.unicode
= TRUE
;
3248 user
.str
.w
= lpUserNameBuf
;
3250 org
.str
.w
= lpOrgNameBuf
;
3251 serial
.unicode
= TRUE
;
3252 serial
.str
.w
= lpSerialBuf
;
3254 return MSI_GetUserInfo( szProduct
, &user
, pcchUserNameBuf
,
3255 &org
, pcchOrgNameBuf
,
3256 &serial
, pcchSerialBuf
);
3259 USERINFOSTATE WINAPI
MsiGetUserInfoA(LPCSTR szProduct
,
3260 LPSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3261 LPSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3262 LPSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3264 awstring user
, org
, serial
;
3268 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3269 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3270 (lpSerialBuf
&& !pcchSerialBuf
))
3271 return USERINFOSTATE_INVALIDARG
;
3273 prod
= strdupAtoW( szProduct
);
3274 if (szProduct
&& !prod
)
3275 return ERROR_OUTOFMEMORY
;
3277 user
.unicode
= FALSE
;
3278 user
.str
.a
= lpUserNameBuf
;
3279 org
.unicode
= FALSE
;
3280 org
.str
.a
= lpOrgNameBuf
;
3281 serial
.unicode
= FALSE
;
3282 serial
.str
.a
= lpSerialBuf
;
3284 r
= MSI_GetUserInfo( prod
, &user
, pcchUserNameBuf
,
3285 &org
, pcchOrgNameBuf
,
3286 &serial
, pcchSerialBuf
);
3293 UINT WINAPI
MsiCollectUserInfoW(LPCWSTR szProduct
)
3297 MSIPACKAGE
*package
;
3298 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3300 TRACE("(%s)\n",debugstr_w(szProduct
));
3302 rc
= MsiOpenProductW(szProduct
,&handle
);
3303 if (rc
!= ERROR_SUCCESS
)
3304 return ERROR_INVALID_PARAMETER
;
3306 /* MsiCollectUserInfo cannot be called from a custom action. */
3307 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3309 return ERROR_CALL_NOT_IMPLEMENTED
;
3311 rc
= ACTION_PerformUIAction(package
, szFirstRun
, -1);
3312 msiobj_release( &package
->hdr
);
3314 MsiCloseHandle(handle
);
3319 UINT WINAPI
MsiCollectUserInfoA(LPCSTR szProduct
)
3323 MSIPACKAGE
*package
;
3324 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3326 TRACE("(%s)\n",debugstr_a(szProduct
));
3328 rc
= MsiOpenProductA(szProduct
,&handle
);
3329 if (rc
!= ERROR_SUCCESS
)
3330 return ERROR_INVALID_PARAMETER
;
3332 /* MsiCollectUserInfo cannot be called from a custom action. */
3333 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3335 return ERROR_CALL_NOT_IMPLEMENTED
;
3337 rc
= ACTION_PerformUIAction(package
, szFirstRun
, -1);
3338 msiobj_release( &package
->hdr
);
3340 MsiCloseHandle(handle
);
3345 /***********************************************************************
3346 * MsiConfigureFeatureA [MSI.@]
3348 UINT WINAPI
MsiConfigureFeatureA(LPCSTR szProduct
, LPCSTR szFeature
, INSTALLSTATE eInstallState
)
3350 LPWSTR prod
, feat
= NULL
;
3351 UINT r
= ERROR_OUTOFMEMORY
;
3353 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
), eInstallState
);
3355 prod
= strdupAtoW( szProduct
);
3356 if (szProduct
&& !prod
)
3359 feat
= strdupAtoW( szFeature
);
3360 if (szFeature
&& !feat
)
3363 r
= MsiConfigureFeatureW(prod
, feat
, eInstallState
);
3372 /***********************************************************************
3373 * MsiConfigureFeatureW [MSI.@]
3375 UINT WINAPI
MsiConfigureFeatureW(LPCWSTR szProduct
, LPCWSTR szFeature
, INSTALLSTATE eInstallState
)
3377 static const WCHAR szCostInit
[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3378 MSIPACKAGE
*package
= NULL
;
3380 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
3383 TRACE("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
), eInstallState
);
3385 if (!szProduct
|| !szFeature
)
3386 return ERROR_INVALID_PARAMETER
;
3388 switch (eInstallState
)
3390 case INSTALLSTATE_DEFAULT
:
3391 /* FIXME: how do we figure out the default location? */
3392 eInstallState
= INSTALLSTATE_LOCAL
;
3394 case INSTALLSTATE_LOCAL
:
3395 case INSTALLSTATE_SOURCE
:
3396 case INSTALLSTATE_ABSENT
:
3397 case INSTALLSTATE_ADVERTISED
:
3400 return ERROR_INVALID_PARAMETER
;
3403 r
= MSI_OpenProductW( szProduct
, &package
);
3404 if (r
!= ERROR_SUCCESS
)
3407 sz
= sizeof(sourcepath
);
3408 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3409 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3411 sz
= sizeof(filename
);
3412 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3413 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3415 lstrcatW( sourcepath
, filename
);
3417 MsiSetInternalUI( INSTALLUILEVEL_BASIC
, NULL
);
3419 r
= ACTION_PerformUIAction( package
, szCostInit
, -1 );
3420 if (r
!= ERROR_SUCCESS
)
3423 r
= MSI_SetFeatureStateW( package
, szFeature
, eInstallState
);
3424 if (r
!= ERROR_SUCCESS
)
3427 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3430 msiobj_release( &package
->hdr
);
3435 /***********************************************************************
3436 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3438 * Notes: undocumented
3440 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved
)
3442 WCHAR path
[MAX_PATH
];
3444 TRACE("%d\n", dwReserved
);
3448 FIXME("dwReserved=%d\n", dwReserved
);
3449 return ERROR_INVALID_PARAMETER
;
3452 if (!GetWindowsDirectoryW(path
, MAX_PATH
))
3453 return ERROR_FUNCTION_FAILED
;
3455 lstrcatW(path
, installerW
);
3457 if (!CreateDirectoryW(path
, NULL
))
3458 return ERROR_FUNCTION_FAILED
;
3460 return ERROR_SUCCESS
;
3463 /***********************************************************************
3464 * MsiGetShortcutTargetA [MSI.@]
3466 UINT WINAPI
MsiGetShortcutTargetA( LPCSTR szShortcutTarget
,
3467 LPSTR szProductCode
, LPSTR szFeatureId
,
3468 LPSTR szComponentCode
)
3471 const int len
= MAX_FEATURE_CHARS
+1;
3472 WCHAR product
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1];
3475 target
= strdupAtoW( szShortcutTarget
);
3476 if (szShortcutTarget
&& !target
)
3477 return ERROR_OUTOFMEMORY
;
3481 r
= MsiGetShortcutTargetW( target
, product
, feature
, component
);
3483 if (r
== ERROR_SUCCESS
)
3485 WideCharToMultiByte( CP_ACP
, 0, product
, -1, szProductCode
, len
, NULL
, NULL
);
3486 WideCharToMultiByte( CP_ACP
, 0, feature
, -1, szFeatureId
, len
, NULL
, NULL
);
3487 WideCharToMultiByte( CP_ACP
, 0, component
, -1, szComponentCode
, len
, NULL
, NULL
);
3492 /***********************************************************************
3493 * MsiGetShortcutTargetW [MSI.@]
3495 UINT WINAPI
MsiGetShortcutTargetW( LPCWSTR szShortcutTarget
,
3496 LPWSTR szProductCode
, LPWSTR szFeatureId
,
3497 LPWSTR szComponentCode
)
3499 IShellLinkDataList
*dl
= NULL
;
3500 IPersistFile
*pf
= NULL
;
3501 LPEXP_DARWIN_LINK darwin
= NULL
;
3504 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget
),
3505 szProductCode
, szFeatureId
, szComponentCode
);
3507 init
= CoInitialize(NULL
);
3509 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3510 &IID_IPersistFile
, (LPVOID
*) &pf
);
3511 if( SUCCEEDED( r
) )
3513 r
= IPersistFile_Load( pf
, szShortcutTarget
,
3514 STGM_READ
| STGM_SHARE_DENY_WRITE
);
3515 if( SUCCEEDED( r
) )
3517 r
= IPersistFile_QueryInterface( pf
, &IID_IShellLinkDataList
,
3519 if( SUCCEEDED( r
) )
3521 IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
,
3523 IShellLinkDataList_Release( dl
);
3526 IPersistFile_Release( pf
);
3529 if (SUCCEEDED(init
))
3532 TRACE("darwin = %p\n", darwin
);
3539 ret
= MsiDecomposeDescriptorW( darwin
->szwDarwinID
,
3540 szProductCode
, szFeatureId
, szComponentCode
, &sz
);
3541 LocalFree( darwin
);
3545 return ERROR_FUNCTION_FAILED
;
3548 UINT WINAPI
MsiReinstallFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3549 DWORD dwReinstallMode
)
3551 MSIPACKAGE
* package
= NULL
;
3553 WCHAR sourcepath
[MAX_PATH
];
3554 WCHAR filename
[MAX_PATH
];
3555 static const WCHAR szLogVerbose
[] = {
3556 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3557 WCHAR reinstallmode
[11];
3561 FIXME("%s %s 0x%08x\n",
3562 debugstr_w(szProduct
), debugstr_w(szFeature
), dwReinstallMode
);
3564 ptr
= reinstallmode
;
3566 if (dwReinstallMode
& REINSTALLMODE_FILEMISSING
)
3568 if (dwReinstallMode
& REINSTALLMODE_FILEOLDERVERSION
)
3570 if (dwReinstallMode
& REINSTALLMODE_FILEEQUALVERSION
)
3572 if (dwReinstallMode
& REINSTALLMODE_FILEEXACT
)
3574 if (dwReinstallMode
& REINSTALLMODE_FILEVERIFY
)
3576 if (dwReinstallMode
& REINSTALLMODE_FILEREPLACE
)
3578 if (dwReinstallMode
& REINSTALLMODE_USERDATA
)
3580 if (dwReinstallMode
& REINSTALLMODE_MACHINEDATA
)
3582 if (dwReinstallMode
& REINSTALLMODE_SHORTCUT
)
3584 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3588 sz
= sizeof(sourcepath
);
3589 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3590 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3592 sz
= sizeof(filename
);
3593 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3594 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3596 lstrcatW( sourcepath
, filename
);
3598 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3599 r
= MSI_OpenPackageW( sourcepath
, &package
);
3601 r
= MSI_OpenProductW( szProduct
, &package
);
3603 if (r
!= ERROR_SUCCESS
)
3606 msi_set_property( package
->db
, szReinstallMode
, reinstallmode
);
3607 msi_set_property( package
->db
, szInstalled
, szOne
);
3608 msi_set_property( package
->db
, szLogVerbose
, szOne
);
3609 msi_set_property( package
->db
, szReinstall
, szFeature
);
3611 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3613 msiobj_release( &package
->hdr
);
3618 UINT WINAPI
MsiReinstallFeatureA( LPCSTR szProduct
, LPCSTR szFeature
,
3619 DWORD dwReinstallMode
)
3625 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3628 wszProduct
= strdupAtoW(szProduct
);
3629 wszFeature
= strdupAtoW(szFeature
);
3631 rc
= MsiReinstallFeatureW(wszProduct
, wszFeature
, dwReinstallMode
);
3633 msi_free(wszProduct
);
3634 msi_free(wszFeature
);
3641 unsigned int buf
[4];
3642 unsigned char in
[64];
3643 unsigned char digest
[16];
3646 extern VOID WINAPI
MD5Init( MD5_CTX
*);
3647 extern VOID WINAPI
MD5Update( MD5_CTX
*, const unsigned char *, unsigned int );
3648 extern VOID WINAPI
MD5Final( MD5_CTX
*);
3650 /***********************************************************************
3651 * MsiGetFileHashW [MSI.@]
3653 UINT WINAPI
MsiGetFileHashW( LPCWSTR szFilePath
, DWORD dwOptions
,
3654 PMSIFILEHASHINFO pHash
)
3656 HANDLE handle
, mapping
;
3659 UINT r
= ERROR_FUNCTION_FAILED
;
3661 TRACE("%s %08x %p\n", debugstr_w(szFilePath
), dwOptions
, pHash
);
3664 return ERROR_INVALID_PARAMETER
;
3667 return ERROR_PATH_NOT_FOUND
;
3670 return ERROR_INVALID_PARAMETER
;
3672 return ERROR_INVALID_PARAMETER
;
3673 if (pHash
->dwFileHashInfoSize
< sizeof *pHash
)
3674 return ERROR_INVALID_PARAMETER
;
3676 handle
= CreateFileW( szFilePath
, GENERIC_READ
,
3677 FILE_SHARE_READ
| FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, 0, NULL
);
3678 if (handle
== INVALID_HANDLE_VALUE
)
3680 WARN("can't open file %u\n", GetLastError());
3681 return ERROR_FILE_NOT_FOUND
;
3683 length
= GetFileSize( handle
, NULL
);
3685 mapping
= CreateFileMappingW( handle
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
3688 p
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, length
);
3694 MD5Update( &ctx
, p
, length
);
3696 UnmapViewOfFile( p
);
3698 memcpy( pHash
->dwData
, ctx
.digest
, sizeof pHash
->dwData
);
3701 CloseHandle( mapping
);
3703 CloseHandle( handle
);
3708 /***********************************************************************
3709 * MsiGetFileHashA [MSI.@]
3711 UINT WINAPI
MsiGetFileHashA( LPCSTR szFilePath
, DWORD dwOptions
,
3712 PMSIFILEHASHINFO pHash
)
3717 TRACE("%s %08x %p\n", debugstr_a(szFilePath
), dwOptions
, pHash
);
3719 file
= strdupAtoW( szFilePath
);
3720 if (szFilePath
&& !file
)
3721 return ERROR_OUTOFMEMORY
;
3723 r
= MsiGetFileHashW( file
, dwOptions
, pHash
);
3728 /***********************************************************************
3729 * MsiAdvertiseScriptW [MSI.@]
3731 UINT WINAPI
MsiAdvertiseScriptW( LPCWSTR szScriptFile
, DWORD dwFlags
,
3732 PHKEY phRegData
, BOOL fRemoveItems
)
3734 FIXME("%s %08x %p %d\n",
3735 debugstr_w( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3736 return ERROR_CALL_NOT_IMPLEMENTED
;
3739 /***********************************************************************
3740 * MsiAdvertiseScriptA [MSI.@]
3742 UINT WINAPI
MsiAdvertiseScriptA( LPCSTR szScriptFile
, DWORD dwFlags
,
3743 PHKEY phRegData
, BOOL fRemoveItems
)
3745 FIXME("%s %08x %p %d\n",
3746 debugstr_a( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3747 return ERROR_CALL_NOT_IMPLEMENTED
;
3750 /***********************************************************************
3751 * MsiIsProductElevatedW [MSI.@]
3753 UINT WINAPI
MsiIsProductElevatedW( LPCWSTR szProduct
, BOOL
*pfElevated
)
3755 FIXME("%s %p - stub\n",
3756 debugstr_w( szProduct
), pfElevated
);
3758 return ERROR_SUCCESS
;
3761 /***********************************************************************
3762 * MsiIsProductElevatedA [MSI.@]
3764 UINT WINAPI
MsiIsProductElevatedA( LPCSTR szProduct
, BOOL
*pfElevated
)
3766 FIXME("%s %p - stub\n",
3767 debugstr_a( szProduct
), pfElevated
);
3769 return ERROR_SUCCESS
;
3772 /***********************************************************************
3773 * MsiSetExternalUIRecord [MSI.@]
3775 UINT WINAPI
MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler
,
3776 DWORD filter
, LPVOID context
,
3777 PINSTALLUI_HANDLER_RECORD prev
)
3779 TRACE("%p %08x %p %p\n", handler
, filter
, context
, prev
);
3782 *prev
= gUIHandlerRecord
;
3784 gUIHandlerRecord
= handler
;
3786 gUIContext
= context
;
3788 return ERROR_SUCCESS
;
3791 /***********************************************************************
3792 * MsiInstallMissingComponentA [MSI.@]
3794 UINT WINAPI
MsiInstallMissingComponentA( LPCSTR product
, LPCSTR component
, INSTALLSTATE state
)
3797 WCHAR
*productW
= NULL
, *componentW
= NULL
;
3799 TRACE("%s, %s, %d\n", debugstr_a(product
), debugstr_a(component
), state
);
3801 if (product
&& !(productW
= strdupAtoW( product
)))
3802 return ERROR_OUTOFMEMORY
;
3804 if (component
&& !(componentW
= strdupAtoW( component
)))
3806 msi_free( productW
);
3807 return ERROR_OUTOFMEMORY
;
3810 r
= MsiInstallMissingComponentW( productW
, componentW
, state
);
3811 msi_free( productW
);
3812 msi_free( componentW
);
3816 /***********************************************************************
3817 * MsiInstallMissingComponentW [MSI.@]
3819 UINT WINAPI
MsiInstallMissingComponentW(LPCWSTR szProduct
, LPCWSTR szComponent
, INSTALLSTATE eInstallState
)
3821 FIXME("(%s %s %d\n", debugstr_w(szProduct
), debugstr_w(szComponent
), eInstallState
);
3822 return ERROR_SUCCESS
;
3825 /***********************************************************************
3826 * MsiBeginTransactionA [MSI.@]
3828 UINT WINAPI
MsiBeginTransactionA( LPCSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
3833 FIXME("%s %u %p %p\n", debugstr_a(name
), attrs
, id
, event
);
3835 nameW
= strdupAtoW( name
);
3837 return ERROR_OUTOFMEMORY
;
3839 r
= MsiBeginTransactionW( nameW
, attrs
, id
, event
);
3844 /***********************************************************************
3845 * MsiBeginTransactionW [MSI.@]
3847 UINT WINAPI
MsiBeginTransactionW( LPCWSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
3849 FIXME("%s %u %p %p\n", debugstr_w(name
), attrs
, id
, event
);
3851 *id
= (MSIHANDLE
)0xdeadbeef;
3852 *event
= (HANDLE
)0xdeadbeef;
3854 return ERROR_SUCCESS
;
3857 /***********************************************************************
3858 * MsiEndTransaction [MSI.@]
3860 UINT WINAPI
MsiEndTransaction( DWORD state
)
3862 FIXME("%u\n", state
);
3863 return ERROR_SUCCESS
;