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 patcheq
[] = {'P','A','T','C','H','=',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
= lstrlenW(cmd_ptr
) + lstrlenW(patcheq
) + lstrlenW(szPatchPackage
) + 1;
367 cmd
= msi_alloc(size
* sizeof(WCHAR
));
371 return ERROR_OUTOFMEMORY
;
374 lstrcpyW(cmd
, cmd_ptr
);
375 if (szCommandLine
) lstrcatW(cmd
, szSpace
);
376 lstrcatW(cmd
, patcheq
);
377 lstrcatW(cmd
, szPatchPackage
);
380 r
= MsiConfigureProductExW(szProductCode
, INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
384 while ((end
= strchrW(beg
, '}')))
387 r
= MsiConfigureProductExW(beg
, INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
388 if (r
== ERROR_SUCCESS
)
390 TRACE("patch applied\n");
405 UINT WINAPI
MsiApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szInstallPackage
,
406 INSTALLTYPE eInstallType
, LPCWSTR szCommandLine
)
408 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage
), debugstr_w(szInstallPackage
),
409 eInstallType
, debugstr_w(szCommandLine
));
411 if (szInstallPackage
|| eInstallType
== INSTALLTYPE_NETWORK_IMAGE
||
412 eInstallType
== INSTALLTYPE_SINGLE_INSTANCE
)
414 FIXME("Only reading target products from patch\n");
415 return ERROR_CALL_NOT_IMPLEMENTED
;
418 return MSI_ApplyPatchW(szPatchPackage
, NULL
, szCommandLine
);
421 UINT WINAPI
MsiApplyMultiplePatchesA(LPCSTR szPatchPackages
,
422 LPCSTR szProductCode
, LPCSTR szPropertiesList
)
424 LPWSTR patch_packages
= NULL
;
425 LPWSTR product_code
= NULL
;
426 LPWSTR properties_list
= NULL
;
427 UINT r
= ERROR_OUTOFMEMORY
;
429 TRACE("%s %s %s\n", debugstr_a(szPatchPackages
), debugstr_a(szProductCode
),
430 debugstr_a(szPropertiesList
));
432 if (!szPatchPackages
|| !szPatchPackages
[0])
433 return ERROR_INVALID_PARAMETER
;
435 if (!(patch_packages
= strdupAtoW(szPatchPackages
)))
436 return ERROR_OUTOFMEMORY
;
438 if (szProductCode
&& !(product_code
= strdupAtoW(szProductCode
)))
441 if (szPropertiesList
&& !(properties_list
= strdupAtoW(szPropertiesList
)))
444 r
= MsiApplyMultiplePatchesW(patch_packages
, product_code
, properties_list
);
447 msi_free(patch_packages
);
448 msi_free(product_code
);
449 msi_free(properties_list
);
454 UINT WINAPI
MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages
,
455 LPCWSTR szProductCode
, LPCWSTR szPropertiesList
)
457 UINT r
= ERROR_SUCCESS
;
460 TRACE("%s %s %s\n", debugstr_w(szPatchPackages
), debugstr_w(szProductCode
),
461 debugstr_w(szPropertiesList
));
463 if (!szPatchPackages
|| !szPatchPackages
[0])
464 return ERROR_INVALID_PARAMETER
;
466 beg
= end
= szPatchPackages
;
472 while (*beg
== ' ') beg
++;
473 while (*end
&& *end
!= ';') end
++;
476 while (len
&& beg
[len
- 1] == ' ') len
--;
478 if (!len
) return ERROR_INVALID_NAME
;
480 patch
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
482 return ERROR_OUTOFMEMORY
;
484 memcpy(patch
, beg
, len
* sizeof(WCHAR
));
487 r
= MSI_ApplyPatchW(patch
, szProductCode
, szPropertiesList
);
490 if (r
!= ERROR_SUCCESS
)
498 UINT WINAPI
MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath
,
499 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
502 WCHAR
*package_path
= NULL
;
503 MSIPATCHSEQUENCEINFOW
*psi
;
505 TRACE("(%s, %d, %p)\n", debugstr_a(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
507 if (szProductPackagePath
&& !(package_path
= strdupAtoW( szProductPackagePath
)))
508 return ERROR_OUTOFMEMORY
;
510 psi
= msi_alloc( cPatchInfo
* sizeof(*psi
) );
513 msi_free( package_path
);
514 return ERROR_OUTOFMEMORY
;
517 for (i
= 0; i
< cPatchInfo
; i
++)
519 psi
[i
].szPatchData
= strdupAtoW( pPatchInfo
[i
].szPatchData
);
520 psi
[i
].ePatchDataType
= pPatchInfo
[i
].ePatchDataType
;
523 r
= MsiDetermineApplicablePatchesW( package_path
, cPatchInfo
, psi
);
524 if (r
== ERROR_SUCCESS
)
526 for (i
= 0; i
< cPatchInfo
; i
++)
528 pPatchInfo
[i
].dwOrder
= psi
[i
].dwOrder
;
529 pPatchInfo
[i
].uStatus
= psi
[i
].uStatus
;
533 msi_free( package_path
);
534 for (i
= 0; i
< cPatchInfo
; i
++)
535 msi_free( (WCHAR
*)psi
[i
].szPatchData
);
540 static UINT
MSI_ApplicablePatchW( MSIPACKAGE
*package
, LPCWSTR patch
)
543 MSIDATABASE
*patch_db
;
544 UINT r
= ERROR_SUCCESS
;
546 r
= MSI_OpenDatabaseW( patch
, MSIDBOPEN_READONLY
, &patch_db
);
547 if (r
!= ERROR_SUCCESS
)
549 WARN("failed to open patch file %s\n", debugstr_w(patch
));
553 si
= MSI_GetSummaryInformationW( patch_db
->storage
, 0 );
556 msiobj_release( &patch_db
->hdr
);
557 return ERROR_FUNCTION_FAILED
;
560 r
= msi_check_patch_applicable( package
, si
);
561 if (r
!= ERROR_SUCCESS
)
562 TRACE("patch not applicable\n");
564 msiobj_release( &patch_db
->hdr
);
565 msiobj_release( &si
->hdr
);
569 UINT WINAPI
MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath
,
570 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
572 UINT i
, r
, ret
= ERROR_FUNCTION_FAILED
;
575 TRACE("(%s, %d, %p)\n", debugstr_w(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
577 r
= MSI_OpenPackageW( szProductPackagePath
, &package
);
578 if (r
!= ERROR_SUCCESS
)
580 ERR("failed to open package %u\n", r
);
584 for (i
= 0; i
< cPatchInfo
; i
++)
586 switch (pPatchInfo
[i
].ePatchDataType
)
588 case MSIPATCH_DATATYPE_PATCHFILE
:
590 FIXME("patch ordering not supported\n");
591 r
= MSI_ApplicablePatchW( package
, pPatchInfo
[i
].szPatchData
);
592 if (r
!= ERROR_SUCCESS
)
594 pPatchInfo
[i
].dwOrder
= ~0u;
595 pPatchInfo
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
599 pPatchInfo
[i
].dwOrder
= i
;
600 pPatchInfo
[i
].uStatus
= ret
= ERROR_SUCCESS
;
606 FIXME("patch data type %u not supported\n", pPatchInfo
[i
].ePatchDataType
);
607 pPatchInfo
[i
].dwOrder
= ~0u;
608 pPatchInfo
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
613 TRACE(" szPatchData: %s\n", debugstr_w(pPatchInfo
[i
].szPatchData
));
614 TRACE("ePatchDataType: %u\n", pPatchInfo
[i
].ePatchDataType
);
615 TRACE(" dwOrder: %u\n", pPatchInfo
[i
].dwOrder
);
616 TRACE(" uStatus: %u\n", pPatchInfo
[i
].uStatus
);
621 UINT WINAPI
MsiDeterminePatchSequenceA(LPCSTR szProductCode
, LPCSTR szUserSid
,
622 MSIINSTALLCONTEXT dwContext
, DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
624 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_a(szProductCode
),
625 debugstr_a(szUserSid
), dwContext
, cPatchInfo
, pPatchInfo
);
627 return ERROR_CALL_NOT_IMPLEMENTED
;
630 UINT WINAPI
MsiDeterminePatchSequenceW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
631 MSIINSTALLCONTEXT dwContext
, DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
633 FIXME("(%s, %s, %d, %d, %p): stub!\n", debugstr_w(szProductCode
),
634 debugstr_w(szUserSid
), dwContext
, cPatchInfo
, pPatchInfo
);
636 return ERROR_CALL_NOT_IMPLEMENTED
;
639 static UINT
msi_open_package(LPCWSTR product
, MSIINSTALLCONTEXT context
,
640 MSIPACKAGE
**package
)
646 WCHAR sourcepath
[MAX_PATH
];
647 WCHAR filename
[MAX_PATH
];
649 r
= MSIREG_OpenInstallProps(product
, context
, NULL
, &props
, FALSE
);
650 if (r
!= ERROR_SUCCESS
)
651 return ERROR_BAD_CONFIGURATION
;
653 localpack
= msi_reg_get_val_str(props
, szLocalPackage
);
656 lstrcpyW(sourcepath
, localpack
);
660 if (!localpack
|| GetFileAttributesW(sourcepath
) == INVALID_FILE_ATTRIBUTES
)
662 sz
= sizeof(sourcepath
);
663 MsiSourceListGetInfoW(product
, NULL
, context
, MSICODE_PRODUCT
,
664 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
666 sz
= sizeof(filename
);
667 MsiSourceListGetInfoW(product
, NULL
, context
, MSICODE_PRODUCT
,
668 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
670 lstrcatW(sourcepath
, filename
);
673 if (GetFileAttributesW(sourcepath
) == INVALID_FILE_ATTRIBUTES
)
674 return ERROR_INSTALL_SOURCE_ABSENT
;
676 return MSI_OpenPackageW(sourcepath
, package
);
679 UINT WINAPI
MsiConfigureProductExW(LPCWSTR szProduct
, int iInstallLevel
,
680 INSTALLSTATE eInstallState
, LPCWSTR szCommandLine
)
682 MSIPACKAGE
* package
= NULL
;
683 MSIINSTALLCONTEXT context
;
686 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
689 static const WCHAR szInstalled
[] = {
690 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
691 static const WCHAR szRemoveAll
[] = {
692 ' ','R','E','M','O','V','E','=','A','L','L',0};
693 static const WCHAR szMachine
[] = {
694 ' ','A','L','L','U','S','E','R','S','=','1',0};
696 TRACE("%s %d %d %s\n",debugstr_w(szProduct
), iInstallLevel
, eInstallState
,
697 debugstr_w(szCommandLine
));
699 if (!szProduct
|| lstrlenW(szProduct
) != GUID_SIZE
- 1)
700 return ERROR_INVALID_PARAMETER
;
702 if (eInstallState
== INSTALLSTATE_ADVERTISED
||
703 eInstallState
== INSTALLSTATE_SOURCE
)
705 FIXME("State %d not implemented\n", eInstallState
);
706 return ERROR_CALL_NOT_IMPLEMENTED
;
709 r
= msi_locate_product(szProduct
, &context
);
710 if (r
!= ERROR_SUCCESS
)
713 r
= msi_open_package(szProduct
, context
, &package
);
714 if (r
!= ERROR_SUCCESS
)
717 sz
= lstrlenW(szInstalled
) + 1;
720 sz
+= lstrlenW(szCommandLine
);
722 if (eInstallState
== INSTALLSTATE_ABSENT
)
723 sz
+= lstrlenW(szRemoveAll
);
725 if (context
== MSIINSTALLCONTEXT_MACHINE
)
726 sz
+= lstrlenW(szMachine
);
728 commandline
= msi_alloc(sz
* sizeof(WCHAR
));
731 r
= ERROR_OUTOFMEMORY
;
737 lstrcpyW(commandline
,szCommandLine
);
739 if (eInstallState
== INSTALLSTATE_ABSENT
)
740 lstrcatW(commandline
, szRemoveAll
);
742 if (context
== MSIINSTALLCONTEXT_MACHINE
)
743 lstrcatW(commandline
, szMachine
);
745 sz
= sizeof(sourcepath
);
746 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
747 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
749 sz
= sizeof(filename
);
750 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
751 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
753 strcatW(sourcepath
, filename
);
755 r
= MSI_InstallPackage( package
, sourcepath
, commandline
);
757 msi_free(commandline
);
760 msiobj_release( &package
->hdr
);
765 UINT WINAPI
MsiConfigureProductExA(LPCSTR szProduct
, int iInstallLevel
,
766 INSTALLSTATE eInstallState
, LPCSTR szCommandLine
)
768 LPWSTR szwProduct
= NULL
;
769 LPWSTR szwCommandLine
= NULL
;
770 UINT r
= ERROR_OUTOFMEMORY
;
774 szwProduct
= strdupAtoW( szProduct
);
781 szwCommandLine
= strdupAtoW( szCommandLine
);
786 r
= MsiConfigureProductExW( szwProduct
, iInstallLevel
, eInstallState
,
789 msi_free( szwProduct
);
790 msi_free( szwCommandLine
);
795 UINT WINAPI
MsiConfigureProductA(LPCSTR szProduct
, int iInstallLevel
,
796 INSTALLSTATE eInstallState
)
798 LPWSTR szwProduct
= NULL
;
801 TRACE("%s %d %d\n",debugstr_a(szProduct
), iInstallLevel
, eInstallState
);
805 szwProduct
= strdupAtoW( szProduct
);
807 return ERROR_OUTOFMEMORY
;
810 r
= MsiConfigureProductW( szwProduct
, iInstallLevel
, eInstallState
);
811 msi_free( szwProduct
);
816 UINT WINAPI
MsiConfigureProductW(LPCWSTR szProduct
, int iInstallLevel
,
817 INSTALLSTATE eInstallState
)
819 return MsiConfigureProductExW(szProduct
, iInstallLevel
, eInstallState
, NULL
);
822 UINT WINAPI
MsiGetProductCodeA(LPCSTR szComponent
, LPSTR szBuffer
)
824 LPWSTR szwComponent
= NULL
;
826 WCHAR szwBuffer
[GUID_SIZE
];
828 TRACE("%s %p\n", debugstr_a(szComponent
), szBuffer
);
832 szwComponent
= strdupAtoW( szComponent
);
834 return ERROR_OUTOFMEMORY
;
838 r
= MsiGetProductCodeW( szwComponent
, szwBuffer
);
841 WideCharToMultiByte(CP_ACP
, 0, szwBuffer
, -1, szBuffer
, GUID_SIZE
, NULL
, NULL
);
843 msi_free( szwComponent
);
848 UINT WINAPI
MsiGetProductCodeW(LPCWSTR szComponent
, LPWSTR szBuffer
)
851 HKEY compkey
, prodkey
;
852 WCHAR squished_comp
[GUID_SIZE
];
853 WCHAR squished_prod
[GUID_SIZE
];
854 DWORD sz
= GUID_SIZE
;
856 TRACE("%s %p\n", debugstr_w(szComponent
), szBuffer
);
858 if (!szComponent
|| !*szComponent
)
859 return ERROR_INVALID_PARAMETER
;
861 if (!squash_guid(szComponent
, squished_comp
))
862 return ERROR_INVALID_PARAMETER
;
864 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &compkey
, FALSE
) != ERROR_SUCCESS
&&
865 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &compkey
, FALSE
) != ERROR_SUCCESS
)
867 return ERROR_UNKNOWN_COMPONENT
;
870 rc
= RegEnumValueW(compkey
, 0, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
871 if (rc
!= ERROR_SUCCESS
)
873 RegCloseKey(compkey
);
874 return ERROR_UNKNOWN_COMPONENT
;
877 /* check simple case, only one product */
878 rc
= RegEnumValueW(compkey
, 1, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
879 if (rc
== ERROR_NO_MORE_ITEMS
)
886 while ((rc
= RegEnumValueW(compkey
, index
, squished_prod
, &sz
,
887 NULL
, NULL
, NULL
, NULL
)) != ERROR_NO_MORE_ITEMS
)
891 unsquash_guid(squished_prod
, szBuffer
);
893 if (MSIREG_OpenProductKey(szBuffer
, NULL
,
894 MSIINSTALLCONTEXT_USERMANAGED
,
895 &prodkey
, FALSE
) == ERROR_SUCCESS
||
896 MSIREG_OpenProductKey(szBuffer
, NULL
,
897 MSIINSTALLCONTEXT_USERUNMANAGED
,
898 &prodkey
, FALSE
) == ERROR_SUCCESS
||
899 MSIREG_OpenProductKey(szBuffer
, NULL
,
900 MSIINSTALLCONTEXT_MACHINE
,
901 &prodkey
, FALSE
) == ERROR_SUCCESS
)
903 RegCloseKey(prodkey
);
909 rc
= ERROR_INSTALL_FAILURE
;
912 RegCloseKey(compkey
);
913 unsquash_guid(squished_prod
, szBuffer
);
917 static LPWSTR
msi_reg_get_value(HKEY hkey
, LPCWSTR name
, DWORD
*type
)
923 static const WCHAR format
[] = {'%','d',0};
925 res
= RegQueryValueExW(hkey
, name
, NULL
, type
, NULL
, NULL
);
926 if (res
!= ERROR_SUCCESS
)
930 return msi_reg_get_val_str(hkey
, name
);
932 if (!msi_reg_get_val_dword(hkey
, name
, &dval
))
935 sprintfW(temp
, format
, dval
);
936 return strdupW(temp
);
939 static UINT
MSI_GetProductInfo(LPCWSTR szProduct
, LPCWSTR szAttribute
,
940 awstring
*szValue
, LPDWORD pcchValueBuf
)
942 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
943 UINT r
= ERROR_UNKNOWN_PROPERTY
;
944 HKEY prodkey
, userdata
, source
;
946 WCHAR squished_pc
[GUID_SIZE
];
947 WCHAR packagecode
[GUID_SIZE
];
948 BOOL badconfig
= FALSE
;
950 DWORD type
= REG_NONE
;
952 static WCHAR empty
[] = {0};
953 static const WCHAR sourcelist
[] = {
954 'S','o','u','r','c','e','L','i','s','t',0};
955 static const WCHAR display_name
[] = {
956 'D','i','s','p','l','a','y','N','a','m','e',0};
957 static const WCHAR display_version
[] = {
958 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
959 static const WCHAR assignment
[] = {
960 'A','s','s','i','g','n','m','e','n','t',0};
962 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
963 debugstr_w(szAttribute
), szValue
, pcchValueBuf
);
965 if ((szValue
->str
.w
&& !pcchValueBuf
) || !szProduct
|| !szAttribute
)
966 return ERROR_INVALID_PARAMETER
;
968 if (!squash_guid(szProduct
, squished_pc
))
969 return ERROR_INVALID_PARAMETER
;
971 if ((r
= MSIREG_OpenProductKey(szProduct
, NULL
,
972 MSIINSTALLCONTEXT_USERMANAGED
,
973 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
974 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
975 MSIINSTALLCONTEXT_USERUNMANAGED
,
976 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
977 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
978 MSIINSTALLCONTEXT_MACHINE
,
979 &prodkey
, FALSE
)) == ERROR_SUCCESS
)
981 context
= MSIINSTALLCONTEXT_MACHINE
;
984 MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
986 if (!lstrcmpW(szAttribute
, INSTALLPROPERTY_HELPLINKW
) ||
987 !lstrcmpW(szAttribute
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
988 !lstrcmpW(szAttribute
, INSTALLPROPERTY_INSTALLDATEW
) ||
989 !lstrcmpW(szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
990 !lstrcmpW(szAttribute
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
991 !lstrcmpW(szAttribute
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
992 !lstrcmpW(szAttribute
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
993 !lstrcmpW(szAttribute
, INSTALLPROPERTY_PUBLISHERW
) ||
994 !lstrcmpW(szAttribute
, INSTALLPROPERTY_URLINFOABOUTW
) ||
995 !lstrcmpW(szAttribute
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
996 !lstrcmpW(szAttribute
, INSTALLPROPERTY_VERSIONMINORW
) ||
997 !lstrcmpW(szAttribute
, INSTALLPROPERTY_VERSIONMAJORW
) ||
998 !lstrcmpW(szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
999 !lstrcmpW(szAttribute
, INSTALLPROPERTY_PRODUCTIDW
) ||
1000 !lstrcmpW(szAttribute
, INSTALLPROPERTY_REGCOMPANYW
) ||
1001 !lstrcmpW(szAttribute
, INSTALLPROPERTY_REGOWNERW
))
1005 r
= ERROR_UNKNOWN_PRODUCT
;
1010 return ERROR_UNKNOWN_PROPERTY
;
1012 if (!lstrcmpW(szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1013 szAttribute
= display_name
;
1014 else if (!lstrcmpW(szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
))
1015 szAttribute
= display_version
;
1017 val
= msi_reg_get_value(userdata
, szAttribute
, &type
);
1021 else if (!lstrcmpW(szAttribute
, INSTALLPROPERTY_INSTANCETYPEW
) ||
1022 !lstrcmpW(szAttribute
, INSTALLPROPERTY_TRANSFORMSW
) ||
1023 !lstrcmpW(szAttribute
, INSTALLPROPERTY_LANGUAGEW
) ||
1024 !lstrcmpW(szAttribute
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1025 !lstrcmpW(szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
) ||
1026 !lstrcmpW(szAttribute
, INSTALLPROPERTY_PACKAGECODEW
) ||
1027 !lstrcmpW(szAttribute
, INSTALLPROPERTY_VERSIONW
) ||
1028 !lstrcmpW(szAttribute
, INSTALLPROPERTY_PRODUCTICONW
) ||
1029 !lstrcmpW(szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1030 !lstrcmpW(szAttribute
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1034 r
= ERROR_UNKNOWN_PRODUCT
;
1038 if (!lstrcmpW(szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1039 szAttribute
= assignment
;
1041 if (!lstrcmpW(szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
))
1043 res
= RegOpenKeyW(prodkey
, sourcelist
, &source
);
1044 if (res
!= ERROR_SUCCESS
)
1046 r
= ERROR_UNKNOWN_PRODUCT
;
1050 val
= msi_reg_get_value(source
, szAttribute
, &type
);
1054 RegCloseKey(source
);
1058 val
= msi_reg_get_value(prodkey
, szAttribute
, &type
);
1063 if (val
!= empty
&& type
!= REG_DWORD
&&
1064 !lstrcmpW(szAttribute
, INSTALLPROPERTY_PACKAGECODEW
))
1066 if (lstrlenW(val
) != SQUISH_GUID_SIZE
- 1)
1070 unsquash_guid(val
, packagecode
);
1072 val
= strdupW(packagecode
);
1079 r
= ERROR_UNKNOWN_PROPERTY
;
1085 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1086 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1087 * can't rely on its value.
1089 if (szValue
->str
.a
|| szValue
->str
.w
)
1091 DWORD size
= *pcchValueBuf
;
1092 if (strlenW(val
) < size
)
1093 r
= msi_strcpy_to_awstring(val
, szValue
, &size
);
1096 r
= ERROR_MORE_DATA
;
1101 *pcchValueBuf
= lstrlenW(val
);
1105 r
= ERROR_BAD_CONFIGURATION
;
1111 RegCloseKey(prodkey
);
1112 RegCloseKey(userdata
);
1116 UINT WINAPI
MsiGetProductInfoA(LPCSTR szProduct
, LPCSTR szAttribute
,
1117 LPSTR szBuffer
, LPDWORD pcchValueBuf
)
1119 LPWSTR szwProduct
, szwAttribute
= NULL
;
1120 UINT r
= ERROR_OUTOFMEMORY
;
1123 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szAttribute
),
1124 szBuffer
, pcchValueBuf
);
1126 szwProduct
= strdupAtoW( szProduct
);
1127 if( szProduct
&& !szwProduct
)
1130 szwAttribute
= strdupAtoW( szAttribute
);
1131 if( szAttribute
&& !szwAttribute
)
1134 buffer
.unicode
= FALSE
;
1135 buffer
.str
.a
= szBuffer
;
1137 r
= MSI_GetProductInfo( szwProduct
, szwAttribute
,
1138 &buffer
, pcchValueBuf
);
1141 msi_free( szwProduct
);
1142 msi_free( szwAttribute
);
1147 UINT WINAPI
MsiGetProductInfoW(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1148 LPWSTR szBuffer
, LPDWORD pcchValueBuf
)
1152 TRACE("%s %s %p %p\n", debugstr_w(szProduct
), debugstr_w(szAttribute
),
1153 szBuffer
, pcchValueBuf
);
1155 buffer
.unicode
= TRUE
;
1156 buffer
.str
.w
= szBuffer
;
1158 return MSI_GetProductInfo( szProduct
, szAttribute
,
1159 &buffer
, pcchValueBuf
);
1162 UINT WINAPI
MsiGetProductInfoExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1163 MSIINSTALLCONTEXT dwContext
, LPCSTR szProperty
,
1164 LPSTR szValue
, LPDWORD pcchValue
)
1166 LPWSTR product
= NULL
;
1167 LPWSTR usersid
= NULL
;
1168 LPWSTR property
= NULL
;
1169 LPWSTR value
= NULL
;
1173 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode
),
1174 debugstr_a(szUserSid
), dwContext
, debugstr_a(szProperty
),
1175 szValue
, pcchValue
);
1177 if (szValue
&& !pcchValue
)
1178 return ERROR_INVALID_PARAMETER
;
1180 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1181 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1182 if (szProperty
) property
= strdupAtoW(szProperty
);
1184 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1186 if (r
!= ERROR_SUCCESS
)
1189 value
= msi_alloc(++len
* sizeof(WCHAR
));
1192 r
= ERROR_OUTOFMEMORY
;
1196 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1198 if (r
!= ERROR_SUCCESS
)
1204 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
1205 if (*pcchValue
>= len
)
1206 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
1209 r
= ERROR_MORE_DATA
;
1214 if (*pcchValue
<= len
|| !szValue
)
1215 len
= len
* sizeof(WCHAR
) - 1;
1217 *pcchValue
= len
- 1;
1228 static UINT
msi_copy_outval(LPWSTR val
, LPWSTR out
, LPDWORD size
)
1230 UINT r
= ERROR_SUCCESS
;
1233 return ERROR_UNKNOWN_PROPERTY
;
1237 if (strlenW(val
) >= *size
)
1239 r
= ERROR_MORE_DATA
;
1248 *size
= lstrlenW(val
);
1253 UINT WINAPI
MsiGetProductInfoExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
1254 MSIINSTALLCONTEXT dwContext
, LPCWSTR szProperty
,
1255 LPWSTR szValue
, LPDWORD pcchValue
)
1257 WCHAR squished_pc
[GUID_SIZE
];
1259 LPCWSTR package
= NULL
;
1260 HKEY props
= NULL
, prod
;
1261 HKEY classes
= NULL
, managed
;
1264 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1266 static const WCHAR five
[] = {'5',0};
1267 static const WCHAR displayname
[] = {
1268 'D','i','s','p','l','a','y','N','a','m','e',0};
1269 static const WCHAR displayversion
[] = {
1270 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1271 static const WCHAR managed_local_package
[] = {
1272 'M','a','n','a','g','e','d','L','o','c','a','l',
1273 'P','a','c','k','a','g','e',0};
1275 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode
),
1276 debugstr_w(szUserSid
), dwContext
, debugstr_w(szProperty
),
1277 szValue
, pcchValue
);
1279 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1280 return ERROR_INVALID_PARAMETER
;
1282 if (szValue
&& !pcchValue
)
1283 return ERROR_INVALID_PARAMETER
;
1285 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1286 dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1287 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1288 return ERROR_INVALID_PARAMETER
;
1290 if (!szProperty
|| !*szProperty
)
1291 return ERROR_INVALID_PARAMETER
;
1293 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1294 return ERROR_INVALID_PARAMETER
;
1296 /* FIXME: dwContext is provided, no need to search for it */
1297 MSIREG_OpenProductKey(szProductCode
, NULL
,MSIINSTALLCONTEXT_USERMANAGED
,
1299 MSIREG_OpenProductKey(szProductCode
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1302 MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
, &props
, FALSE
);
1304 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1306 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1308 if (!props
&& !prod
)
1311 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1313 package
= managed_local_package
;
1315 if (!props
&& !managed
)
1318 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1320 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1321 MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
, &classes
, FALSE
);
1323 if (!props
&& !classes
)
1327 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_HELPLINKW
) ||
1328 !lstrcmpW(szProperty
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1329 !lstrcmpW(szProperty
, INSTALLPROPERTY_INSTALLDATEW
) ||
1330 !lstrcmpW(szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1331 !lstrcmpW(szProperty
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1332 !lstrcmpW(szProperty
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1333 !lstrcmpW(szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1334 !lstrcmpW(szProperty
, INSTALLPROPERTY_PUBLISHERW
) ||
1335 !lstrcmpW(szProperty
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1336 !lstrcmpW(szProperty
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1337 !lstrcmpW(szProperty
, INSTALLPROPERTY_VERSIONMINORW
) ||
1338 !lstrcmpW(szProperty
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1339 !lstrcmpW(szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1340 !lstrcmpW(szProperty
, INSTALLPROPERTY_PRODUCTIDW
) ||
1341 !lstrcmpW(szProperty
, INSTALLPROPERTY_REGCOMPANYW
) ||
1342 !lstrcmpW(szProperty
, INSTALLPROPERTY_REGOWNERW
) ||
1343 !lstrcmpW(szProperty
, INSTALLPROPERTY_INSTANCETYPEW
))
1345 val
= msi_reg_get_value(props
, package
, &type
);
1348 if (prod
|| classes
)
1349 r
= ERROR_UNKNOWN_PROPERTY
;
1356 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1357 szProperty
= displayname
;
1358 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
))
1359 szProperty
= displayversion
;
1361 val
= msi_reg_get_value(props
, szProperty
, &type
);
1363 val
= strdupW(szEmpty
);
1365 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1367 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_TRANSFORMSW
) ||
1368 !lstrcmpW(szProperty
, INSTALLPROPERTY_LANGUAGEW
) ||
1369 !lstrcmpW(szProperty
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1370 !lstrcmpW(szProperty
, INSTALLPROPERTY_PACKAGECODEW
) ||
1371 !lstrcmpW(szProperty
, INSTALLPROPERTY_VERSIONW
) ||
1372 !lstrcmpW(szProperty
, INSTALLPROPERTY_PRODUCTICONW
) ||
1373 !lstrcmpW(szProperty
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1374 !lstrcmpW(szProperty
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1376 if (!prod
&& !classes
)
1379 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1381 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1383 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1386 val
= msi_reg_get_value(hkey
, szProperty
, &type
);
1388 val
= strdupW(szEmpty
);
1390 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1392 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_PRODUCTSTATEW
))
1394 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1398 val
= msi_reg_get_value(props
, package
, &type
);
1403 val
= strdupW(five
);
1406 val
= strdupW(szOne
);
1408 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1411 else if (props
&& (val
= msi_reg_get_value(props
, package
, &type
)))
1414 val
= strdupW(five
);
1415 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1419 if (prod
|| managed
)
1420 val
= strdupW(szOne
);
1424 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1426 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1428 if (!prod
&& !classes
)
1432 val
= strdupW(szEmpty
);
1433 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1436 r
= ERROR_UNKNOWN_PROPERTY
;
1441 RegCloseKey(managed
);
1442 RegCloseKey(classes
);
1448 UINT WINAPI
MsiGetPatchInfoExA(LPCSTR szPatchCode
, LPCSTR szProductCode
,
1449 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1450 LPCSTR szProperty
, LPSTR lpValue
, DWORD
*pcchValue
)
1452 LPWSTR patch
= NULL
, product
= NULL
, usersid
= NULL
;
1453 LPWSTR property
= NULL
, val
= NULL
;
1457 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode
),
1458 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
,
1459 debugstr_a(szProperty
), lpValue
, pcchValue
);
1461 if (lpValue
&& !pcchValue
)
1462 return ERROR_INVALID_PARAMETER
;
1464 if (szPatchCode
) patch
= strdupAtoW(szPatchCode
);
1465 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1466 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1467 if (szProperty
) property
= strdupAtoW(szProperty
);
1470 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1472 if (r
!= ERROR_SUCCESS
)
1475 val
= msi_alloc(++len
* sizeof(WCHAR
));
1478 r
= ERROR_OUTOFMEMORY
;
1482 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1484 if (r
!= ERROR_SUCCESS
|| !pcchValue
)
1488 WideCharToMultiByte(CP_ACP
, 0, val
, -1, lpValue
,
1489 *pcchValue
- 1, NULL
, NULL
);
1491 len
= lstrlenW(val
);
1492 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1496 r
= ERROR_MORE_DATA
;
1497 lpValue
[*pcchValue
- 1] = '\0';
1500 *pcchValue
= len
* sizeof(WCHAR
);
1515 UINT WINAPI
MsiGetPatchInfoExW(LPCWSTR szPatchCode
, LPCWSTR szProductCode
,
1516 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1517 LPCWSTR szProperty
, LPWSTR lpValue
, DWORD
*pcchValue
)
1519 WCHAR squished_pc
[GUID_SIZE
];
1520 WCHAR squished_patch
[GUID_SIZE
];
1521 HKEY udprod
= 0, prod
= 0, props
= 0;
1522 HKEY patch
= 0, patches
= 0;
1523 HKEY udpatch
= 0, datakey
= 0;
1524 HKEY prodpatches
= 0;
1526 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1530 static const WCHAR szManagedPackage
[] = {'M','a','n','a','g','e','d',
1531 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1533 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode
),
1534 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
,
1535 debugstr_w(szProperty
), lpValue
, pcchValue
);
1537 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1538 return ERROR_INVALID_PARAMETER
;
1540 if (!szPatchCode
|| !squash_guid(szPatchCode
, squished_patch
))
1541 return ERROR_INVALID_PARAMETER
;
1544 return ERROR_INVALID_PARAMETER
;
1546 if (lpValue
&& !pcchValue
)
1547 return ERROR_INVALID_PARAMETER
;
1549 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1550 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1551 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1552 return ERROR_INVALID_PARAMETER
;
1554 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1555 return ERROR_INVALID_PARAMETER
;
1557 if (!lstrcmpW(szUserSid
, szLocalSid
))
1558 return ERROR_INVALID_PARAMETER
;
1560 if (MSIREG_OpenUserDataProductKey(szProductCode
, dwContext
, NULL
,
1561 &udprod
, FALSE
) != ERROR_SUCCESS
)
1564 if (MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
,
1565 &props
, FALSE
) != ERROR_SUCCESS
)
1568 r
= ERROR_UNKNOWN_PATCH
;
1570 res
= RegOpenKeyExW(udprod
, szPatches
, 0, KEY_READ
, &patches
);
1571 if (res
!= ERROR_SUCCESS
)
1574 res
= RegOpenKeyExW(patches
, squished_patch
, 0, KEY_READ
, &patch
);
1575 if (res
!= ERROR_SUCCESS
)
1578 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_TRANSFORMSW
))
1580 if (MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
,
1581 &prod
, FALSE
) != ERROR_SUCCESS
)
1584 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_ALL_ACCESS
, &prodpatches
);
1585 if (res
!= ERROR_SUCCESS
)
1588 datakey
= prodpatches
;
1589 szProperty
= squished_patch
;
1593 if (MSIREG_OpenUserDataPatchKey(szPatchCode
, dwContext
,
1594 &udpatch
, FALSE
) != ERROR_SUCCESS
)
1597 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1599 if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1600 szProperty
= szManagedPackage
;
1603 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_INSTALLDATEW
))
1606 szProperty
= szInstalled
;
1608 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1612 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_UNINSTALLABLEW
) ||
1613 !lstrcmpW(szProperty
, INSTALLPROPERTY_PATCHSTATEW
) ||
1614 !lstrcmpW(szProperty
, INSTALLPROPERTY_DISPLAYNAMEW
) ||
1615 !lstrcmpW(szProperty
, INSTALLPROPERTY_MOREINFOURLW
))
1621 r
= ERROR_UNKNOWN_PROPERTY
;
1626 val
= msi_reg_get_val_str(datakey
, szProperty
);
1628 val
= strdupW(szEmpty
);
1636 lstrcpynW(lpValue
, val
, *pcchValue
);
1638 len
= lstrlenW(val
);
1639 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1642 r
= ERROR_MORE_DATA
;
1644 *pcchValue
= len
* sizeof(WCHAR
);
1651 RegCloseKey(prodpatches
);
1654 RegCloseKey(patches
);
1655 RegCloseKey(udpatch
);
1657 RegCloseKey(udprod
);
1662 UINT WINAPI
MsiGetPatchInfoA( LPCSTR patch
, LPCSTR attr
, LPSTR buffer
, LPDWORD buflen
)
1664 UINT r
= ERROR_OUTOFMEMORY
;
1666 LPWSTR patchW
= NULL
, attrW
= NULL
, bufferW
= NULL
;
1668 TRACE("%s %s %p %p\n", debugstr_a(patch
), debugstr_a(attr
), buffer
, buflen
);
1670 if (!patch
|| !attr
)
1671 return ERROR_INVALID_PARAMETER
;
1673 if (!(patchW
= strdupAtoW( patch
)))
1676 if (!(attrW
= strdupAtoW( attr
)))
1680 r
= MsiGetPatchInfoW( patchW
, attrW
, NULL
, &size
);
1681 if (r
!= ERROR_SUCCESS
)
1685 if (!(bufferW
= msi_alloc( size
* sizeof(WCHAR
) )))
1687 r
= ERROR_OUTOFMEMORY
;
1691 r
= MsiGetPatchInfoW( patchW
, attrW
, bufferW
, &size
);
1692 if (r
== ERROR_SUCCESS
)
1694 int len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
1696 r
= ERROR_MORE_DATA
;
1698 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *buflen
, NULL
, NULL
);
1706 msi_free( bufferW
);
1710 UINT WINAPI
MsiGetPatchInfoW( LPCWSTR patch
, LPCWSTR attr
, LPWSTR buffer
, LPDWORD buflen
)
1713 WCHAR product
[GUID_SIZE
];
1716 TRACE("%s %s %p %p\n", debugstr_w(patch
), debugstr_w(attr
), buffer
, buflen
);
1718 if (!patch
|| !attr
)
1719 return ERROR_INVALID_PARAMETER
;
1721 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW
, attr
))
1722 return ERROR_UNKNOWN_PROPERTY
;
1727 r
= MsiEnumProductsW( index
, product
);
1728 if (r
!= ERROR_SUCCESS
)
1731 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, attr
, buffer
, buflen
);
1732 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1735 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, attr
, buffer
, buflen
);
1736 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1739 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_MACHINE
, attr
, buffer
, buflen
);
1740 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1746 return ERROR_UNKNOWN_PRODUCT
;
1749 UINT WINAPI
MsiEnableLogA(DWORD dwLogMode
, LPCSTR szLogFile
, DWORD attributes
)
1751 LPWSTR szwLogFile
= NULL
;
1754 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_a(szLogFile
), attributes
);
1758 szwLogFile
= strdupAtoW( szLogFile
);
1760 return ERROR_OUTOFMEMORY
;
1762 r
= MsiEnableLogW( dwLogMode
, szwLogFile
, attributes
);
1763 msi_free( szwLogFile
);
1767 UINT WINAPI
MsiEnableLogW(DWORD dwLogMode
, LPCWSTR szLogFile
, DWORD attributes
)
1769 HANDLE file
= INVALID_HANDLE_VALUE
;
1771 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_w(szLogFile
), attributes
);
1775 lstrcpyW(gszLogFile
,szLogFile
);
1776 if (!(attributes
& INSTALLLOGATTRIBUTES_APPEND
))
1777 DeleteFileW(szLogFile
);
1778 file
= CreateFileW(szLogFile
, GENERIC_WRITE
, 0, NULL
, OPEN_ALWAYS
,
1779 FILE_ATTRIBUTE_NORMAL
, NULL
);
1780 if (file
!= INVALID_HANDLE_VALUE
)
1783 ERR("Unable to enable log %s\n",debugstr_w(szLogFile
));
1786 gszLogFile
[0] = '\0';
1788 return ERROR_SUCCESS
;
1791 UINT WINAPI
MsiEnumComponentCostsW(MSIHANDLE hInstall
, LPCWSTR szComponent
,
1792 DWORD dwIndex
, INSTALLSTATE iState
,
1793 LPWSTR lpDriveBuf
, DWORD
*pcchDriveBuf
,
1794 int *piCost
, int *pTempCost
)
1796 FIXME("(%d, %s, %d, %d, %p, %p, %p %p): stub!\n", hInstall
,
1797 debugstr_w(szComponent
), dwIndex
, iState
, lpDriveBuf
,
1798 pcchDriveBuf
, piCost
, pTempCost
);
1800 return ERROR_NO_MORE_ITEMS
;
1803 UINT WINAPI
MsiQueryComponentStateA(LPCSTR szProductCode
,
1804 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1805 LPCSTR szComponent
, INSTALLSTATE
*pdwState
)
1807 LPWSTR prodcode
= NULL
, usersid
= NULL
, comp
= NULL
;
1810 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode
),
1811 debugstr_a(szUserSid
), dwContext
, debugstr_a(szComponent
), pdwState
);
1813 if (szProductCode
&& !(prodcode
= strdupAtoW(szProductCode
)))
1814 return ERROR_OUTOFMEMORY
;
1816 if (szUserSid
&& !(usersid
= strdupAtoW(szUserSid
)))
1817 return ERROR_OUTOFMEMORY
;
1819 if (szComponent
&& !(comp
= strdupAtoW(szComponent
)))
1820 return ERROR_OUTOFMEMORY
;
1822 r
= MsiQueryComponentStateW(prodcode
, usersid
, dwContext
, comp
, pdwState
);
1831 static BOOL
msi_comp_find_prod_key(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
1836 r
= MSIREG_OpenProductKey(prodcode
, NULL
, context
, &hkey
, FALSE
);
1838 return (r
== ERROR_SUCCESS
);
1841 static BOOL
msi_comp_find_package(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
1849 static const WCHAR local_package
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
1850 static const WCHAR managed_local_package
[] = {
1851 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
1854 r
= MSIREG_OpenInstallProps(prodcode
, context
, NULL
, &hkey
, FALSE
);
1855 if (r
!= ERROR_SUCCESS
)
1858 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
1859 package
= managed_local_package
;
1861 package
= local_package
;
1864 res
= RegQueryValueExW(hkey
, package
, NULL
, NULL
, NULL
, &sz
);
1867 return (res
== ERROR_SUCCESS
);
1870 static BOOL
msi_comp_find_prodcode(LPWSTR squished_pc
,
1871 MSIINSTALLCONTEXT context
,
1872 LPCWSTR comp
, LPWSTR val
, DWORD
*sz
)
1878 if (context
== MSIINSTALLCONTEXT_MACHINE
)
1879 r
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
1881 r
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
1883 if (r
!= ERROR_SUCCESS
)
1886 res
= RegQueryValueExW(hkey
, squished_pc
, NULL
, NULL
, (BYTE
*)val
, sz
);
1887 if (res
!= ERROR_SUCCESS
)
1894 UINT WINAPI
MsiQueryComponentStateW(LPCWSTR szProductCode
,
1895 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1896 LPCWSTR szComponent
, INSTALLSTATE
*pdwState
)
1898 WCHAR squished_pc
[GUID_SIZE
];
1899 WCHAR val
[MAX_PATH
];
1903 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode
),
1904 debugstr_w(szUserSid
), dwContext
, debugstr_w(szComponent
), pdwState
);
1906 if (!pdwState
|| !szComponent
)
1907 return ERROR_INVALID_PARAMETER
;
1909 if (!szProductCode
|| !*szProductCode
|| lstrlenW(szProductCode
) != GUID_SIZE
- 1)
1910 return ERROR_INVALID_PARAMETER
;
1912 if (!squash_guid(szProductCode
, squished_pc
))
1913 return ERROR_INVALID_PARAMETER
;
1915 found
= msi_comp_find_prod_key(szProductCode
, dwContext
);
1917 if (!msi_comp_find_package(szProductCode
, dwContext
))
1921 *pdwState
= INSTALLSTATE_UNKNOWN
;
1922 return ERROR_UNKNOWN_COMPONENT
;
1925 return ERROR_UNKNOWN_PRODUCT
;
1928 *pdwState
= INSTALLSTATE_UNKNOWN
;
1931 if (!msi_comp_find_prodcode(squished_pc
, dwContext
, szComponent
, val
, &sz
))
1932 return ERROR_UNKNOWN_COMPONENT
;
1935 *pdwState
= INSTALLSTATE_NOTUSED
;
1938 if (lstrlenW(val
) > 2 &&
1939 val
[0] >= '0' && val
[0] <= '9' && val
[1] >= '0' && val
[1] <= '9')
1941 *pdwState
= INSTALLSTATE_SOURCE
;
1944 *pdwState
= INSTALLSTATE_LOCAL
;
1947 return ERROR_SUCCESS
;
1950 INSTALLSTATE WINAPI
MsiQueryProductStateA(LPCSTR szProduct
)
1952 LPWSTR szwProduct
= NULL
;
1957 szwProduct
= strdupAtoW( szProduct
);
1959 return ERROR_OUTOFMEMORY
;
1961 r
= MsiQueryProductStateW( szwProduct
);
1962 msi_free( szwProduct
);
1966 INSTALLSTATE WINAPI
MsiQueryProductStateW(LPCWSTR szProduct
)
1968 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
1969 INSTALLSTATE state
= INSTALLSTATE_ADVERTISED
;
1970 HKEY prodkey
= 0, userdata
= 0;
1974 static const WCHAR szWindowsInstaller
[] = {
1975 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
1977 TRACE("%s\n", debugstr_w(szProduct
));
1979 if (!szProduct
|| !*szProduct
)
1980 return INSTALLSTATE_INVALIDARG
;
1982 if (lstrlenW(szProduct
) != GUID_SIZE
- 1)
1983 return INSTALLSTATE_INVALIDARG
;
1985 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
1986 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
1987 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1988 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
1989 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
1990 &prodkey
, FALSE
) == ERROR_SUCCESS
)
1992 context
= MSIINSTALLCONTEXT_MACHINE
;
1995 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
1996 if (r
!= ERROR_SUCCESS
)
1999 if (!msi_reg_get_val_dword(userdata
, szWindowsInstaller
, &val
))
2003 state
= INSTALLSTATE_DEFAULT
;
2005 state
= INSTALLSTATE_UNKNOWN
;
2010 state
= INSTALLSTATE_UNKNOWN
;
2013 state
= INSTALLSTATE_ABSENT
;
2016 RegCloseKey(prodkey
);
2017 RegCloseKey(userdata
);
2021 INSTALLUILEVEL WINAPI
MsiSetInternalUI(INSTALLUILEVEL dwUILevel
, HWND
*phWnd
)
2023 INSTALLUILEVEL old
= gUILevel
;
2024 HWND oldwnd
= gUIhwnd
;
2026 TRACE("%08x %p\n", dwUILevel
, phWnd
);
2028 gUILevel
= dwUILevel
;
2037 INSTALLUI_HANDLERA WINAPI
MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler
,
2038 DWORD dwMessageFilter
, LPVOID pvContext
)
2040 INSTALLUI_HANDLERA prev
= gUIHandlerA
;
2042 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2044 gUIHandlerA
= puiHandler
;
2046 gUIFilter
= dwMessageFilter
;
2047 gUIContext
= pvContext
;
2052 INSTALLUI_HANDLERW WINAPI
MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler
,
2053 DWORD dwMessageFilter
, LPVOID pvContext
)
2055 INSTALLUI_HANDLERW prev
= gUIHandlerW
;
2057 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2060 gUIHandlerW
= puiHandler
;
2061 gUIFilter
= dwMessageFilter
;
2062 gUIContext
= pvContext
;
2067 /******************************************************************
2068 * MsiLoadStringW [MSI.@]
2070 * Loads a string from MSI's string resources.
2074 * handle [I] only -1 is handled currently
2075 * id [I] id of the string to be loaded
2076 * lpBuffer [O] buffer for the string to be written to
2077 * nBufferMax [I] maximum size of the buffer in characters
2078 * lang [I] the preferred language for the string
2082 * If successful, this function returns the language id of the string loaded
2083 * If the function fails, the function returns zero.
2087 * The type of the first parameter is unknown. LoadString's prototype
2088 * suggests that it might be a module handle. I have made it an MSI handle
2089 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2090 * handle. Maybe strings can be stored in an MSI database somehow.
2092 LANGID WINAPI
MsiLoadStringW( MSIHANDLE handle
, UINT id
, LPWSTR lpBuffer
,
2093 int nBufferMax
, LANGID lang
)
2100 TRACE("%d %u %p %d %d\n", handle
, id
, lpBuffer
, nBufferMax
, lang
);
2103 FIXME("don't know how to deal with handle = %08x\n", handle
);
2106 lang
= GetUserDefaultLangID();
2108 hres
= FindResourceExW( msi_hInstance
, (LPCWSTR
) RT_STRING
,
2112 hResData
= LoadResource( msi_hInstance
, hres
);
2115 p
= LockResource( hResData
);
2119 for (i
= 0; i
< (id
&0xf); i
++)
2123 if( nBufferMax
<= len
)
2126 memcpy( lpBuffer
, p
+1, len
* sizeof(WCHAR
));
2127 lpBuffer
[ len
] = 0;
2129 TRACE("found -> %s\n", debugstr_w(lpBuffer
));
2134 LANGID WINAPI
MsiLoadStringA( MSIHANDLE handle
, UINT id
, LPSTR lpBuffer
,
2135 int nBufferMax
, LANGID lang
)
2141 bufW
= msi_alloc(nBufferMax
*sizeof(WCHAR
));
2142 r
= MsiLoadStringW(handle
, id
, bufW
, nBufferMax
, lang
);
2145 len
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
2146 if( len
<= nBufferMax
)
2147 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1,
2148 lpBuffer
, nBufferMax
, NULL
, NULL
);
2156 INSTALLSTATE WINAPI
MsiLocateComponentA(LPCSTR szComponent
, LPSTR lpPathBuf
,
2159 char szProduct
[GUID_SIZE
];
2161 TRACE("%s %p %p\n", debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2163 if (!szComponent
|| !pcchBuf
)
2164 return INSTALLSTATE_INVALIDARG
;
2166 if (MsiGetProductCodeA( szComponent
, szProduct
) != ERROR_SUCCESS
)
2167 return INSTALLSTATE_UNKNOWN
;
2169 return MsiGetComponentPathA( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2172 INSTALLSTATE WINAPI
MsiLocateComponentW(LPCWSTR szComponent
, LPWSTR lpPathBuf
,
2175 WCHAR szProduct
[GUID_SIZE
];
2177 TRACE("%s %p %p\n", debugstr_w(szComponent
), lpPathBuf
, pcchBuf
);
2179 if (!szComponent
|| !pcchBuf
)
2180 return INSTALLSTATE_INVALIDARG
;
2182 if (MsiGetProductCodeW( szComponent
, szProduct
) != ERROR_SUCCESS
)
2183 return INSTALLSTATE_UNKNOWN
;
2185 return MsiGetComponentPathW( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2188 UINT WINAPI
MsiMessageBoxA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2189 WORD wLanguageId
, DWORD f
)
2191 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_a(lpText
), debugstr_a(lpCaption
),
2192 uType
, wLanguageId
, f
);
2193 return MessageBoxExA(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2196 UINT WINAPI
MsiMessageBoxW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2197 WORD wLanguageId
, DWORD f
)
2199 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_w(lpText
), debugstr_w(lpCaption
),
2200 uType
, wLanguageId
, f
);
2201 return MessageBoxExW(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2204 UINT WINAPI
MsiMessageBoxExA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2205 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2207 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_a(lpText
),
2208 debugstr_a(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2209 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2212 UINT WINAPI
MsiMessageBoxExW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2213 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2215 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_w(lpText
),
2216 debugstr_w(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2217 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2220 UINT WINAPI
MsiProvideAssemblyA( LPCSTR szAssemblyName
, LPCSTR szAppContext
,
2221 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPSTR lpPathBuf
,
2222 LPDWORD pcchPathBuf
)
2224 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName
),
2225 debugstr_a(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2227 return ERROR_CALL_NOT_IMPLEMENTED
;
2230 UINT WINAPI
MsiProvideAssemblyW( LPCWSTR szAssemblyName
, LPCWSTR szAppContext
,
2231 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPWSTR lpPathBuf
,
2232 LPDWORD pcchPathBuf
)
2234 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName
),
2235 debugstr_w(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2237 return ERROR_CALL_NOT_IMPLEMENTED
;
2240 UINT WINAPI
MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor
,
2241 LPSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2243 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2244 return ERROR_CALL_NOT_IMPLEMENTED
;
2247 UINT WINAPI
MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor
,
2248 LPWSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2250 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2251 return ERROR_CALL_NOT_IMPLEMENTED
;
2254 HRESULT WINAPI
MsiGetFileSignatureInformationA( LPCSTR szSignedObjectPath
,
2255 DWORD dwFlags
, PCCERT_CONTEXT
* ppcCertContext
, LPBYTE pbHashData
,
2256 LPDWORD pcbHashData
)
2258 FIXME("%s %08x %p %p %p\n", debugstr_a(szSignedObjectPath
), dwFlags
,
2259 ppcCertContext
, pbHashData
, pcbHashData
);
2260 return ERROR_CALL_NOT_IMPLEMENTED
;
2263 HRESULT WINAPI
MsiGetFileSignatureInformationW( LPCWSTR szSignedObjectPath
,
2264 DWORD dwFlags
, PCCERT_CONTEXT
* ppcCertContext
, LPBYTE pbHashData
,
2265 LPDWORD pcbHashData
)
2267 FIXME("%s %08x %p %p %p\n", debugstr_w(szSignedObjectPath
), dwFlags
,
2268 ppcCertContext
, pbHashData
, pcbHashData
);
2269 return ERROR_CALL_NOT_IMPLEMENTED
;
2272 /******************************************************************
2273 * MsiGetProductPropertyA [MSI.@]
2275 UINT WINAPI
MsiGetProductPropertyA(MSIHANDLE hProduct
, LPCSTR szProperty
,
2276 LPSTR szValue
, LPDWORD pccbValue
)
2278 LPWSTR prop
= NULL
, val
= NULL
;
2282 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_a(szProperty
),
2283 szValue
, pccbValue
);
2285 if (szValue
&& !pccbValue
)
2286 return ERROR_INVALID_PARAMETER
;
2288 if (szProperty
) prop
= strdupAtoW(szProperty
);
2291 r
= MsiGetProductPropertyW(hProduct
, prop
, NULL
, &len
);
2292 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2295 if (r
== ERROR_SUCCESS
)
2297 if (szValue
) *szValue
= '\0';
2298 if (pccbValue
) *pccbValue
= 0;
2302 val
= msi_alloc(++len
* sizeof(WCHAR
));
2305 r
= ERROR_OUTOFMEMORY
;
2309 r
= MsiGetProductPropertyW(hProduct
, prop
, val
, &len
);
2310 if (r
!= ERROR_SUCCESS
)
2313 len
= WideCharToMultiByte(CP_ACP
, 0, val
, -1, NULL
, 0, NULL
, NULL
);
2316 WideCharToMultiByte(CP_ACP
, 0, val
, -1, szValue
,
2317 *pccbValue
, NULL
, NULL
);
2321 if (len
> *pccbValue
)
2322 r
= ERROR_MORE_DATA
;
2324 *pccbValue
= len
- 1;
2334 /******************************************************************
2335 * MsiGetProductPropertyW [MSI.@]
2337 UINT WINAPI
MsiGetProductPropertyW(MSIHANDLE hProduct
, LPCWSTR szProperty
,
2338 LPWSTR szValue
, LPDWORD pccbValue
)
2340 MSIPACKAGE
*package
;
2341 MSIQUERY
*view
= NULL
;
2342 MSIRECORD
*rec
= NULL
;
2346 static const WCHAR query
[] = {
2347 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2348 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2349 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2351 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_w(szProperty
),
2352 szValue
, pccbValue
);
2355 return ERROR_INVALID_PARAMETER
;
2357 if (szValue
&& !pccbValue
)
2358 return ERROR_INVALID_PARAMETER
;
2360 package
= msihandle2msiinfo(hProduct
, MSIHANDLETYPE_PACKAGE
);
2362 return ERROR_INVALID_HANDLE
;
2364 r
= MSI_OpenQuery(package
->db
, &view
, query
, szProperty
);
2365 if (r
!= ERROR_SUCCESS
)
2368 r
= MSI_ViewExecute(view
, 0);
2369 if (r
!= ERROR_SUCCESS
)
2372 r
= MSI_ViewFetch(view
, &rec
);
2373 if (r
!= ERROR_SUCCESS
)
2376 val
= MSI_RecordGetString(rec
, 2);
2380 if (lstrlenW(val
) >= *pccbValue
)
2382 lstrcpynW(szValue
, val
, *pccbValue
);
2383 *pccbValue
= lstrlenW(val
);
2384 r
= ERROR_MORE_DATA
;
2388 lstrcpyW(szValue
, val
);
2389 *pccbValue
= lstrlenW(val
);
2396 MSI_ViewClose(view
);
2397 msiobj_release(&view
->hdr
);
2398 if (rec
) msiobj_release(&rec
->hdr
);
2403 if (szValue
) *szValue
= '\0';
2404 if (pccbValue
) *pccbValue
= 0;
2408 msiobj_release(&package
->hdr
);
2412 UINT WINAPI
MsiVerifyPackageA( LPCSTR szPackage
)
2415 LPWSTR szPack
= NULL
;
2417 TRACE("%s\n", debugstr_a(szPackage
) );
2421 szPack
= strdupAtoW( szPackage
);
2423 return ERROR_OUTOFMEMORY
;
2426 r
= MsiVerifyPackageW( szPack
);
2433 UINT WINAPI
MsiVerifyPackageW( LPCWSTR szPackage
)
2438 TRACE("%s\n", debugstr_w(szPackage
) );
2440 r
= MsiOpenDatabaseW( szPackage
, MSIDBOPEN_READONLY
, &handle
);
2441 MsiCloseHandle( handle
);
2446 static INSTALLSTATE
MSI_GetComponentPath(LPCWSTR szProduct
, LPCWSTR szComponent
,
2447 awstring
* lpPathBuf
, LPDWORD pcchBuf
)
2449 WCHAR squished_pc
[GUID_SIZE
];
2450 WCHAR squished_comp
[GUID_SIZE
];
2456 static const WCHAR wininstaller
[] = {
2457 'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2459 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
2460 debugstr_w(szComponent
), lpPathBuf
->str
.w
, pcchBuf
);
2462 if (!szProduct
|| !szComponent
)
2463 return INSTALLSTATE_INVALIDARG
;
2465 if (lpPathBuf
->str
.w
&& !pcchBuf
)
2466 return INSTALLSTATE_INVALIDARG
;
2468 if (!squash_guid(szProduct
, squished_pc
) ||
2469 !squash_guid(szComponent
, squished_comp
))
2470 return INSTALLSTATE_INVALIDARG
;
2472 state
= INSTALLSTATE_UNKNOWN
;
2474 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2475 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2477 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2480 state
= INSTALLSTATE_ABSENT
;
2482 if ((MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
, NULL
,
2483 &hkey
, FALSE
) == ERROR_SUCCESS
||
2484 MSIREG_OpenUserDataProductKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2485 NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
) &&
2486 msi_reg_get_val_dword(hkey
, wininstaller
, &version
) &&
2487 GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2490 state
= INSTALLSTATE_LOCAL
;
2494 if (state
!= INSTALLSTATE_LOCAL
&&
2495 (MSIREG_OpenProductKey(szProduct
, NULL
,
2496 MSIINSTALLCONTEXT_USERUNMANAGED
,
2497 &hkey
, FALSE
) == ERROR_SUCCESS
||
2498 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2499 &hkey
, FALSE
) == ERROR_SUCCESS
))
2503 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2504 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2507 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2510 state
= INSTALLSTATE_ABSENT
;
2512 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2513 state
= INSTALLSTATE_LOCAL
;
2518 return INSTALLSTATE_UNKNOWN
;
2520 if (state
== INSTALLSTATE_LOCAL
&& !*path
)
2521 state
= INSTALLSTATE_NOTUSED
;
2523 msi_strcpy_to_awstring(path
, lpPathBuf
, pcchBuf
);
2528 /******************************************************************
2529 * MsiGetComponentPathW [MSI.@]
2531 INSTALLSTATE WINAPI
MsiGetComponentPathW(LPCWSTR szProduct
, LPCWSTR szComponent
,
2532 LPWSTR lpPathBuf
, LPDWORD pcchBuf
)
2536 path
.unicode
= TRUE
;
2537 path
.str
.w
= lpPathBuf
;
2539 return MSI_GetComponentPath( szProduct
, szComponent
, &path
, pcchBuf
);
2542 /******************************************************************
2543 * MsiGetComponentPathA [MSI.@]
2545 INSTALLSTATE WINAPI
MsiGetComponentPathA(LPCSTR szProduct
, LPCSTR szComponent
,
2546 LPSTR lpPathBuf
, LPDWORD pcchBuf
)
2548 LPWSTR szwProduct
, szwComponent
= NULL
;
2549 INSTALLSTATE r
= INSTALLSTATE_UNKNOWN
;
2552 szwProduct
= strdupAtoW( szProduct
);
2553 if( szProduct
&& !szwProduct
)
2556 szwComponent
= strdupAtoW( szComponent
);
2557 if( szComponent
&& !szwComponent
)
2560 path
.unicode
= FALSE
;
2561 path
.str
.a
= lpPathBuf
;
2563 r
= MSI_GetComponentPath( szwProduct
, szwComponent
, &path
, pcchBuf
);
2566 msi_free( szwProduct
);
2567 msi_free( szwComponent
);
2572 /******************************************************************
2573 * MsiQueryFeatureStateA [MSI.@]
2575 INSTALLSTATE WINAPI
MsiQueryFeatureStateA(LPCSTR szProduct
, LPCSTR szFeature
)
2577 LPWSTR szwProduct
= NULL
, szwFeature
= NULL
;
2578 INSTALLSTATE rc
= INSTALLSTATE_UNKNOWN
;
2580 szwProduct
= strdupAtoW( szProduct
);
2581 if ( szProduct
&& !szwProduct
)
2584 szwFeature
= strdupAtoW( szFeature
);
2585 if ( szFeature
&& !szwFeature
)
2588 rc
= MsiQueryFeatureStateW(szwProduct
, szwFeature
);
2591 msi_free( szwProduct
);
2592 msi_free( szwFeature
);
2597 /******************************************************************
2598 * MsiQueryFeatureStateW [MSI.@]
2600 * Checks the state of a feature
2603 * szProduct [I] Product's GUID string
2604 * szFeature [I] Feature's GUID string
2607 * INSTALLSTATE_LOCAL Feature is installed and usable
2608 * INSTALLSTATE_ABSENT Feature is absent
2609 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2610 * INSTALLSTATE_UNKNOWN An error occurred
2611 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2614 INSTALLSTATE WINAPI
MsiQueryFeatureStateW(LPCWSTR szProduct
, LPCWSTR szFeature
)
2616 WCHAR squishProduct
[33], comp
[GUID_SIZE
];
2618 LPWSTR components
, p
, parent_feature
, path
;
2622 BOOL missing
= FALSE
;
2623 BOOL machine
= FALSE
;
2624 BOOL source
= FALSE
;
2626 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szFeature
));
2628 if (!szProduct
|| !szFeature
)
2629 return INSTALLSTATE_INVALIDARG
;
2631 if (!squash_guid( szProduct
, squishProduct
))
2632 return INSTALLSTATE_INVALIDARG
;
2634 if (MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERMANAGED
,
2635 &hkey
, FALSE
) != ERROR_SUCCESS
&&
2636 MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2637 &hkey
, FALSE
) != ERROR_SUCCESS
)
2639 rc
= MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
2641 if (rc
!= ERROR_SUCCESS
)
2642 return INSTALLSTATE_UNKNOWN
;
2647 parent_feature
= msi_reg_get_val_str( hkey
, szFeature
);
2650 if (!parent_feature
)
2651 return INSTALLSTATE_UNKNOWN
;
2653 r
= (parent_feature
[0] == 6) ? INSTALLSTATE_ABSENT
: INSTALLSTATE_LOCAL
;
2654 msi_free(parent_feature
);
2655 if (r
== INSTALLSTATE_ABSENT
)
2659 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2660 MSIINSTALLCONTEXT_MACHINE
,
2663 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2664 MSIINSTALLCONTEXT_USERUNMANAGED
,
2667 if (rc
!= ERROR_SUCCESS
)
2668 return INSTALLSTATE_ADVERTISED
;
2670 components
= msi_reg_get_val_str( hkey
, szFeature
);
2673 TRACE("rc = %d buffer = %s\n", rc
, debugstr_w(components
));
2676 return INSTALLSTATE_ADVERTISED
;
2678 for( p
= components
; *p
&& *p
!= 2 ; p
+= 20)
2680 if (!decode_base85_guid( p
, &guid
))
2682 if (p
!= components
)
2685 msi_free(components
);
2686 return INSTALLSTATE_BADCONFIG
;
2689 StringFromGUID2(&guid
, comp
, GUID_SIZE
);
2692 rc
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2694 rc
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2696 if (rc
!= ERROR_SUCCESS
)
2698 msi_free(components
);
2699 return INSTALLSTATE_ADVERTISED
;
2702 path
= msi_reg_get_val_str(hkey
, squishProduct
);
2705 else if (lstrlenW(path
) > 2 &&
2706 path
[0] >= '0' && path
[0] <= '9' &&
2707 path
[1] >= '0' && path
[1] <= '9')
2715 TRACE("%s %s -> %d\n", debugstr_w(szProduct
), debugstr_w(szFeature
), r
);
2716 msi_free(components
);
2719 return INSTALLSTATE_ADVERTISED
;
2722 return INSTALLSTATE_SOURCE
;
2724 return INSTALLSTATE_LOCAL
;
2727 /******************************************************************
2728 * MsiGetFileVersionA [MSI.@]
2730 UINT WINAPI
MsiGetFileVersionA(LPCSTR szFilePath
, LPSTR lpVersionBuf
,
2731 LPDWORD pcchVersionBuf
, LPSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2733 LPWSTR szwFilePath
= NULL
, lpwVersionBuff
= NULL
, lpwLangBuff
= NULL
;
2734 UINT ret
= ERROR_OUTOFMEMORY
;
2736 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
2737 (lpLangBuf
&& !pcchLangBuf
))
2738 return ERROR_INVALID_PARAMETER
;
2742 szwFilePath
= strdupAtoW( szFilePath
);
2747 if( lpVersionBuf
&& pcchVersionBuf
&& *pcchVersionBuf
)
2749 lpwVersionBuff
= msi_alloc(*pcchVersionBuf
*sizeof(WCHAR
));
2750 if( !lpwVersionBuff
)
2754 if( lpLangBuf
&& pcchLangBuf
&& *pcchLangBuf
)
2756 lpwLangBuff
= msi_alloc(*pcchLangBuf
*sizeof(WCHAR
));
2761 ret
= MsiGetFileVersionW(szwFilePath
, lpwVersionBuff
, pcchVersionBuf
,
2762 lpwLangBuff
, pcchLangBuf
);
2764 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwVersionBuff
)
2765 WideCharToMultiByte(CP_ACP
, 0, lpwVersionBuff
, -1,
2766 lpVersionBuf
, *pcchVersionBuf
+ 1, NULL
, NULL
);
2767 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwLangBuff
)
2768 WideCharToMultiByte(CP_ACP
, 0, lpwLangBuff
, -1,
2769 lpLangBuf
, *pcchLangBuf
+ 1, NULL
, NULL
);
2772 msi_free(szwFilePath
);
2773 msi_free(lpwVersionBuff
);
2774 msi_free(lpwLangBuff
);
2779 /******************************************************************
2780 * MsiGetFileVersionW [MSI.@]
2782 UINT WINAPI
MsiGetFileVersionW(LPCWSTR szFilePath
, LPWSTR lpVersionBuf
,
2783 LPDWORD pcchVersionBuf
, LPWSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2785 static const WCHAR szVersionResource
[] = {'\\',0};
2786 static const WCHAR szVersionFormat
[] = {
2787 '%','d','.','%','d','.','%','d','.','%','d',0};
2788 static const WCHAR szLangResource
[] = {
2789 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
2790 'T','r','a','n','s','l','a','t','i','o','n',0};
2791 static const WCHAR szLangFormat
[] = {'%','d',0};
2793 DWORD dwVerLen
, gle
;
2794 LPVOID lpVer
= NULL
;
2795 VS_FIXEDFILEINFO
*ffi
;
2800 TRACE("%s %p %d %p %d\n", debugstr_w(szFilePath
),
2801 lpVersionBuf
, pcchVersionBuf
?*pcchVersionBuf
:0,
2802 lpLangBuf
, pcchLangBuf
?*pcchLangBuf
:0);
2804 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
2805 (lpLangBuf
&& !pcchLangBuf
))
2806 return ERROR_INVALID_PARAMETER
;
2808 dwVerLen
= GetFileVersionInfoSizeW(szFilePath
, NULL
);
2811 gle
= GetLastError();
2812 if (gle
== ERROR_BAD_PATHNAME
)
2813 return ERROR_FILE_NOT_FOUND
;
2814 else if (gle
== ERROR_RESOURCE_DATA_NOT_FOUND
)
2815 return ERROR_FILE_INVALID
;
2820 lpVer
= msi_alloc(dwVerLen
);
2823 ret
= ERROR_OUTOFMEMORY
;
2827 if( !GetFileVersionInfoW(szFilePath
, 0, dwVerLen
, lpVer
) )
2829 ret
= GetLastError();
2835 if( VerQueryValueW(lpVer
, szVersionResource
, (LPVOID
*)&ffi
, &puLen
) &&
2838 wsprintfW(tmp
, szVersionFormat
,
2839 HIWORD(ffi
->dwFileVersionMS
), LOWORD(ffi
->dwFileVersionMS
),
2840 HIWORD(ffi
->dwFileVersionLS
), LOWORD(ffi
->dwFileVersionLS
));
2841 if (lpVersionBuf
) lstrcpynW(lpVersionBuf
, tmp
, *pcchVersionBuf
);
2843 if (strlenW(tmp
) >= *pcchVersionBuf
)
2844 ret
= ERROR_MORE_DATA
;
2846 *pcchVersionBuf
= lstrlenW(tmp
);
2850 if (lpVersionBuf
) *lpVersionBuf
= 0;
2851 *pcchVersionBuf
= 0;
2857 if (VerQueryValueW(lpVer
, szLangResource
, (LPVOID
*)&lang
, &puLen
) &&
2860 wsprintfW(tmp
, szLangFormat
, *lang
);
2861 if (lpLangBuf
) lstrcpynW(lpLangBuf
, tmp
, *pcchLangBuf
);
2863 if (strlenW(tmp
) >= *pcchLangBuf
)
2864 ret
= ERROR_MORE_DATA
;
2866 *pcchLangBuf
= lstrlenW(tmp
);
2870 if (lpLangBuf
) *lpLangBuf
= 0;
2880 /***********************************************************************
2881 * MsiGetFeatureUsageW [MSI.@]
2883 UINT WINAPI
MsiGetFeatureUsageW( LPCWSTR szProduct
, LPCWSTR szFeature
,
2884 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
2886 FIXME("%s %s %p %p\n",debugstr_w(szProduct
), debugstr_w(szFeature
),
2887 pdwUseCount
, pwDateUsed
);
2888 return ERROR_CALL_NOT_IMPLEMENTED
;
2891 /***********************************************************************
2892 * MsiGetFeatureUsageA [MSI.@]
2894 UINT WINAPI
MsiGetFeatureUsageA( LPCSTR szProduct
, LPCSTR szFeature
,
2895 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
2897 LPWSTR prod
= NULL
, feat
= NULL
;
2898 UINT ret
= ERROR_OUTOFMEMORY
;
2900 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
2901 pdwUseCount
, pwDateUsed
);
2903 prod
= strdupAtoW( szProduct
);
2904 if (szProduct
&& !prod
)
2907 feat
= strdupAtoW( szFeature
);
2908 if (szFeature
&& !feat
)
2911 ret
= MsiGetFeatureUsageW( prod
, feat
, pdwUseCount
, pwDateUsed
);
2920 /***********************************************************************
2921 * MsiUseFeatureExW [MSI.@]
2923 INSTALLSTATE WINAPI
MsiUseFeatureExW( LPCWSTR szProduct
, LPCWSTR szFeature
,
2924 DWORD dwInstallMode
, DWORD dwReserved
)
2928 TRACE("%s %s %i %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
2929 dwInstallMode
, dwReserved
);
2931 state
= MsiQueryFeatureStateW( szProduct
, szFeature
);
2934 return INSTALLSTATE_INVALIDARG
;
2936 if (state
== INSTALLSTATE_LOCAL
&& dwInstallMode
!= INSTALLMODE_NODETECTION
)
2938 FIXME("mark product %s feature %s as used\n",
2939 debugstr_w(szProduct
), debugstr_w(szFeature
) );
2945 /***********************************************************************
2946 * MsiUseFeatureExA [MSI.@]
2948 INSTALLSTATE WINAPI
MsiUseFeatureExA( LPCSTR szProduct
, LPCSTR szFeature
,
2949 DWORD dwInstallMode
, DWORD dwReserved
)
2951 INSTALLSTATE ret
= INSTALLSTATE_UNKNOWN
;
2952 LPWSTR prod
= NULL
, feat
= NULL
;
2954 TRACE("%s %s %i %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
2955 dwInstallMode
, dwReserved
);
2957 prod
= strdupAtoW( szProduct
);
2958 if (szProduct
&& !prod
)
2961 feat
= strdupAtoW( szFeature
);
2962 if (szFeature
&& !feat
)
2965 ret
= MsiUseFeatureExW( prod
, feat
, dwInstallMode
, dwReserved
);
2974 /***********************************************************************
2975 * MsiUseFeatureW [MSI.@]
2977 INSTALLSTATE WINAPI
MsiUseFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
)
2979 return MsiUseFeatureExW(szProduct
, szFeature
, 0, 0);
2982 /***********************************************************************
2983 * MsiUseFeatureA [MSI.@]
2985 INSTALLSTATE WINAPI
MsiUseFeatureA( LPCSTR szProduct
, LPCSTR szFeature
)
2987 return MsiUseFeatureExA(szProduct
, szFeature
, 0, 0);
2990 /***********************************************************************
2991 * MSI_ProvideQualifiedComponentEx [internal]
2993 static UINT
MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent
,
2994 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
2995 DWORD Unused1
, DWORD Unused2
, awstring
*lpPathBuf
,
2996 LPDWORD pcchPathBuf
)
2998 WCHAR product
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1],
2999 feature
[MAX_FEATURE_CHARS
+1];
3005 TRACE("%s %s %i %s %i %i %p %p\n", debugstr_w(szComponent
),
3006 debugstr_w(szQualifier
), dwInstallMode
, debugstr_w(szProduct
),
3007 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3009 rc
= MSIREG_OpenUserComponentsKey(szComponent
, &hkey
, FALSE
);
3010 if (rc
!= ERROR_SUCCESS
)
3011 return ERROR_INDEX_ABSENT
;
3013 info
= msi_reg_get_val_str( hkey
, szQualifier
);
3017 return ERROR_INDEX_ABSENT
;
3019 MsiDecomposeDescriptorW(info
, product
, feature
, component
, &sz
);
3022 rc
= MSI_GetComponentPath(product
, component
, lpPathBuf
, pcchPathBuf
);
3024 rc
= MSI_GetComponentPath(szProduct
, component
, lpPathBuf
, pcchPathBuf
);
3028 if (rc
!= INSTALLSTATE_LOCAL
)
3029 return ERROR_FILE_NOT_FOUND
;
3031 return ERROR_SUCCESS
;
3034 /***********************************************************************
3035 * MsiProvideQualifiedComponentExW [MSI.@]
3037 UINT WINAPI
MsiProvideQualifiedComponentExW(LPCWSTR szComponent
,
3038 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3039 DWORD Unused1
, DWORD Unused2
, LPWSTR lpPathBuf
,
3040 LPDWORD pcchPathBuf
)
3044 path
.unicode
= TRUE
;
3045 path
.str
.w
= lpPathBuf
;
3047 return MSI_ProvideQualifiedComponentEx(szComponent
, szQualifier
,
3048 dwInstallMode
, szProduct
, Unused1
, Unused2
, &path
, pcchPathBuf
);
3051 /***********************************************************************
3052 * MsiProvideQualifiedComponentExA [MSI.@]
3054 UINT WINAPI
MsiProvideQualifiedComponentExA(LPCSTR szComponent
,
3055 LPCSTR szQualifier
, DWORD dwInstallMode
, LPCSTR szProduct
,
3056 DWORD Unused1
, DWORD Unused2
, LPSTR lpPathBuf
,
3057 LPDWORD pcchPathBuf
)
3059 LPWSTR szwComponent
, szwQualifier
= NULL
, szwProduct
= NULL
;
3060 UINT r
= ERROR_OUTOFMEMORY
;
3063 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent
),
3064 debugstr_a(szQualifier
), dwInstallMode
, debugstr_a(szProduct
),
3065 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3067 szwComponent
= strdupAtoW( szComponent
);
3068 if (szComponent
&& !szwComponent
)
3071 szwQualifier
= strdupAtoW( szQualifier
);
3072 if (szQualifier
&& !szwQualifier
)
3075 szwProduct
= strdupAtoW( szProduct
);
3076 if (szProduct
&& !szwProduct
)
3079 path
.unicode
= FALSE
;
3080 path
.str
.a
= lpPathBuf
;
3082 r
= MSI_ProvideQualifiedComponentEx(szwComponent
, szwQualifier
,
3083 dwInstallMode
, szwProduct
, Unused1
,
3084 Unused2
, &path
, pcchPathBuf
);
3086 msi_free(szwProduct
);
3087 msi_free(szwComponent
);
3088 msi_free(szwQualifier
);
3093 /***********************************************************************
3094 * MsiProvideQualifiedComponentW [MSI.@]
3096 UINT WINAPI
MsiProvideQualifiedComponentW( LPCWSTR szComponent
,
3097 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPWSTR lpPathBuf
,
3098 LPDWORD pcchPathBuf
)
3100 return MsiProvideQualifiedComponentExW(szComponent
, szQualifier
,
3101 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3104 /***********************************************************************
3105 * MsiProvideQualifiedComponentA [MSI.@]
3107 UINT WINAPI
MsiProvideQualifiedComponentA( LPCSTR szComponent
,
3108 LPCSTR szQualifier
, DWORD dwInstallMode
, LPSTR lpPathBuf
,
3109 LPDWORD pcchPathBuf
)
3111 return MsiProvideQualifiedComponentExA(szComponent
, szQualifier
,
3112 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3115 /***********************************************************************
3116 * MSI_GetUserInfo [internal]
3118 static USERINFOSTATE
MSI_GetUserInfo(LPCWSTR szProduct
,
3119 awstring
*lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3120 awstring
*lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3121 awstring
*lpSerialBuf
, LPDWORD pcchSerialBuf
)
3123 WCHAR squished_pc
[SQUISH_GUID_SIZE
];
3124 LPWSTR user
, org
, serial
;
3125 USERINFOSTATE state
;
3130 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct
), lpUserNameBuf
,
3131 pcchUserNameBuf
, lpOrgNameBuf
, pcchOrgNameBuf
, lpSerialBuf
,
3134 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
3135 return USERINFOSTATE_INVALIDARG
;
3137 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
3138 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3139 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3140 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3141 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
3142 &hkey
, FALSE
) != ERROR_SUCCESS
)
3144 return USERINFOSTATE_UNKNOWN
;
3147 if (MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3148 NULL
, &props
, FALSE
) != ERROR_SUCCESS
&&
3149 MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
3150 NULL
, &props
, FALSE
) != ERROR_SUCCESS
)
3153 return USERINFOSTATE_ABSENT
;
3156 user
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGOWNERW
);
3157 org
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGCOMPANYW
);
3158 serial
= msi_reg_get_val_str(props
, INSTALLPROPERTY_PRODUCTIDW
);
3159 state
= USERINFOSTATE_ABSENT
;
3165 state
= USERINFOSTATE_PRESENT
;
3167 if (pcchUserNameBuf
)
3169 if (lpUserNameBuf
&& !user
)
3171 (*pcchUserNameBuf
)--;
3175 r
= msi_strcpy_to_awstring(user
, lpUserNameBuf
, pcchUserNameBuf
);
3176 if (r
== ERROR_MORE_DATA
)
3178 state
= USERINFOSTATE_MOREDATA
;
3186 if (!orgptr
) orgptr
= szEmpty
;
3188 r
= msi_strcpy_to_awstring(orgptr
, lpOrgNameBuf
, pcchOrgNameBuf
);
3189 if (r
== ERROR_MORE_DATA
)
3191 state
= USERINFOSTATE_MOREDATA
;
3204 r
= msi_strcpy_to_awstring(serial
, lpSerialBuf
, pcchSerialBuf
);
3205 if (r
== ERROR_MORE_DATA
)
3206 state
= USERINFOSTATE_MOREDATA
;
3217 /***********************************************************************
3218 * MsiGetUserInfoW [MSI.@]
3220 USERINFOSTATE WINAPI
MsiGetUserInfoW(LPCWSTR szProduct
,
3221 LPWSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3222 LPWSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3223 LPWSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3225 awstring user
, org
, serial
;
3227 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3228 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3229 (lpSerialBuf
&& !pcchSerialBuf
))
3230 return USERINFOSTATE_INVALIDARG
;
3232 user
.unicode
= TRUE
;
3233 user
.str
.w
= lpUserNameBuf
;
3235 org
.str
.w
= lpOrgNameBuf
;
3236 serial
.unicode
= TRUE
;
3237 serial
.str
.w
= lpSerialBuf
;
3239 return MSI_GetUserInfo( szProduct
, &user
, pcchUserNameBuf
,
3240 &org
, pcchOrgNameBuf
,
3241 &serial
, pcchSerialBuf
);
3244 USERINFOSTATE WINAPI
MsiGetUserInfoA(LPCSTR szProduct
,
3245 LPSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3246 LPSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3247 LPSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3249 awstring user
, org
, serial
;
3253 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3254 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3255 (lpSerialBuf
&& !pcchSerialBuf
))
3256 return USERINFOSTATE_INVALIDARG
;
3258 prod
= strdupAtoW( szProduct
);
3259 if (szProduct
&& !prod
)
3260 return ERROR_OUTOFMEMORY
;
3262 user
.unicode
= FALSE
;
3263 user
.str
.a
= lpUserNameBuf
;
3264 org
.unicode
= FALSE
;
3265 org
.str
.a
= lpOrgNameBuf
;
3266 serial
.unicode
= FALSE
;
3267 serial
.str
.a
= lpSerialBuf
;
3269 r
= MSI_GetUserInfo( prod
, &user
, pcchUserNameBuf
,
3270 &org
, pcchOrgNameBuf
,
3271 &serial
, pcchSerialBuf
);
3278 UINT WINAPI
MsiCollectUserInfoW(LPCWSTR szProduct
)
3282 MSIPACKAGE
*package
;
3283 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3285 TRACE("(%s)\n",debugstr_w(szProduct
));
3287 rc
= MsiOpenProductW(szProduct
,&handle
);
3288 if (rc
!= ERROR_SUCCESS
)
3289 return ERROR_INVALID_PARAMETER
;
3291 /* MsiCollectUserInfo cannot be called from a custom action. */
3292 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3294 return ERROR_CALL_NOT_IMPLEMENTED
;
3296 rc
= ACTION_PerformUIAction(package
, szFirstRun
, -1);
3297 msiobj_release( &package
->hdr
);
3299 MsiCloseHandle(handle
);
3304 UINT WINAPI
MsiCollectUserInfoA(LPCSTR szProduct
)
3308 MSIPACKAGE
*package
;
3309 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3311 TRACE("(%s)\n",debugstr_a(szProduct
));
3313 rc
= MsiOpenProductA(szProduct
,&handle
);
3314 if (rc
!= ERROR_SUCCESS
)
3315 return ERROR_INVALID_PARAMETER
;
3317 /* MsiCollectUserInfo cannot be called from a custom action. */
3318 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3320 return ERROR_CALL_NOT_IMPLEMENTED
;
3322 rc
= ACTION_PerformUIAction(package
, szFirstRun
, -1);
3323 msiobj_release( &package
->hdr
);
3325 MsiCloseHandle(handle
);
3330 /***********************************************************************
3331 * MsiConfigureFeatureA [MSI.@]
3333 UINT WINAPI
MsiConfigureFeatureA(LPCSTR szProduct
, LPCSTR szFeature
, INSTALLSTATE eInstallState
)
3335 LPWSTR prod
, feat
= NULL
;
3336 UINT r
= ERROR_OUTOFMEMORY
;
3338 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
), eInstallState
);
3340 prod
= strdupAtoW( szProduct
);
3341 if (szProduct
&& !prod
)
3344 feat
= strdupAtoW( szFeature
);
3345 if (szFeature
&& !feat
)
3348 r
= MsiConfigureFeatureW(prod
, feat
, eInstallState
);
3357 /***********************************************************************
3358 * MsiConfigureFeatureW [MSI.@]
3360 UINT WINAPI
MsiConfigureFeatureW(LPCWSTR szProduct
, LPCWSTR szFeature
, INSTALLSTATE eInstallState
)
3362 static const WCHAR szCostInit
[] = { 'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0 };
3363 MSIPACKAGE
*package
= NULL
;
3365 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
3368 TRACE("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
), eInstallState
);
3370 if (!szProduct
|| !szFeature
)
3371 return ERROR_INVALID_PARAMETER
;
3373 switch (eInstallState
)
3375 case INSTALLSTATE_DEFAULT
:
3376 /* FIXME: how do we figure out the default location? */
3377 eInstallState
= INSTALLSTATE_LOCAL
;
3379 case INSTALLSTATE_LOCAL
:
3380 case INSTALLSTATE_SOURCE
:
3381 case INSTALLSTATE_ABSENT
:
3382 case INSTALLSTATE_ADVERTISED
:
3385 return ERROR_INVALID_PARAMETER
;
3388 r
= MSI_OpenProductW( szProduct
, &package
);
3389 if (r
!= ERROR_SUCCESS
)
3392 sz
= sizeof(sourcepath
);
3393 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3394 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3396 sz
= sizeof(filename
);
3397 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3398 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3400 lstrcatW( sourcepath
, filename
);
3402 MsiSetInternalUI( INSTALLUILEVEL_BASIC
, NULL
);
3404 r
= ACTION_PerformUIAction( package
, szCostInit
, -1 );
3405 if (r
!= ERROR_SUCCESS
)
3408 r
= MSI_SetFeatureStateW( package
, szFeature
, eInstallState
);
3409 if (r
!= ERROR_SUCCESS
)
3412 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3415 msiobj_release( &package
->hdr
);
3420 /***********************************************************************
3421 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3423 * Notes: undocumented
3425 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved
)
3427 WCHAR path
[MAX_PATH
];
3429 TRACE("%d\n", dwReserved
);
3433 FIXME("dwReserved=%d\n", dwReserved
);
3434 return ERROR_INVALID_PARAMETER
;
3437 if (!GetWindowsDirectoryW(path
, MAX_PATH
))
3438 return ERROR_FUNCTION_FAILED
;
3440 lstrcatW(path
, installerW
);
3442 if (!CreateDirectoryW(path
, NULL
))
3443 return ERROR_FUNCTION_FAILED
;
3445 return ERROR_SUCCESS
;
3448 /***********************************************************************
3449 * MsiGetShortcutTargetA [MSI.@]
3451 UINT WINAPI
MsiGetShortcutTargetA( LPCSTR szShortcutTarget
,
3452 LPSTR szProductCode
, LPSTR szFeatureId
,
3453 LPSTR szComponentCode
)
3456 const int len
= MAX_FEATURE_CHARS
+1;
3457 WCHAR product
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1];
3460 target
= strdupAtoW( szShortcutTarget
);
3461 if (szShortcutTarget
&& !target
)
3462 return ERROR_OUTOFMEMORY
;
3466 r
= MsiGetShortcutTargetW( target
, product
, feature
, component
);
3468 if (r
== ERROR_SUCCESS
)
3470 WideCharToMultiByte( CP_ACP
, 0, product
, -1, szProductCode
, len
, NULL
, NULL
);
3471 WideCharToMultiByte( CP_ACP
, 0, feature
, -1, szFeatureId
, len
, NULL
, NULL
);
3472 WideCharToMultiByte( CP_ACP
, 0, component
, -1, szComponentCode
, len
, NULL
, NULL
);
3477 /***********************************************************************
3478 * MsiGetShortcutTargetW [MSI.@]
3480 UINT WINAPI
MsiGetShortcutTargetW( LPCWSTR szShortcutTarget
,
3481 LPWSTR szProductCode
, LPWSTR szFeatureId
,
3482 LPWSTR szComponentCode
)
3484 IShellLinkDataList
*dl
= NULL
;
3485 IPersistFile
*pf
= NULL
;
3486 LPEXP_DARWIN_LINK darwin
= NULL
;
3489 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget
),
3490 szProductCode
, szFeatureId
, szComponentCode
);
3492 init
= CoInitialize(NULL
);
3494 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3495 &IID_IPersistFile
, (LPVOID
*) &pf
);
3496 if( SUCCEEDED( r
) )
3498 r
= IPersistFile_Load( pf
, szShortcutTarget
,
3499 STGM_READ
| STGM_SHARE_DENY_WRITE
);
3500 if( SUCCEEDED( r
) )
3502 r
= IPersistFile_QueryInterface( pf
, &IID_IShellLinkDataList
,
3504 if( SUCCEEDED( r
) )
3506 IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
,
3508 IShellLinkDataList_Release( dl
);
3511 IPersistFile_Release( pf
);
3514 if (SUCCEEDED(init
))
3517 TRACE("darwin = %p\n", darwin
);
3524 ret
= MsiDecomposeDescriptorW( darwin
->szwDarwinID
,
3525 szProductCode
, szFeatureId
, szComponentCode
, &sz
);
3526 LocalFree( darwin
);
3530 return ERROR_FUNCTION_FAILED
;
3533 UINT WINAPI
MsiReinstallFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3534 DWORD dwReinstallMode
)
3536 MSIPACKAGE
* package
= NULL
;
3538 WCHAR sourcepath
[MAX_PATH
];
3539 WCHAR filename
[MAX_PATH
];
3540 static const WCHAR szLogVerbose
[] = {
3541 ' ','L','O','G','V','E','R','B','O','S','E',0 };
3542 WCHAR reinstallmode
[11];
3546 FIXME("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
3549 ptr
= reinstallmode
;
3551 if (dwReinstallMode
& REINSTALLMODE_FILEMISSING
)
3553 if (dwReinstallMode
& REINSTALLMODE_FILEOLDERVERSION
)
3555 if (dwReinstallMode
& REINSTALLMODE_FILEEQUALVERSION
)
3557 if (dwReinstallMode
& REINSTALLMODE_FILEEXACT
)
3559 if (dwReinstallMode
& REINSTALLMODE_FILEVERIFY
)
3561 if (dwReinstallMode
& REINSTALLMODE_FILEREPLACE
)
3563 if (dwReinstallMode
& REINSTALLMODE_USERDATA
)
3565 if (dwReinstallMode
& REINSTALLMODE_MACHINEDATA
)
3567 if (dwReinstallMode
& REINSTALLMODE_SHORTCUT
)
3569 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3573 sz
= sizeof(sourcepath
);
3574 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3575 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3577 sz
= sizeof(filename
);
3578 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3579 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3581 lstrcatW( sourcepath
, filename
);
3583 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3584 r
= MSI_OpenPackageW( sourcepath
, &package
);
3586 r
= MSI_OpenProductW( szProduct
, &package
);
3588 if (r
!= ERROR_SUCCESS
)
3591 msi_set_property( package
->db
, szReinstallMode
, reinstallmode
);
3592 msi_set_property( package
->db
, szInstalled
, szOne
);
3593 msi_set_property( package
->db
, szLogVerbose
, szOne
);
3594 msi_set_property( package
->db
, szReinstall
, szFeature
);
3596 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3598 msiobj_release( &package
->hdr
);
3603 UINT WINAPI
MsiReinstallFeatureA( LPCSTR szProduct
, LPCSTR szFeature
,
3604 DWORD dwReinstallMode
)
3610 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3613 wszProduct
= strdupAtoW(szProduct
);
3614 wszFeature
= strdupAtoW(szFeature
);
3616 rc
= MsiReinstallFeatureW(wszProduct
, wszFeature
, dwReinstallMode
);
3618 msi_free(wszProduct
);
3619 msi_free(wszFeature
);
3626 unsigned int buf
[4];
3627 unsigned char in
[64];
3628 unsigned char digest
[16];
3631 extern VOID WINAPI
MD5Init( MD5_CTX
*);
3632 extern VOID WINAPI
MD5Update( MD5_CTX
*, const unsigned char *, unsigned int );
3633 extern VOID WINAPI
MD5Final( MD5_CTX
*);
3635 /***********************************************************************
3636 * MsiGetFileHashW [MSI.@]
3638 UINT WINAPI
MsiGetFileHashW( LPCWSTR szFilePath
, DWORD dwOptions
,
3639 PMSIFILEHASHINFO pHash
)
3641 HANDLE handle
, mapping
;
3644 UINT r
= ERROR_FUNCTION_FAILED
;
3646 TRACE("%s %08x %p\n", debugstr_w(szFilePath
), dwOptions
, pHash
);
3649 return ERROR_INVALID_PARAMETER
;
3652 return ERROR_PATH_NOT_FOUND
;
3655 return ERROR_INVALID_PARAMETER
;
3657 return ERROR_INVALID_PARAMETER
;
3658 if (pHash
->dwFileHashInfoSize
< sizeof *pHash
)
3659 return ERROR_INVALID_PARAMETER
;
3661 handle
= CreateFileW( szFilePath
, GENERIC_READ
,
3662 FILE_SHARE_READ
| FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, 0, NULL
);
3663 if (handle
== INVALID_HANDLE_VALUE
)
3664 return ERROR_FILE_NOT_FOUND
;
3666 length
= GetFileSize( handle
, NULL
);
3668 mapping
= CreateFileMappingW( handle
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
3671 p
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, length
);
3677 MD5Update( &ctx
, p
, length
);
3679 UnmapViewOfFile( p
);
3681 memcpy( pHash
->dwData
, ctx
.digest
, sizeof pHash
->dwData
);
3684 CloseHandle( mapping
);
3686 CloseHandle( handle
);
3691 /***********************************************************************
3692 * MsiGetFileHashA [MSI.@]
3694 UINT WINAPI
MsiGetFileHashA( LPCSTR szFilePath
, DWORD dwOptions
,
3695 PMSIFILEHASHINFO pHash
)
3700 TRACE("%s %08x %p\n", debugstr_a(szFilePath
), dwOptions
, pHash
);
3702 file
= strdupAtoW( szFilePath
);
3703 if (szFilePath
&& !file
)
3704 return ERROR_OUTOFMEMORY
;
3706 r
= MsiGetFileHashW( file
, dwOptions
, pHash
);
3711 /***********************************************************************
3712 * MsiAdvertiseScriptW [MSI.@]
3714 UINT WINAPI
MsiAdvertiseScriptW( LPCWSTR szScriptFile
, DWORD dwFlags
,
3715 PHKEY phRegData
, BOOL fRemoveItems
)
3717 FIXME("%s %08x %p %d\n",
3718 debugstr_w( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3719 return ERROR_CALL_NOT_IMPLEMENTED
;
3722 /***********************************************************************
3723 * MsiAdvertiseScriptA [MSI.@]
3725 UINT WINAPI
MsiAdvertiseScriptA( LPCSTR szScriptFile
, DWORD dwFlags
,
3726 PHKEY phRegData
, BOOL fRemoveItems
)
3728 FIXME("%s %08x %p %d\n",
3729 debugstr_a( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3730 return ERROR_CALL_NOT_IMPLEMENTED
;
3733 /***********************************************************************
3734 * MsiIsProductElevatedW [MSI.@]
3736 UINT WINAPI
MsiIsProductElevatedW( LPCWSTR szProduct
, BOOL
*pfElevated
)
3738 FIXME("%s %p - stub\n",
3739 debugstr_w( szProduct
), pfElevated
);
3741 return ERROR_SUCCESS
;
3744 /***********************************************************************
3745 * MsiIsProductElevatedA [MSI.@]
3747 UINT WINAPI
MsiIsProductElevatedA( LPCSTR szProduct
, BOOL
*pfElevated
)
3749 FIXME("%s %p - stub\n",
3750 debugstr_a( szProduct
), pfElevated
);
3752 return ERROR_SUCCESS
;
3755 /***********************************************************************
3756 * MsiSetExternalUIRecord [MSI.@]
3758 UINT WINAPI
MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler
,
3759 DWORD filter
, LPVOID context
,
3760 PINSTALLUI_HANDLER_RECORD prev
)
3762 TRACE("%p %08x %p %p\n", handler
, filter
, context
, prev
);
3765 *prev
= gUIHandlerRecord
;
3767 gUIHandlerRecord
= handler
;
3769 gUIContext
= context
;
3771 return ERROR_SUCCESS
;
3774 /***********************************************************************
3775 * MsiInstallMissingComponentW [MSI.@]
3777 UINT WINAPI
MsiInstallMissingComponentW(LPCWSTR szProduct
, LPCWSTR szComponent
, INSTALLSTATE eInstallState
)
3779 FIXME("(%s %s %d\n", debugstr_w(szProduct
), debugstr_w(szComponent
), eInstallState
);
3780 return ERROR_SUCCESS
;