1*32b1fd08SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*32b1fd08SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*32b1fd08SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*32b1fd08SAndrew Rist * distributed with this work for additional information
6*32b1fd08SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*32b1fd08SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*32b1fd08SAndrew Rist * "License"); you may not use this file except in compliance
9*32b1fd08SAndrew Rist * with the License. You may obtain a copy of the License at
10*32b1fd08SAndrew Rist *
11*32b1fd08SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*32b1fd08SAndrew Rist *
13*32b1fd08SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*32b1fd08SAndrew Rist * software distributed under the License is distributed on an
15*32b1fd08SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*32b1fd08SAndrew Rist * KIND, either express or implied. See the License for the
17*32b1fd08SAndrew Rist * specific language governing permissions and limitations
18*32b1fd08SAndrew Rist * under the License.
19*32b1fd08SAndrew Rist *
20*32b1fd08SAndrew Rist *************************************************************/
21*32b1fd08SAndrew Rist
22*32b1fd08SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #define _WIN32_WINNT 0x0401
25cdf0e10cSrcweir
26cdf0e10cSrcweir #ifdef _MSC_VER
27cdf0e10cSrcweir #pragma warning(push, 1) /* disable warnings within system headers */
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN
30cdf0e10cSrcweir #include <windows.h>
31cdf0e10cSrcweir #include <msiquery.h>
32cdf0e10cSrcweir #ifdef _MSC_VER
33cdf0e10cSrcweir #pragma warning(pop)
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <malloc.h>
37cdf0e10cSrcweir #include <assert.h>
38cdf0e10cSrcweir
39cdf0e10cSrcweir #ifdef UNICODE
40cdf0e10cSrcweir #define _UNICODE
41cdf0e10cSrcweir #define _tstring wstring
42cdf0e10cSrcweir #else
43cdf0e10cSrcweir #define _tstring string
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #include <tchar.h>
46cdf0e10cSrcweir #include <string>
47cdf0e10cSrcweir #include <queue>
48cdf0e10cSrcweir #include <stdio.h>
49cdf0e10cSrcweir #include <strsafe.h>
50cdf0e10cSrcweir
51cdf0e10cSrcweir #include <systools/win32/uwinapi.h>
52cdf0e10cSrcweir
53cdf0e10cSrcweir //----------------------------------------------------------
54cdf0e10cSrcweir #ifdef DEBUG
OutputDebugStringFormat(LPCSTR pFormat,...)55cdf0e10cSrcweir inline void OutputDebugStringFormat( LPCSTR pFormat, ... )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir CHAR buffer[1024];
58cdf0e10cSrcweir va_list args;
59cdf0e10cSrcweir
60cdf0e10cSrcweir va_start( args, pFormat );
61cdf0e10cSrcweir StringCchVPrintfA( buffer, sizeof(buffer), pFormat, args );
62cdf0e10cSrcweir OutputDebugStringA( buffer );
63cdf0e10cSrcweir }
64cdf0e10cSrcweir #else
OutputDebugStringFormat(LPCSTR,...)65cdf0e10cSrcweir static inline void OutputDebugStringFormat( LPCSTR, ... )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir }
68cdf0e10cSrcweir #endif
69cdf0e10cSrcweir
GetMsiProperty(MSIHANDLE handle,const std::_tstring & sProperty)70cdf0e10cSrcweir static std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir std::_tstring result;
73cdf0e10cSrcweir TCHAR szDummy[1] = TEXT("");
74cdf0e10cSrcweir DWORD nChars = 0;
75cdf0e10cSrcweir
76cdf0e10cSrcweir if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir DWORD nBytes = ++nChars * sizeof(TCHAR);
79cdf0e10cSrcweir LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes));
80cdf0e10cSrcweir ZeroMemory( buffer, nBytes );
81cdf0e10cSrcweir MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars);
82cdf0e10cSrcweir result = buffer;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir return result;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
SetMsiProperty(MSIHANDLE handle,const std::_tstring & sProperty)88cdf0e10cSrcweir static void SetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir MsiSetProperty( handle, sProperty.c_str(), TEXT("1") );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
CheckPatchList(MSIHANDLE handle)93cdf0e10cSrcweir extern "C" UINT __stdcall CheckPatchList( MSIHANDLE handle )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir std::_tstring sPatchList = GetMsiProperty( handle, TEXT("PATCH") );
96cdf0e10cSrcweir std::_tstring sRequiredPatch = GetMsiProperty( handle, TEXT("PREREQUIREDPATCH") );
97cdf0e10cSrcweir
98cdf0e10cSrcweir OutputDebugStringFormat( "CheckPatchList called with PATCH=%s and PRQ= %s\n", sPatchList.c_str(), sRequiredPatch.c_str() );
99cdf0e10cSrcweir
100cdf0e10cSrcweir if ( ( sPatchList.length() != 0 ) && ( sRequiredPatch.length() != 0 ) )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir if ( _tcsstr( sPatchList.c_str(), sRequiredPatch.c_str() ) )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir SetMsiProperty( handle, TEXT("IGNOREPREREQUIREDPATCH") );
105cdf0e10cSrcweir OutputDebugStringFormat( "Set Property IgnorePrerequiredPatch!\n" );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir return ERROR_SUCCESS;
109cdf0e10cSrcweir }
110