bnc#530872: Save old associations for MS doc types when installing
Then restore them, if still relevant, when uninstalling LibreOffice. git log from build repository: commit 1737ec9b6675cc7e30df03fa5537012a429425bb Author: Tor Lillqvist <tlillqvist@novell.com> Date: Thu Oct 14 15:28:55 2010 +0300 Make win32-restore-associations.diff apply again commit 72a25ab4a055cd1d3cf5aec627cfe120113bfb34 Author: Tor Lillqvist <tlillqvist@novell.com> Date: Thu May 20 10:34:24 2010 +0300 Make patches apply for a Windows build commit d635f716a75d8c1648eab0c1d598b390be8c4f07 Author: Tor Lillqvist <tlillqvist@novell.com> Date: Thu Sep 17 22:16:40 2009 +0300 Add new patch to restore MSO file associations on uninstall * patches/dev300/apply: Add it to Win32Only * patches/dev300/win32-restore-associations.diff: New file. Save previous associations of the MS Office file formats on installation of OOo. On uninstallation of OOo, restore them. Still a bit experimental, but seems to work.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
FindRegisteredExtensions
|
FindRegisteredExtensions
|
||||||
LookForRegisteredExtensions
|
LookForRegisteredExtensions
|
||||||
RegisterSomeExtensions
|
RegisterSomeExtensions
|
||||||
|
RestoreRegAllMSDoc
|
||||||
|
@@ -213,6 +213,9 @@ static LONG DeleteSubKeyTree( HKEY RootKey, LPCSTR lpKey )
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unused
|
||||||
|
#if 0
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
static BOOL RemoveExtensionInRegistry( LPCSTR lpSubKey )
|
static BOOL RemoveExtensionInRegistry( LPCSTR lpSubKey )
|
||||||
{
|
{
|
||||||
@@ -263,6 +266,8 @@ static BOOL RemoveExtensionInRegistry( LPCSTR lpSubKey )
|
|||||||
return ( ERROR_SUCCESS == lResult );
|
return ( ERROR_SUCCESS == lResult );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
bool GetMsiProp( MSIHANDLE handle, LPCSTR name, /*out*/std::string& value )
|
bool GetMsiProp( MSIHANDLE handle, LPCSTR name, /*out*/std::string& value )
|
||||||
{
|
{
|
||||||
@@ -306,12 +311,60 @@ static void registerForExtension( MSIHANDLE handle, const int nIndex, bool bRegi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
static void saveOldRegistration( LPCSTR lpSubKey )
|
||||||
|
{
|
||||||
|
BOOL bRet = false;
|
||||||
|
HKEY hKey = NULL;
|
||||||
|
LONG lResult = RegOpenKeyExA( HKEY_CLASSES_ROOT, lpSubKey, 0,
|
||||||
|
KEY_QUERY_VALUE|KEY_SET_VALUE, &hKey );
|
||||||
|
|
||||||
|
if ( ERROR_SUCCESS == lResult )
|
||||||
|
{
|
||||||
|
CHAR szBuffer[1024];
|
||||||
|
DWORD nSize = sizeof( szBuffer );
|
||||||
|
|
||||||
|
lResult = RegQueryValueExA( hKey, "", NULL, NULL, (LPBYTE)szBuffer, &nSize );
|
||||||
|
if ( ERROR_SUCCESS == lResult )
|
||||||
|
{
|
||||||
|
szBuffer[nSize] = '\0';
|
||||||
|
|
||||||
|
// No need to save assocations for our own types
|
||||||
|
if ( strncmp( szBuffer, "OpenOffice.org.", 15 ) != 0 )
|
||||||
|
{
|
||||||
|
// Save the old association
|
||||||
|
RegSetValueExA( hKey, "OOoBackupAssociation", 0,
|
||||||
|
REG_SZ, (LPBYTE)szBuffer, nSize );
|
||||||
|
// Also save what the old association means, just so we can try to verify
|
||||||
|
// if/when restoring it that the old application still exists
|
||||||
|
HKEY hKey2 = NULL;
|
||||||
|
lResult = RegOpenKeyExA( HKEY_CLASSES_ROOT, szBuffer, 0,
|
||||||
|
KEY_QUERY_VALUE, &hKey2 );
|
||||||
|
if ( ERROR_SUCCESS == lResult )
|
||||||
|
{
|
||||||
|
nSize = sizeof( szBuffer );
|
||||||
|
lResult = RegQueryValueExA( hKey2, "", NULL, NULL, (LPBYTE)szBuffer, &nSize );
|
||||||
|
if ( ERROR_SUCCESS == lResult )
|
||||||
|
{
|
||||||
|
RegSetValueExA( hKey, "OOoBackupAssociationDeref", 0,
|
||||||
|
REG_SZ, (LPBYTE)szBuffer, nSize );
|
||||||
|
}
|
||||||
|
RegCloseKey( hKey2 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RegCloseKey( hKey );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
static void registerForExtensions( MSIHANDLE handle, BOOL bRegisterAll )
|
static void registerForExtensions( MSIHANDLE handle, BOOL bRegisterAll )
|
||||||
{ // Check all file extensions
|
{ // Check all file extensions
|
||||||
int nIndex = 0;
|
int nIndex = 0;
|
||||||
while ( g_Extensions[nIndex] != 0 )
|
while ( g_Extensions[nIndex] != 0 )
|
||||||
{
|
{
|
||||||
|
saveOldRegistration( g_Extensions[nIndex] );
|
||||||
|
|
||||||
BOOL bRegister = bRegisterAll || CheckExtensionInRegistry( g_Extensions[nIndex] );
|
BOOL bRegister = bRegisterAll || CheckExtensionInRegistry( g_Extensions[nIndex] );
|
||||||
if ( bRegister )
|
if ( bRegister )
|
||||||
registerForExtension( handle, nIndex, true );
|
registerForExtension( handle, nIndex, true );
|
||||||
@@ -478,6 +531,10 @@ extern "C" UINT __stdcall RegisterSomeExtensions( MSIHANDLE handle )
|
|||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This is the (slightly misleadinly named) entry point for the
|
||||||
|
// custom action called Regallmsdocdll.
|
||||||
|
//
|
||||||
extern "C" UINT __stdcall FindRegisteredExtensions( MSIHANDLE handle )
|
extern "C" UINT __stdcall FindRegisteredExtensions( MSIHANDLE handle )
|
||||||
{
|
{
|
||||||
if ( IsSetMsiProp( handle, "FILETYPEDIALOGUSED" ) )
|
if ( IsSetMsiProp( handle, "FILETYPEDIALOGUSED" ) )
|
||||||
@@ -514,7 +571,12 @@ extern "C" UINT __stdcall FindRegisteredExtensions( MSIHANDLE handle )
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This entry is not called for any custom action.
|
||||||
|
//
|
||||||
extern "C" UINT __stdcall DeleteRegisteredExtensions( MSIHANDLE /*handle*/ )
|
extern "C" UINT __stdcall DeleteRegisteredExtensions( MSIHANDLE /*handle*/ )
|
||||||
{
|
{
|
||||||
OutputDebugStringFormat( "DeleteRegisteredExtensions\n" );
|
OutputDebugStringFormat( "DeleteRegisteredExtensions\n" );
|
||||||
@@ -530,4 +592,78 @@ extern "C" UINT __stdcall DeleteRegisteredExtensions( MSIHANDLE /*handle*/ )
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
static void restoreOldRegistration( LPCSTR lpSubKey )
|
||||||
|
{
|
||||||
|
BOOL bRet = false;
|
||||||
|
HKEY hKey = NULL;
|
||||||
|
LONG lResult = RegOpenKeyExA( HKEY_CLASSES_ROOT, lpSubKey, 0,
|
||||||
|
KEY_QUERY_VALUE|KEY_SET_VALUE, &hKey );
|
||||||
|
|
||||||
|
if ( ERROR_SUCCESS == lResult )
|
||||||
|
{
|
||||||
|
CHAR szBuffer[1024];
|
||||||
|
DWORD nSize = sizeof( szBuffer );
|
||||||
|
|
||||||
|
lResult = RegQueryValueExA( hKey, "OOoBackupAssociation", NULL, NULL,
|
||||||
|
(LPBYTE)szBuffer, &nSize );
|
||||||
|
if ( ERROR_SUCCESS == lResult )
|
||||||
|
{
|
||||||
|
HKEY hKey2 = NULL;
|
||||||
|
lResult = RegOpenKeyExA( HKEY_CLASSES_ROOT, szBuffer, 0,
|
||||||
|
KEY_QUERY_VALUE, &hKey2 );
|
||||||
|
if ( ERROR_SUCCESS == lResult )
|
||||||
|
{
|
||||||
|
CHAR szBuffer2[1024];
|
||||||
|
DWORD nSize2 = sizeof( szBuffer2 );
|
||||||
|
|
||||||
|
lResult = RegQueryValueExA( hKey2, "", NULL, NULL, (LPBYTE)szBuffer2, &nSize2 );
|
||||||
|
if ( ERROR_SUCCESS == lResult )
|
||||||
|
{
|
||||||
|
CHAR szBuffer3[1024];
|
||||||
|
DWORD nSize3 = sizeof( szBuffer3 );
|
||||||
|
|
||||||
|
// Try to verify that the old association is OK to restore
|
||||||
|
lResult = RegQueryValueExA( hKey, "OOoBackupAssociationDeref", NULL, NULL,
|
||||||
|
(LPBYTE)szBuffer3, &nSize3 );
|
||||||
|
if ( ERROR_SUCCESS == lResult )
|
||||||
|
{
|
||||||
|
if ( nSize2 == nSize3 && strcmp (szBuffer2, szBuffer3) == 0)
|
||||||
|
{
|
||||||
|
// Yep. So restore it
|
||||||
|
RegSetValueExA( hKey, "", 0, REG_SZ, (LPBYTE)szBuffer, nSize );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RegCloseKey( hKey2 );
|
||||||
|
}
|
||||||
|
RegDeleteValueA( hKey, "OOoBackupAssociation" );
|
||||||
|
}
|
||||||
|
RegDeleteValueA( hKey, "OOoBackupAssociationDeref" );
|
||||||
|
RegCloseKey( hKey );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This function is not in OO.o. We call this from the
|
||||||
|
// Restoreregallmsdocdll custom action.
|
||||||
|
//
|
||||||
|
extern "C" UINT __stdcall RestoreRegAllMSDoc( MSIHANDLE /*handle*/ )
|
||||||
|
{
|
||||||
|
OutputDebugStringFormat( "RestoreRegAllMSDoc\n" );
|
||||||
|
|
||||||
|
int nIndex = 0;
|
||||||
|
while ( g_Extensions[nIndex] != 0 )
|
||||||
|
{
|
||||||
|
restoreOldRegistration( g_Extensions[nIndex] );
|
||||||
|
++nIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
Reference in New Issue
Block a user