Update ooo320-m1
[ooovba.git] / setup_native / source / win32 / customactions / regpatchactivex / regpatchactivex.cxx
blob4790d550a4af043f67d683af76b2aab702fd0031
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: regpatchactivex.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #define UNICODE
33 #ifdef _MSC_VER
34 #pragma warning(push,1) // disable warnings within system headers
35 #endif
36 #include <windows.h>
37 #include <msiquery.h>
38 #ifdef _MSC_VER
39 #pragma warning(pop)
40 #endif
42 #include <string.h>
43 #include <malloc.h>
44 #include <stdio.h>
46 //----------------------------------------------------------
47 BOOL UnicodeEquals( wchar_t* pStr1, wchar_t* pStr2 )
49 if ( pStr1 == NULL && pStr2 == NULL )
50 return TRUE;
51 else if ( pStr1 == NULL || pStr2 == NULL )
52 return FALSE;
54 while( *pStr1 == *pStr2 && *pStr1 && *pStr2 )
55 pStr1++, pStr2++;
57 return ( *pStr1 == 0 && *pStr2 == 0 );
60 //----------------------------------------------------------
61 BOOL GetMsiProp( MSIHANDLE hMSI, const wchar_t* pPropName, wchar_t** ppValue )
63 DWORD sz = 0;
64 if ( MsiGetProperty( hMSI, pPropName, L"", &sz ) == ERROR_MORE_DATA )
66 sz++;
67 DWORD nbytes = sz * sizeof( wchar_t );
68 wchar_t* buff = reinterpret_cast<wchar_t*>( malloc( nbytes ) );
69 ZeroMemory( buff, nbytes );
70 MsiGetProperty( hMSI, pPropName, buff, &sz );
71 *ppValue = buff;
73 return TRUE;
76 return FALSE;
79 //----------------------------------------------------------
80 BOOL MakeInstallForAllUsers( MSIHANDLE hMSI )
82 BOOL bResult = FALSE;
83 wchar_t* pVal = NULL;
84 if ( GetMsiProp( hMSI, L"ALLUSERS", &pVal ) && pVal )
86 bResult = UnicodeEquals( pVal , L"1" );
87 free( pVal );
90 return bResult;
93 //----------------------------------------------------------
94 extern "C" UINT __stdcall PatchActiveXControl( MSIHANDLE hMSI )
96 // MessageBox(NULL, L"PatchActiveXControl", L"Information", MB_OK | MB_ICONINFORMATION);
98 INSTALLSTATE current_state;
99 INSTALLSTATE future_state;
101 if ( ERROR_SUCCESS == MsiGetFeatureState( hMSI, L"gm_o_Activexcontrol", &current_state, &future_state ) )
103 BOOL bInstallForAllUsers = MakeInstallForAllUsers( hMSI );
105 if ( future_state == INSTALLSTATE_LOCAL
106 || ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_UNKNOWN ) )
108 HKEY hkey = NULL;
109 char* aSubKey = "Software\\Classes\\MIME\\DataBase\\Content Type\\application/vnd.sun.xml.base";
110 if ( ERROR_SUCCESS == RegCreateKeyA(bInstallForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
112 RegDeleteValueA( hkey, "CLSID" );
113 RegCloseKey( hkey ), hkey = NULL;
117 else
119 // assert( FALSE );
122 return ERROR_SUCCESS;