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 UNICODE
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #ifdef _MSC_VER
27cdf0e10cSrcweir #pragma warning(push,1) // disable warnings within system headers
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #include <windows.h>
30cdf0e10cSrcweir #include <msiquery.h>
31cdf0e10cSrcweir #ifdef _MSC_VER
32cdf0e10cSrcweir #pragma warning(pop)
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <string.h>
36cdf0e10cSrcweir #include <malloc.h>
37cdf0e10cSrcweir #include <stdio.h>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //----------------------------------------------------------
UnicodeEquals(wchar_t * pStr1,wchar_t * pStr2)40cdf0e10cSrcweir BOOL UnicodeEquals( wchar_t* pStr1, wchar_t* pStr2 )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	if ( pStr1 == NULL && pStr2 == NULL )
43cdf0e10cSrcweir 		return TRUE;
44cdf0e10cSrcweir 	else if ( pStr1 == NULL || pStr2 == NULL )
45cdf0e10cSrcweir 		return FALSE;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 	while( *pStr1 == *pStr2 && *pStr1 && *pStr2 )
48cdf0e10cSrcweir 		pStr1++, pStr2++;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 	return ( *pStr1 == 0 && *pStr2 == 0 );
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir //----------------------------------------------------------
GetMsiProp(MSIHANDLE hMSI,const wchar_t * pPropName,wchar_t ** ppValue)54cdf0e10cSrcweir BOOL GetMsiProp( MSIHANDLE hMSI, const wchar_t* pPropName, wchar_t** ppValue )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir     DWORD sz = 0;
57cdf0e10cSrcweir    	if ( MsiGetProperty( hMSI, pPropName, L"", &sz ) == ERROR_MORE_DATA )
58cdf0e10cSrcweir    	{
59cdf0e10cSrcweir        	sz++;
60cdf0e10cSrcweir        	DWORD nbytes = sz * sizeof( wchar_t );
61cdf0e10cSrcweir        	wchar_t* buff = reinterpret_cast<wchar_t*>( malloc( nbytes ) );
62cdf0e10cSrcweir        	ZeroMemory( buff, nbytes );
63cdf0e10cSrcweir        	MsiGetProperty( hMSI, pPropName, buff, &sz );
64cdf0e10cSrcweir    		*ppValue = buff;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 		return TRUE;
67cdf0e10cSrcweir 	}
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	return FALSE;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir //----------------------------------------------------------
MakeInstallForAllUsers(MSIHANDLE hMSI)73cdf0e10cSrcweir BOOL MakeInstallForAllUsers( MSIHANDLE hMSI )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	BOOL bResult = FALSE;
76cdf0e10cSrcweir 	wchar_t* pVal = NULL;
77cdf0e10cSrcweir 	if ( GetMsiProp( hMSI, L"ALLUSERS", &pVal ) && pVal )
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 		bResult = UnicodeEquals( pVal , L"1" );
80cdf0e10cSrcweir 		free( pVal );
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	return bResult;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //----------------------------------------------------------
PatchActiveXControl(MSIHANDLE hMSI)87cdf0e10cSrcweir extern "C" UINT __stdcall PatchActiveXControl( MSIHANDLE hMSI )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	// MessageBox(NULL, L"PatchActiveXControl", L"Information", MB_OK | MB_ICONINFORMATION);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	INSTALLSTATE current_state;
92cdf0e10cSrcweir 	INSTALLSTATE future_state;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	if ( ERROR_SUCCESS == MsiGetFeatureState( hMSI, L"gm_o_Activexcontrol", &current_state, &future_state ) )
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir 		BOOL bInstallForAllUsers = MakeInstallForAllUsers( hMSI );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 		if ( future_state == INSTALLSTATE_LOCAL
99cdf0e10cSrcweir 		  || ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_UNKNOWN ) )
100cdf0e10cSrcweir 		{
101cdf0e10cSrcweir 			HKEY hkey = NULL;
102cdf0e10cSrcweir 			char* aSubKey = "Software\\Classes\\MIME\\DataBase\\Content Type\\application/vnd.sun.xml.base";
103cdf0e10cSrcweir 	   		if ( ERROR_SUCCESS == RegCreateKeyA(bInstallForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
104cdf0e10cSrcweir 			{
105cdf0e10cSrcweir 	   			RegDeleteValueA( hkey, "CLSID" );
106cdf0e10cSrcweir 				RegCloseKey( hkey ), hkey = NULL;
107cdf0e10cSrcweir 			}
108cdf0e10cSrcweir 		}
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir 	else
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		// assert( FALSE );
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	return ERROR_SUCCESS;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119