diff --git a/setup_native/source/win32/customactions/reg4allmsdoc/exports.dxp b/setup_native/source/win32/customactions/reg4allmsdoc/exports.dxp index 566981ba569e..54ebb2f675f4 100644 --- a/setup_native/source/win32/customactions/reg4allmsdoc/exports.dxp +++ b/setup_native/source/win32/customactions/reg4allmsdoc/exports.dxp @@ -1,3 +1,4 @@ FindRegisteredExtensions LookForRegisteredExtensions -RegisterSomeExtensions \ No newline at end of file +RegisterSomeExtensions +RestoreRegAllMSDoc diff --git a/setup_native/source/win32/customactions/reg4allmsdoc/reg4allmsi.cxx b/setup_native/source/win32/customactions/reg4allmsdoc/reg4allmsi.cxx index 54a40cd08d8f..7b9cfc992245 100644 --- a/setup_native/source/win32/customactions/reg4allmsdoc/reg4allmsi.cxx +++ b/setup_native/source/win32/customactions/reg4allmsdoc/reg4allmsi.cxx @@ -213,6 +213,9 @@ static LONG DeleteSubKeyTree( HKEY RootKey, LPCSTR lpKey ) return rc; } +// Unused +#if 0 + //---------------------------------------------------------- static BOOL RemoveExtensionInRegistry( LPCSTR lpSubKey ) { @@ -263,6 +266,8 @@ static BOOL RemoveExtensionInRegistry( LPCSTR lpSubKey ) return ( ERROR_SUCCESS == lResult ); } +#endif + //---------------------------------------------------------- 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 ) { // Check all file extensions int nIndex = 0; while ( g_Extensions[nIndex] != 0 ) { + saveOldRegistration( g_Extensions[nIndex] ); + BOOL bRegister = bRegisterAll || CheckExtensionInRegistry( g_Extensions[nIndex] ); if ( bRegister ) 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 ) { if ( IsSetMsiProp( handle, "FILETYPEDIALOGUSED" ) ) @@ -514,7 +571,12 @@ extern "C" UINT __stdcall FindRegisteredExtensions( MSIHANDLE handle ) return ERROR_SUCCESS; } +#if 0 + //---------------------------------------------------------- +// +// This entry is not called for any custom action. +// extern "C" UINT __stdcall DeleteRegisteredExtensions( MSIHANDLE /*handle*/ ) { OutputDebugStringFormat( "DeleteRegisteredExtensions\n" ); @@ -530,4 +592,78 @@ extern "C" UINT __stdcall DeleteRegisteredExtensions( MSIHANDLE /*handle*/ ) 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: */