LibreOffice Module setup_native (master) 1
checkversion.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#define WIN32_LEAN_AND_MEAN
21#include <windows.h>
22#include <msiquery.h>
23
24#include <cassert>
25#include <string.h>
26#include <malloc.h>
27#include <stdio.h>
28#include <strsafe.h>
29
30#include "seterror.hxx"
31
32
33static bool GetMsiPropW( MSIHANDLE hMSI, const wchar_t* pPropName, wchar_t** ppValue )
34{
35 DWORD sz = 0;
36 if ( MsiGetPropertyW( hMSI, pPropName, const_cast<wchar_t *>(L""), &sz ) == ERROR_MORE_DATA )
37 {
38 sz++;
39 DWORD nbytes = sz * sizeof( wchar_t );
40 wchar_t* buff = static_cast<wchar_t*>( malloc( nbytes ) );
41 assert(buff); // Don't handle OOM conditions
42 ZeroMemory( buff, nbytes );
43 MsiGetPropertyW( hMSI, pPropName, buff, &sz );
44 *ppValue = buff;
45
46 return true;
47 }
48
49 return false;
50}
51
52
53#ifdef DEBUG
54inline void OutputDebugStringFormatW( PCWSTR pFormat, ... )
55{
56 WCHAR buffer[1024];
57 va_list args;
58
59 va_start( args, pFormat );
60 StringCchVPrintfW( buffer, sizeof(buffer)/sizeof(buffer[0]), pFormat, args );
61 OutputDebugStringW( buffer );
62 va_end(args);
63}
64#else
65static void OutputDebugStringFormatW( PCWSTR, ... )
66{
67}
68#endif
69
70
71extern "C" __declspec(dllexport) UINT __stdcall CheckVersions( MSIHANDLE hMSI )
72{
73 // MessageBoxW(NULL, L"CheckVersions", L"Information", MB_OK | MB_ICONINFORMATION);
74
75 wchar_t* pVal = nullptr;
76
77 if ( GetMsiPropW( hMSI, L"NEWPRODUCTS", &pVal ) && pVal )
78 {
79 OutputDebugStringFormatW( L"DEBUG: NEWPRODUCTS found [%s]", pVal );
80 if ( *pVal != 0 )
82 free( pVal );
83 }
84 pVal = nullptr;
85 if ( GetMsiPropW( hMSI, L"OLDPRODUCTS", &pVal ) && pVal )
86 {
87 OutputDebugStringFormatW( L"DEBUG: OLDPRODUCTS found [%s]", pVal );
88 if ( *pVal != 0 )
90 free( pVal );
91 }
92 pVal = nullptr;
93
94 return ERROR_SUCCESS;
95}
96
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool GetMsiPropW(MSIHANDLE hMSI, const wchar_t *pPropName, wchar_t **ppValue)
void OutputDebugStringFormatW(PCWSTR pFormat,...)
__declspec(dllexport) UINT __stdcall CheckVersions(MSIHANDLE hMSI)
args
void SetMsiErrorCode(int nErrorCode)
Definition: seterror.cxx:49
#define MSI_ERROR_OLD_VERSION_FOUND
Definition: seterror.hxx:27
#define MSI_ERROR_NEW_VERSION_FOUND
Definition: seterror.hxx:26