tdf#133368: update extensions website URLs and use https
[LibreOffice.git] / setup_native / source / win32 / customactions / tools / checkversion.cxx
blob3f0b30f3ce34f8b8dfadb2ee18144d01af205923
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #define WIN32_LEAN_AND_MEAN
21 #include <windows.h>
22 #include <msiquery.h>
24 #include <cassert>
25 #include <string.h>
26 #include <malloc.h>
27 #include <stdio.h>
28 #include <strsafe.h>
30 #include "seterror.hxx"
33 static bool GetMsiPropW( MSIHANDLE hMSI, const wchar_t* pPropName, wchar_t** ppValue )
35 DWORD sz = 0;
36 if ( MsiGetPropertyW( hMSI, pPropName, const_cast<wchar_t *>(L""), &sz ) == ERROR_MORE_DATA )
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;
46 return true;
49 return false;
53 #ifdef DEBUG
54 inline void OutputDebugStringFormatW( PCWSTR pFormat, ... )
56 WCHAR buffer[1024];
57 va_list args;
59 va_start( args, pFormat );
60 StringCchVPrintfW( buffer, sizeof(buffer)/sizeof(buffer[0]), pFormat, args );
61 OutputDebugStringW( buffer );
62 va_end(args);
64 #else
65 static void OutputDebugStringFormatW( PCWSTR, ... )
68 #endif
71 extern "C" __declspec(dllexport) UINT __stdcall CheckVersions( MSIHANDLE hMSI )
73 // MessageBoxW(NULL, L"CheckVersions", L"Information", MB_OK | MB_ICONINFORMATION);
75 wchar_t* pVal = nullptr;
77 if ( GetMsiPropW( hMSI, L"NEWPRODUCTS", &pVal ) && pVal )
79 OutputDebugStringFormatW( L"DEBUG: NEWPRODUCTS found [%s]", pVal );
80 if ( *pVal != 0 )
81 SetMsiErrorCode( MSI_ERROR_NEW_VERSION_FOUND );
82 free( pVal );
84 pVal = nullptr;
85 if ( GetMsiPropW( hMSI, L"OLDPRODUCTS", &pVal ) && pVal )
87 OutputDebugStringFormatW( L"DEBUG: OLDPRODUCTS found [%s]", pVal );
88 if ( *pVal != 0 )
89 SetMsiErrorCode( MSI_ERROR_OLD_VERSION_FOUND );
90 free( pVal );
92 pVal = nullptr;
94 return ERROR_SUCCESS;
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */