diff options
author | Dirk Völzke <dv@openoffice.org> | 2009-08-24 07:40:00 +0000 |
---|---|---|
committer | Dirk Völzke <dv@openoffice.org> | 2009-08-24 07:40:00 +0000 |
commit | b6103ae98b92524b04d3fe261c445135002a65c2 (patch) | |
tree | 7bcedb197c63bc562878b69e677effc67d58ad3e /extensions/source/update/check/download.cxx | |
parent | 5fb2028499e85dfe2ceaa2328adc90439946ff25 (diff) |
#i88957# Improved handling of already downloaded updates
Diffstat (limited to 'extensions/source/update/check/download.cxx')
-rw-r--r-- | extensions/source/update/check/download.cxx | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/extensions/source/update/check/download.cxx b/extensions/source/update/check/download.cxx index eaa16a9f9368..8c64c037da7e 100644 --- a/extensions/source/update/check/download.cxx +++ b/extensions/source/update/check/download.cxx @@ -172,7 +172,9 @@ progress_callback( void *clientp, double dltotal, double dlnow, double ultotal, if( ! out->StopCondition.check() ) { - double fPercent = (dlnow + out->Offset) * 100 / (dltotal + out->Offset); + double fPercent = 0; + if ( dltotal + out->Offset ) + fPercent = (dlnow + out->Offset) * 100 / (dltotal + out->Offset); if( fPercent < 0 ) fPercent = 0; @@ -333,14 +335,52 @@ Download::start(const rtl::OUString& rURL, const rtl::OUString& rFile, const rtl OSL_ASSERT( m_aHandler.is() ); OutData out(m_aCondition); + rtl::OUString aFile( rFile ); - out.File = rFile; + // when rFile is empty, there is no remembered file name. If there is already a file with the + // same name ask the user if she wants to resume a download or restart the download + if ( !aFile.getLength() ) + { + // GetFileName() + rtl::OUString aURL( rURL ); + // ensure no trailing '/' + sal_Int32 nLen = aURL.getLength(); + while( (nLen > 0) && ('/' == aURL[ nLen-1 ]) ) + aURL = aURL.copy( 0, --nLen ); + + // extract file name last '/' + sal_Int32 nIndex = aURL.lastIndexOf('/'); + aFile = rDestinationDir + aURL.copy( nIndex ); + + // check for existing file + oslFileError rc = osl_openFile( aFile.pData, &out.FileHandle, osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ); + osl_closeFile(out.FileHandle); + out.FileHandle = NULL; + + if( osl_File_E_EXIST == rc ) + { + if ( m_aHandler->checkDownloadDestination( aURL.copy( nIndex+1 ) ) ) + { + osl_removeFile( aFile.pData ); + aFile = rtl::OUString(); + } + else + m_aHandler->downloadStarted( aFile, 1 ); + } + else + { + osl_removeFile( aFile.pData ); + aFile = rtl::OUString(); + } + } + + out.File = aFile; out.DestinationDir = rDestinationDir; out.Handler = m_aHandler; - if( rFile.getLength() > 0 ) + if( aFile.getLength() > 0 ) { - oslFileError rc = osl_openFile(rFile.pData, &out.FileHandle, osl_File_OpenFlag_Write); + oslFileError rc = osl_openFile(aFile.pData, &out.FileHandle, osl_File_OpenFlag_Write); if( osl_File_E_None == rc ) { |