1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #define UNICODE
29 
30 #ifdef _MSC_VER
31 #pragma warning(push,1) // disable warnings within system headers
32 #endif
33 #include <windows.h>
34 #include <msiquery.h>
35 #ifdef _MSC_VER
36 #pragma warning(pop)
37 #endif
38 
39 #include <string.h>
40 #include <malloc.h>
41 #include <stdio.h>
42 #include "strsafe.h"
43 
44 #include <seterror.hxx>
45 
46 //----------------------------------------------------------
47 BOOL GetMsiProp( MSIHANDLE hMSI, const wchar_t* pPropName, wchar_t** ppValue )
48 {
49     DWORD sz = 0;
50    	if ( MsiGetProperty( hMSI, pPropName, L"", &sz ) == ERROR_MORE_DATA )
51    	{
52        	sz++;
53        	DWORD nbytes = sz * sizeof( wchar_t );
54        	wchar_t* buff = reinterpret_cast<wchar_t*>( malloc( nbytes ) );
55        	ZeroMemory( buff, nbytes );
56        	MsiGetProperty( hMSI, pPropName, buff, &sz );
57    		*ppValue = buff;
58 
59 		return TRUE;
60 	}
61 
62 	return FALSE;
63 }
64 
65 //----------------------------------------------------------
66 #ifdef DEBUG
67 inline void OutputDebugStringFormat( LPCTSTR pFormat, ... )
68 {
69 	TCHAR    buffer[1024];
70 	va_list  args;
71 
72 	va_start( args, pFormat );
73 	StringCchVPrintf( buffer, sizeof(buffer), pFormat, args );
74 	OutputDebugString( buffer );
75 }
76 #else
77 static inline void OutputDebugStringFormat( LPCTSTR, ... )
78 {
79 }
80 #endif
81 
82 //----------------------------------------------------------
83 extern "C" UINT __stdcall CheckVersions( MSIHANDLE hMSI )
84 {
85 	// MessageBox(NULL, L"CheckVersions", L"Information", MB_OK | MB_ICONINFORMATION);
86 
87     wchar_t* pVal = NULL;
88 
89 	if ( GetMsiProp( hMSI, L"NEWPRODUCTS", &pVal ) && pVal )
90 	{
91         OutputDebugStringFormat( TEXT("DEBUG: NEWPRODUCTS found [%s]"), pVal );
92 		if ( *pVal != 0 )
93             SetMsiErrorCode( MSI_ERROR_NEW_VERSION_FOUND );
94 		free( pVal );
95 	}
96     pVal = NULL;
97 	if ( GetMsiProp( hMSI, L"SAMEPRODUCTS", &pVal ) && pVal )
98 	{
99         OutputDebugStringFormat( TEXT("DEBUG: SAMEPRODUCTS found [%s]"), pVal );
100 		if ( *pVal != 0 )
101             SetMsiErrorCode( MSI_ERROR_SAME_VERSION_FOUND );
102 		free( pVal );
103 	}
104     pVal = NULL;
105 	if ( GetMsiProp( hMSI, L"OLDPRODUCTS", &pVal ) && pVal )
106 	{
107         OutputDebugStringFormat( TEXT("DEBUG: OLDPRODUCTS found [%s]"), pVal );
108 		if ( *pVal != 0 )
109             SetMsiErrorCode( MSI_ERROR_OLD_VERSION_FOUND );
110 		free( pVal );
111 	}
112     pVal = NULL;
113 	if ( GetMsiProp( hMSI, L"BETAPRODUCTS", &pVal ) && pVal )
114 	{
115         OutputDebugStringFormat( TEXT("DEBUG: BETAPRODUCTS found [%s]"), pVal );
116 		if ( *pVal != 0 )
117             SetMsiErrorCode( MSI_ERROR_OLD_VERSION_FOUND );
118 		free( pVal );
119 	}
120 
121     pVal = NULL;
122 	if ( GetMsiProp( hMSI, L"NEWPRODUCTSPATCH", &pVal ) && pVal )
123 	{
124         OutputDebugStringFormat( TEXT("DEBUG: NEWPRODUCTSPATCH found [%s]"), pVal );
125 		if ( *pVal != 0 )
126             SetMsiErrorCode( MSI_ERROR_NEW_PATCH_FOUND );
127 		free( pVal );
128 	}
129     pVal = NULL;
130 	if ( GetMsiProp( hMSI, L"SAMEPRODUCTSPATCH", &pVal ) && pVal )
131 	{
132         OutputDebugStringFormat( TEXT("DEBUG: SAMEPRODUCTSPATCH found [%s]"), pVal );
133 		if ( *pVal != 0 )
134             SetMsiErrorCode( MSI_ERROR_SAME_PATCH_FOUND );
135 		free( pVal );
136 	}
137     pVal = NULL;
138 	if ( GetMsiProp( hMSI, L"OLDPRODUCTSPATCH", &pVal ) && pVal )
139 	{
140         OutputDebugStringFormat( TEXT("DEBUG: OLDPRODUCTSPATCH found [%s]"), pVal );
141 		if ( *pVal != 0 )
142             SetMsiErrorCode( MSI_ERROR_OLD_PATCH_FOUND );
143 		free( pVal );
144 	}
145 
146 	return ERROR_SUCCESS;
147 }
148 
149 
150