2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
35 #include "msiserver.h"
45 #include "wine/debug.h"
46 #include "wine/unicode.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
50 static const WCHAR installerW
[] = {'\\','I','n','s','t','a','l','l','e','r',0};
52 UINT
msi_locate_product(LPCWSTR szProduct
, MSIINSTALLCONTEXT
*context
)
56 *context
= MSIINSTALLCONTEXT_NONE
;
57 if (!szProduct
) return ERROR_UNKNOWN_PRODUCT
;
59 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
60 &hkey
, FALSE
) == ERROR_SUCCESS
)
61 *context
= MSIINSTALLCONTEXT_USERMANAGED
;
62 else if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
63 &hkey
, FALSE
) == ERROR_SUCCESS
)
64 *context
= MSIINSTALLCONTEXT_MACHINE
;
65 else if (MSIREG_OpenProductKey(szProduct
, NULL
,
66 MSIINSTALLCONTEXT_USERUNMANAGED
,
67 &hkey
, FALSE
) == ERROR_SUCCESS
)
68 *context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
72 if (*context
== MSIINSTALLCONTEXT_NONE
)
73 return ERROR_UNKNOWN_PRODUCT
;
78 UINT WINAPI
MsiOpenProductA(LPCSTR szProduct
, MSIHANDLE
*phProduct
)
81 LPWSTR szwProd
= NULL
;
83 TRACE("%s %p\n",debugstr_a(szProduct
), phProduct
);
87 szwProd
= strdupAtoW( szProduct
);
89 return ERROR_OUTOFMEMORY
;
92 r
= MsiOpenProductW( szwProd
, phProduct
);
99 static UINT
MSI_OpenProductW(LPCWSTR szProduct
, MSIPACKAGE
**package
)
104 MSIINSTALLCONTEXT context
;
106 static const WCHAR managed
[] = {
107 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0};
108 static const WCHAR local
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
110 TRACE("%s %p\n", debugstr_w(szProduct
), package
);
112 r
= msi_locate_product(szProduct
, &context
);
113 if (r
!= ERROR_SUCCESS
)
116 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &props
, FALSE
);
117 if (r
!= ERROR_SUCCESS
)
118 return ERROR_UNKNOWN_PRODUCT
;
120 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
121 path
= msi_reg_get_val_str(props
, managed
);
123 path
= msi_reg_get_val_str(props
, local
);
125 r
= ERROR_UNKNOWN_PRODUCT
;
127 if (!path
|| GetFileAttributesW(path
) == INVALID_FILE_ATTRIBUTES
)
130 if (PathIsRelativeW(path
))
132 r
= ERROR_INSTALL_PACKAGE_OPEN_FAILED
;
136 r
= MSI_OpenPackageW(path
, package
);
144 UINT WINAPI
MsiOpenProductW(LPCWSTR szProduct
, MSIHANDLE
*phProduct
)
146 MSIPACKAGE
*package
= NULL
;
147 WCHAR squished_pc
[GUID_SIZE
];
150 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
151 return ERROR_INVALID_PARAMETER
;
154 return ERROR_INVALID_PARAMETER
;
156 r
= MSI_OpenProductW(szProduct
, &package
);
157 if (r
!= ERROR_SUCCESS
)
160 *phProduct
= alloc_msihandle(&package
->hdr
);
162 r
= ERROR_NOT_ENOUGH_MEMORY
;
164 msiobj_release(&package
->hdr
);
168 UINT WINAPI
MsiAdvertiseProductA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
169 LPCSTR szTransforms
, LANGID lgidLanguage
)
171 FIXME("%s %s %s %08x\n",debugstr_a(szPackagePath
),
172 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
), lgidLanguage
);
173 return ERROR_CALL_NOT_IMPLEMENTED
;
176 UINT WINAPI
MsiAdvertiseProductW(LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
177 LPCWSTR szTransforms
, LANGID lgidLanguage
)
179 FIXME("%s %s %s %08x\n",debugstr_w(szPackagePath
),
180 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
), lgidLanguage
);
181 return ERROR_CALL_NOT_IMPLEMENTED
;
184 UINT WINAPI
MsiAdvertiseProductExA(LPCSTR szPackagePath
, LPCSTR szScriptfilePath
,
185 LPCSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
187 FIXME("%s %s %s %08x %08x %08x\n", debugstr_a(szPackagePath
),
188 debugstr_a(szScriptfilePath
), debugstr_a(szTransforms
),
189 lgidLanguage
, dwPlatform
, dwOptions
);
190 return ERROR_CALL_NOT_IMPLEMENTED
;
193 UINT WINAPI
MsiAdvertiseProductExW( LPCWSTR szPackagePath
, LPCWSTR szScriptfilePath
,
194 LPCWSTR szTransforms
, LANGID lgidLanguage
, DWORD dwPlatform
, DWORD dwOptions
)
196 FIXME("%s %s %s %08x %08x %08x\n", debugstr_w(szPackagePath
),
197 debugstr_w(szScriptfilePath
), debugstr_w(szTransforms
),
198 lgidLanguage
, dwPlatform
, dwOptions
);
199 return ERROR_CALL_NOT_IMPLEMENTED
;
202 UINT WINAPI
MsiInstallProductA(LPCSTR szPackagePath
, LPCSTR szCommandLine
)
204 LPWSTR szwPath
= NULL
, szwCommand
= NULL
;
205 UINT r
= ERROR_OUTOFMEMORY
;
207 TRACE("%s %s\n",debugstr_a(szPackagePath
), debugstr_a(szCommandLine
));
211 szwPath
= strdupAtoW( szPackagePath
);
218 szwCommand
= strdupAtoW( szCommandLine
);
223 r
= MsiInstallProductW( szwPath
, szwCommand
);
227 msi_free( szwCommand
);
232 UINT WINAPI
MsiInstallProductW(LPCWSTR szPackagePath
, LPCWSTR szCommandLine
)
234 MSIPACKAGE
*package
= NULL
;
237 TRACE("%s %s\n",debugstr_w(szPackagePath
), debugstr_w(szCommandLine
));
240 return ERROR_INVALID_PARAMETER
;
243 return ERROR_PATH_NOT_FOUND
;
245 r
= MSI_OpenPackageW( szPackagePath
, &package
);
246 if (r
== ERROR_SUCCESS
)
248 r
= MSI_InstallPackage( package
, szPackagePath
, szCommandLine
);
249 msiobj_release( &package
->hdr
);
255 UINT WINAPI
MsiReinstallProductA(LPCSTR szProduct
, DWORD dwReinstallMode
)
260 TRACE("%s %08x\n", debugstr_a(szProduct
), dwReinstallMode
);
262 wszProduct
= strdupAtoW(szProduct
);
264 rc
= MsiReinstallProductW(wszProduct
, dwReinstallMode
);
266 msi_free(wszProduct
);
270 UINT WINAPI
MsiReinstallProductW(LPCWSTR szProduct
, DWORD dwReinstallMode
)
272 TRACE("%s %08x\n", debugstr_w(szProduct
), dwReinstallMode
);
274 return MsiReinstallFeatureW(szProduct
, szAll
, dwReinstallMode
);
277 UINT WINAPI
MsiApplyPatchA(LPCSTR szPatchPackage
, LPCSTR szInstallPackage
,
278 INSTALLTYPE eInstallType
, LPCSTR szCommandLine
)
280 LPWSTR patch_package
= NULL
;
281 LPWSTR install_package
= NULL
;
282 LPWSTR command_line
= NULL
;
283 UINT r
= ERROR_OUTOFMEMORY
;
285 TRACE("%s %s %d %s\n", debugstr_a(szPatchPackage
), debugstr_a(szInstallPackage
),
286 eInstallType
, debugstr_a(szCommandLine
));
288 if (szPatchPackage
&& !(patch_package
= strdupAtoW(szPatchPackage
)))
291 if (szInstallPackage
&& !(install_package
= strdupAtoW(szInstallPackage
)))
294 if (szCommandLine
&& !(command_line
= strdupAtoW(szCommandLine
)))
297 r
= MsiApplyPatchW(patch_package
, install_package
, eInstallType
, command_line
);
300 msi_free(patch_package
);
301 msi_free(install_package
);
302 msi_free(command_line
);
308 static UINT
get_patch_product_codes( LPCWSTR szPatchPackage
, WCHAR
***product_codes
)
310 MSIHANDLE patch
, info
= 0;
313 static WCHAR empty
[] = {0};
316 r
= MsiOpenDatabaseW( szPatchPackage
, MSIDBOPEN_READONLY
, &patch
);
317 if (r
!= ERROR_SUCCESS
)
320 r
= MsiGetSummaryInformationW( patch
, NULL
, 0, &info
);
321 if (r
!= ERROR_SUCCESS
)
325 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, empty
, &size
);
326 if (r
!= ERROR_MORE_DATA
|| !size
|| type
!= VT_LPSTR
)
328 ERR("Failed to read product codes from patch\n");
329 r
= ERROR_FUNCTION_FAILED
;
333 codes
= msi_alloc( ++size
* sizeof(WCHAR
) );
336 r
= ERROR_OUTOFMEMORY
;
340 r
= MsiSummaryInfoGetPropertyW( info
, PID_TEMPLATE
, &type
, NULL
, NULL
, codes
, &size
);
341 if (r
== ERROR_SUCCESS
)
342 *product_codes
= msi_split_string( codes
, ';' );
345 MsiCloseHandle( info
);
346 MsiCloseHandle( patch
);
351 static UINT
MSI_ApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szProductCode
, LPCWSTR szCommandLine
)
353 UINT i
, r
= ERROR_FUNCTION_FAILED
;
355 LPCWSTR cmd_ptr
= szCommandLine
;
356 LPWSTR cmd
, *codes
= NULL
;
357 BOOL succeeded
= FALSE
;
359 static const WCHAR fmt
[] = {'%','s',' ','P','A','T','C','H','=','"','%','s','"',0};
360 static WCHAR empty
[] = {0};
362 if (!szPatchPackage
|| !szPatchPackage
[0])
363 return ERROR_INVALID_PARAMETER
;
365 if (!szProductCode
&& (r
= get_patch_product_codes( szPatchPackage
, &codes
)))
371 size
= strlenW(cmd_ptr
) + strlenW(fmt
) + strlenW(szPatchPackage
) + 1;
372 cmd
= msi_alloc(size
* sizeof(WCHAR
));
376 return ERROR_OUTOFMEMORY
;
378 sprintfW(cmd
, fmt
, cmd_ptr
, szPatchPackage
);
381 r
= MsiConfigureProductExW(szProductCode
, INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
384 for (i
= 0; codes
[i
]; i
++)
386 r
= MsiConfigureProductExW(codes
[i
], INSTALLLEVEL_DEFAULT
, INSTALLSTATE_DEFAULT
, cmd
);
387 if (r
== ERROR_SUCCESS
)
389 TRACE("patch applied\n");
403 UINT WINAPI
MsiApplyPatchW(LPCWSTR szPatchPackage
, LPCWSTR szInstallPackage
,
404 INSTALLTYPE eInstallType
, LPCWSTR szCommandLine
)
406 TRACE("%s %s %d %s\n", debugstr_w(szPatchPackage
), debugstr_w(szInstallPackage
),
407 eInstallType
, debugstr_w(szCommandLine
));
409 if (szInstallPackage
|| eInstallType
== INSTALLTYPE_NETWORK_IMAGE
||
410 eInstallType
== INSTALLTYPE_SINGLE_INSTANCE
)
412 FIXME("Only reading target products from patch\n");
413 return ERROR_CALL_NOT_IMPLEMENTED
;
416 return MSI_ApplyPatchW(szPatchPackage
, NULL
, szCommandLine
);
419 UINT WINAPI
MsiApplyMultiplePatchesA(LPCSTR szPatchPackages
,
420 LPCSTR szProductCode
, LPCSTR szPropertiesList
)
422 LPWSTR patch_packages
= NULL
;
423 LPWSTR product_code
= NULL
;
424 LPWSTR properties_list
= NULL
;
425 UINT r
= ERROR_OUTOFMEMORY
;
427 TRACE("%s %s %s\n", debugstr_a(szPatchPackages
), debugstr_a(szProductCode
),
428 debugstr_a(szPropertiesList
));
430 if (!szPatchPackages
|| !szPatchPackages
[0])
431 return ERROR_INVALID_PARAMETER
;
433 if (!(patch_packages
= strdupAtoW(szPatchPackages
)))
434 return ERROR_OUTOFMEMORY
;
436 if (szProductCode
&& !(product_code
= strdupAtoW(szProductCode
)))
439 if (szPropertiesList
&& !(properties_list
= strdupAtoW(szPropertiesList
)))
442 r
= MsiApplyMultiplePatchesW(patch_packages
, product_code
, properties_list
);
445 msi_free(patch_packages
);
446 msi_free(product_code
);
447 msi_free(properties_list
);
452 UINT WINAPI
MsiApplyMultiplePatchesW(LPCWSTR szPatchPackages
,
453 LPCWSTR szProductCode
, LPCWSTR szPropertiesList
)
455 UINT r
= ERROR_SUCCESS
;
458 TRACE("%s %s %s\n", debugstr_w(szPatchPackages
), debugstr_w(szProductCode
),
459 debugstr_w(szPropertiesList
));
461 if (!szPatchPackages
|| !szPatchPackages
[0])
462 return ERROR_INVALID_PARAMETER
;
464 beg
= end
= szPatchPackages
;
470 while (*beg
== ' ') beg
++;
471 while (*end
&& *end
!= ';') end
++;
474 while (len
&& beg
[len
- 1] == ' ') len
--;
476 if (!len
) return ERROR_INVALID_NAME
;
478 patch
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
480 return ERROR_OUTOFMEMORY
;
482 memcpy(patch
, beg
, len
* sizeof(WCHAR
));
485 r
= MSI_ApplyPatchW(patch
, szProductCode
, szPropertiesList
);
488 if (r
!= ERROR_SUCCESS
)
496 static void free_patchinfo( DWORD count
, MSIPATCHSEQUENCEINFOW
*info
)
499 for (i
= 0; i
< count
; i
++) msi_free( (WCHAR
*)info
[i
].szPatchData
);
503 static MSIPATCHSEQUENCEINFOW
*patchinfoAtoW( DWORD count
, const MSIPATCHSEQUENCEINFOA
*info
)
506 MSIPATCHSEQUENCEINFOW
*ret
;
508 if (!(ret
= msi_alloc( count
* sizeof(MSIPATCHSEQUENCEINFOW
) ))) return NULL
;
509 for (i
= 0; i
< count
; i
++)
511 if (info
[i
].szPatchData
&& !(ret
[i
].szPatchData
= strdupAtoW( info
[i
].szPatchData
)))
513 free_patchinfo( i
, ret
);
516 ret
[i
].ePatchDataType
= info
[i
].ePatchDataType
;
517 ret
[i
].dwOrder
= info
[i
].dwOrder
;
518 ret
[i
].uStatus
= info
[i
].uStatus
;
523 UINT WINAPI
MsiDetermineApplicablePatchesA(LPCSTR szProductPackagePath
,
524 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOA pPatchInfo
)
527 WCHAR
*package_path
= NULL
;
528 MSIPATCHSEQUENCEINFOW
*psi
;
530 TRACE("%s, %u, %p\n", debugstr_a(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
532 if (szProductPackagePath
&& !(package_path
= strdupAtoW( szProductPackagePath
)))
533 return ERROR_OUTOFMEMORY
;
535 if (!(psi
= patchinfoAtoW( cPatchInfo
, pPatchInfo
)))
537 msi_free( package_path
);
538 return ERROR_OUTOFMEMORY
;
540 r
= MsiDetermineApplicablePatchesW( package_path
, cPatchInfo
, psi
);
541 if (r
== ERROR_SUCCESS
)
543 for (i
= 0; i
< cPatchInfo
; i
++)
545 pPatchInfo
[i
].dwOrder
= psi
[i
].dwOrder
;
546 pPatchInfo
[i
].uStatus
= psi
[i
].uStatus
;
549 msi_free( package_path
);
550 free_patchinfo( cPatchInfo
, psi
);
554 static UINT
MSI_ApplicablePatchW( MSIPACKAGE
*package
, LPCWSTR patch
)
557 MSIDATABASE
*patch_db
;
558 UINT r
= ERROR_SUCCESS
;
560 r
= MSI_OpenDatabaseW( patch
, MSIDBOPEN_READONLY
, &patch_db
);
561 if (r
!= ERROR_SUCCESS
)
563 WARN("failed to open patch file %s\n", debugstr_w(patch
));
567 si
= MSI_GetSummaryInformationW( patch_db
->storage
, 0 );
570 msiobj_release( &patch_db
->hdr
);
571 return ERROR_FUNCTION_FAILED
;
574 r
= msi_check_patch_applicable( package
, si
);
575 if (r
!= ERROR_SUCCESS
)
576 TRACE("patch not applicable\n");
578 msiobj_release( &patch_db
->hdr
);
579 msiobj_release( &si
->hdr
);
583 static UINT
determine_patch_sequence( MSIPACKAGE
*package
, DWORD count
, MSIPATCHSEQUENCEINFOW
*info
)
587 for (i
= 0; i
< count
; i
++)
589 switch (info
[i
].ePatchDataType
)
591 case MSIPATCH_DATATYPE_PATCHFILE
:
593 FIXME("patch ordering not supported\n");
594 if (MSI_ApplicablePatchW( package
, info
[i
].szPatchData
) != ERROR_SUCCESS
)
596 info
[i
].dwOrder
= ~0u;
597 info
[i
].uStatus
= ERROR_PATCH_TARGET_NOT_FOUND
;
602 info
[i
].uStatus
= ERROR_SUCCESS
;
608 FIXME("patch data type %u not supported\n", info
[i
].ePatchDataType
);
610 info
[i
].uStatus
= ERROR_SUCCESS
;
614 TRACE("szPatchData: %s\n", debugstr_w(info
[i
].szPatchData
));
615 TRACE("ePatchDataType: %u\n", info
[i
].ePatchDataType
);
616 TRACE("dwOrder: %u\n", info
[i
].dwOrder
);
617 TRACE("uStatus: %u\n", info
[i
].uStatus
);
619 return ERROR_SUCCESS
;
622 UINT WINAPI
MsiDetermineApplicablePatchesW(LPCWSTR szProductPackagePath
,
623 DWORD cPatchInfo
, PMSIPATCHSEQUENCEINFOW pPatchInfo
)
628 TRACE("%s, %u, %p\n", debugstr_w(szProductPackagePath
), cPatchInfo
, pPatchInfo
);
630 r
= MSI_OpenPackageW( szProductPackagePath
, &package
);
631 if (r
!= ERROR_SUCCESS
)
633 ERR("failed to open package %u\n", r
);
636 r
= determine_patch_sequence( package
, cPatchInfo
, pPatchInfo
);
637 msiobj_release( &package
->hdr
);
641 UINT WINAPI
MsiDeterminePatchSequenceA( LPCSTR product
, LPCSTR usersid
,
642 MSIINSTALLCONTEXT context
, DWORD count
, PMSIPATCHSEQUENCEINFOA patchinfo
)
645 WCHAR
*productW
, *usersidW
= NULL
;
646 MSIPATCHSEQUENCEINFOW
*patchinfoW
;
648 TRACE("%s, %s, %d, %d, %p\n", debugstr_a(product
), debugstr_a(usersid
),
649 context
, count
, patchinfo
);
651 if (!product
) return ERROR_INVALID_PARAMETER
;
652 if (!(productW
= strdupAtoW( product
))) return ERROR_OUTOFMEMORY
;
653 if (usersid
&& !(usersidW
= strdupAtoW( usersid
)))
655 msi_free( productW
);
656 return ERROR_OUTOFMEMORY
;
658 if (!(patchinfoW
= patchinfoAtoW( count
, patchinfo
)))
660 msi_free( productW
);
661 msi_free( usersidW
);
662 return ERROR_OUTOFMEMORY
;
664 r
= MsiDeterminePatchSequenceW( productW
, usersidW
, context
, count
, patchinfoW
);
665 if (r
== ERROR_SUCCESS
)
667 for (i
= 0; i
< count
; i
++)
669 patchinfo
[i
].dwOrder
= patchinfoW
[i
].dwOrder
;
670 patchinfo
[i
].uStatus
= patchinfoW
[i
].uStatus
;
673 msi_free( productW
);
674 msi_free( usersidW
);
675 free_patchinfo( count
, patchinfoW
);
679 static UINT
open_package( const WCHAR
*product
, const WCHAR
*usersid
,
680 MSIINSTALLCONTEXT context
, MSIPACKAGE
**package
)
684 WCHAR
*localpath
, sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
686 r
= MSIREG_OpenInstallProps( product
, context
, usersid
, &props
, FALSE
);
687 if (r
!= ERROR_SUCCESS
) return ERROR_BAD_CONFIGURATION
;
689 if ((localpath
= msi_reg_get_val_str( props
, szLocalPackage
)))
691 strcpyW( sourcepath
, localpath
);
692 msi_free( localpath
);
694 RegCloseKey( props
);
695 if (!localpath
|| GetFileAttributesW( sourcepath
) == INVALID_FILE_ATTRIBUTES
)
697 DWORD sz
= sizeof(sourcepath
);
698 MsiSourceListGetInfoW( product
, usersid
, context
, MSICODE_PRODUCT
,
699 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
700 sz
= sizeof(filename
);
701 MsiSourceListGetInfoW( product
, usersid
, context
, MSICODE_PRODUCT
,
702 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
703 strcatW( sourcepath
, filename
);
705 if (GetFileAttributesW( sourcepath
) == INVALID_FILE_ATTRIBUTES
)
706 return ERROR_INSTALL_SOURCE_ABSENT
;
708 return MSI_OpenPackageW( sourcepath
, package
);
711 UINT WINAPI
MsiDeterminePatchSequenceW( LPCWSTR product
, LPCWSTR usersid
,
712 MSIINSTALLCONTEXT context
, DWORD count
, PMSIPATCHSEQUENCEINFOW patchinfo
)
717 TRACE("%s, %s, %d, %d, %p\n", debugstr_w(product
), debugstr_w(usersid
),
718 context
, count
, patchinfo
);
720 if (!product
) return ERROR_INVALID_PARAMETER
;
721 r
= open_package( product
, usersid
, context
, &package
);
722 if (r
!= ERROR_SUCCESS
) return r
;
724 r
= determine_patch_sequence( package
, count
, patchinfo
);
725 msiobj_release( &package
->hdr
);
729 UINT WINAPI
MsiConfigureProductExW(LPCWSTR szProduct
, int iInstallLevel
,
730 INSTALLSTATE eInstallState
, LPCWSTR szCommandLine
)
732 MSIPACKAGE
* package
= NULL
;
733 MSIINSTALLCONTEXT context
;
736 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
739 static const WCHAR szInstalled
[] = {
740 ' ','I','n','s','t','a','l','l','e','d','=','1',0};
741 static const WCHAR szMaxInstallLevel
[] = {
742 ' ','I','N','S','T','A','L','L','L','E','V','E','L','=','3','2','7','6','7',0};
743 static const WCHAR szRemoveAll
[] = {
744 ' ','R','E','M','O','V','E','=','A','L','L',0};
745 static const WCHAR szMachine
[] = {
746 ' ','A','L','L','U','S','E','R','S','=','1',0};
748 TRACE("%s %d %d %s\n",debugstr_w(szProduct
), iInstallLevel
, eInstallState
,
749 debugstr_w(szCommandLine
));
751 if (!szProduct
|| lstrlenW(szProduct
) != GUID_SIZE
- 1)
752 return ERROR_INVALID_PARAMETER
;
754 if (eInstallState
== INSTALLSTATE_ADVERTISED
||
755 eInstallState
== INSTALLSTATE_SOURCE
)
757 FIXME("State %d not implemented\n", eInstallState
);
758 return ERROR_CALL_NOT_IMPLEMENTED
;
761 r
= msi_locate_product(szProduct
, &context
);
762 if (r
!= ERROR_SUCCESS
)
765 r
= open_package(szProduct
, NULL
, context
, &package
);
766 if (r
!= ERROR_SUCCESS
)
769 sz
= lstrlenW(szInstalled
) + 1;
772 sz
+= lstrlenW(szCommandLine
);
774 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
775 sz
+= lstrlenW(szMaxInstallLevel
);
777 if (eInstallState
== INSTALLSTATE_ABSENT
)
778 sz
+= lstrlenW(szRemoveAll
);
780 if (context
== MSIINSTALLCONTEXT_MACHINE
)
781 sz
+= lstrlenW(szMachine
);
783 commandline
= msi_alloc(sz
* sizeof(WCHAR
));
786 r
= ERROR_OUTOFMEMORY
;
792 lstrcpyW(commandline
,szCommandLine
);
794 if (eInstallState
!= INSTALLSTATE_DEFAULT
)
795 lstrcatW(commandline
, szMaxInstallLevel
);
797 if (eInstallState
== INSTALLSTATE_ABSENT
)
798 lstrcatW(commandline
, szRemoveAll
);
800 if (context
== MSIINSTALLCONTEXT_MACHINE
)
801 lstrcatW(commandline
, szMachine
);
803 sz
= sizeof(sourcepath
);
804 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
805 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
807 sz
= sizeof(filename
);
808 MsiSourceListGetInfoW(szProduct
, NULL
, context
, MSICODE_PRODUCT
,
809 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
811 strcatW(sourcepath
, filename
);
813 r
= MSI_InstallPackage( package
, sourcepath
, commandline
);
815 msi_free(commandline
);
818 msiobj_release( &package
->hdr
);
823 UINT WINAPI
MsiConfigureProductExA(LPCSTR szProduct
, int iInstallLevel
,
824 INSTALLSTATE eInstallState
, LPCSTR szCommandLine
)
826 LPWSTR szwProduct
= NULL
;
827 LPWSTR szwCommandLine
= NULL
;
828 UINT r
= ERROR_OUTOFMEMORY
;
832 szwProduct
= strdupAtoW( szProduct
);
839 szwCommandLine
= strdupAtoW( szCommandLine
);
844 r
= MsiConfigureProductExW( szwProduct
, iInstallLevel
, eInstallState
,
847 msi_free( szwProduct
);
848 msi_free( szwCommandLine
);
853 UINT WINAPI
MsiConfigureProductA(LPCSTR szProduct
, int iInstallLevel
,
854 INSTALLSTATE eInstallState
)
856 LPWSTR szwProduct
= NULL
;
859 TRACE("%s %d %d\n",debugstr_a(szProduct
), iInstallLevel
, eInstallState
);
863 szwProduct
= strdupAtoW( szProduct
);
865 return ERROR_OUTOFMEMORY
;
868 r
= MsiConfigureProductW( szwProduct
, iInstallLevel
, eInstallState
);
869 msi_free( szwProduct
);
874 UINT WINAPI
MsiConfigureProductW(LPCWSTR szProduct
, int iInstallLevel
,
875 INSTALLSTATE eInstallState
)
877 return MsiConfigureProductExW(szProduct
, iInstallLevel
, eInstallState
, NULL
);
880 UINT WINAPI
MsiGetProductCodeA(LPCSTR szComponent
, LPSTR szBuffer
)
882 LPWSTR szwComponent
= NULL
;
884 WCHAR szwBuffer
[GUID_SIZE
];
886 TRACE("%s %p\n", debugstr_a(szComponent
), szBuffer
);
890 szwComponent
= strdupAtoW( szComponent
);
892 return ERROR_OUTOFMEMORY
;
896 r
= MsiGetProductCodeW( szwComponent
, szwBuffer
);
899 WideCharToMultiByte(CP_ACP
, 0, szwBuffer
, -1, szBuffer
, GUID_SIZE
, NULL
, NULL
);
901 msi_free( szwComponent
);
906 UINT WINAPI
MsiGetProductCodeW(LPCWSTR szComponent
, LPWSTR szBuffer
)
909 HKEY compkey
, prodkey
;
910 WCHAR squished_comp
[GUID_SIZE
];
911 WCHAR squished_prod
[GUID_SIZE
];
912 DWORD sz
= GUID_SIZE
;
914 TRACE("%s %p\n", debugstr_w(szComponent
), szBuffer
);
916 if (!szComponent
|| !*szComponent
)
917 return ERROR_INVALID_PARAMETER
;
919 if (!squash_guid(szComponent
, squished_comp
))
920 return ERROR_INVALID_PARAMETER
;
922 if (MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &compkey
, FALSE
) != ERROR_SUCCESS
&&
923 MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &compkey
, FALSE
) != ERROR_SUCCESS
)
925 return ERROR_UNKNOWN_COMPONENT
;
928 rc
= RegEnumValueW(compkey
, 0, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
929 if (rc
!= ERROR_SUCCESS
)
931 RegCloseKey(compkey
);
932 return ERROR_UNKNOWN_COMPONENT
;
935 /* check simple case, only one product */
936 rc
= RegEnumValueW(compkey
, 1, squished_prod
, &sz
, NULL
, NULL
, NULL
, NULL
);
937 if (rc
== ERROR_NO_MORE_ITEMS
)
944 while ((rc
= RegEnumValueW(compkey
, index
, squished_prod
, &sz
,
945 NULL
, NULL
, NULL
, NULL
)) != ERROR_NO_MORE_ITEMS
)
949 unsquash_guid(squished_prod
, szBuffer
);
951 if (MSIREG_OpenProductKey(szBuffer
, NULL
,
952 MSIINSTALLCONTEXT_USERMANAGED
,
953 &prodkey
, FALSE
) == ERROR_SUCCESS
||
954 MSIREG_OpenProductKey(szBuffer
, NULL
,
955 MSIINSTALLCONTEXT_USERUNMANAGED
,
956 &prodkey
, FALSE
) == ERROR_SUCCESS
||
957 MSIREG_OpenProductKey(szBuffer
, NULL
,
958 MSIINSTALLCONTEXT_MACHINE
,
959 &prodkey
, FALSE
) == ERROR_SUCCESS
)
961 RegCloseKey(prodkey
);
967 rc
= ERROR_INSTALL_FAILURE
;
970 RegCloseKey(compkey
);
971 unsquash_guid(squished_prod
, szBuffer
);
975 static LPWSTR
msi_reg_get_value(HKEY hkey
, LPCWSTR name
, DWORD
*type
)
981 static const WCHAR format
[] = {'%','d',0};
983 res
= RegQueryValueExW(hkey
, name
, NULL
, type
, NULL
, NULL
);
984 if (res
!= ERROR_SUCCESS
)
988 return msi_reg_get_val_str(hkey
, name
);
990 if (!msi_reg_get_val_dword(hkey
, name
, &dval
))
993 sprintfW(temp
, format
, dval
);
994 return strdupW(temp
);
997 static UINT
MSI_GetProductInfo(LPCWSTR szProduct
, LPCWSTR szAttribute
,
998 awstring
*szValue
, LPDWORD pcchValueBuf
)
1000 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
1001 UINT r
= ERROR_UNKNOWN_PROPERTY
;
1002 HKEY prodkey
, userdata
, source
;
1004 WCHAR squished_pc
[GUID_SIZE
];
1005 WCHAR packagecode
[GUID_SIZE
];
1006 BOOL badconfig
= FALSE
;
1008 DWORD type
= REG_NONE
;
1010 static WCHAR empty
[] = {0};
1011 static const WCHAR sourcelist
[] = {
1012 'S','o','u','r','c','e','L','i','s','t',0};
1013 static const WCHAR display_name
[] = {
1014 'D','i','s','p','l','a','y','N','a','m','e',0};
1015 static const WCHAR display_version
[] = {
1016 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1017 static const WCHAR assignment
[] = {
1018 'A','s','s','i','g','n','m','e','n','t',0};
1020 TRACE("%s %s %p %p\n", debugstr_w(szProduct
),
1021 debugstr_w(szAttribute
), szValue
, pcchValueBuf
);
1023 if ((szValue
->str
.w
&& !pcchValueBuf
) || !szProduct
|| !szAttribute
)
1024 return ERROR_INVALID_PARAMETER
;
1026 if (!squash_guid(szProduct
, squished_pc
))
1027 return ERROR_INVALID_PARAMETER
;
1029 if ((r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1030 MSIINSTALLCONTEXT_USERMANAGED
,
1031 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
1032 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1033 MSIINSTALLCONTEXT_USERUNMANAGED
,
1034 &prodkey
, FALSE
)) != ERROR_SUCCESS
&&
1035 (r
= MSIREG_OpenProductKey(szProduct
, NULL
,
1036 MSIINSTALLCONTEXT_MACHINE
,
1037 &prodkey
, FALSE
)) == ERROR_SUCCESS
)
1039 context
= MSIINSTALLCONTEXT_MACHINE
;
1042 MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
1044 if (!strcmpW( szAttribute
, INSTALLPROPERTY_HELPLINKW
) ||
1045 !strcmpW( szAttribute
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1046 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLDATEW
) ||
1047 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1048 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1049 !strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1050 !strcmpW( szAttribute
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1051 !strcmpW( szAttribute
, INSTALLPROPERTY_PUBLISHERW
) ||
1052 !strcmpW( szAttribute
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1053 !strcmpW( szAttribute
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1054 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMINORW
) ||
1055 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1056 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1057 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTIDW
) ||
1058 !strcmpW( szAttribute
, INSTALLPROPERTY_REGCOMPANYW
) ||
1059 !strcmpW( szAttribute
, INSTALLPROPERTY_REGOWNERW
))
1063 r
= ERROR_UNKNOWN_PRODUCT
;
1068 return ERROR_UNKNOWN_PROPERTY
;
1070 if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1071 szAttribute
= display_name
;
1072 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONSTRINGW
))
1073 szAttribute
= display_version
;
1075 val
= msi_reg_get_value(userdata
, szAttribute
, &type
);
1079 else if (!strcmpW( szAttribute
, INSTALLPROPERTY_INSTANCETYPEW
) ||
1080 !strcmpW( szAttribute
, INSTALLPROPERTY_TRANSFORMSW
) ||
1081 !strcmpW( szAttribute
, INSTALLPROPERTY_LANGUAGEW
) ||
1082 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1083 !strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
) ||
1084 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
) ||
1085 !strcmpW( szAttribute
, INSTALLPROPERTY_VERSIONW
) ||
1086 !strcmpW( szAttribute
, INSTALLPROPERTY_PRODUCTICONW
) ||
1087 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1088 !strcmpW( szAttribute
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1092 r
= ERROR_UNKNOWN_PRODUCT
;
1096 if (!strcmpW( szAttribute
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1097 szAttribute
= assignment
;
1099 if (!strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGENAMEW
))
1101 res
= RegOpenKeyW(prodkey
, sourcelist
, &source
);
1102 if (res
!= ERROR_SUCCESS
)
1104 r
= ERROR_UNKNOWN_PRODUCT
;
1108 val
= msi_reg_get_value(source
, szAttribute
, &type
);
1112 RegCloseKey(source
);
1116 val
= msi_reg_get_value(prodkey
, szAttribute
, &type
);
1121 if (val
!= empty
&& type
!= REG_DWORD
&&
1122 !strcmpW( szAttribute
, INSTALLPROPERTY_PACKAGECODEW
))
1124 if (lstrlenW(val
) != SQUISH_GUID_SIZE
- 1)
1128 unsquash_guid(val
, packagecode
);
1130 val
= strdupW(packagecode
);
1137 r
= ERROR_UNKNOWN_PROPERTY
;
1143 /* If szBuffer (szValue->str) is NULL, there's no need to copy the value
1144 * out. Also, *pcchValueBuf may be uninitialized in this case, so we
1145 * can't rely on its value.
1147 if (szValue
->str
.a
|| szValue
->str
.w
)
1149 DWORD size
= *pcchValueBuf
;
1150 if (strlenW(val
) < size
)
1151 r
= msi_strcpy_to_awstring(val
, szValue
, &size
);
1154 r
= ERROR_MORE_DATA
;
1159 *pcchValueBuf
= lstrlenW(val
);
1163 r
= ERROR_BAD_CONFIGURATION
;
1169 RegCloseKey(prodkey
);
1170 RegCloseKey(userdata
);
1174 UINT WINAPI
MsiGetProductInfoA(LPCSTR szProduct
, LPCSTR szAttribute
,
1175 LPSTR szBuffer
, LPDWORD pcchValueBuf
)
1177 LPWSTR szwProduct
, szwAttribute
= NULL
;
1178 UINT r
= ERROR_OUTOFMEMORY
;
1181 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szAttribute
),
1182 szBuffer
, pcchValueBuf
);
1184 szwProduct
= strdupAtoW( szProduct
);
1185 if( szProduct
&& !szwProduct
)
1188 szwAttribute
= strdupAtoW( szAttribute
);
1189 if( szAttribute
&& !szwAttribute
)
1192 buffer
.unicode
= FALSE
;
1193 buffer
.str
.a
= szBuffer
;
1195 r
= MSI_GetProductInfo( szwProduct
, szwAttribute
,
1196 &buffer
, pcchValueBuf
);
1199 msi_free( szwProduct
);
1200 msi_free( szwAttribute
);
1205 UINT WINAPI
MsiGetProductInfoW(LPCWSTR szProduct
, LPCWSTR szAttribute
,
1206 LPWSTR szBuffer
, LPDWORD pcchValueBuf
)
1210 TRACE("%s %s %p %p\n", debugstr_w(szProduct
), debugstr_w(szAttribute
),
1211 szBuffer
, pcchValueBuf
);
1213 buffer
.unicode
= TRUE
;
1214 buffer
.str
.w
= szBuffer
;
1216 return MSI_GetProductInfo( szProduct
, szAttribute
,
1217 &buffer
, pcchValueBuf
);
1220 UINT WINAPI
MsiGetProductInfoExA(LPCSTR szProductCode
, LPCSTR szUserSid
,
1221 MSIINSTALLCONTEXT dwContext
, LPCSTR szProperty
,
1222 LPSTR szValue
, LPDWORD pcchValue
)
1224 LPWSTR product
= NULL
;
1225 LPWSTR usersid
= NULL
;
1226 LPWSTR property
= NULL
;
1227 LPWSTR value
= NULL
;
1231 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_a(szProductCode
),
1232 debugstr_a(szUserSid
), dwContext
, debugstr_a(szProperty
),
1233 szValue
, pcchValue
);
1235 if (szValue
&& !pcchValue
)
1236 return ERROR_INVALID_PARAMETER
;
1238 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1239 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1240 if (szProperty
) property
= strdupAtoW(szProperty
);
1242 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1244 if (r
!= ERROR_SUCCESS
)
1247 value
= msi_alloc(++len
* sizeof(WCHAR
));
1250 r
= ERROR_OUTOFMEMORY
;
1254 r
= MsiGetProductInfoExW(product
, usersid
, dwContext
, property
,
1256 if (r
!= ERROR_SUCCESS
)
1262 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
1263 if (*pcchValue
>= len
)
1264 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
1267 r
= ERROR_MORE_DATA
;
1272 if (*pcchValue
<= len
|| !szValue
)
1273 len
= len
* sizeof(WCHAR
) - 1;
1275 *pcchValue
= len
- 1;
1286 static UINT
msi_copy_outval(LPWSTR val
, LPWSTR out
, LPDWORD size
)
1288 UINT r
= ERROR_SUCCESS
;
1291 return ERROR_UNKNOWN_PROPERTY
;
1295 if (strlenW(val
) >= *size
)
1297 r
= ERROR_MORE_DATA
;
1306 *size
= lstrlenW(val
);
1311 UINT WINAPI
MsiGetProductInfoExW(LPCWSTR szProductCode
, LPCWSTR szUserSid
,
1312 MSIINSTALLCONTEXT dwContext
, LPCWSTR szProperty
,
1313 LPWSTR szValue
, LPDWORD pcchValue
)
1315 WCHAR squished_pc
[GUID_SIZE
];
1317 LPCWSTR package
= NULL
;
1318 HKEY props
= NULL
, prod
;
1319 HKEY classes
= NULL
, managed
;
1322 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1324 static const WCHAR five
[] = {'5',0};
1325 static const WCHAR displayname
[] = {
1326 'D','i','s','p','l','a','y','N','a','m','e',0};
1327 static const WCHAR displayversion
[] = {
1328 'D','i','s','p','l','a','y','V','e','r','s','i','o','n',0};
1329 static const WCHAR managed_local_package
[] = {
1330 'M','a','n','a','g','e','d','L','o','c','a','l',
1331 'P','a','c','k','a','g','e',0};
1333 TRACE("(%s, %s, %d, %s, %p, %p)\n", debugstr_w(szProductCode
),
1334 debugstr_w(szUserSid
), dwContext
, debugstr_w(szProperty
),
1335 szValue
, pcchValue
);
1337 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1338 return ERROR_INVALID_PARAMETER
;
1340 if (szValue
&& !pcchValue
)
1341 return ERROR_INVALID_PARAMETER
;
1343 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1344 dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1345 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1346 return ERROR_INVALID_PARAMETER
;
1348 if (!szProperty
|| !*szProperty
)
1349 return ERROR_INVALID_PARAMETER
;
1351 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1352 return ERROR_INVALID_PARAMETER
;
1354 /* FIXME: dwContext is provided, no need to search for it */
1355 MSIREG_OpenProductKey(szProductCode
, NULL
,MSIINSTALLCONTEXT_USERMANAGED
,
1357 MSIREG_OpenProductKey(szProductCode
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
1360 MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
, &props
, FALSE
);
1362 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1364 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1366 if (!props
&& !prod
)
1369 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1371 package
= managed_local_package
;
1373 if (!props
&& !managed
)
1376 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1378 package
= INSTALLPROPERTY_LOCALPACKAGEW
;
1379 MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
, &classes
, FALSE
);
1381 if (!props
&& !classes
)
1385 if (!strcmpW( szProperty
, INSTALLPROPERTY_HELPLINKW
) ||
1386 !strcmpW( szProperty
, INSTALLPROPERTY_HELPTELEPHONEW
) ||
1387 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
) ||
1388 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
) ||
1389 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLLOCATIONW
) ||
1390 !strcmpW( szProperty
, INSTALLPROPERTY_INSTALLSOURCEW
) ||
1391 !strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
) ||
1392 !strcmpW( szProperty
, INSTALLPROPERTY_PUBLISHERW
) ||
1393 !strcmpW( szProperty
, INSTALLPROPERTY_URLINFOABOUTW
) ||
1394 !strcmpW( szProperty
, INSTALLPROPERTY_URLUPDATEINFOW
) ||
1395 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMINORW
) ||
1396 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONMAJORW
) ||
1397 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
) ||
1398 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTIDW
) ||
1399 !strcmpW( szProperty
, INSTALLPROPERTY_REGCOMPANYW
) ||
1400 !strcmpW( szProperty
, INSTALLPROPERTY_REGOWNERW
) ||
1401 !strcmpW( szProperty
, INSTALLPROPERTY_INSTANCETYPEW
))
1403 val
= msi_reg_get_value(props
, package
, &type
);
1406 if (prod
|| classes
)
1407 r
= ERROR_UNKNOWN_PROPERTY
;
1414 if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLEDPRODUCTNAMEW
))
1415 szProperty
= displayname
;
1416 else if (!strcmpW( szProperty
, INSTALLPROPERTY_VERSIONSTRINGW
))
1417 szProperty
= displayversion
;
1419 val
= msi_reg_get_value(props
, szProperty
, &type
);
1421 val
= strdupW(szEmpty
);
1423 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1425 else if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
) ||
1426 !strcmpW( szProperty
, INSTALLPROPERTY_LANGUAGEW
) ||
1427 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTNAMEW
) ||
1428 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGECODEW
) ||
1429 !strcmpW( szProperty
, INSTALLPROPERTY_VERSIONW
) ||
1430 !strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTICONW
) ||
1431 !strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
) ||
1432 !strcmpW( szProperty
, INSTALLPROPERTY_AUTHORIZED_LUA_APPW
))
1434 if (!prod
&& !classes
)
1437 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
1439 else if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1441 else if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1444 val
= msi_reg_get_value(hkey
, szProperty
, &type
);
1446 val
= strdupW(szEmpty
);
1448 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1450 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PRODUCTSTATEW
))
1452 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
)
1456 val
= msi_reg_get_value(props
, package
, &type
);
1461 val
= strdupW(five
);
1464 val
= strdupW(szOne
);
1466 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1469 else if (props
&& (val
= msi_reg_get_value(props
, package
, &type
)))
1472 val
= strdupW(five
);
1473 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1477 if (prod
|| managed
)
1478 val
= strdupW(szOne
);
1482 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1484 else if (!strcmpW( szProperty
, INSTALLPROPERTY_ASSIGNMENTTYPEW
))
1486 if (!prod
&& !classes
)
1490 val
= strdupW(szEmpty
);
1491 r
= msi_copy_outval(val
, szValue
, pcchValue
);
1494 r
= ERROR_UNKNOWN_PROPERTY
;
1499 RegCloseKey(managed
);
1500 RegCloseKey(classes
);
1506 UINT WINAPI
MsiGetPatchInfoExA(LPCSTR szPatchCode
, LPCSTR szProductCode
,
1507 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1508 LPCSTR szProperty
, LPSTR lpValue
, DWORD
*pcchValue
)
1510 LPWSTR patch
= NULL
, product
= NULL
, usersid
= NULL
;
1511 LPWSTR property
= NULL
, val
= NULL
;
1515 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_a(szPatchCode
),
1516 debugstr_a(szProductCode
), debugstr_a(szUserSid
), dwContext
,
1517 debugstr_a(szProperty
), lpValue
, pcchValue
);
1519 if (lpValue
&& !pcchValue
)
1520 return ERROR_INVALID_PARAMETER
;
1522 if (szPatchCode
) patch
= strdupAtoW(szPatchCode
);
1523 if (szProductCode
) product
= strdupAtoW(szProductCode
);
1524 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1525 if (szProperty
) property
= strdupAtoW(szProperty
);
1528 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1530 if (r
!= ERROR_SUCCESS
)
1533 val
= msi_alloc(++len
* sizeof(WCHAR
));
1536 r
= ERROR_OUTOFMEMORY
;
1540 r
= MsiGetPatchInfoExW(patch
, product
, usersid
, dwContext
, property
,
1542 if (r
!= ERROR_SUCCESS
|| !pcchValue
)
1546 WideCharToMultiByte(CP_ACP
, 0, val
, -1, lpValue
,
1547 *pcchValue
- 1, NULL
, NULL
);
1549 len
= lstrlenW(val
);
1550 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1554 r
= ERROR_MORE_DATA
;
1555 lpValue
[*pcchValue
- 1] = '\0';
1558 *pcchValue
= len
* sizeof(WCHAR
);
1573 UINT WINAPI
MsiGetPatchInfoExW(LPCWSTR szPatchCode
, LPCWSTR szProductCode
,
1574 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1575 LPCWSTR szProperty
, LPWSTR lpValue
, DWORD
*pcchValue
)
1577 WCHAR squished_pc
[GUID_SIZE
];
1578 WCHAR squished_patch
[GUID_SIZE
];
1579 HKEY udprod
= 0, prod
= 0, props
= 0;
1580 HKEY patch
= 0, patches
= 0;
1581 HKEY udpatch
= 0, datakey
= 0;
1582 HKEY prodpatches
= 0;
1584 UINT r
= ERROR_UNKNOWN_PRODUCT
;
1588 static const WCHAR szManagedPackage
[] = {'M','a','n','a','g','e','d',
1589 'L','o','c','a','l','P','a','c','k','a','g','e',0};
1591 TRACE("(%s, %s, %s, %d, %s, %p, %p)\n", debugstr_w(szPatchCode
),
1592 debugstr_w(szProductCode
), debugstr_w(szUserSid
), dwContext
,
1593 debugstr_w(szProperty
), lpValue
, pcchValue
);
1595 if (!szProductCode
|| !squash_guid(szProductCode
, squished_pc
))
1596 return ERROR_INVALID_PARAMETER
;
1598 if (!szPatchCode
|| !squash_guid(szPatchCode
, squished_patch
))
1599 return ERROR_INVALID_PARAMETER
;
1602 return ERROR_INVALID_PARAMETER
;
1604 if (lpValue
&& !pcchValue
)
1605 return ERROR_INVALID_PARAMETER
;
1607 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
1608 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
1609 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
1610 return ERROR_INVALID_PARAMETER
;
1612 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
1613 return ERROR_INVALID_PARAMETER
;
1615 if (szUserSid
&& !strcmpW( szUserSid
, szLocalSid
))
1616 return ERROR_INVALID_PARAMETER
;
1618 if (MSIREG_OpenUserDataProductKey(szProductCode
, dwContext
, NULL
,
1619 &udprod
, FALSE
) != ERROR_SUCCESS
)
1622 if (MSIREG_OpenInstallProps(szProductCode
, dwContext
, NULL
,
1623 &props
, FALSE
) != ERROR_SUCCESS
)
1626 r
= ERROR_UNKNOWN_PATCH
;
1628 res
= RegOpenKeyExW(udprod
, szPatches
, 0, KEY_WOW64_64KEY
|KEY_READ
, &patches
);
1629 if (res
!= ERROR_SUCCESS
)
1632 res
= RegOpenKeyExW(patches
, squished_patch
, 0, KEY_WOW64_64KEY
|KEY_READ
, &patch
);
1633 if (res
!= ERROR_SUCCESS
)
1636 if (!strcmpW( szProperty
, INSTALLPROPERTY_TRANSFORMSW
))
1638 if (MSIREG_OpenProductKey(szProductCode
, NULL
, dwContext
,
1639 &prod
, FALSE
) != ERROR_SUCCESS
)
1642 res
= RegOpenKeyExW(prod
, szPatches
, 0, KEY_WOW64_64KEY
|KEY_ALL_ACCESS
, &prodpatches
);
1643 if (res
!= ERROR_SUCCESS
)
1646 datakey
= prodpatches
;
1647 szProperty
= squished_patch
;
1651 if (MSIREG_OpenUserDataPatchKey(szPatchCode
, dwContext
,
1652 &udpatch
, FALSE
) != ERROR_SUCCESS
)
1655 if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1657 if (dwContext
== MSIINSTALLCONTEXT_USERMANAGED
)
1658 szProperty
= szManagedPackage
;
1661 else if (!strcmpW( szProperty
, INSTALLPROPERTY_INSTALLDATEW
))
1664 szProperty
= szInstalled
;
1666 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LOCALPACKAGEW
))
1670 else if (!strcmpW( szProperty
, INSTALLPROPERTY_UNINSTALLABLEW
) ||
1671 !strcmpW( szProperty
, INSTALLPROPERTY_PATCHSTATEW
) ||
1672 !strcmpW( szProperty
, INSTALLPROPERTY_DISPLAYNAMEW
) ||
1673 !strcmpW( szProperty
, INSTALLPROPERTY_MOREINFOURLW
))
1679 r
= ERROR_UNKNOWN_PROPERTY
;
1684 val
= msi_reg_get_val_str(datakey
, szProperty
);
1686 val
= strdupW(szEmpty
);
1694 lstrcpynW(lpValue
, val
, *pcchValue
);
1696 len
= lstrlenW(val
);
1697 if ((*val
&& *pcchValue
< len
+ 1) || !lpValue
)
1700 r
= ERROR_MORE_DATA
;
1702 *pcchValue
= len
* sizeof(WCHAR
);
1709 RegCloseKey(prodpatches
);
1712 RegCloseKey(patches
);
1713 RegCloseKey(udpatch
);
1715 RegCloseKey(udprod
);
1720 UINT WINAPI
MsiGetPatchInfoA( LPCSTR patch
, LPCSTR attr
, LPSTR buffer
, LPDWORD buflen
)
1722 UINT r
= ERROR_OUTOFMEMORY
;
1724 LPWSTR patchW
= NULL
, attrW
= NULL
, bufferW
= NULL
;
1726 TRACE("%s %s %p %p\n", debugstr_a(patch
), debugstr_a(attr
), buffer
, buflen
);
1728 if (!patch
|| !attr
)
1729 return ERROR_INVALID_PARAMETER
;
1731 if (!(patchW
= strdupAtoW( patch
)))
1734 if (!(attrW
= strdupAtoW( attr
)))
1738 r
= MsiGetPatchInfoW( patchW
, attrW
, NULL
, &size
);
1739 if (r
!= ERROR_SUCCESS
)
1743 if (!(bufferW
= msi_alloc( size
* sizeof(WCHAR
) )))
1745 r
= ERROR_OUTOFMEMORY
;
1749 r
= MsiGetPatchInfoW( patchW
, attrW
, bufferW
, &size
);
1750 if (r
== ERROR_SUCCESS
)
1752 int len
= WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, NULL
, 0, NULL
, NULL
);
1754 r
= ERROR_MORE_DATA
;
1756 WideCharToMultiByte( CP_ACP
, 0, bufferW
, -1, buffer
, *buflen
, NULL
, NULL
);
1764 msi_free( bufferW
);
1768 UINT WINAPI
MsiGetPatchInfoW( LPCWSTR patch
, LPCWSTR attr
, LPWSTR buffer
, LPDWORD buflen
)
1771 WCHAR product
[GUID_SIZE
];
1774 TRACE("%s %s %p %p\n", debugstr_w(patch
), debugstr_w(attr
), buffer
, buflen
);
1776 if (!patch
|| !attr
)
1777 return ERROR_INVALID_PARAMETER
;
1779 if (strcmpW( INSTALLPROPERTY_LOCALPACKAGEW
, attr
))
1780 return ERROR_UNKNOWN_PROPERTY
;
1785 r
= MsiEnumProductsW( index
, product
);
1786 if (r
!= ERROR_SUCCESS
)
1789 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, attr
, buffer
, buflen
);
1790 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1793 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, attr
, buffer
, buflen
);
1794 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1797 r
= MsiGetPatchInfoExW( patch
, product
, NULL
, MSIINSTALLCONTEXT_MACHINE
, attr
, buffer
, buflen
);
1798 if (r
== ERROR_SUCCESS
|| r
== ERROR_MORE_DATA
)
1804 return ERROR_UNKNOWN_PRODUCT
;
1807 UINT WINAPI
MsiEnableLogA(DWORD dwLogMode
, LPCSTR szLogFile
, DWORD attributes
)
1809 LPWSTR szwLogFile
= NULL
;
1812 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_a(szLogFile
), attributes
);
1816 szwLogFile
= strdupAtoW( szLogFile
);
1818 return ERROR_OUTOFMEMORY
;
1820 r
= MsiEnableLogW( dwLogMode
, szwLogFile
, attributes
);
1821 msi_free( szwLogFile
);
1825 UINT WINAPI
MsiEnableLogW(DWORD dwLogMode
, LPCWSTR szLogFile
, DWORD attributes
)
1827 TRACE("%08x %s %08x\n", dwLogMode
, debugstr_w(szLogFile
), attributes
);
1829 msi_free(gszLogFile
);
1835 if (!(attributes
& INSTALLLOGATTRIBUTES_APPEND
))
1836 DeleteFileW(szLogFile
);
1837 file
= CreateFileW(szLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_ALWAYS
,
1838 FILE_ATTRIBUTE_NORMAL
, NULL
);
1839 if (file
!= INVALID_HANDLE_VALUE
)
1841 gszLogFile
= strdupW(szLogFile
);
1845 ERR("Unable to enable log %s (%u)\n", debugstr_w(szLogFile
), GetLastError());
1848 return ERROR_SUCCESS
;
1851 UINT WINAPI
MsiEnumComponentCostsA( MSIHANDLE handle
, LPCSTR component
, DWORD index
,
1852 INSTALLSTATE state
, LPSTR drive
, DWORD
*buflen
,
1853 int *cost
, int *temp
)
1857 WCHAR
*driveW
, *componentW
= NULL
;
1859 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle
, debugstr_a(component
), index
,
1860 state
, drive
, buflen
, cost
, temp
);
1862 if (!drive
|| !buflen
) return ERROR_INVALID_PARAMETER
;
1863 if (component
&& !(componentW
= strdupAtoW( component
))) return ERROR_OUTOFMEMORY
;
1866 if (!(driveW
= msi_alloc( len
* sizeof(WCHAR
) )))
1868 msi_free( componentW
);
1869 return ERROR_OUTOFMEMORY
;
1871 r
= MsiEnumComponentCostsW( handle
, componentW
, index
, state
, driveW
, buflen
, cost
, temp
);
1874 WideCharToMultiByte( CP_ACP
, 0, driveW
, -1, drive
, len
, NULL
, NULL
);
1876 msi_free( componentW
);
1881 static UINT
set_drive( WCHAR
*buffer
, WCHAR letter
)
1889 UINT WINAPI
MsiEnumComponentCostsW( MSIHANDLE handle
, LPCWSTR component
, DWORD index
,
1890 INSTALLSTATE state
, LPWSTR drive
, DWORD
*buflen
,
1891 int *cost
, int *temp
)
1893 UINT r
= ERROR_NO_MORE_ITEMS
;
1894 MSICOMPONENT
*comp
= NULL
;
1895 MSIPACKAGE
*package
;
1898 WCHAR path
[MAX_PATH
];
1900 TRACE("%d, %s, %u, %d, %p, %p, %p %p\n", handle
, debugstr_w(component
), index
,
1901 state
, drive
, buflen
, cost
, temp
);
1903 if (!drive
|| !buflen
|| !cost
|| !temp
) return ERROR_INVALID_PARAMETER
;
1904 if (!(package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
)))
1907 IWineMsiRemotePackage
*remote_package
;
1910 if (!(remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
)))
1911 return ERROR_INVALID_HANDLE
;
1913 if (component
&& !(bname
= SysAllocString( component
)))
1915 IWineMsiRemotePackage_Release( remote_package
);
1916 return ERROR_OUTOFMEMORY
;
1918 hr
= IWineMsiRemotePackage_EnumComponentCosts( remote_package
, bname
, index
, state
, drive
, buflen
, cost
, temp
);
1919 IWineMsiRemotePackage_Release( remote_package
);
1920 SysFreeString( bname
);
1923 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
) return HRESULT_CODE(hr
);
1924 return ERROR_FUNCTION_FAILED
;
1926 return ERROR_SUCCESS
;
1929 if (!msi_get_property_int( package
->db
, szCostingComplete
, 0 ))
1931 msiobj_release( &package
->hdr
);
1932 return ERROR_FUNCTION_NOT_CALLED
;
1934 if (component
&& component
[0] && !(comp
= msi_get_loaded_component( package
, component
)))
1936 msiobj_release( &package
->hdr
);
1937 return ERROR_UNKNOWN_COMPONENT
;
1942 msiobj_release( &package
->hdr
);
1943 return ERROR_MORE_DATA
;
1947 msiobj_release( &package
->hdr
);
1948 return ERROR_NO_MORE_ITEMS
;
1953 GetWindowsDirectoryW( path
, MAX_PATH
);
1954 if (component
&& component
[0])
1956 if (comp
->assembly
&& !comp
->assembly
->application
) *temp
= comp
->Cost
;
1957 if (!comp
->Enabled
|| !comp
->KeyPath
)
1960 *buflen
= set_drive( drive
, path
[0] );
1963 else if ((file
= msi_get_loaded_file( package
, comp
->KeyPath
)))
1965 *cost
= max( 8, comp
->Cost
/ 512 );
1966 *buflen
= set_drive( drive
, file
->TargetPath
[0] );
1970 else if (IStorage_Stat( package
->db
->storage
, &stat
, STATFLAG_NONAME
) == S_OK
)
1972 *temp
= max( 8, stat
.cbSize
.QuadPart
/ 512 );
1973 *buflen
= set_drive( drive
, path
[0] );
1976 msiobj_release( &package
->hdr
);
1980 UINT WINAPI
MsiQueryComponentStateA(LPCSTR szProductCode
,
1981 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
1982 LPCSTR szComponent
, INSTALLSTATE
*pdwState
)
1984 LPWSTR prodcode
= NULL
, usersid
= NULL
, comp
= NULL
;
1987 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_a(szProductCode
),
1988 debugstr_a(szUserSid
), dwContext
, debugstr_a(szComponent
), pdwState
);
1990 if (szProductCode
&& !(prodcode
= strdupAtoW(szProductCode
)))
1991 return ERROR_OUTOFMEMORY
;
1993 if (szUserSid
&& !(usersid
= strdupAtoW(szUserSid
)))
1994 return ERROR_OUTOFMEMORY
;
1996 if (szComponent
&& !(comp
= strdupAtoW(szComponent
)))
1997 return ERROR_OUTOFMEMORY
;
1999 r
= MsiQueryComponentStateW(prodcode
, usersid
, dwContext
, comp
, pdwState
);
2008 static BOOL
msi_comp_find_prod_key(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
2013 r
= MSIREG_OpenProductKey(prodcode
, NULL
, context
, &hkey
, FALSE
);
2015 return (r
== ERROR_SUCCESS
);
2018 static BOOL
msi_comp_find_package(LPCWSTR prodcode
, MSIINSTALLCONTEXT context
)
2026 static const WCHAR local_package
[] = {'L','o','c','a','l','P','a','c','k','a','g','e',0};
2027 static const WCHAR managed_local_package
[] = {
2028 'M','a','n','a','g','e','d','L','o','c','a','l','P','a','c','k','a','g','e',0
2031 r
= MSIREG_OpenInstallProps(prodcode
, context
, NULL
, &hkey
, FALSE
);
2032 if (r
!= ERROR_SUCCESS
)
2035 if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
2036 package
= managed_local_package
;
2038 package
= local_package
;
2041 res
= RegQueryValueExW(hkey
, package
, NULL
, NULL
, NULL
, &sz
);
2044 return (res
== ERROR_SUCCESS
);
2047 static BOOL
msi_comp_find_prodcode(LPWSTR squished_pc
,
2048 MSIINSTALLCONTEXT context
,
2049 LPCWSTR comp
, LPWSTR val
, DWORD
*sz
)
2055 if (context
== MSIINSTALLCONTEXT_MACHINE
)
2056 r
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2058 r
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2060 if (r
!= ERROR_SUCCESS
)
2063 res
= RegQueryValueExW(hkey
, squished_pc
, NULL
, NULL
, (BYTE
*)val
, sz
);
2064 if (res
!= ERROR_SUCCESS
)
2071 UINT WINAPI
MsiQueryComponentStateW(LPCWSTR szProductCode
,
2072 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
2073 LPCWSTR szComponent
, INSTALLSTATE
*pdwState
)
2075 WCHAR squished_pc
[GUID_SIZE
];
2076 WCHAR val
[MAX_PATH
];
2080 TRACE("(%s, %s, %d, %s, %p)\n", debugstr_w(szProductCode
),
2081 debugstr_w(szUserSid
), dwContext
, debugstr_w(szComponent
), pdwState
);
2083 if (!pdwState
|| !szComponent
)
2084 return ERROR_INVALID_PARAMETER
;
2086 if (!szProductCode
|| !*szProductCode
|| lstrlenW(szProductCode
) != GUID_SIZE
- 1)
2087 return ERROR_INVALID_PARAMETER
;
2089 if (!squash_guid(szProductCode
, squished_pc
))
2090 return ERROR_INVALID_PARAMETER
;
2092 found
= msi_comp_find_prod_key(szProductCode
, dwContext
);
2094 if (!msi_comp_find_package(szProductCode
, dwContext
))
2098 *pdwState
= INSTALLSTATE_UNKNOWN
;
2099 return ERROR_UNKNOWN_COMPONENT
;
2102 return ERROR_UNKNOWN_PRODUCT
;
2105 *pdwState
= INSTALLSTATE_UNKNOWN
;
2108 if (!msi_comp_find_prodcode(squished_pc
, dwContext
, szComponent
, val
, &sz
))
2109 return ERROR_UNKNOWN_COMPONENT
;
2112 *pdwState
= INSTALLSTATE_NOTUSED
;
2115 if (lstrlenW(val
) > 2 &&
2116 val
[0] >= '0' && val
[0] <= '9' && val
[1] >= '0' && val
[1] <= '9')
2118 *pdwState
= INSTALLSTATE_SOURCE
;
2121 *pdwState
= INSTALLSTATE_LOCAL
;
2124 TRACE("-> %d\n", *pdwState
);
2125 return ERROR_SUCCESS
;
2128 INSTALLSTATE WINAPI
MsiQueryProductStateA(LPCSTR szProduct
)
2130 LPWSTR szwProduct
= NULL
;
2135 szwProduct
= strdupAtoW( szProduct
);
2137 return ERROR_OUTOFMEMORY
;
2139 r
= MsiQueryProductStateW( szwProduct
);
2140 msi_free( szwProduct
);
2144 INSTALLSTATE WINAPI
MsiQueryProductStateW(LPCWSTR szProduct
)
2146 MSIINSTALLCONTEXT context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
2147 INSTALLSTATE state
= INSTALLSTATE_ADVERTISED
;
2148 HKEY prodkey
= 0, userdata
= 0;
2152 TRACE("%s\n", debugstr_w(szProduct
));
2154 if (!szProduct
|| !*szProduct
)
2155 return INSTALLSTATE_INVALIDARG
;
2157 if (lstrlenW(szProduct
) != GUID_SIZE
- 1)
2158 return INSTALLSTATE_INVALIDARG
;
2160 if (szProduct
[0] != '{' || szProduct
[37] != '}')
2161 return INSTALLSTATE_UNKNOWN
;
2163 SetLastError( ERROR_SUCCESS
);
2165 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
2166 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2167 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2168 &prodkey
, FALSE
) != ERROR_SUCCESS
&&
2169 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2170 &prodkey
, FALSE
) == ERROR_SUCCESS
)
2172 context
= MSIINSTALLCONTEXT_MACHINE
;
2175 r
= MSIREG_OpenInstallProps(szProduct
, context
, NULL
, &userdata
, FALSE
);
2176 if (r
!= ERROR_SUCCESS
)
2179 if (!msi_reg_get_val_dword(userdata
, szWindowsInstaller
, &val
))
2183 state
= INSTALLSTATE_DEFAULT
;
2185 state
= INSTALLSTATE_UNKNOWN
;
2190 state
= INSTALLSTATE_UNKNOWN
;
2193 state
= INSTALLSTATE_ABSENT
;
2196 RegCloseKey(prodkey
);
2197 RegCloseKey(userdata
);
2198 TRACE("-> %d\n", state
);
2202 INSTALLUILEVEL WINAPI
MsiSetInternalUI(INSTALLUILEVEL dwUILevel
, HWND
*phWnd
)
2204 INSTALLUILEVEL old
= gUILevel
;
2205 HWND oldwnd
= gUIhwnd
;
2207 TRACE("%08x %p\n", dwUILevel
, phWnd
);
2209 gUILevel
= dwUILevel
;
2218 INSTALLUI_HANDLERA WINAPI
MsiSetExternalUIA(INSTALLUI_HANDLERA puiHandler
,
2219 DWORD dwMessageFilter
, LPVOID pvContext
)
2221 INSTALLUI_HANDLERA prev
= gUIHandlerA
;
2223 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2225 gUIHandlerA
= puiHandler
;
2227 gUIFilter
= dwMessageFilter
;
2228 gUIContext
= pvContext
;
2233 INSTALLUI_HANDLERW WINAPI
MsiSetExternalUIW(INSTALLUI_HANDLERW puiHandler
,
2234 DWORD dwMessageFilter
, LPVOID pvContext
)
2236 INSTALLUI_HANDLERW prev
= gUIHandlerW
;
2238 TRACE("%p %08x %p\n", puiHandler
, dwMessageFilter
, pvContext
);
2241 gUIHandlerW
= puiHandler
;
2242 gUIFilter
= dwMessageFilter
;
2243 gUIContext
= pvContext
;
2248 /******************************************************************
2249 * MsiLoadStringW [MSI.@]
2251 * Loads a string from MSI's string resources.
2255 * handle [I] only -1 is handled currently
2256 * id [I] id of the string to be loaded
2257 * lpBuffer [O] buffer for the string to be written to
2258 * nBufferMax [I] maximum size of the buffer in characters
2259 * lang [I] the preferred language for the string
2263 * If successful, this function returns the language id of the string loaded
2264 * If the function fails, the function returns zero.
2268 * The type of the first parameter is unknown. LoadString's prototype
2269 * suggests that it might be a module handle. I have made it an MSI handle
2270 * for starters, as -1 is an invalid MSI handle, but not an invalid module
2271 * handle. Maybe strings can be stored in an MSI database somehow.
2273 LANGID WINAPI
MsiLoadStringW( MSIHANDLE handle
, UINT id
, LPWSTR lpBuffer
,
2274 int nBufferMax
, LANGID lang
)
2281 TRACE("%d %u %p %d %d\n", handle
, id
, lpBuffer
, nBufferMax
, lang
);
2284 FIXME("don't know how to deal with handle = %08x\n", handle
);
2287 lang
= GetUserDefaultLangID();
2289 hres
= FindResourceExW( msi_hInstance
, (LPCWSTR
) RT_STRING
,
2293 hResData
= LoadResource( msi_hInstance
, hres
);
2296 p
= LockResource( hResData
);
2300 for (i
= 0; i
< (id
& 0xf); i
++) p
+= *p
+ 1;
2303 if( nBufferMax
<= len
)
2306 memcpy( lpBuffer
, p
+1, len
* sizeof(WCHAR
));
2307 lpBuffer
[ len
] = 0;
2309 TRACE("found -> %s\n", debugstr_w(lpBuffer
));
2313 LANGID WINAPI
MsiLoadStringA( MSIHANDLE handle
, UINT id
, LPSTR lpBuffer
,
2314 int nBufferMax
, LANGID lang
)
2320 bufW
= msi_alloc(nBufferMax
*sizeof(WCHAR
));
2321 r
= MsiLoadStringW(handle
, id
, bufW
, nBufferMax
, lang
);
2324 len
= WideCharToMultiByte(CP_ACP
, 0, bufW
, -1, NULL
, 0, NULL
, NULL
);
2325 if( len
<= nBufferMax
)
2326 WideCharToMultiByte( CP_ACP
, 0, bufW
, -1,
2327 lpBuffer
, nBufferMax
, NULL
, NULL
);
2335 INSTALLSTATE WINAPI
MsiLocateComponentA(LPCSTR szComponent
, LPSTR lpPathBuf
,
2338 char szProduct
[GUID_SIZE
];
2340 TRACE("%s %p %p\n", debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2342 if (!szComponent
|| !pcchBuf
)
2343 return INSTALLSTATE_INVALIDARG
;
2345 if (MsiGetProductCodeA( szComponent
, szProduct
) != ERROR_SUCCESS
)
2346 return INSTALLSTATE_UNKNOWN
;
2348 return MsiGetComponentPathA( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2351 INSTALLSTATE WINAPI
MsiLocateComponentW(LPCWSTR szComponent
, LPWSTR lpPathBuf
,
2354 WCHAR szProduct
[GUID_SIZE
];
2356 TRACE("%s %p %p\n", debugstr_w(szComponent
), lpPathBuf
, pcchBuf
);
2358 if (!szComponent
|| !pcchBuf
)
2359 return INSTALLSTATE_INVALIDARG
;
2361 if (MsiGetProductCodeW( szComponent
, szProduct
) != ERROR_SUCCESS
)
2362 return INSTALLSTATE_UNKNOWN
;
2364 return MsiGetComponentPathW( szProduct
, szComponent
, lpPathBuf
, pcchBuf
);
2367 UINT WINAPI
MsiMessageBoxA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2368 WORD wLanguageId
, DWORD f
)
2370 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_a(lpText
), debugstr_a(lpCaption
),
2371 uType
, wLanguageId
, f
);
2372 return MessageBoxExA(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2375 UINT WINAPI
MsiMessageBoxW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2376 WORD wLanguageId
, DWORD f
)
2378 FIXME("%p %s %s %u %08x %08x\n", hWnd
, debugstr_w(lpText
), debugstr_w(lpCaption
),
2379 uType
, wLanguageId
, f
);
2380 return MessageBoxExW(hWnd
,lpText
,lpCaption
,uType
,wLanguageId
);
2383 UINT WINAPI
MsiMessageBoxExA(HWND hWnd
, LPCSTR lpText
, LPCSTR lpCaption
, UINT uType
,
2384 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2386 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_a(lpText
),
2387 debugstr_a(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2388 return MessageBoxExA(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2391 UINT WINAPI
MsiMessageBoxExW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
,
2392 DWORD unknown
, WORD wLanguageId
, DWORD f
)
2394 FIXME("(%p, %s, %s, %u, 0x%08x, 0x%08x, 0x%08x): semi-stub\n", hWnd
, debugstr_w(lpText
),
2395 debugstr_w(lpCaption
), uType
, unknown
, wLanguageId
, f
);
2396 return MessageBoxExW(hWnd
, lpText
, lpCaption
, uType
, wLanguageId
);
2399 UINT WINAPI
MsiProvideAssemblyA( LPCSTR szAssemblyName
, LPCSTR szAppContext
,
2400 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPSTR lpPathBuf
,
2401 LPDWORD pcchPathBuf
)
2403 FIXME("%s %s %08x %08x %p %p\n", debugstr_a(szAssemblyName
),
2404 debugstr_a(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2406 return ERROR_CALL_NOT_IMPLEMENTED
;
2409 UINT WINAPI
MsiProvideAssemblyW( LPCWSTR szAssemblyName
, LPCWSTR szAppContext
,
2410 DWORD dwInstallMode
, DWORD dwAssemblyInfo
, LPWSTR lpPathBuf
,
2411 LPDWORD pcchPathBuf
)
2413 FIXME("%s %s %08x %08x %p %p\n", debugstr_w(szAssemblyName
),
2414 debugstr_w(szAppContext
), dwInstallMode
, dwAssemblyInfo
, lpPathBuf
,
2416 return ERROR_CALL_NOT_IMPLEMENTED
;
2419 UINT WINAPI
MsiProvideComponentFromDescriptorA( LPCSTR szDescriptor
,
2420 LPSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2422 FIXME("%s %p %p %p\n", debugstr_a(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2423 return ERROR_CALL_NOT_IMPLEMENTED
;
2426 UINT WINAPI
MsiProvideComponentFromDescriptorW( LPCWSTR szDescriptor
,
2427 LPWSTR szPath
, LPDWORD pcchPath
, LPDWORD pcchArgs
)
2429 FIXME("%s %p %p %p\n", debugstr_w(szDescriptor
), szPath
, pcchPath
, pcchArgs
);
2430 return ERROR_CALL_NOT_IMPLEMENTED
;
2433 HRESULT WINAPI
MsiGetFileSignatureInformationA( LPCSTR path
, DWORD flags
, PCCERT_CONTEXT
*cert
,
2434 LPBYTE hash
, LPDWORD hashlen
)
2437 WCHAR
*pathW
= NULL
;
2439 TRACE("%s %08x %p %p %p\n", debugstr_a(path
), flags
, cert
, hash
, hashlen
);
2441 if (path
&& !(pathW
= strdupAtoW( path
))) return ERROR_OUTOFMEMORY
;
2442 r
= MsiGetFileSignatureInformationW( pathW
, flags
, cert
, hash
, hashlen
);
2447 HRESULT WINAPI
MsiGetFileSignatureInformationW( LPCWSTR path
, DWORD flags
, PCCERT_CONTEXT
*cert
,
2448 LPBYTE hash
, LPDWORD hashlen
)
2450 static GUID generic_verify_v2
= WINTRUST_ACTION_GENERIC_VERIFY_V2
;
2453 WINTRUST_FILE_INFO info
;
2454 CRYPT_PROVIDER_SGNR
*signer
;
2455 CRYPT_PROVIDER_CERT
*provider
;
2457 TRACE("%s %08x %p %p %p\n", debugstr_w(path
), flags
, cert
, hash
, hashlen
);
2459 if (!path
|| !cert
) return E_INVALIDARG
;
2461 info
.cbStruct
= sizeof(info
);
2462 info
.pcwszFilePath
= path
;
2464 info
.pgKnownSubject
= NULL
;
2466 data
.cbStruct
= sizeof(data
);
2467 data
.pPolicyCallbackData
= NULL
;
2468 data
.pSIPClientData
= NULL
;
2469 data
.dwUIChoice
= WTD_UI_NONE
;
2470 data
.fdwRevocationChecks
= WTD_REVOKE_WHOLECHAIN
;
2471 data
.dwUnionChoice
= WTD_CHOICE_FILE
;
2472 data
.u
.pFile
= &info
;
2473 data
.dwStateAction
= WTD_STATEACTION_VERIFY
;
2474 data
.hWVTStateData
= NULL
;
2475 data
.pwszURLReference
= NULL
;
2476 data
.dwProvFlags
= 0;
2477 data
.dwUIContext
= WTD_UICONTEXT_INSTALL
;
2478 hr
= WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2479 if (FAILED(hr
)) goto done
;
2481 if (!(signer
= WTHelperGetProvSignerFromChain( data
.hWVTStateData
, 0, FALSE
, 0 )))
2483 hr
= TRUST_E_NOSIGNATURE
;
2488 DWORD len
= signer
->psSigner
->EncryptedHash
.cbData
;
2492 hr
= HRESULT_FROM_WIN32(ERROR_MORE_DATA
);
2495 memcpy( hash
, signer
->psSigner
->EncryptedHash
.pbData
, len
);
2498 if (!(provider
= WTHelperGetProvCertFromChain( signer
, 0 )))
2500 hr
= TRUST_E_PROVIDER_UNKNOWN
;
2503 *cert
= CertDuplicateCertificateContext( provider
->pCert
);
2506 data
.dwStateAction
= WTD_STATEACTION_CLOSE
;
2507 WinVerifyTrustEx( INVALID_HANDLE_VALUE
, &generic_verify_v2
, &data
);
2511 /******************************************************************
2512 * MsiGetProductPropertyA [MSI.@]
2514 UINT WINAPI
MsiGetProductPropertyA(MSIHANDLE hProduct
, LPCSTR szProperty
,
2515 LPSTR szValue
, LPDWORD pccbValue
)
2517 LPWSTR prop
= NULL
, val
= NULL
;
2521 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_a(szProperty
),
2522 szValue
, pccbValue
);
2524 if (szValue
&& !pccbValue
)
2525 return ERROR_INVALID_PARAMETER
;
2527 if (szProperty
) prop
= strdupAtoW(szProperty
);
2530 r
= MsiGetProductPropertyW(hProduct
, prop
, NULL
, &len
);
2531 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2534 if (r
== ERROR_SUCCESS
)
2536 if (szValue
) *szValue
= '\0';
2537 if (pccbValue
) *pccbValue
= 0;
2541 val
= msi_alloc(++len
* sizeof(WCHAR
));
2544 r
= ERROR_OUTOFMEMORY
;
2548 r
= MsiGetProductPropertyW(hProduct
, prop
, val
, &len
);
2549 if (r
!= ERROR_SUCCESS
)
2552 len
= WideCharToMultiByte(CP_ACP
, 0, val
, -1, NULL
, 0, NULL
, NULL
);
2555 WideCharToMultiByte(CP_ACP
, 0, val
, -1, szValue
,
2556 *pccbValue
, NULL
, NULL
);
2560 if (len
> *pccbValue
)
2561 r
= ERROR_MORE_DATA
;
2563 *pccbValue
= len
- 1;
2573 /******************************************************************
2574 * MsiGetProductPropertyW [MSI.@]
2576 UINT WINAPI
MsiGetProductPropertyW(MSIHANDLE hProduct
, LPCWSTR szProperty
,
2577 LPWSTR szValue
, LPDWORD pccbValue
)
2579 MSIPACKAGE
*package
;
2580 MSIQUERY
*view
= NULL
;
2581 MSIRECORD
*rec
= NULL
;
2585 static const WCHAR query
[] = {
2586 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
2587 '`','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2588 '`','P','r','o','p','e','r','t','y','`','=','\'','%','s','\'',0};
2590 TRACE("(%d, %s, %p, %p)\n", hProduct
, debugstr_w(szProperty
),
2591 szValue
, pccbValue
);
2594 return ERROR_INVALID_PARAMETER
;
2596 if (szValue
&& !pccbValue
)
2597 return ERROR_INVALID_PARAMETER
;
2599 package
= msihandle2msiinfo(hProduct
, MSIHANDLETYPE_PACKAGE
);
2601 return ERROR_INVALID_HANDLE
;
2603 r
= MSI_OpenQuery(package
->db
, &view
, query
, szProperty
);
2604 if (r
!= ERROR_SUCCESS
)
2607 r
= MSI_ViewExecute(view
, 0);
2608 if (r
!= ERROR_SUCCESS
)
2611 r
= MSI_ViewFetch(view
, &rec
);
2612 if (r
!= ERROR_SUCCESS
)
2615 val
= MSI_RecordGetString(rec
, 2);
2619 if (lstrlenW(val
) >= *pccbValue
)
2621 lstrcpynW(szValue
, val
, *pccbValue
);
2622 *pccbValue
= lstrlenW(val
);
2623 r
= ERROR_MORE_DATA
;
2627 lstrcpyW(szValue
, val
);
2628 *pccbValue
= lstrlenW(val
);
2635 MSI_ViewClose(view
);
2636 msiobj_release(&view
->hdr
);
2637 if (rec
) msiobj_release(&rec
->hdr
);
2642 if (szValue
) *szValue
= '\0';
2643 if (pccbValue
) *pccbValue
= 0;
2647 msiobj_release(&package
->hdr
);
2651 UINT WINAPI
MsiVerifyPackageA( LPCSTR szPackage
)
2654 LPWSTR szPack
= NULL
;
2656 TRACE("%s\n", debugstr_a(szPackage
) );
2660 szPack
= strdupAtoW( szPackage
);
2662 return ERROR_OUTOFMEMORY
;
2665 r
= MsiVerifyPackageW( szPack
);
2672 UINT WINAPI
MsiVerifyPackageW( LPCWSTR szPackage
)
2677 TRACE("%s\n", debugstr_w(szPackage
) );
2679 r
= MsiOpenDatabaseW( szPackage
, MSIDBOPEN_READONLY
, &handle
);
2680 MsiCloseHandle( handle
);
2685 static INSTALLSTATE
MSI_GetComponentPath(LPCWSTR szProduct
, LPCWSTR szComponent
,
2686 awstring
* lpPathBuf
, LPDWORD pcchBuf
)
2688 static const WCHAR wininstaller
[] =
2689 {'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0};
2690 WCHAR squished_pc
[GUID_SIZE
];
2691 WCHAR squished_comp
[GUID_SIZE
];
2697 if (!szProduct
|| !szComponent
)
2698 return INSTALLSTATE_INVALIDARG
;
2700 if (lpPathBuf
->str
.w
&& !pcchBuf
)
2701 return INSTALLSTATE_INVALIDARG
;
2703 if (!squash_guid(szProduct
, squished_pc
) ||
2704 !squash_guid(szComponent
, squished_comp
))
2705 return INSTALLSTATE_INVALIDARG
;
2707 state
= INSTALLSTATE_UNKNOWN
;
2709 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2710 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2712 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2715 state
= INSTALLSTATE_ABSENT
;
2717 if ((MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
, NULL
,
2718 &hkey
, FALSE
) == ERROR_SUCCESS
||
2719 MSIREG_OpenUserDataProductKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2720 NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
) &&
2721 msi_reg_get_val_dword(hkey
, wininstaller
, &version
) &&
2722 GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2725 state
= INSTALLSTATE_LOCAL
;
2729 if (state
!= INSTALLSTATE_LOCAL
&&
2730 (MSIREG_OpenProductKey(szProduct
, NULL
,
2731 MSIINSTALLCONTEXT_USERUNMANAGED
,
2732 &hkey
, FALSE
) == ERROR_SUCCESS
||
2733 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
2734 &hkey
, FALSE
) == ERROR_SUCCESS
))
2738 if (MSIREG_OpenUserDataComponentKey(szComponent
, szLocalSid
, &hkey
, FALSE
) == ERROR_SUCCESS
||
2739 MSIREG_OpenUserDataComponentKey(szComponent
, NULL
, &hkey
, FALSE
) == ERROR_SUCCESS
)
2742 path
= msi_reg_get_val_str(hkey
, squished_pc
);
2745 state
= INSTALLSTATE_ABSENT
;
2747 if (GetFileAttributesW(path
) != INVALID_FILE_ATTRIBUTES
)
2748 state
= INSTALLSTATE_LOCAL
;
2753 return INSTALLSTATE_UNKNOWN
;
2755 if (state
== INSTALLSTATE_LOCAL
&& !*path
)
2756 state
= INSTALLSTATE_NOTUSED
;
2758 msi_strcpy_to_awstring(path
, lpPathBuf
, pcchBuf
);
2763 /******************************************************************
2764 * MsiGetComponentPathW [MSI.@]
2766 INSTALLSTATE WINAPI
MsiGetComponentPathW(LPCWSTR szProduct
, LPCWSTR szComponent
,
2767 LPWSTR lpPathBuf
, LPDWORD pcchBuf
)
2771 TRACE("%s %s %p %p\n", debugstr_w(szProduct
), debugstr_w(szComponent
), lpPathBuf
, pcchBuf
);
2773 path
.unicode
= TRUE
;
2774 path
.str
.w
= lpPathBuf
;
2776 return MSI_GetComponentPath( szProduct
, szComponent
, &path
, pcchBuf
);
2779 /******************************************************************
2780 * MsiGetComponentPathA [MSI.@]
2782 INSTALLSTATE WINAPI
MsiGetComponentPathA(LPCSTR szProduct
, LPCSTR szComponent
,
2783 LPSTR lpPathBuf
, LPDWORD pcchBuf
)
2785 LPWSTR szwProduct
, szwComponent
= NULL
;
2786 INSTALLSTATE r
= INSTALLSTATE_UNKNOWN
;
2789 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szComponent
), lpPathBuf
, pcchBuf
);
2791 szwProduct
= strdupAtoW( szProduct
);
2792 if( szProduct
&& !szwProduct
)
2795 szwComponent
= strdupAtoW( szComponent
);
2796 if( szComponent
&& !szwComponent
)
2799 path
.unicode
= FALSE
;
2800 path
.str
.a
= lpPathBuf
;
2802 r
= MSI_GetComponentPath( szwProduct
, szwComponent
, &path
, pcchBuf
);
2805 msi_free( szwProduct
);
2806 msi_free( szwComponent
);
2811 /******************************************************************
2812 * MsiQueryFeatureStateA [MSI.@]
2814 INSTALLSTATE WINAPI
MsiQueryFeatureStateA(LPCSTR szProduct
, LPCSTR szFeature
)
2816 LPWSTR szwProduct
= NULL
, szwFeature
= NULL
;
2817 INSTALLSTATE rc
= INSTALLSTATE_UNKNOWN
;
2819 szwProduct
= strdupAtoW( szProduct
);
2820 if ( szProduct
&& !szwProduct
)
2823 szwFeature
= strdupAtoW( szFeature
);
2824 if ( szFeature
&& !szwFeature
)
2827 rc
= MsiQueryFeatureStateW(szwProduct
, szwFeature
);
2830 msi_free( szwProduct
);
2831 msi_free( szwFeature
);
2836 /******************************************************************
2837 * MsiQueryFeatureStateW [MSI.@]
2839 * Checks the state of a feature
2842 * szProduct [I] Product's GUID string
2843 * szFeature [I] Feature's GUID string
2846 * INSTALLSTATE_LOCAL Feature is installed and usable
2847 * INSTALLSTATE_ABSENT Feature is absent
2848 * INSTALLSTATE_ADVERTISED Feature should be installed on demand
2849 * INSTALLSTATE_UNKNOWN An error occurred
2850 * INSTALLSTATE_INVALIDARG One of the GUIDs was invalid
2853 INSTALLSTATE WINAPI
MsiQueryFeatureStateW(LPCWSTR szProduct
, LPCWSTR szFeature
)
2855 WCHAR squishProduct
[33], comp
[GUID_SIZE
];
2857 LPWSTR components
, p
, parent_feature
, path
;
2861 BOOL missing
= FALSE
;
2862 BOOL machine
= FALSE
;
2863 BOOL source
= FALSE
;
2865 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szFeature
));
2867 if (!szProduct
|| !szFeature
)
2868 return INSTALLSTATE_INVALIDARG
;
2870 if (!squash_guid( szProduct
, squishProduct
))
2871 return INSTALLSTATE_INVALIDARG
;
2873 SetLastError( ERROR_SUCCESS
);
2875 if (MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERMANAGED
,
2876 &hkey
, FALSE
) != ERROR_SUCCESS
&&
2877 MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
2878 &hkey
, FALSE
) != ERROR_SUCCESS
)
2880 rc
= MSIREG_OpenFeaturesKey(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
2882 if (rc
!= ERROR_SUCCESS
)
2883 return INSTALLSTATE_UNKNOWN
;
2888 parent_feature
= msi_reg_get_val_str( hkey
, szFeature
);
2891 if (!parent_feature
)
2892 return INSTALLSTATE_UNKNOWN
;
2894 r
= (parent_feature
[0] == 6) ? INSTALLSTATE_ABSENT
: INSTALLSTATE_LOCAL
;
2895 msi_free(parent_feature
);
2896 if (r
== INSTALLSTATE_ABSENT
)
2900 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2901 MSIINSTALLCONTEXT_MACHINE
,
2904 rc
= MSIREG_OpenUserDataFeaturesKey(szProduct
,
2905 MSIINSTALLCONTEXT_USERUNMANAGED
,
2908 if (rc
!= ERROR_SUCCESS
)
2909 return INSTALLSTATE_ADVERTISED
;
2911 components
= msi_reg_get_val_str( hkey
, szFeature
);
2914 TRACE("rc = %d buffer = %s\n", rc
, debugstr_w(components
));
2917 return INSTALLSTATE_ADVERTISED
;
2919 for( p
= components
; *p
&& *p
!= 2 ; p
+= 20)
2921 if (!decode_base85_guid( p
, &guid
))
2923 if (p
!= components
)
2926 msi_free(components
);
2927 return INSTALLSTATE_BADCONFIG
;
2930 StringFromGUID2(&guid
, comp
, GUID_SIZE
);
2933 rc
= MSIREG_OpenUserDataComponentKey(comp
, szLocalSid
, &hkey
, FALSE
);
2935 rc
= MSIREG_OpenUserDataComponentKey(comp
, NULL
, &hkey
, FALSE
);
2937 if (rc
!= ERROR_SUCCESS
)
2939 msi_free(components
);
2940 return INSTALLSTATE_ADVERTISED
;
2943 path
= msi_reg_get_val_str(hkey
, squishProduct
);
2946 else if (lstrlenW(path
) > 2 &&
2947 path
[0] >= '0' && path
[0] <= '9' &&
2948 path
[1] >= '0' && path
[1] <= '9')
2955 msi_free(components
);
2958 r
= INSTALLSTATE_ADVERTISED
;
2960 r
= INSTALLSTATE_SOURCE
;
2962 r
= INSTALLSTATE_LOCAL
;
2964 TRACE("-> %d\n", r
);
2968 /******************************************************************
2969 * MsiGetFileVersionA [MSI.@]
2971 UINT WINAPI
MsiGetFileVersionA(LPCSTR szFilePath
, LPSTR lpVersionBuf
,
2972 LPDWORD pcchVersionBuf
, LPSTR lpLangBuf
, LPDWORD pcchLangBuf
)
2974 LPWSTR szwFilePath
= NULL
, lpwVersionBuff
= NULL
, lpwLangBuff
= NULL
;
2975 UINT ret
= ERROR_OUTOFMEMORY
;
2977 if ((lpVersionBuf
&& !pcchVersionBuf
) ||
2978 (lpLangBuf
&& !pcchLangBuf
))
2979 return ERROR_INVALID_PARAMETER
;
2983 szwFilePath
= strdupAtoW( szFilePath
);
2988 if( lpVersionBuf
&& pcchVersionBuf
&& *pcchVersionBuf
)
2990 lpwVersionBuff
= msi_alloc(*pcchVersionBuf
*sizeof(WCHAR
));
2991 if( !lpwVersionBuff
)
2995 if( lpLangBuf
&& pcchLangBuf
&& *pcchLangBuf
)
2997 lpwLangBuff
= msi_alloc(*pcchLangBuf
*sizeof(WCHAR
));
3002 ret
= MsiGetFileVersionW(szwFilePath
, lpwVersionBuff
, pcchVersionBuf
,
3003 lpwLangBuff
, pcchLangBuf
);
3005 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwVersionBuff
)
3006 WideCharToMultiByte(CP_ACP
, 0, lpwVersionBuff
, -1,
3007 lpVersionBuf
, *pcchVersionBuf
+ 1, NULL
, NULL
);
3008 if( (ret
== ERROR_SUCCESS
|| ret
== ERROR_MORE_DATA
) && lpwLangBuff
)
3009 WideCharToMultiByte(CP_ACP
, 0, lpwLangBuff
, -1,
3010 lpLangBuf
, *pcchLangBuf
+ 1, NULL
, NULL
);
3013 msi_free(szwFilePath
);
3014 msi_free(lpwVersionBuff
);
3015 msi_free(lpwLangBuff
);
3020 static UINT
get_file_version( const WCHAR
*path
, WCHAR
*verbuf
, DWORD
*verlen
,
3021 WCHAR
*langbuf
, DWORD
*langlen
)
3023 static const WCHAR szVersionResource
[] = {'\\',0};
3024 static const WCHAR szVersionFormat
[] = {
3025 '%','d','.','%','d','.','%','d','.','%','d',0};
3026 static const WCHAR szLangResource
[] = {
3027 '\\','V','a','r','F','i','l','e','I','n','f','o','\\',
3028 'T','r','a','n','s','l','a','t','i','o','n',0};
3029 static const WCHAR szLangFormat
[] = {'%','d',0};
3030 UINT ret
= ERROR_SUCCESS
;
3033 VS_FIXEDFILEINFO
*ffi
;
3037 if (!(len
= GetFileVersionInfoSizeW( path
, NULL
)))
3039 error
= GetLastError();
3040 if (error
== ERROR_BAD_PATHNAME
) return ERROR_FILE_NOT_FOUND
;
3043 if (!(version
= msi_alloc( len
))) return ERROR_OUTOFMEMORY
;
3044 if (!GetFileVersionInfoW( path
, 0, len
, version
))
3046 msi_free( version
);
3047 return GetLastError();
3051 if (VerQueryValueW( version
, szVersionResource
, (LPVOID
*)&ffi
, &len
) && len
> 0)
3053 sprintfW( tmp
, szVersionFormat
,
3054 HIWORD(ffi
->dwFileVersionMS
), LOWORD(ffi
->dwFileVersionMS
),
3055 HIWORD(ffi
->dwFileVersionLS
), LOWORD(ffi
->dwFileVersionLS
) );
3056 if (verbuf
) lstrcpynW( verbuf
, tmp
, *verlen
);
3057 len
= strlenW( tmp
);
3058 if (len
>= *verlen
) ret
= ERROR_MORE_DATA
;
3063 if (verbuf
) *verbuf
= 0;
3069 if (VerQueryValueW( version
, szLangResource
, (LPVOID
*)&lang
, &len
) && len
> 0)
3071 sprintfW( tmp
, szLangFormat
, *lang
);
3072 if (langbuf
) lstrcpynW( langbuf
, tmp
, *langlen
);
3073 len
= strlenW( tmp
);
3074 if (len
>= *langlen
) ret
= ERROR_MORE_DATA
;
3079 if (langbuf
) *langbuf
= 0;
3083 msi_free( version
);
3088 /******************************************************************
3089 * MsiGetFileVersionW [MSI.@]
3091 UINT WINAPI
MsiGetFileVersionW( LPCWSTR path
, LPWSTR verbuf
, LPDWORD verlen
,
3092 LPWSTR langbuf
, LPDWORD langlen
)
3096 TRACE("%s %p %u %p %u\n", debugstr_w(path
), verbuf
, verlen
? *verlen
: 0,
3097 langbuf
, langlen
? *langlen
: 0);
3099 if ((verbuf
&& !verlen
) || (langbuf
&& !langlen
))
3100 return ERROR_INVALID_PARAMETER
;
3102 ret
= get_file_version( path
, verbuf
, verlen
, langbuf
, langlen
);
3103 if (ret
== ERROR_RESOURCE_DATA_NOT_FOUND
)
3106 WCHAR
*version
= msi_font_version_from_file( path
);
3107 if (!version
) return ERROR_FILE_INVALID
;
3108 len
= strlenW( version
);
3111 strcpyW( verbuf
, version
);
3112 ret
= ERROR_SUCCESS
;
3114 else ret
= ERROR_MORE_DATA
;
3116 msi_free( version
);
3121 /***********************************************************************
3122 * MsiGetFeatureUsageW [MSI.@]
3124 UINT WINAPI
MsiGetFeatureUsageW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3125 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
3127 FIXME("%s %s %p %p\n",debugstr_w(szProduct
), debugstr_w(szFeature
),
3128 pdwUseCount
, pwDateUsed
);
3129 return ERROR_CALL_NOT_IMPLEMENTED
;
3132 /***********************************************************************
3133 * MsiGetFeatureUsageA [MSI.@]
3135 UINT WINAPI
MsiGetFeatureUsageA( LPCSTR szProduct
, LPCSTR szFeature
,
3136 LPDWORD pdwUseCount
, LPWORD pwDateUsed
)
3138 LPWSTR prod
= NULL
, feat
= NULL
;
3139 UINT ret
= ERROR_OUTOFMEMORY
;
3141 TRACE("%s %s %p %p\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3142 pdwUseCount
, pwDateUsed
);
3144 prod
= strdupAtoW( szProduct
);
3145 if (szProduct
&& !prod
)
3148 feat
= strdupAtoW( szFeature
);
3149 if (szFeature
&& !feat
)
3152 ret
= MsiGetFeatureUsageW( prod
, feat
, pdwUseCount
, pwDateUsed
);
3161 /***********************************************************************
3162 * MsiUseFeatureExW [MSI.@]
3164 INSTALLSTATE WINAPI
MsiUseFeatureExW( LPCWSTR szProduct
, LPCWSTR szFeature
,
3165 DWORD dwInstallMode
, DWORD dwReserved
)
3169 TRACE("%s %s %i %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
),
3170 dwInstallMode
, dwReserved
);
3172 state
= MsiQueryFeatureStateW( szProduct
, szFeature
);
3175 return INSTALLSTATE_INVALIDARG
;
3177 if (state
== INSTALLSTATE_LOCAL
&& dwInstallMode
!= INSTALLMODE_NODETECTION
)
3179 FIXME("mark product %s feature %s as used\n",
3180 debugstr_w(szProduct
), debugstr_w(szFeature
) );
3186 /***********************************************************************
3187 * MsiUseFeatureExA [MSI.@]
3189 INSTALLSTATE WINAPI
MsiUseFeatureExA( LPCSTR szProduct
, LPCSTR szFeature
,
3190 DWORD dwInstallMode
, DWORD dwReserved
)
3192 INSTALLSTATE ret
= INSTALLSTATE_UNKNOWN
;
3193 LPWSTR prod
= NULL
, feat
= NULL
;
3195 TRACE("%s %s %i %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3196 dwInstallMode
, dwReserved
);
3198 prod
= strdupAtoW( szProduct
);
3199 if (szProduct
&& !prod
)
3202 feat
= strdupAtoW( szFeature
);
3203 if (szFeature
&& !feat
)
3206 ret
= MsiUseFeatureExW( prod
, feat
, dwInstallMode
, dwReserved
);
3215 /***********************************************************************
3216 * MsiUseFeatureW [MSI.@]
3218 INSTALLSTATE WINAPI
MsiUseFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
)
3220 return MsiUseFeatureExW(szProduct
, szFeature
, 0, 0);
3223 /***********************************************************************
3224 * MsiUseFeatureA [MSI.@]
3226 INSTALLSTATE WINAPI
MsiUseFeatureA( LPCSTR szProduct
, LPCSTR szFeature
)
3228 return MsiUseFeatureExA(szProduct
, szFeature
, 0, 0);
3231 /***********************************************************************
3232 * MSI_ProvideQualifiedComponentEx [internal]
3234 static UINT
MSI_ProvideQualifiedComponentEx(LPCWSTR szComponent
,
3235 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3236 DWORD Unused1
, DWORD Unused2
, awstring
*lpPathBuf
,
3237 LPDWORD pcchPathBuf
)
3239 WCHAR product
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1],
3240 feature
[MAX_FEATURE_CHARS
+1];
3246 rc
= MSIREG_OpenUserComponentsKey(szComponent
, &hkey
, FALSE
);
3247 if (rc
!= ERROR_SUCCESS
)
3248 return ERROR_INDEX_ABSENT
;
3250 info
= msi_reg_get_val_str( hkey
, szQualifier
);
3254 return ERROR_INDEX_ABSENT
;
3256 MsiDecomposeDescriptorW(info
, product
, feature
, component
, &sz
);
3259 rc
= MSI_GetComponentPath(product
, component
, lpPathBuf
, pcchPathBuf
);
3261 rc
= MSI_GetComponentPath(szProduct
, component
, lpPathBuf
, pcchPathBuf
);
3265 if (rc
!= INSTALLSTATE_LOCAL
)
3266 return ERROR_FILE_NOT_FOUND
;
3268 return ERROR_SUCCESS
;
3271 /***********************************************************************
3272 * MsiProvideQualifiedComponentExW [MSI.@]
3274 UINT WINAPI
MsiProvideQualifiedComponentExW(LPCWSTR szComponent
,
3275 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPCWSTR szProduct
,
3276 DWORD Unused1
, DWORD Unused2
, LPWSTR lpPathBuf
,
3277 LPDWORD pcchPathBuf
)
3281 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_w(szComponent
),
3282 debugstr_w(szQualifier
), dwInstallMode
, debugstr_w(szProduct
),
3283 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3285 path
.unicode
= TRUE
;
3286 path
.str
.w
= lpPathBuf
;
3288 return MSI_ProvideQualifiedComponentEx(szComponent
, szQualifier
,
3289 dwInstallMode
, szProduct
, Unused1
, Unused2
, &path
, pcchPathBuf
);
3292 /***********************************************************************
3293 * MsiProvideQualifiedComponentExA [MSI.@]
3295 UINT WINAPI
MsiProvideQualifiedComponentExA(LPCSTR szComponent
,
3296 LPCSTR szQualifier
, DWORD dwInstallMode
, LPCSTR szProduct
,
3297 DWORD Unused1
, DWORD Unused2
, LPSTR lpPathBuf
,
3298 LPDWORD pcchPathBuf
)
3300 LPWSTR szwComponent
, szwQualifier
= NULL
, szwProduct
= NULL
;
3301 UINT r
= ERROR_OUTOFMEMORY
;
3304 TRACE("%s %s %u %s %u %u %p %p\n", debugstr_a(szComponent
),
3305 debugstr_a(szQualifier
), dwInstallMode
, debugstr_a(szProduct
),
3306 Unused1
, Unused2
, lpPathBuf
, pcchPathBuf
);
3308 szwComponent
= strdupAtoW( szComponent
);
3309 if (szComponent
&& !szwComponent
)
3312 szwQualifier
= strdupAtoW( szQualifier
);
3313 if (szQualifier
&& !szwQualifier
)
3316 szwProduct
= strdupAtoW( szProduct
);
3317 if (szProduct
&& !szwProduct
)
3320 path
.unicode
= FALSE
;
3321 path
.str
.a
= lpPathBuf
;
3323 r
= MSI_ProvideQualifiedComponentEx(szwComponent
, szwQualifier
,
3324 dwInstallMode
, szwProduct
, Unused1
,
3325 Unused2
, &path
, pcchPathBuf
);
3327 msi_free(szwProduct
);
3328 msi_free(szwComponent
);
3329 msi_free(szwQualifier
);
3334 /***********************************************************************
3335 * MsiProvideQualifiedComponentW [MSI.@]
3337 UINT WINAPI
MsiProvideQualifiedComponentW( LPCWSTR szComponent
,
3338 LPCWSTR szQualifier
, DWORD dwInstallMode
, LPWSTR lpPathBuf
,
3339 LPDWORD pcchPathBuf
)
3341 return MsiProvideQualifiedComponentExW(szComponent
, szQualifier
,
3342 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3345 /***********************************************************************
3346 * MsiProvideQualifiedComponentA [MSI.@]
3348 UINT WINAPI
MsiProvideQualifiedComponentA( LPCSTR szComponent
,
3349 LPCSTR szQualifier
, DWORD dwInstallMode
, LPSTR lpPathBuf
,
3350 LPDWORD pcchPathBuf
)
3352 return MsiProvideQualifiedComponentExA(szComponent
, szQualifier
,
3353 dwInstallMode
, NULL
, 0, 0, lpPathBuf
, pcchPathBuf
);
3356 /***********************************************************************
3357 * MSI_GetUserInfo [internal]
3359 static USERINFOSTATE
MSI_GetUserInfo(LPCWSTR szProduct
,
3360 awstring
*lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3361 awstring
*lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3362 awstring
*lpSerialBuf
, LPDWORD pcchSerialBuf
)
3364 WCHAR squished_pc
[SQUISH_GUID_SIZE
];
3365 LPWSTR user
, org
, serial
;
3366 USERINFOSTATE state
;
3371 TRACE("%s %p %p %p %p %p %p\n", debugstr_w(szProduct
), lpUserNameBuf
,
3372 pcchUserNameBuf
, lpOrgNameBuf
, pcchOrgNameBuf
, lpSerialBuf
,
3375 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
3376 return USERINFOSTATE_INVALIDARG
;
3378 if (MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
,
3379 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3380 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3381 &hkey
, FALSE
) != ERROR_SUCCESS
&&
3382 MSIREG_OpenProductKey(szProduct
, NULL
, MSIINSTALLCONTEXT_MACHINE
,
3383 &hkey
, FALSE
) != ERROR_SUCCESS
)
3385 return USERINFOSTATE_UNKNOWN
;
3388 if (MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3389 NULL
, &props
, FALSE
) != ERROR_SUCCESS
&&
3390 MSIREG_OpenInstallProps(szProduct
, MSIINSTALLCONTEXT_MACHINE
,
3391 NULL
, &props
, FALSE
) != ERROR_SUCCESS
)
3394 return USERINFOSTATE_ABSENT
;
3397 user
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGOWNERW
);
3398 org
= msi_reg_get_val_str(props
, INSTALLPROPERTY_REGCOMPANYW
);
3399 serial
= msi_reg_get_val_str(props
, INSTALLPROPERTY_PRODUCTIDW
);
3400 state
= USERINFOSTATE_ABSENT
;
3406 state
= USERINFOSTATE_PRESENT
;
3408 if (pcchUserNameBuf
)
3410 if (lpUserNameBuf
&& !user
)
3412 (*pcchUserNameBuf
)--;
3416 r
= msi_strcpy_to_awstring(user
, lpUserNameBuf
, pcchUserNameBuf
);
3417 if (r
== ERROR_MORE_DATA
)
3419 state
= USERINFOSTATE_MOREDATA
;
3427 if (!orgptr
) orgptr
= szEmpty
;
3429 r
= msi_strcpy_to_awstring(orgptr
, lpOrgNameBuf
, pcchOrgNameBuf
);
3430 if (r
== ERROR_MORE_DATA
)
3432 state
= USERINFOSTATE_MOREDATA
;
3445 r
= msi_strcpy_to_awstring(serial
, lpSerialBuf
, pcchSerialBuf
);
3446 if (r
== ERROR_MORE_DATA
)
3447 state
= USERINFOSTATE_MOREDATA
;
3458 /***********************************************************************
3459 * MsiGetUserInfoW [MSI.@]
3461 USERINFOSTATE WINAPI
MsiGetUserInfoW(LPCWSTR szProduct
,
3462 LPWSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3463 LPWSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3464 LPWSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3466 awstring user
, org
, serial
;
3468 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3469 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3470 (lpSerialBuf
&& !pcchSerialBuf
))
3471 return USERINFOSTATE_INVALIDARG
;
3473 user
.unicode
= TRUE
;
3474 user
.str
.w
= lpUserNameBuf
;
3476 org
.str
.w
= lpOrgNameBuf
;
3477 serial
.unicode
= TRUE
;
3478 serial
.str
.w
= lpSerialBuf
;
3480 return MSI_GetUserInfo( szProduct
, &user
, pcchUserNameBuf
,
3481 &org
, pcchOrgNameBuf
,
3482 &serial
, pcchSerialBuf
);
3485 USERINFOSTATE WINAPI
MsiGetUserInfoA(LPCSTR szProduct
,
3486 LPSTR lpUserNameBuf
, LPDWORD pcchUserNameBuf
,
3487 LPSTR lpOrgNameBuf
, LPDWORD pcchOrgNameBuf
,
3488 LPSTR lpSerialBuf
, LPDWORD pcchSerialBuf
)
3490 awstring user
, org
, serial
;
3494 if ((lpUserNameBuf
&& !pcchUserNameBuf
) ||
3495 (lpOrgNameBuf
&& !pcchOrgNameBuf
) ||
3496 (lpSerialBuf
&& !pcchSerialBuf
))
3497 return USERINFOSTATE_INVALIDARG
;
3499 prod
= strdupAtoW( szProduct
);
3500 if (szProduct
&& !prod
)
3501 return ERROR_OUTOFMEMORY
;
3503 user
.unicode
= FALSE
;
3504 user
.str
.a
= lpUserNameBuf
;
3505 org
.unicode
= FALSE
;
3506 org
.str
.a
= lpOrgNameBuf
;
3507 serial
.unicode
= FALSE
;
3508 serial
.str
.a
= lpSerialBuf
;
3510 r
= MSI_GetUserInfo( prod
, &user
, pcchUserNameBuf
,
3511 &org
, pcchOrgNameBuf
,
3512 &serial
, pcchSerialBuf
);
3519 UINT WINAPI
MsiCollectUserInfoW(LPCWSTR szProduct
)
3523 MSIPACKAGE
*package
;
3524 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3526 TRACE("(%s)\n",debugstr_w(szProduct
));
3528 rc
= MsiOpenProductW(szProduct
,&handle
);
3529 if (rc
!= ERROR_SUCCESS
)
3530 return ERROR_INVALID_PARAMETER
;
3532 /* MsiCollectUserInfo cannot be called from a custom action. */
3533 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3535 return ERROR_CALL_NOT_IMPLEMENTED
;
3537 rc
= ACTION_PerformUIAction(package
, szFirstRun
, SCRIPT_NONE
);
3538 msiobj_release( &package
->hdr
);
3540 MsiCloseHandle(handle
);
3545 UINT WINAPI
MsiCollectUserInfoA(LPCSTR szProduct
)
3549 MSIPACKAGE
*package
;
3550 static const WCHAR szFirstRun
[] = {'F','i','r','s','t','R','u','n',0};
3552 TRACE("(%s)\n",debugstr_a(szProduct
));
3554 rc
= MsiOpenProductA(szProduct
,&handle
);
3555 if (rc
!= ERROR_SUCCESS
)
3556 return ERROR_INVALID_PARAMETER
;
3558 /* MsiCollectUserInfo cannot be called from a custom action. */
3559 package
= msihandle2msiinfo(handle
, MSIHANDLETYPE_PACKAGE
);
3561 return ERROR_CALL_NOT_IMPLEMENTED
;
3563 rc
= ACTION_PerformUIAction(package
, szFirstRun
, SCRIPT_NONE
);
3564 msiobj_release( &package
->hdr
);
3566 MsiCloseHandle(handle
);
3571 /***********************************************************************
3572 * MsiConfigureFeatureA [MSI.@]
3574 UINT WINAPI
MsiConfigureFeatureA(LPCSTR szProduct
, LPCSTR szFeature
, INSTALLSTATE eInstallState
)
3576 LPWSTR prod
, feat
= NULL
;
3577 UINT r
= ERROR_OUTOFMEMORY
;
3579 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
), eInstallState
);
3581 prod
= strdupAtoW( szProduct
);
3582 if (szProduct
&& !prod
)
3585 feat
= strdupAtoW( szFeature
);
3586 if (szFeature
&& !feat
)
3589 r
= MsiConfigureFeatureW(prod
, feat
, eInstallState
);
3598 /***********************************************************************
3599 * MsiConfigureFeatureW [MSI.@]
3601 UINT WINAPI
MsiConfigureFeatureW(LPCWSTR szProduct
, LPCWSTR szFeature
, INSTALLSTATE eInstallState
)
3603 MSIPACKAGE
*package
= NULL
;
3605 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
];
3608 TRACE("%s %s %i\n", debugstr_w(szProduct
), debugstr_w(szFeature
), eInstallState
);
3610 if (!szProduct
|| !szFeature
)
3611 return ERROR_INVALID_PARAMETER
;
3613 switch (eInstallState
)
3615 case INSTALLSTATE_DEFAULT
:
3616 /* FIXME: how do we figure out the default location? */
3617 eInstallState
= INSTALLSTATE_LOCAL
;
3619 case INSTALLSTATE_LOCAL
:
3620 case INSTALLSTATE_SOURCE
:
3621 case INSTALLSTATE_ABSENT
:
3622 case INSTALLSTATE_ADVERTISED
:
3625 return ERROR_INVALID_PARAMETER
;
3628 r
= MSI_OpenProductW( szProduct
, &package
);
3629 if (r
!= ERROR_SUCCESS
)
3632 sz
= sizeof(sourcepath
);
3633 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3634 MSICODE_PRODUCT
, INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3636 sz
= sizeof(filename
);
3637 MsiSourceListGetInfoW(szProduct
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
,
3638 MSICODE_PRODUCT
, INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3640 lstrcatW( sourcepath
, filename
);
3642 MsiSetInternalUI( INSTALLUILEVEL_BASIC
, NULL
);
3644 r
= ACTION_PerformUIAction( package
, szCostInitialize
, SCRIPT_NONE
);
3645 if (r
!= ERROR_SUCCESS
)
3648 r
= MSI_SetFeatureStateW( package
, szFeature
, eInstallState
);
3649 if (r
!= ERROR_SUCCESS
)
3652 r
= MSI_InstallPackage( package
, sourcepath
, NULL
);
3655 msiobj_release( &package
->hdr
);
3660 /***********************************************************************
3661 * MsiCreateAndVerifyInstallerDirectory [MSI.@]
3663 * Notes: undocumented
3665 UINT WINAPI
MsiCreateAndVerifyInstallerDirectory(DWORD dwReserved
)
3667 WCHAR path
[MAX_PATH
];
3669 TRACE("%d\n", dwReserved
);
3673 FIXME("dwReserved=%d\n", dwReserved
);
3674 return ERROR_INVALID_PARAMETER
;
3677 if (!GetWindowsDirectoryW(path
, MAX_PATH
))
3678 return ERROR_FUNCTION_FAILED
;
3680 lstrcatW(path
, installerW
);
3682 if (!CreateDirectoryW(path
, NULL
))
3683 return ERROR_FUNCTION_FAILED
;
3685 return ERROR_SUCCESS
;
3688 /***********************************************************************
3689 * MsiGetShortcutTargetA [MSI.@]
3691 UINT WINAPI
MsiGetShortcutTargetA( LPCSTR szShortcutTarget
,
3692 LPSTR szProductCode
, LPSTR szFeatureId
,
3693 LPSTR szComponentCode
)
3696 const int len
= MAX_FEATURE_CHARS
+1;
3697 WCHAR product
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1], component
[MAX_FEATURE_CHARS
+1];
3700 target
= strdupAtoW( szShortcutTarget
);
3701 if (szShortcutTarget
&& !target
)
3702 return ERROR_OUTOFMEMORY
;
3706 r
= MsiGetShortcutTargetW( target
, product
, feature
, component
);
3708 if (r
== ERROR_SUCCESS
)
3710 WideCharToMultiByte( CP_ACP
, 0, product
, -1, szProductCode
, len
, NULL
, NULL
);
3711 WideCharToMultiByte( CP_ACP
, 0, feature
, -1, szFeatureId
, len
, NULL
, NULL
);
3712 WideCharToMultiByte( CP_ACP
, 0, component
, -1, szComponentCode
, len
, NULL
, NULL
);
3717 /***********************************************************************
3718 * MsiGetShortcutTargetW [MSI.@]
3720 UINT WINAPI
MsiGetShortcutTargetW( LPCWSTR szShortcutTarget
,
3721 LPWSTR szProductCode
, LPWSTR szFeatureId
,
3722 LPWSTR szComponentCode
)
3724 IShellLinkDataList
*dl
= NULL
;
3725 IPersistFile
*pf
= NULL
;
3726 LPEXP_DARWIN_LINK darwin
= NULL
;
3729 TRACE("%s %p %p %p\n", debugstr_w(szShortcutTarget
),
3730 szProductCode
, szFeatureId
, szComponentCode
);
3732 init
= CoInitialize(NULL
);
3734 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
3735 &IID_IPersistFile
, (LPVOID
*) &pf
);
3736 if( SUCCEEDED( r
) )
3738 r
= IPersistFile_Load( pf
, szShortcutTarget
,
3739 STGM_READ
| STGM_SHARE_DENY_WRITE
);
3740 if( SUCCEEDED( r
) )
3742 r
= IPersistFile_QueryInterface( pf
, &IID_IShellLinkDataList
,
3744 if( SUCCEEDED( r
) )
3746 IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
,
3748 IShellLinkDataList_Release( dl
);
3751 IPersistFile_Release( pf
);
3754 if (SUCCEEDED(init
))
3757 TRACE("darwin = %p\n", darwin
);
3764 ret
= MsiDecomposeDescriptorW( darwin
->szwDarwinID
,
3765 szProductCode
, szFeatureId
, szComponentCode
, &sz
);
3766 LocalFree( darwin
);
3770 return ERROR_FUNCTION_FAILED
;
3773 UINT WINAPI
MsiReinstallFeatureW( LPCWSTR szProduct
, LPCWSTR szFeature
, DWORD dwReinstallMode
)
3775 static const WCHAR fmtW
[] = {'%','s','=','%','s',' ','%','s','=','%','s',0};
3776 MSIPACKAGE
*package
;
3777 MSIINSTALLCONTEXT context
;
3779 WCHAR sourcepath
[MAX_PATH
], filename
[MAX_PATH
], reinstallmode
[11];
3780 WCHAR
*ptr
, *cmdline
;
3783 TRACE("%s, %s, 0x%08x\n", debugstr_w(szProduct
), debugstr_w(szFeature
), dwReinstallMode
);
3785 r
= msi_locate_product( szProduct
, &context
);
3786 if (r
!= ERROR_SUCCESS
)
3789 ptr
= reinstallmode
;
3791 if (dwReinstallMode
& REINSTALLMODE_FILEMISSING
)
3793 if (dwReinstallMode
& REINSTALLMODE_FILEOLDERVERSION
)
3795 if (dwReinstallMode
& REINSTALLMODE_FILEEQUALVERSION
)
3797 if (dwReinstallMode
& REINSTALLMODE_FILEEXACT
)
3799 if (dwReinstallMode
& REINSTALLMODE_FILEVERIFY
)
3801 if (dwReinstallMode
& REINSTALLMODE_FILEREPLACE
)
3803 if (dwReinstallMode
& REINSTALLMODE_USERDATA
)
3805 if (dwReinstallMode
& REINSTALLMODE_MACHINEDATA
)
3807 if (dwReinstallMode
& REINSTALLMODE_SHORTCUT
)
3809 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3813 sz
= sizeof(sourcepath
);
3814 MsiSourceListGetInfoW( szProduct
, NULL
, context
, MSICODE_PRODUCT
,
3815 INSTALLPROPERTY_LASTUSEDSOURCEW
, sourcepath
, &sz
);
3816 sz
= sizeof(filename
);
3817 MsiSourceListGetInfoW( szProduct
, NULL
, context
, MSICODE_PRODUCT
,
3818 INSTALLPROPERTY_PACKAGENAMEW
, filename
, &sz
);
3819 strcatW( sourcepath
, filename
);
3821 if (dwReinstallMode
& REINSTALLMODE_PACKAGE
)
3822 r
= MSI_OpenPackageW( sourcepath
, &package
);
3824 r
= MSI_OpenProductW( szProduct
, &package
);
3826 if (r
!= ERROR_SUCCESS
)
3829 sz
= (strlenW( fmtW
) + strlenW( szReinstallMode
) + strlenW( reinstallmode
)) * sizeof(WCHAR
);
3830 sz
+= (strlenW( szReinstall
) + strlenW( szFeature
)) * sizeof(WCHAR
);
3831 if (!(cmdline
= msi_alloc( sz
)))
3833 msiobj_release( &package
->hdr
);
3834 return ERROR_OUTOFMEMORY
;
3836 sprintfW( cmdline
, fmtW
, szReinstallMode
, reinstallmode
, szReinstall
, szFeature
);
3838 r
= MSI_InstallPackage( package
, sourcepath
, cmdline
);
3839 msiobj_release( &package
->hdr
);
3840 msi_free( cmdline
);
3845 UINT WINAPI
MsiReinstallFeatureA( LPCSTR szProduct
, LPCSTR szFeature
,
3846 DWORD dwReinstallMode
)
3852 TRACE("%s %s %i\n", debugstr_a(szProduct
), debugstr_a(szFeature
),
3855 wszProduct
= strdupAtoW(szProduct
);
3856 wszFeature
= strdupAtoW(szFeature
);
3858 rc
= MsiReinstallFeatureW(wszProduct
, wszFeature
, dwReinstallMode
);
3860 msi_free(wszProduct
);
3861 msi_free(wszFeature
);
3868 unsigned int buf
[4];
3869 unsigned char in
[64];
3870 unsigned char digest
[16];
3873 extern VOID WINAPI
MD5Init( MD5_CTX
*);
3874 extern VOID WINAPI
MD5Update( MD5_CTX
*, const unsigned char *, unsigned int );
3875 extern VOID WINAPI
MD5Final( MD5_CTX
*);
3877 /***********************************************************************
3878 * MsiGetFileHashW [MSI.@]
3880 UINT WINAPI
MsiGetFileHashW( LPCWSTR szFilePath
, DWORD dwOptions
,
3881 PMSIFILEHASHINFO pHash
)
3883 HANDLE handle
, mapping
;
3886 UINT r
= ERROR_FUNCTION_FAILED
;
3888 TRACE("%s %08x %p\n", debugstr_w(szFilePath
), dwOptions
, pHash
);
3891 return ERROR_INVALID_PARAMETER
;
3894 return ERROR_PATH_NOT_FOUND
;
3897 return ERROR_INVALID_PARAMETER
;
3899 return ERROR_INVALID_PARAMETER
;
3900 if (pHash
->dwFileHashInfoSize
< sizeof *pHash
)
3901 return ERROR_INVALID_PARAMETER
;
3903 handle
= CreateFileW( szFilePath
, GENERIC_READ
,
3904 FILE_SHARE_READ
| FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, 0, NULL
);
3905 if (handle
== INVALID_HANDLE_VALUE
)
3907 WARN("can't open file %u\n", GetLastError());
3908 return ERROR_FILE_NOT_FOUND
;
3910 length
= GetFileSize( handle
, NULL
);
3912 mapping
= CreateFileMappingW( handle
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
3915 p
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, length
);
3921 MD5Update( &ctx
, p
, length
);
3923 UnmapViewOfFile( p
);
3925 memcpy( pHash
->dwData
, ctx
.digest
, sizeof pHash
->dwData
);
3928 CloseHandle( mapping
);
3930 CloseHandle( handle
);
3935 /***********************************************************************
3936 * MsiGetFileHashA [MSI.@]
3938 UINT WINAPI
MsiGetFileHashA( LPCSTR szFilePath
, DWORD dwOptions
,
3939 PMSIFILEHASHINFO pHash
)
3944 TRACE("%s %08x %p\n", debugstr_a(szFilePath
), dwOptions
, pHash
);
3946 file
= strdupAtoW( szFilePath
);
3947 if (szFilePath
&& !file
)
3948 return ERROR_OUTOFMEMORY
;
3950 r
= MsiGetFileHashW( file
, dwOptions
, pHash
);
3955 /***********************************************************************
3956 * MsiAdvertiseScriptW [MSI.@]
3958 UINT WINAPI
MsiAdvertiseScriptW( LPCWSTR szScriptFile
, DWORD dwFlags
,
3959 PHKEY phRegData
, BOOL fRemoveItems
)
3961 FIXME("%s %08x %p %d\n",
3962 debugstr_w( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3963 return ERROR_CALL_NOT_IMPLEMENTED
;
3966 /***********************************************************************
3967 * MsiAdvertiseScriptA [MSI.@]
3969 UINT WINAPI
MsiAdvertiseScriptA( LPCSTR szScriptFile
, DWORD dwFlags
,
3970 PHKEY phRegData
, BOOL fRemoveItems
)
3972 FIXME("%s %08x %p %d\n",
3973 debugstr_a( szScriptFile
), dwFlags
, phRegData
, fRemoveItems
);
3974 return ERROR_CALL_NOT_IMPLEMENTED
;
3977 /***********************************************************************
3978 * MsiIsProductElevatedW [MSI.@]
3980 UINT WINAPI
MsiIsProductElevatedW( LPCWSTR szProduct
, BOOL
*pfElevated
)
3982 FIXME("%s %p - stub\n",
3983 debugstr_w( szProduct
), pfElevated
);
3985 return ERROR_SUCCESS
;
3988 /***********************************************************************
3989 * MsiIsProductElevatedA [MSI.@]
3991 UINT WINAPI
MsiIsProductElevatedA( LPCSTR szProduct
, BOOL
*pfElevated
)
3993 FIXME("%s %p - stub\n",
3994 debugstr_a( szProduct
), pfElevated
);
3996 return ERROR_SUCCESS
;
3999 /***********************************************************************
4000 * MsiSetExternalUIRecord [MSI.@]
4002 UINT WINAPI
MsiSetExternalUIRecord( INSTALLUI_HANDLER_RECORD handler
,
4003 DWORD filter
, LPVOID context
,
4004 PINSTALLUI_HANDLER_RECORD prev
)
4006 TRACE("%p %08x %p %p\n", handler
, filter
, context
, prev
);
4009 *prev
= gUIHandlerRecord
;
4011 gUIHandlerRecord
= handler
;
4013 gUIContext
= context
;
4015 return ERROR_SUCCESS
;
4018 /***********************************************************************
4019 * MsiInstallMissingComponentA [MSI.@]
4021 UINT WINAPI
MsiInstallMissingComponentA( LPCSTR product
, LPCSTR component
, INSTALLSTATE state
)
4024 WCHAR
*productW
= NULL
, *componentW
= NULL
;
4026 TRACE("%s, %s, %d\n", debugstr_a(product
), debugstr_a(component
), state
);
4028 if (product
&& !(productW
= strdupAtoW( product
)))
4029 return ERROR_OUTOFMEMORY
;
4031 if (component
&& !(componentW
= strdupAtoW( component
)))
4033 msi_free( productW
);
4034 return ERROR_OUTOFMEMORY
;
4037 r
= MsiInstallMissingComponentW( productW
, componentW
, state
);
4038 msi_free( productW
);
4039 msi_free( componentW
);
4043 /***********************************************************************
4044 * MsiInstallMissingComponentW [MSI.@]
4046 UINT WINAPI
MsiInstallMissingComponentW(LPCWSTR szProduct
, LPCWSTR szComponent
, INSTALLSTATE eInstallState
)
4048 FIXME("(%s %s %d\n", debugstr_w(szProduct
), debugstr_w(szComponent
), eInstallState
);
4049 return ERROR_SUCCESS
;
4052 /***********************************************************************
4053 * MsiBeginTransactionA [MSI.@]
4055 UINT WINAPI
MsiBeginTransactionA( LPCSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
4060 FIXME("%s %u %p %p\n", debugstr_a(name
), attrs
, id
, event
);
4062 nameW
= strdupAtoW( name
);
4064 return ERROR_OUTOFMEMORY
;
4066 r
= MsiBeginTransactionW( nameW
, attrs
, id
, event
);
4071 /***********************************************************************
4072 * MsiBeginTransactionW [MSI.@]
4074 UINT WINAPI
MsiBeginTransactionW( LPCWSTR name
, DWORD attrs
, MSIHANDLE
*id
, HANDLE
*event
)
4076 FIXME("%s %u %p %p\n", debugstr_w(name
), attrs
, id
, event
);
4078 *id
= (MSIHANDLE
)0xdeadbeef;
4079 *event
= (HANDLE
)0xdeadbeef;
4081 return ERROR_SUCCESS
;
4084 /***********************************************************************
4085 * MsiEndTransaction [MSI.@]
4087 UINT WINAPI
MsiEndTransaction( DWORD state
)
4089 FIXME("%u\n", state
);
4090 return ERROR_SUCCESS
;