Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / setup_native / source / win32 / customactions / regpatchactivex / regpatchactivex.cxx
blob800fde54eab58eda004815ed6b6c1f2345902278
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #define UNICODE
31 #ifdef _MSC_VER
32 #pragma warning(push,1) // disable warnings within system headers
33 #endif
34 #include <windows.h>
35 #include <msiquery.h>
36 #ifdef _MSC_VER
37 #pragma warning(pop)
38 #endif
40 #include <string.h>
41 #include <malloc.h>
42 #include <stdio.h>
44 //----------------------------------------------------------
45 BOOL UnicodeEquals( wchar_t* pStr1, wchar_t* pStr2 )
47 if ( pStr1 == NULL && pStr2 == NULL )
48 return TRUE;
49 else if ( pStr1 == NULL || pStr2 == NULL )
50 return FALSE;
52 while( *pStr1 == *pStr2 && *pStr1 && *pStr2 )
53 pStr1++, pStr2++;
55 return ( *pStr1 == 0 && *pStr2 == 0 );
58 //----------------------------------------------------------
59 BOOL GetMsiProp( MSIHANDLE hMSI, const wchar_t* pPropName, wchar_t** ppValue )
61 DWORD sz = 0;
62 if ( MsiGetProperty( hMSI, pPropName, L"", &sz ) == ERROR_MORE_DATA )
64 sz++;
65 DWORD nbytes = sz * sizeof( wchar_t );
66 wchar_t* buff = reinterpret_cast<wchar_t*>( malloc( nbytes ) );
67 ZeroMemory( buff, nbytes );
68 MsiGetProperty( hMSI, pPropName, buff, &sz );
69 *ppValue = buff;
71 return TRUE;
74 return FALSE;
77 //----------------------------------------------------------
78 BOOL MakeInstallForAllUsers( MSIHANDLE hMSI )
80 BOOL bResult = FALSE;
81 wchar_t* pVal = NULL;
82 if ( GetMsiProp( hMSI, L"ALLUSERS", &pVal ) && pVal )
84 bResult = UnicodeEquals( pVal , L"1" );
85 free( pVal );
88 return bResult;
91 //----------------------------------------------------------
92 extern "C" UINT __stdcall PatchActiveXControl( MSIHANDLE hMSI )
94 // MessageBox(NULL, L"PatchActiveXControl", L"Information", MB_OK | MB_ICONINFORMATION);
96 INSTALLSTATE current_state;
97 INSTALLSTATE future_state;
99 if ( ERROR_SUCCESS == MsiGetFeatureState( hMSI, L"gm_o_Activexcontrol", &current_state, &future_state ) )
101 BOOL bInstallForAllUsers = MakeInstallForAllUsers( hMSI );
103 if ( future_state == INSTALLSTATE_LOCAL
104 || ( current_state == INSTALLSTATE_LOCAL && future_state == INSTALLSTATE_UNKNOWN ) )
106 HKEY hkey = NULL;
107 char* aSubKey = "Software\\Classes\\MIME\\DataBase\\Content Type\\application/vnd.sun.xml.base";
108 if ( ERROR_SUCCESS == RegCreateKeyA(bInstallForAllUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, aSubKey, &hkey) )
110 RegDeleteValueA( hkey, "CLSID" );
111 RegCloseKey( hkey ), hkey = NULL;
115 else
117 // assert( FALSE );
120 return ERROR_SUCCESS;
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */