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