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 ************************************************************************/
30 #pragma warning(push, 1) /* disable warnings within system headers */
32 #define WIN32_LEAN_AND_MEAN
43 //----------------------------------------------------------
44 static const CHAR
* g_Extensions
[] =
46 ".doc", // Microsoft Word Text [0]
47 ".dot", // Microsoft Word Template
49 ".docx", // Office Word 2007 XML document
50 ".docm", // Office Word 2007 XML macro-enabled document
51 ".dotx", // Office Word 2007 XML template
52 ".dotm", // Office Word 2007 XML macro-enabled template
53 ".xlw", // Microsoft Excel
54 ".xls", // Microsoft Excel
55 ".xlt", // Microsoft Excel Template
56 ".xlsx", // Office Excel 2007 XML workbook
57 ".xlsm", // Office Excel 2007 XML macro-enabled workbook
58 ".xltx", // Office Excel 2007 XML template
59 ".xltm", // Office Excel 2007 XML macro-enabled template
60 ".xlsb", // Office Excel 2007 binary workbook (BIFF12)
61 ".ppt", // Microsoft Powerpoint
62 ".pps", // Microsoft Powerpoint
63 ".pot", // Microsoft Powerpoint Template
64 ".pptx", // Office PowerPoint 2007 XML presentation
65 ".pptm", // Office PowerPoint 2007 macro-enabled XML presentation
66 ".potx", // Office PowerPoint 2007 XML template
67 ".potm", // Office PowerPoint 2007 macro-enabled XML template
68 ".ppsx", // Office PowerPoint 2007 XML show
69 ".vsd", // Visio 2000/XP/2003 document
70 ".vst", // Visio 2000/XP/2003 template
74 static const int WORD_START
= 0;
75 static const int EXCEL_START
= 7;
76 static const int POWERPOINT_START
= 15;
77 static const int VISIO_START
= 23;
78 static const int VISIO_END
= 25;
80 // ".xlam", // Office Excel 2007 XML macro-enabled add-in
81 // ".ppam", // Office PowerPoint 2007 macro-enabled XML add-in
82 // ".ppsm", // Office PowerPoint 2007 macro-enabled XML show
84 //----------------------------------------------------------
86 inline void OutputDebugStringFormat( LPCSTR pFormat
, ... )
91 va_start( args
, pFormat
);
92 StringCchVPrintfA( buffer
, sizeof(buffer
), pFormat
, args
);
93 OutputDebugStringA( buffer
);
96 static inline void OutputDebugStringFormat( LPCSTR
, ... )
101 //----------------------------------------------------------
102 static BOOL
CheckExtensionInRegistry( LPCSTR lpSubKey
)
106 LONG lResult
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, lpSubKey
, 0, KEY_QUERY_VALUE
, &hKey
);
108 if ( ERROR_SUCCESS
== lResult
)
111 DWORD nSize
= sizeof( szBuffer
);
113 lResult
= RegQueryValueExA( hKey
, "", NULL
, NULL
, (LPBYTE
)szBuffer
, &nSize
);
114 if ( ERROR_SUCCESS
== lResult
)
116 szBuffer
[nSize
] = '\0';
117 OutputDebugStringFormat( "Found value [%s] for key [%s].\n", szBuffer
, lpSubKey
);
119 if ( strncmp( szBuffer
, "WordPad.Document.1", 18 ) == 0 )
120 { // We will replace registration for word pad
123 else if ( strncmp( szBuffer
, "LibreOffice.", 12 ) == 0 )
124 { // We will replace registration for our own types, too
127 else if ( strncmp( szBuffer
, "lostub.", 7 ) == 0 )
128 { // We will replace registration for ooostub, too
133 OutputDebugStringFormat( " Checking OpenWithList of [%s].\n", lpSubKey
);
135 lResult
= RegOpenKeyExA( hKey
, "OpenWithList", 0, KEY_ENUMERATE_SUB_KEYS
, &hSubKey
);
136 if ( ERROR_SUCCESS
== lResult
)
139 while ( ERROR_SUCCESS
== lResult
)
141 nSize
= sizeof( szBuffer
);
142 lResult
= RegEnumKeyExA( hSubKey
, nIndex
++, szBuffer
, &nSize
, NULL
, NULL
, NULL
, NULL
);
143 if ( ERROR_SUCCESS
== lResult
)
145 OutputDebugStringFormat( " Found value [%s] in OpenWithList of [%s].\n", szBuffer
, lpSubKey
);
146 if ( strncmp( szBuffer
, "WordPad.exe", 11 ) == 0 )
147 { // We will replace registration for word pad
150 else if ( nSize
> 0 )
157 OutputDebugStringFormat( " No OpenWithList found!\n" );
161 else // no default value found -> return TRUE to register for that key
166 else // no key found -> return TRUE to register for that key
172 //----------------------------------------------------------
173 static LONG
DeleteSubKeyTree( HKEY RootKey
, LPCSTR lpKey
)
176 LONG rc
= RegOpenKeyExA( RootKey
, lpKey
, 0, KEY_READ
| DELETE
, &hKey
);
178 if (ERROR_SUCCESS
== rc
)
183 rc
= RegQueryInfoKeyA( hKey
, 0, 0, 0, 0, &nMaxSubKeyLen
, 0, 0, 0, 0, 0, 0 );
184 nMaxSubKeyLen
++; // space for trailing '\0'
185 lpSubKey
= reinterpret_cast<CHAR
*>( _alloca( nMaxSubKeyLen
*sizeof(CHAR
) ) );
187 while (ERROR_SUCCESS
== rc
)
189 DWORD nLen
= nMaxSubKeyLen
;
190 rc
= RegEnumKeyExA( hKey
, 0, (LPSTR
)lpSubKey
, &nLen
, 0, 0, 0, 0); // always index zero
192 if ( ERROR_NO_MORE_ITEMS
== rc
)
194 rc
= RegDeleteKeyA( RootKey
, lpKey
);
195 if ( rc
== ERROR_SUCCESS
)
196 OutputDebugStringFormat( "deleted key [%s] from registry.\n", lpKey
);
198 OutputDebugStringFormat( "RegDeleteKeyA %s returned %ld.\n", lpKey
, rc
);
201 else if ( rc
== ERROR_SUCCESS
)
203 rc
= DeleteSubKeyTree( hKey
, lpSubKey
);
204 if ( ERROR_SUCCESS
!= rc
)
205 OutputDebugStringFormat( "RegDeleteKeyA %s returned %ld.\n", lpSubKey
, rc
);
213 OutputDebugStringFormat( "RegOpenKeyExA %s returned %ld.\n", lpKey
, rc
);
222 //----------------------------------------------------------
223 static BOOL
RemoveExtensionInRegistry( LPCSTR lpSubKey
)
226 DWORD nSize
= sizeof( szBuffer
);
229 LONG lResult
= RegOpenKeyExA( HKEY_LOCAL_MACHINE
, "SOFTWARE\\Classes", 0, KEY_QUERY_VALUE
, &hKey
);
231 if ( ERROR_SUCCESS
== lResult
)
233 lResult
= RegOpenKeyExA( hKey
, lpSubKey
, 0, KEY_QUERY_VALUE
, &hSubKey
);
235 if ( ERROR_SUCCESS
== lResult
)
240 // we get the value of the default key fist and while we are on querying,
241 // we ask for the subkey count, too
242 lResult
= RegQueryValueExA( hSubKey
, "", NULL
, NULL
, (LPBYTE
)szBuffer
, &nSize
);
243 if ( ERROR_SUCCESS
== lResult
)
244 RegQueryInfoKeyA( hSubKey
, 0, 0, 0, &nSubKeys
, 0, 0, 0, 0, 0, 0, 0 );
245 RegCloseKey( hSubKey
);
247 // we will remove all key with an default value starting with ooostub but
248 // we have to be careful about MSO keys
249 if ( strncmp( szBuffer
, "opendocument.", 13 ) == 0 )
253 DeleteSubKeyTree( hKey
, lpSubKey
);
257 lResult
= RegOpenKeyExA( hKey
, lpSubKey
, 0, KEY_SET_VALUE
, &hSubKey
);
258 if ( ERROR_SUCCESS
== lResult
)
259 RegDeleteValueA( hSubKey
, "" );
261 OutputDebugStringFormat( "Could not open key %s for deleting: RegOpenKeyEx returned %ld.\n", lpSubKey
, lResult
);
269 return ( ERROR_SUCCESS
== lResult
);
274 //----------------------------------------------------------
275 bool GetMsiProp( MSIHANDLE handle
, LPCSTR name
, /*out*/std::string
& value
)
279 if (MsiGetPropertyA(handle
, name
, dummy
, &sz
) == ERROR_MORE_DATA
)
282 DWORD nbytes
= sz
* sizeof(TCHAR
);
283 LPSTR buff
= reinterpret_cast<LPSTR
>(_alloca(nbytes
));
284 ZeroMemory(buff
, nbytes
);
285 MsiGetPropertyA(handle
, name
, buff
, &sz
);
292 //----------------------------------------------------------
293 bool IsSetMsiProp( MSIHANDLE handle
, LPCSTR name
)
296 GetMsiProp( handle
, name
, val
);
300 //----------------------------------------------------------
301 static void registerForExtension( MSIHANDLE handle
, const int nIndex
, bool bRegister
)
304 StringCchCopyA( sPropName
, 256, "REGISTER_" );
305 StringCchCatA( sPropName
, 256, (g_Extensions
[nIndex
])+1 );
306 CharUpperBuffA( sPropName
+9, 4 );
309 MsiSetPropertyA( handle
, sPropName
, "1" );
310 OutputDebugStringFormat( "Set MSI property %s.\n", sPropName
);
312 MsiSetPropertyA( handle
, sPropName
, "0" );
313 OutputDebugStringFormat( "Unset MSI property %s.\n", sPropName
);
317 //----------------------------------------------------------
318 static void saveOldRegistration( LPCSTR lpSubKey
)
322 LONG lResult
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, lpSubKey
, 0,
323 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hKey
);
325 if ( ERROR_SUCCESS
== lResult
)
328 DWORD nSize
= sizeof( szBuffer
);
330 lResult
= RegQueryValueExA( hKey
, "", NULL
, NULL
, (LPBYTE
)szBuffer
, &nSize
);
331 if ( ERROR_SUCCESS
== lResult
)
333 szBuffer
[nSize
] = '\0';
335 // No need to save assocations for our own types
336 if ( strncmp( szBuffer
, "LibreOffice.", 12 ) != 0 )
338 // Save the old association
339 RegSetValueExA( hKey
, "LOBackupAssociation", 0,
340 REG_SZ
, (LPBYTE
)szBuffer
, nSize
);
341 // Also save what the old association means, just so we can try to verify
342 // if/when restoring it that the old application still exists
344 lResult
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, szBuffer
, 0,
345 KEY_QUERY_VALUE
, &hKey2
);
346 if ( ERROR_SUCCESS
== lResult
)
348 nSize
= sizeof( szBuffer
);
349 lResult
= RegQueryValueExA( hKey2
, "", NULL
, NULL
, (LPBYTE
)szBuffer
, &nSize
);
350 if ( ERROR_SUCCESS
== lResult
)
352 RegSetValueExA( hKey
, "LOBackupAssociationDeref", 0,
353 REG_SZ
, (LPBYTE
)szBuffer
, nSize
);
355 RegCloseKey( hKey2
);
363 //----------------------------------------------------------
364 static void registerForExtensions( MSIHANDLE handle
, BOOL bRegisterAll
)
365 { // Check all file extensions
367 while ( g_Extensions
[nIndex
] != 0 )
369 saveOldRegistration( g_Extensions
[nIndex
] );
371 BOOL bRegister
= bRegisterAll
|| CheckExtensionInRegistry( g_Extensions
[nIndex
] );
373 registerForExtension( handle
, nIndex
, true );
378 //----------------------------------------------------------
379 static bool checkSomeExtensionInRegistry( const int nStart
, const int nEnd
)
380 { // Check all file extensions
384 while ( !bFound
&& ( g_Extensions
[nIndex
] != 0 ) && ( nIndex
< nEnd
) )
386 bFound
= ! CheckExtensionInRegistry( g_Extensions
[nIndex
] );
389 OutputDebugStringFormat( "Found registration for [%s].\n", g_Extensions
[nIndex
] );
396 //----------------------------------------------------------
397 static void registerSomeExtensions( MSIHANDLE handle
, const int nStart
, const int nEnd
, bool bRegister
)
398 { // Check all file extensions
401 while ( ( g_Extensions
[nIndex
] != 0 ) && ( nIndex
< nEnd
) )
403 registerForExtension( handle
, nIndex
++, bRegister
);
407 //----------------------------------------------------------
408 //----------------------------------------------------------
409 //----------------------------------------------------------
410 extern "C" UINT __stdcall
LookForRegisteredExtensions( MSIHANDLE handle
)
412 OutputDebugStringFormat( "LookForRegisteredExtensions: " );
414 INSTALLSTATE current_state
;
415 INSTALLSTATE future_state
;
417 bool bWriterEnabled
= false;
418 bool bCalcEnabled
= false;
419 bool bImpressEnabled
= false;
420 bool bDrawEnabled
= false;
421 bool bRegisterNone
= IsSetMsiProp( handle
, "REGISTER_NO_MSO_TYPES" );
423 if ( ( ERROR_SUCCESS
== MsiGetFeatureState( handle
, L
"gm_p_Wrt", ¤t_state
, &future_state
) ) &&
424 ( (future_state
== INSTALLSTATE_LOCAL
) || ((current_state
== INSTALLSTATE_LOCAL
) && (future_state
== INSTALLSTATE_UNKNOWN
) ) ) )
425 bWriterEnabled
= true;
427 OutputDebugStringFormat( "LookForRegisteredExtensions: Install state Writer is [%d], will be [%d]", current_state
, future_state
);
428 if ( bWriterEnabled
)
429 OutputDebugStringFormat( "LookForRegisteredExtensions: Writer is enabled" );
431 OutputDebugStringFormat( "LookForRegisteredExtensions: Writer is NOT enabled" );
433 if ( ( ERROR_SUCCESS
== MsiGetFeatureState( handle
, L
"gm_p_Calc", ¤t_state
, &future_state
) ) &&
434 ( (future_state
== INSTALLSTATE_LOCAL
) || ((current_state
== INSTALLSTATE_LOCAL
) && (future_state
== INSTALLSTATE_UNKNOWN
) ) ) )
437 OutputDebugStringFormat( "LookForRegisteredExtensions: Install state Calc is [%d], will be [%d]", current_state
, future_state
);
439 OutputDebugStringFormat( "LookForRegisteredExtensions: Calc is enabled" );
441 OutputDebugStringFormat( "LookForRegisteredExtensions: Calc is NOT enabled" );
443 if ( ( ERROR_SUCCESS
== MsiGetFeatureState( handle
, L
"gm_p_Impress", ¤t_state
, &future_state
) ) &&
444 ( (future_state
== INSTALLSTATE_LOCAL
) || ((current_state
== INSTALLSTATE_LOCAL
) && (future_state
== INSTALLSTATE_UNKNOWN
) ) ) )
445 bImpressEnabled
= true;
447 OutputDebugStringFormat( "LookForRegisteredExtensions: Install state Impress is [%d], will be [%d]", current_state
, future_state
);
448 if ( bImpressEnabled
)
449 OutputDebugStringFormat( "LookForRegisteredExtensions: Impress is enabled" );
451 OutputDebugStringFormat( "LookForRegisteredExtensions: Impress is NOT enabled" );
453 if ( ( ERROR_SUCCESS
== MsiGetFeatureState( handle
, L
"gm_p_Draw", ¤t_state
, &future_state
) ) &&
454 ( (future_state
== INSTALLSTATE_LOCAL
) || ((current_state
== INSTALLSTATE_LOCAL
) && (future_state
== INSTALLSTATE_UNKNOWN
) ) ) )
457 OutputDebugStringFormat( "LookForRegisteredExtensions: Install state Draw is [%d], will be [%d]", current_state
, future_state
);
458 if ( bImpressEnabled
)
459 OutputDebugStringFormat( "LookForRegisteredExtensions: Draw is enabled" );
461 OutputDebugStringFormat( "LookForRegisteredExtensions: Draw is NOT enabled" );
463 MsiSetPropertyA( handle
, "SELECT_WORD", "" );
464 MsiSetPropertyA( handle
, "SELECT_EXCEL", "" );
465 MsiSetPropertyA( handle
, "SELECT_POWERPOINT", "" );
466 MsiSetPropertyA( handle
, "SELECT_VISIO", "" );
468 if ( ! bRegisterNone
)
470 if ( IsSetMsiProp( handle
, "REGISTER_ALL_MSO_TYPES" ) )
472 if ( bWriterEnabled
)
473 MsiSetPropertyA( handle
, "SELECT_WORD", "1" );
475 MsiSetPropertyA( handle
, "SELECT_EXCEL", "1" );
476 if ( bImpressEnabled
)
477 MsiSetPropertyA( handle
, "SELECT_POWERPOINT", "1" );
479 MsiSetPropertyA( handle
, "SELECT_VISIO", "1" );
483 if ( bWriterEnabled
&& ! checkSomeExtensionInRegistry( WORD_START
, EXCEL_START
) )
485 MsiSetPropertyA( handle
, "SELECT_WORD", "1" );
486 OutputDebugStringFormat( "LookForRegisteredExtensions: Register for Microsoft Word" );
488 if ( bCalcEnabled
&& ! checkSomeExtensionInRegistry( EXCEL_START
, POWERPOINT_START
) )
490 MsiSetPropertyA( handle
, "SELECT_EXCEL", "1" );
491 OutputDebugStringFormat( "LookForRegisteredExtensions: Register for Microsoft Excel" );
493 if ( bImpressEnabled
&& ! checkSomeExtensionInRegistry( POWERPOINT_START
, VISIO_START
) )
495 MsiSetPropertyA( handle
, "SELECT_POWERPOINT", "1" );
496 OutputDebugStringFormat( "LookForRegisteredExtensions: Register for Microsoft PowerPoint" );
498 if ( bImpressEnabled
&& ! checkSomeExtensionInRegistry( VISIO_START
, VISIO_END
) )
500 MsiSetPropertyA( handle
, "SELECT_VISIO", "1" );
501 OutputDebugStringFormat( "LookForRegisteredExtensions: Register for Microsoft Visio" );
506 MsiSetPropertyA( handle
, "FILETYPEDIALOGUSED", "1" );
508 return ERROR_SUCCESS
;
511 //----------------------------------------------------------
512 extern "C" UINT __stdcall
RegisterSomeExtensions( MSIHANDLE handle
)
514 OutputDebugStringFormat( "RegisterSomeExtensions: " );
516 if ( IsSetMsiProp( handle
, "SELECT_WORD" ) )
518 registerSomeExtensions( handle
, WORD_START
, EXCEL_START
, true );
519 MsiSetFeatureState( handle
, L
"gm_p_Wrt_MSO_Reg", INSTALLSTATE_LOCAL
);
520 OutputDebugStringFormat( "RegisterSomeExtensions: Register for Microsoft Word" );
524 registerSomeExtensions( handle
, WORD_START
, EXCEL_START
, false );
525 MsiSetFeatureState( handle
, L
"gm_p_Wrt_MSO_Reg", INSTALLSTATE_ABSENT
);
528 if ( IsSetMsiProp( handle
, "SELECT_EXCEL" ) )
530 registerSomeExtensions( handle
, EXCEL_START
, POWERPOINT_START
, true );
531 MsiSetFeatureState( handle
, L
"gm_p_Calc_MSO_Reg", INSTALLSTATE_LOCAL
);
532 OutputDebugStringFormat( "RegisterSomeExtensions: Register for Microsoft Excel" );
536 registerSomeExtensions( handle
, EXCEL_START
, POWERPOINT_START
, false );
537 MsiSetFeatureState( handle
, L
"gm_p_Calc_MSO_Reg", INSTALLSTATE_ABSENT
);
540 if ( IsSetMsiProp( handle
, "SELECT_POWERPOINT" ) )
542 registerSomeExtensions( handle
, POWERPOINT_START
, VISIO_START
, true );
543 MsiSetFeatureState( handle
, L
"gm_p_Impress_MSO_Reg", INSTALLSTATE_LOCAL
);
544 OutputDebugStringFormat( "RegisterSomeExtensions: Register for Microsoft PowerPoint" );
548 registerSomeExtensions( handle
, POWERPOINT_START
, VISIO_START
, false );
549 MsiSetFeatureState( handle
, L
"gm_p_Impress_MSO_Reg", INSTALLSTATE_ABSENT
);
552 if ( IsSetMsiProp( handle
, "SELECT_VISIO" ) )
554 registerSomeExtensions( handle
, VISIO_START
, VISIO_END
, true );
555 MsiSetFeatureState( handle
, L
"gm_p_Draw_MSO_Reg", INSTALLSTATE_LOCAL
);
556 OutputDebugStringFormat( "RegisterSomeExtensions: Register for Microsoft Visio" );
560 registerSomeExtensions( handle
, VISIO_START
, VISIO_END
, false );
561 MsiSetFeatureState( handle
, L
"gm_p_Draw_MSO_Reg", INSTALLSTATE_ABSENT
);
563 return ERROR_SUCCESS
;
566 //----------------------------------------------------------
568 // This is the (slightly misleadinly named) entry point for the
569 // custom action called Regallmsdocdll.
571 extern "C" UINT __stdcall
FindRegisteredExtensions( MSIHANDLE handle
)
573 if ( IsSetMsiProp( handle
, "FILETYPEDIALOGUSED" ) )
575 OutputDebugStringFormat( "FindRegisteredExtensions: FILETYPEDIALOGUSED!" );
576 return ERROR_SUCCESS
;
579 OutputDebugStringFormat( "FindRegisteredExtensions:" );
581 bool bRegisterAll
= IsSetMsiProp( handle
, "REGISTER_ALL_MSO_TYPES" );
583 if ( IsSetMsiProp( handle
, "REGISTER_NO_MSO_TYPES" ) )
585 OutputDebugStringFormat( "FindRegisteredExtensions: Register none!" );
586 return ERROR_SUCCESS
;
588 else if ( bRegisterAll
)
589 OutputDebugStringFormat( "FindRegisteredExtensions: Force all on" );
591 OutputDebugStringFormat( "FindRegisteredExtensions: " );
593 // setting the msi properties SELECT_* will force registering for all corresponding
595 if ( IsSetMsiProp( handle
, "SELECT_WORD" ) )
596 registerSomeExtensions( handle
, WORD_START
, EXCEL_START
, true );
597 if ( IsSetMsiProp( handle
, "SELECT_EXCEL" ) )
598 registerSomeExtensions( handle
, EXCEL_START
, POWERPOINT_START
, true );
599 if ( IsSetMsiProp( handle
, "SELECT_POWERPOINT" ) )
600 registerSomeExtensions( handle
, POWERPOINT_START
, VISIO_START
, true );
601 if ( IsSetMsiProp( handle
, "SELECT_VISIO" ) )
602 registerSomeExtensions( handle
, VISIO_START
, VISIO_END
, true );
604 registerForExtensions( handle
, bRegisterAll
);
606 return ERROR_SUCCESS
;
611 //----------------------------------------------------------
613 // This entry is not called for any custom action.
615 extern "C" UINT __stdcall
DeleteRegisteredExtensions( MSIHANDLE
/*handle*/ )
617 OutputDebugStringFormat( "DeleteRegisteredExtensions\n" );
619 // remove all file extensions
621 while ( g_Extensions
[nIndex
] != 0 )
623 RemoveExtensionInRegistry( g_Extensions
[nIndex
] );
627 return ERROR_SUCCESS
;
632 //----------------------------------------------------------
633 static void restoreOldRegistration( LPCSTR lpSubKey
)
637 LONG lResult
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, lpSubKey
, 0,
638 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hKey
);
640 if ( ERROR_SUCCESS
== lResult
)
643 DWORD nSize
= sizeof( szBuffer
);
645 lResult
= RegQueryValueExA( hKey
, "LOBackupAssociation", NULL
, NULL
,
646 (LPBYTE
)szBuffer
, &nSize
);
647 if ( ERROR_SUCCESS
== lResult
)
650 lResult
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, szBuffer
, 0,
651 KEY_QUERY_VALUE
, &hKey2
);
652 if ( ERROR_SUCCESS
== lResult
)
654 CHAR szBuffer2
[1024];
655 DWORD nSize2
= sizeof( szBuffer2
);
657 lResult
= RegQueryValueExA( hKey2
, "", NULL
, NULL
, (LPBYTE
)szBuffer2
, &nSize2
);
658 if ( ERROR_SUCCESS
== lResult
)
660 CHAR szBuffer3
[1024];
661 DWORD nSize3
= sizeof( szBuffer3
);
663 // Try to verify that the old association is OK to restore
664 lResult
= RegQueryValueExA( hKey
, "LOBackupAssociationDeref", NULL
, NULL
,
665 (LPBYTE
)szBuffer3
, &nSize3
);
666 if ( ERROR_SUCCESS
== lResult
)
668 if ( nSize2
== nSize3
&& strcmp (szBuffer2
, szBuffer3
) == 0)
670 // Yep. So restore it
671 RegSetValueExA( hKey
, "", 0, REG_SZ
, (LPBYTE
)szBuffer
, nSize
);
675 RegCloseKey( hKey2
);
677 RegDeleteValueA( hKey
, "LOBackupAssociation" );
679 RegDeleteValueA( hKey
, "LOBackupAssociationDeref" );
684 //----------------------------------------------------------
686 // This function is not in OO.o. We call this from the
687 // Restoreregallmsdocdll custom action.
689 extern "C" UINT __stdcall
RestoreRegAllMSDoc( MSIHANDLE
/*handle*/ )
691 OutputDebugStringFormat( "RestoreRegAllMSDoc\n" );
694 while ( g_Extensions
[nIndex
] != 0 )
696 restoreOldRegistration( g_Extensions
[nIndex
] );
701 return ERROR_SUCCESS
;
704 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */