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