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 ************************************************************************/
32 #pragma warning(push, 1) /* disable warnings within system headers */
43 #define CHART_COMPONENT 1
44 #define DRAW_COMPONENT 2
45 #define IMPRESS_COMPONENT 4
46 #define CALC_COMPONENT 8
47 #define WRITER_COMPONENT 16
48 #define MATH_COMPONENT 32
50 typedef int ( __stdcall
* DllNativeRegProc
) ( int, BOOL
, BOOL
, const char* );
51 typedef int ( __stdcall
* DllNativeUnregProc
) ( int, BOOL
, BOOL
);
53 BOOL
UnicodeEquals( wchar_t* pStr1
, wchar_t* pStr2
)
55 if ( pStr1
== NULL
&& pStr2
== NULL
)
57 else if ( pStr1
== NULL
|| pStr2
== NULL
)
60 while( *pStr1
== *pStr2
&& *pStr1
&& *pStr2
)
63 return ( *pStr1
== 0 && *pStr2
== 0 );
66 //----------------------------------------------------------
67 char* UnicodeToAnsiString( wchar_t* pUniString
)
69 int len
= WideCharToMultiByte(
70 CP_ACP
, 0, pUniString
, -1, 0, 0, 0, 0 );
72 char* buff
= reinterpret_cast<char*>( malloc( len
) );
75 CP_ACP
, 0, pUniString
, -1, buff
, len
, 0, 0 );
80 //----------------------------------------------------------
81 void RegisterActiveXNative( const char* pActiveXPath
, int nMode
, BOOL InstallForAllUser
, BOOL InstallFor64Bit
)
83 // For Win98/WinME the values should be written to the local machine
84 OSVERSIONINFO aVerInfo
;
85 aVerInfo
.dwOSVersionInfoSize
= sizeof( aVerInfo
);
86 if ( GetVersionEx( &aVerInfo
) && aVerInfo
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
)
87 InstallForAllUser
= TRUE
;
89 HINSTANCE hModule
= LoadLibraryExA( pActiveXPath
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
90 if( !( hModule
<= ( HINSTANCE
)HINSTANCE_ERROR
) )
92 DllNativeRegProc pNativeProc
= ( DllNativeRegProc
)GetProcAddress( hModule
, "DllRegisterServerNative" );
93 if( pNativeProc
!=NULL
)
95 int nLen
= strlen( pActiveXPath
);
96 int nRemoveLen
= strlen( "\\so_activex.dll" );
97 if ( nLen
> nRemoveLen
)
99 char* pProgramPath
= reinterpret_cast<char*>( malloc( nLen
- nRemoveLen
+ 1 ) );
100 strncpy( pProgramPath
, pActiveXPath
, nLen
- nRemoveLen
);
101 pProgramPath
[ nLen
- nRemoveLen
] = 0;
103 ( *pNativeProc
)( nMode
, InstallForAllUser
, InstallFor64Bit
, pProgramPath
);
105 free( pProgramPath
);
109 FreeLibrary( hModule
);
113 //----------------------------------------------------------
114 void UnregisterActiveXNative( const char* pActiveXPath
, int nMode
, BOOL InstallForAllUser
, BOOL InstallFor64Bit
)
116 // For Win98/WinME the values should be written to the local machine
117 OSVERSIONINFO aVerInfo
;
118 aVerInfo
.dwOSVersionInfoSize
= sizeof( aVerInfo
);
119 if ( GetVersionEx( &aVerInfo
) && aVerInfo
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
)
120 InstallForAllUser
= TRUE
;
122 HINSTANCE hModule
= LoadLibraryExA( pActiveXPath
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);
123 if( !( hModule
<= ( HINSTANCE
)HINSTANCE_ERROR
) )
125 DllNativeUnregProc pNativeProc
= ( DllNativeUnregProc
)GetProcAddress( hModule
, "DllUnregisterServerNative" );
126 if( pNativeProc
!=NULL
)
127 ( *pNativeProc
)( nMode
, InstallForAllUser
, InstallFor64Bit
);
129 FreeLibrary( hModule
);
133 //----------------------------------------------------------
134 BOOL
GetMsiProp( MSIHANDLE hMSI
, const wchar_t* pPropName
, wchar_t** ppValue
)
137 if ( MsiGetProperty( hMSI
, pPropName
, L
"", &sz
) == ERROR_MORE_DATA
)
140 DWORD nbytes
= sz
* sizeof( wchar_t );
141 wchar_t* buff
= reinterpret_cast<wchar_t*>( malloc( nbytes
) );
142 ZeroMemory( buff
, nbytes
);
143 MsiGetProperty( hMSI
, pPropName
, buff
, &sz
);
152 //----------------------------------------------------------
153 BOOL
GetActiveXControlPath( MSIHANDLE hMSI
, char** ppActiveXPath
)
155 wchar_t* pProgPath
= NULL
;
156 if ( GetMsiProp( hMSI
, L
"INSTALLLOCATION", &pProgPath
) && pProgPath
)
158 char* pCharProgPath
= UnicodeToAnsiString( pProgPath
);
162 int nLen
= strlen( pCharProgPath
);
163 *ppActiveXPath
= reinterpret_cast<char*>( malloc( nLen
+ 23 ) );
164 strncpy( *ppActiveXPath
, pCharProgPath
, nLen
);
165 strncpy( (*ppActiveXPath
) + nLen
, "program\\so_activex.dll", 22 );
166 (*ppActiveXPath
)[nLen
+22] = 0;
168 free( pCharProgPath
);
179 //----------------------------------------------------------
180 BOOL
GetDelta( MSIHANDLE hMSI
, int& nOldInstallMode
, int& nInstallMode
, int& nDeinstallMode
)
182 // for now the chart is always installed
183 nOldInstallMode
= CHART_COMPONENT
;
184 nInstallMode
= CHART_COMPONENT
;
187 INSTALLSTATE current_state
;
188 INSTALLSTATE future_state
;
190 if ( ERROR_SUCCESS
== MsiGetFeatureState( hMSI
, L
"gm_p_Wrt_Bin", ¤t_state
, &future_state
) )
192 // analyze writer installation mode
193 if ( current_state
== INSTALLSTATE_LOCAL
)
194 nOldInstallMode
|= WRITER_COMPONENT
;
196 if ( future_state
== INSTALLSTATE_LOCAL
197 || ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_UNKNOWN
) )
198 nInstallMode
|= WRITER_COMPONENT
;
199 else if ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_ABSENT
)
200 nDeinstallMode
|= WRITER_COMPONENT
;
207 if ( ERROR_SUCCESS
== MsiGetFeatureState( hMSI
, L
"gm_p_Calc_Bin", ¤t_state
, &future_state
) )
209 // analyze calc installation mode
210 if ( current_state
== INSTALLSTATE_LOCAL
)
211 nOldInstallMode
|= CALC_COMPONENT
;
213 if ( future_state
== INSTALLSTATE_LOCAL
214 || ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_UNKNOWN
) )
215 nInstallMode
|= CALC_COMPONENT
;
216 else if ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_ABSENT
)
217 nDeinstallMode
|= CALC_COMPONENT
;
224 if ( ERROR_SUCCESS
== MsiGetFeatureState( hMSI
, L
"gm_p_Draw_Bin", ¤t_state
, &future_state
) )
226 // analyze draw installation mode
227 if ( current_state
== INSTALLSTATE_LOCAL
)
228 nOldInstallMode
|= DRAW_COMPONENT
;
230 if ( future_state
== INSTALLSTATE_LOCAL
231 || ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_UNKNOWN
) )
232 nInstallMode
|= DRAW_COMPONENT
;
233 else if ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_ABSENT
)
234 nDeinstallMode
|= DRAW_COMPONENT
;
241 if ( ERROR_SUCCESS
== MsiGetFeatureState( hMSI
, L
"gm_p_Impress_Bin", ¤t_state
, &future_state
) )
243 // analyze impress installation mode
244 if ( current_state
== INSTALLSTATE_LOCAL
)
245 nOldInstallMode
|= IMPRESS_COMPONENT
;
247 if ( future_state
== INSTALLSTATE_LOCAL
248 || ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_UNKNOWN
) )
249 nInstallMode
|= IMPRESS_COMPONENT
;
250 else if ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_ABSENT
)
251 nDeinstallMode
|= IMPRESS_COMPONENT
;
258 if ( ERROR_SUCCESS
== MsiGetFeatureState( hMSI
, L
"gm_p_Math_Bin", ¤t_state
, &future_state
) )
260 // analyze math installation mode
261 if ( current_state
== INSTALLSTATE_LOCAL
)
262 nOldInstallMode
|= MATH_COMPONENT
;
264 if ( future_state
== INSTALLSTATE_LOCAL
265 || ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_UNKNOWN
) )
266 nInstallMode
|= MATH_COMPONENT
;
267 else if ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_ABSENT
)
268 nDeinstallMode
|= MATH_COMPONENT
;
278 //----------------------------------------------------------
279 BOOL
MakeInstallForAllUsers( MSIHANDLE hMSI
)
281 BOOL bResult
= FALSE
;
282 wchar_t* pVal
= NULL
;
283 if ( GetMsiProp( hMSI
, L
"ALLUSERS", &pVal
) && pVal
)
285 bResult
= UnicodeEquals( pVal
, L
"1" );
292 //----------------------------------------------------------
293 BOOL
MakeInstallFor64Bit( MSIHANDLE hMSI
)
295 BOOL bResult
= FALSE
;
296 wchar_t* pVal
= NULL
;
297 if ( GetMsiProp( hMSI
, L
"VersionNT64", &pVal
) && pVal
)
305 //----------------------------------------------------------
306 extern "C" UINT __stdcall
InstallActiveXControl( MSIHANDLE hMSI
)
308 INSTALLSTATE current_state
;
309 INSTALLSTATE future_state
;
311 if ( ERROR_SUCCESS
== MsiGetFeatureState( hMSI
, L
"gm_o_Activexcontrol", ¤t_state
, &future_state
) )
313 int nOldInstallMode
= 0;
314 int nInstallMode
= 0;
315 int nDeinstallMode
= 0;
316 BOOL bInstallForAllUser
= MakeInstallForAllUsers( hMSI
);
317 BOOL bInstallFor64Bit
= MakeInstallFor64Bit( hMSI
);
319 char* pActiveXPath
= NULL
;
320 if ( GetActiveXControlPath( hMSI
, &pActiveXPath
) && pActiveXPath
321 && GetDelta( hMSI
, nOldInstallMode
, nInstallMode
, nDeinstallMode
) )
323 if ( future_state
== INSTALLSTATE_LOCAL
324 || ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_UNKNOWN
) )
326 // the control is installed in the new selected configuration
328 if ( current_state
== INSTALLSTATE_LOCAL
&& nDeinstallMode
)
329 UnregisterActiveXNative( pActiveXPath
, nDeinstallMode
, bInstallForAllUser
, bInstallFor64Bit
);
332 RegisterActiveXNative( pActiveXPath
, nInstallMode
, bInstallForAllUser
, bInstallFor64Bit
);
334 else if ( current_state
== INSTALLSTATE_LOCAL
&& future_state
== INSTALLSTATE_ABSENT
)
336 if ( nOldInstallMode
)
337 UnregisterActiveXNative( pActiveXPath
, nOldInstallMode
, bInstallForAllUser
, bInstallFor64Bit
);
342 free( pActiveXPath
);
349 return ERROR_SUCCESS
;
352 //----------------------------------------------------------
353 extern "C" UINT __stdcall
DeinstallActiveXControl( MSIHANDLE hMSI
)
355 INSTALLSTATE current_state
;
356 INSTALLSTATE future_state
;
358 if ( ERROR_SUCCESS
== MsiGetFeatureState( hMSI
, L
"gm_o_Activexcontrol", ¤t_state
, &future_state
) )
360 char* pActiveXPath
= NULL
;
361 if ( current_state
== INSTALLSTATE_LOCAL
&& GetActiveXControlPath( hMSI
, &pActiveXPath
) && pActiveXPath
)
363 BOOL bInstallForAllUser
= MakeInstallForAllUsers( hMSI
);
364 BOOL bInstallFor64Bit
= MakeInstallFor64Bit( hMSI
);
367 UnregisterActiveXNative( pActiveXPath
,
378 free( pActiveXPath
);
382 return ERROR_SUCCESS
;
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */