diff options
author | RĂ¼diger Timm <rt@openoffice.org> | 2007-07-06 11:17:47 +0000 |
---|---|---|
committer | RĂ¼diger Timm <rt@openoffice.org> | 2007-07-06 11:17:47 +0000 |
commit | 42f55a768cc081f6224ed1e7d16782cc1bbd9b34 (patch) | |
tree | 37bf38e7c5fe0cf3dcbfad6eba5e3673d1643924 /setup_native | |
parent | aa3d669998ed79216f69db7c34880ee859fe83fb (diff) |
INTEGRATION: CWS c09tosrc (1.4.4); FILE MERGED
2007/06/21 16:24:00 is 1.4.4.1: #144951# c09 to src680 for installation tasks
Diffstat (limited to 'setup_native')
-rw-r--r-- | setup_native/source/win32/customactions/shellextensions/registerextensions.cxx | 149 |
1 files changed, 147 insertions, 2 deletions
diff --git a/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx b/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx index 90eab05db53a..30a875c1a05c 100644 --- a/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx +++ b/setup_native/source/win32/customactions/shellextensions/registerextensions.cxx @@ -4,9 +4,9 @@ * * $RCSfile: registerextensions.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: ihi $ $Date: 2007-06-05 11:26:59 $ + * last change: $Author: rt $ $Date: 2007-07-06 12:17:47 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -46,6 +46,7 @@ #include <malloc.h> #include <assert.h> +#include <string.h> #ifdef UNICODE #define _UNICODE @@ -108,6 +109,94 @@ static BOOL ExecuteCommand( LPCTSTR lpCommand, BOOL bSync ) return fSuccess; } +static BOOL RemoveCompleteDirectory( std::_tstring sPath ) +{ + bool bDirectoryRemoved = true; + + std::_tstring mystr; + std::_tstring sPattern = sPath + TEXT("\\") + TEXT("*.*"); + WIN32_FIND_DATA aFindData; + + // Finding all content in sPath + + HANDLE hFindContent = FindFirstFile( sPattern.c_str(), &aFindData ); + + if ( hFindContent != INVALID_HANDLE_VALUE ) + { + bool fNextFile = false; + + do + { + std::_tstring sFileName = aFindData.cFileName; + std::_tstring sCurrentDir = TEXT("."); + std::_tstring sParentDir = TEXT(".."); + + // mystr = "Current short file: " + sFileName; + // MessageBox(NULL, mystr.c_str(), "Current Content", MB_OK); + + if (( strcmp(sFileName.c_str(),sCurrentDir.c_str()) != 0 ) && + ( strcmp(sFileName.c_str(),sParentDir.c_str()) != 0 )) + { + std::_tstring sCompleteFileName = sPath + TEXT("\\") + sFileName; + + if ( aFindData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ) + { + bool fSuccess = RemoveCompleteDirectory(sCompleteFileName); + if ( fSuccess ) + { + mystr = "Successfully removed content of dir " + sCompleteFileName; + // MessageBox(NULL, mystr.c_str(), "Removed Directory", MB_OK); + } + else + { + mystr = "An error occured during removing content of " + sCompleteFileName; + // MessageBox(NULL, mystr.c_str(), "Error removing directory", MB_OK); + } + } + else + { + bool fSuccess = DeleteFile( sCompleteFileName.c_str() ); + if ( fSuccess ) + { + mystr = "Successfully removed file " + sCompleteFileName; + // MessageBox(NULL, mystr.c_str(), "Removed File", MB_OK); + } + else + { + mystr = "An error occured during removal of file " + sCompleteFileName; + // MessageBox(NULL, mystr.c_str(), "Error removing file", MB_OK); + } + } + } + + fNextFile = FindNextFile( hFindContent, &aFindData ); + + } while ( fNextFile ); + + FindClose( hFindContent ); + + // empty directory can be removed now + // RemoveDirectory is only successful, if the last handle to the directory is closed + // -> first removing content -> closing handle -> remove empty directory + + bool fRemoveDirSuccess = RemoveDirectory(sPath.c_str()); + + if ( fRemoveDirSuccess ) + { + mystr = "Successfully removed dir " + sPath; + // MessageBox(NULL, mystr.c_str(), "Removed Directory", MB_OK); + } + else + { + mystr = "An error occured during removal of empty directory " + sPath; + // MessageBox(NULL, mystr.c_str(), "Error removing directory", MB_OK); + bDirectoryRemoved = false; + } + } + + return bDirectoryRemoved; +} + extern "C" UINT __stdcall RegisterExtensions(MSIHANDLE handle) { std::_tstring sInstDir = GetMsiProperty( handle, TEXT("INSTALLLOCATION") ); @@ -272,3 +361,59 @@ extern "C" UINT __stdcall DeregisterExtensions(MSIHANDLE handle) return ERROR_SUCCESS; } + +extern "C" UINT __stdcall RemoveExtensions(MSIHANDLE handle) +{ + std::_tstring mystr; + + // Finding the product with the help of the propery FINDPRODUCT, + // that contains a Windows Registry key, that points to the install location. + + TCHAR szValue[8192]; + DWORD nValueSize = sizeof(szValue); + HKEY hKey; + std::_tstring sInstDir; + + std::_tstring sProductKey = GetMsiProperty( handle, TEXT("FINDPRODUCT") ); + // MessageBox( NULL, sProductKey.c_str(), "Titel", MB_OK ); + + if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, sProductKey.c_str(), &hKey ) ) + { + if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) ) + { + sInstDir = szValue; + } + RegCloseKey( hKey ); + } + else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, sProductKey.c_str(), &hKey ) ) + { + if ( ERROR_SUCCESS == RegQueryValueEx( hKey, TEXT("INSTALLLOCATION"), NULL, NULL, (LPBYTE)szValue, &nValueSize ) ) + { + sInstDir = szValue; + } + RegCloseKey( hKey ); + } + else + { + return ERROR_SUCCESS; + } + + // Removing complete directory "share\uno_packages\cache" + + std::_tstring sCacheDir = sInstDir + TEXT("share\\uno_packages\\cache"); + + bool fSuccess = RemoveCompleteDirectory( sCacheDir ); + + if ( fSuccess ) + { + mystr = "Executed successfully!"; + // MessageBox(NULL, mystr.c_str(), "Main methode", MB_OK); + } + else + { + mystr = "An error occured during execution!"; + // MessageBox(NULL, mystr.c_str(), "Main methode", MB_OK); + } + + return ERROR_SUCCESS; +} |