1*32b1fd08SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*32b1fd08SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*32b1fd08SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*32b1fd08SAndrew Rist  * distributed with this work for additional information
6*32b1fd08SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*32b1fd08SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*32b1fd08SAndrew Rist  * "License"); you may not use this file except in compliance
9*32b1fd08SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*32b1fd08SAndrew Rist  *
11*32b1fd08SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*32b1fd08SAndrew Rist  *
13*32b1fd08SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*32b1fd08SAndrew Rist  * software distributed under the License is distributed on an
15*32b1fd08SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*32b1fd08SAndrew Rist  * KIND, either express or implied.  See the License for the
17*32b1fd08SAndrew Rist  * specific language governing permissions and limitations
18*32b1fd08SAndrew Rist  * under the License.
19*32b1fd08SAndrew Rist  *
20*32b1fd08SAndrew Rist  *************************************************************/
21*32b1fd08SAndrew Rist 
22*32b1fd08SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #define UNICODE
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #ifdef _MSC_VER
27cdf0e10cSrcweir #pragma warning(push,1) // disable warnings within system headers
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #include <windows.h>
30cdf0e10cSrcweir #include <msiquery.h>
31cdf0e10cSrcweir #ifdef _MSC_VER
32cdf0e10cSrcweir #pragma warning(pop)
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <string.h>
36cdf0e10cSrcweir #include <malloc.h>
37cdf0e10cSrcweir #include <stdio.h>
38cdf0e10cSrcweir #include "strsafe.h"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <seterror.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //----------------------------------------------------------
GetMsiProp(MSIHANDLE hMSI,const wchar_t * pPropName,wchar_t ** ppValue)43cdf0e10cSrcweir BOOL GetMsiProp( MSIHANDLE hMSI, const wchar_t* pPropName, wchar_t** ppValue )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     DWORD sz = 0;
46cdf0e10cSrcweir    	if ( MsiGetProperty( hMSI, pPropName, L"", &sz ) == ERROR_MORE_DATA )
47cdf0e10cSrcweir    	{
48cdf0e10cSrcweir        	sz++;
49cdf0e10cSrcweir        	DWORD nbytes = sz * sizeof( wchar_t );
50cdf0e10cSrcweir        	wchar_t* buff = reinterpret_cast<wchar_t*>( malloc( nbytes ) );
51cdf0e10cSrcweir        	ZeroMemory( buff, nbytes );
52cdf0e10cSrcweir        	MsiGetProperty( hMSI, pPropName, buff, &sz );
53cdf0e10cSrcweir    		*ppValue = buff;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 		return TRUE;
56cdf0e10cSrcweir 	}
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	return FALSE;
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //----------------------------------------------------------
62cdf0e10cSrcweir #ifdef DEBUG
OutputDebugStringFormat(LPCTSTR pFormat,...)63cdf0e10cSrcweir inline void OutputDebugStringFormat( LPCTSTR pFormat, ... )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	TCHAR    buffer[1024];
66cdf0e10cSrcweir 	va_list  args;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	va_start( args, pFormat );
69cdf0e10cSrcweir 	StringCchVPrintf( buffer, sizeof(buffer), pFormat, args );
70cdf0e10cSrcweir 	OutputDebugString( buffer );
71cdf0e10cSrcweir }
72cdf0e10cSrcweir #else
OutputDebugStringFormat(LPCTSTR,...)73cdf0e10cSrcweir static inline void OutputDebugStringFormat( LPCTSTR, ... )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir }
76cdf0e10cSrcweir #endif
77cdf0e10cSrcweir 
78cdf0e10cSrcweir //----------------------------------------------------------
CheckVersions(MSIHANDLE hMSI)79cdf0e10cSrcweir extern "C" UINT __stdcall CheckVersions( MSIHANDLE hMSI )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	// MessageBox(NULL, L"CheckVersions", L"Information", MB_OK | MB_ICONINFORMATION);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     wchar_t* pVal = NULL;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	if ( GetMsiProp( hMSI, L"NEWPRODUCTS", &pVal ) && pVal )
86cdf0e10cSrcweir 	{
87cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: NEWPRODUCTS found [%s]"), pVal );
88cdf0e10cSrcweir 		if ( *pVal != 0 )
89cdf0e10cSrcweir             SetMsiErrorCode( MSI_ERROR_NEW_VERSION_FOUND );
90cdf0e10cSrcweir 		free( pVal );
91cdf0e10cSrcweir 	}
92cdf0e10cSrcweir     pVal = NULL;
93cdf0e10cSrcweir 	if ( GetMsiProp( hMSI, L"SAMEPRODUCTS", &pVal ) && pVal )
94cdf0e10cSrcweir 	{
95cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: SAMEPRODUCTS found [%s]"), pVal );
96cdf0e10cSrcweir 		if ( *pVal != 0 )
97cdf0e10cSrcweir             SetMsiErrorCode( MSI_ERROR_SAME_VERSION_FOUND );
98cdf0e10cSrcweir 		free( pVal );
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir     pVal = NULL;
101cdf0e10cSrcweir 	if ( GetMsiProp( hMSI, L"OLDPRODUCTS", &pVal ) && pVal )
102cdf0e10cSrcweir 	{
103cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: OLDPRODUCTS found [%s]"), pVal );
104cdf0e10cSrcweir 		if ( *pVal != 0 )
105cdf0e10cSrcweir             SetMsiErrorCode( MSI_ERROR_OLD_VERSION_FOUND );
106cdf0e10cSrcweir 		free( pVal );
107cdf0e10cSrcweir 	}
108cdf0e10cSrcweir     pVal = NULL;
109cdf0e10cSrcweir 	if ( GetMsiProp( hMSI, L"BETAPRODUCTS", &pVal ) && pVal )
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: BETAPRODUCTS found [%s]"), pVal );
112cdf0e10cSrcweir 		if ( *pVal != 0 )
113cdf0e10cSrcweir             SetMsiErrorCode( MSI_ERROR_OLD_VERSION_FOUND );
114cdf0e10cSrcweir 		free( pVal );
115cdf0e10cSrcweir 	}
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     pVal = NULL;
118cdf0e10cSrcweir 	if ( GetMsiProp( hMSI, L"NEWPRODUCTSPATCH", &pVal ) && pVal )
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: NEWPRODUCTSPATCH found [%s]"), pVal );
121cdf0e10cSrcweir 		if ( *pVal != 0 )
122cdf0e10cSrcweir             SetMsiErrorCode( MSI_ERROR_NEW_PATCH_FOUND );
123cdf0e10cSrcweir 		free( pVal );
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir     pVal = NULL;
126cdf0e10cSrcweir 	if ( GetMsiProp( hMSI, L"SAMEPRODUCTSPATCH", &pVal ) && pVal )
127cdf0e10cSrcweir 	{
128cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: SAMEPRODUCTSPATCH found [%s]"), pVal );
129cdf0e10cSrcweir 		if ( *pVal != 0 )
130cdf0e10cSrcweir             SetMsiErrorCode( MSI_ERROR_SAME_PATCH_FOUND );
131cdf0e10cSrcweir 		free( pVal );
132cdf0e10cSrcweir 	}
133cdf0e10cSrcweir     pVal = NULL;
134cdf0e10cSrcweir 	if ( GetMsiProp( hMSI, L"OLDPRODUCTSPATCH", &pVal ) && pVal )
135cdf0e10cSrcweir 	{
136cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("DEBUG: OLDPRODUCTSPATCH found [%s]"), pVal );
137cdf0e10cSrcweir 		if ( *pVal != 0 )
138cdf0e10cSrcweir             SetMsiErrorCode( MSI_ERROR_OLD_PATCH_FOUND );
139cdf0e10cSrcweir 		free( pVal );
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	return ERROR_SUCCESS;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
146