xref: /AOO41X/main/setup_native/source/win32/customactions/regpatchactivex/regpatchactivex.cxx (revision 32b1fd08cf0851da51c0ed68f50bc63c4ee660e0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #define UNICODE
25 
26 #ifdef _MSC_VER
27 #pragma warning(push,1) // disable warnings within system headers
28 #endif
29 #include <windows.h>
30 #include <msiquery.h>
31 #ifdef _MSC_VER
32 #pragma warning(pop)
33 #endif
34 
35 #include <string.h>
36 #include <malloc.h>
37 #include <stdio.h>
38 
39 //----------------------------------------------------------
UnicodeEquals(wchar_t * pStr1,wchar_t * pStr2)40 BOOL UnicodeEquals( wchar_t* pStr1, wchar_t* pStr2 )
41 {
42     if ( pStr1 == NULL && pStr2 == NULL )
43         return TRUE;
44     else if ( pStr1 == NULL || pStr2 == NULL )
45         return FALSE;
46 
47     while( *pStr1 == *pStr2 && *pStr1 && *pStr2 )
48         pStr1++, pStr2++;
49 
50     return ( *pStr1 == 0 && *pStr2 == 0 );
51 }
52 
53 //----------------------------------------------------------
GetMsiProp(MSIHANDLE hMSI,const wchar_t * pPropName,wchar_t ** ppValue)54 BOOL GetMsiProp( MSIHANDLE hMSI, const wchar_t* pPropName, wchar_t** ppValue )
55 {
56     DWORD sz = 0;
57     if ( MsiGetProperty( hMSI, pPropName, L"", &sz ) == ERROR_MORE_DATA )
58     {
59         sz++;
60         DWORD nbytes = sz * sizeof( wchar_t );
61         wchar_t* buff = reinterpret_cast<wchar_t*>( malloc( nbytes ) );
62         ZeroMemory( buff, nbytes );
63         MsiGetProperty( hMSI, pPropName, buff, &sz );
64         *ppValue = buff;
65 
66         return TRUE;
67     }
68 
69     return FALSE;
70 }
71 
72 //----------------------------------------------------------
MakeInstallForAllUsers(MSIHANDLE hMSI)73 BOOL MakeInstallForAllUsers( MSIHANDLE hMSI )
74 {
75     BOOL bResult = FALSE;
76     wchar_t* pVal = NULL;
77     if ( GetMsiProp( hMSI, L"ALLUSERS", &pVal ) && pVal )
78     {
79         bResult = UnicodeEquals( pVal , L"1" );
80         free( pVal );
81     }
82 
83     return bResult;
84 }
85 
86 //----------------------------------------------------------
PatchActiveXControl(MSIHANDLE hMSI)87 extern "C" UINT __stdcall PatchActiveXControl( MSIHANDLE hMSI )
88 {
89     // MessageBox(NULL, L"PatchActiveXControl", L"Information", MB_OK | MB_ICONINFORMATION);
90 
91     INSTALLSTATE current_state;
92     INSTALLSTATE future_state;
93 
94     if ( ERROR_SUCCESS == MsiGetFeatureState( hMSI, L"gm_o_Activexcontrol", &current_state, &future_state ) )
95     {
96         BOOL bInstallForAllUsers = MakeInstallForAllUsers( hMSI );
97 
98         if ( future_state == INSTALLSTATE_LOCAL
99           || ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_UNKNOWN ) )
100         {
101             HKEY hkey = NULL;
102             char* aSubKey = "Software\\Classes\\MIME\\DataBase\\Content Type\\application/vnd.sun.xml.base";
103             if ( ERROR_SUCCESS == RegCreateKeyA(bInstallForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
104             {
105                 RegDeleteValueA( hkey, "CLSID" );
106                 RegCloseKey( hkey ), hkey = NULL;
107             }
108         }
109     }
110     else
111     {
112         // assert( FALSE );
113     }
114 
115     return ERROR_SUCCESS;
116 }
117 
118 
119