summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'extensions')
-rw-r--r--extensions/source/update/check/download.cxx48
-rw-r--r--extensions/source/update/check/download.hxx2
-rw-r--r--extensions/source/update/check/updatecheck.cxx69
-rw-r--r--extensions/source/update/check/updatecheck.hxx2
-rw-r--r--extensions/source/update/check/updatehdl.cxx86
-rw-r--r--extensions/source/update/check/updatehdl.hrc3
-rw-r--r--extensions/source/update/check/updatehdl.hxx5
-rw-r--r--extensions/source/update/check/updatehdl.src15
8 files changed, 213 insertions, 17 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 )
{
diff --git a/extensions/source/update/check/download.hxx b/extensions/source/update/check/download.hxx
index 24c2842a709d..034f39dbe733 100644
--- a/extensions/source/update/check/download.hxx
+++ b/extensions/source/update/check/download.hxx
@@ -38,6 +38,8 @@
struct DownloadInteractionHandler : public rtl::IReference
{
+ virtual bool checkDownloadDestination(const rtl::OUString& rFileName) = 0;
+
// called if the destination file already exists, but resume is false
virtual bool downloadTargetExists(const rtl::OUString& rFileName) = 0;
diff --git a/extensions/source/update/check/updatecheck.cxx b/extensions/source/update/check/updatecheck.cxx
index 23d4da29a41f..09776f1fc1c4 100644
--- a/extensions/source/update/check/updatecheck.cxx
+++ b/extensions/source/update/check/updatecheck.cxx
@@ -785,6 +785,8 @@ UpdateCheck::initialize(const uno::Sequence< beans::NamedValue >& rValues,
aModel.getUpdateEntry(m_aUpdateInfo);
bool obsoleteUpdateInfo = isObsoleteUpdateInfo(aUpdateEntryVersion);
+ bool bContinueDownload = false;
+ bool bDownloadAvailable = false;
m_bHasExtensionUpdate = checkForPendingUpdates( xContext );
m_bShowExtUpdDlg = false;
@@ -793,10 +795,7 @@ UpdateCheck::initialize(const uno::Sequence< beans::NamedValue >& rValues,
if( aLocalFileName.getLength() > 0 )
{
- bool downloadPaused = aModel.isDownloadPaused();
-
- enableDownload(true, downloadPaused);
- setUIState(downloadPaused ? UPDATESTATE_DOWNLOAD_PAUSED : UPDATESTATE_DOWNLOADING);
+ bContinueDownload = true;
// Try to get the number of bytes already on disk
osl::DirectoryItem aDirectoryItem;
@@ -805,16 +804,36 @@ UpdateCheck::initialize(const uno::Sequence< beans::NamedValue >& rValues,
osl::FileStatus aFileStatus(FileStatusMask_FileSize);
if( osl::DirectoryItem::E_None == aDirectoryItem.getFileStatus(aFileStatus) )
{
- // Calculate initial percent value.
- if( aModel.getDownloadSize() > 0 )
+ sal_Int64 nDownloadSize = aModel.getDownloadSize();
+ sal_Int64 nFileSize = aFileStatus.getFileSize();
+
+ if( nDownloadSize > 0 )
{
- sal_Int32 nPercent = (sal_Int32) (100 * aFileStatus.getFileSize() / aModel.getDownloadSize());
- getUpdateHandler()->setProgress(nPercent);
+ if ( nDownloadSize == nFileSize ) // we have already downloaded everthing
+ {
+ bContinueDownload = false;
+ bDownloadAvailable = true;
+ m_aImageName = getImageFromFileName( aLocalFileName );
+ }
+ else // Calculate initial percent value.
+ {
+ sal_Int32 nPercent = (sal_Int32) (100 * nFileSize / nDownloadSize);
+ getUpdateHandler()->setProgress( nPercent );
+ }
}
}
}
+
+ if ( bContinueDownload )
+ {
+ bool downloadPaused = aModel.isDownloadPaused();
+
+ enableDownload(true, downloadPaused);
+ setUIState(downloadPaused ? UPDATESTATE_DOWNLOAD_PAUSED : UPDATESTATE_DOWNLOADING);
+ }
+
}
- else
+ if ( !bContinueDownload )
{
// We do this intentionally only if no download is in progress ..
if( obsoleteUpdateInfo )
@@ -827,13 +846,18 @@ UpdateCheck::initialize(const uno::Sequence< beans::NamedValue >& rValues,
// Data is outdated, probably due to installed update
rtl::Reference< UpdateCheckConfig > aConfig = UpdateCheckConfig::get( xContext, *this );
aConfig->clearUpdateFound();
+ aConfig->clearLocalFileName();
+
m_aUpdateInfo = UpdateInfo();
}
else
{
enableAutoCheck(aModel.isAutoCheckEnabled());
- setUIState(getUIState(m_aUpdateInfo));
+ if ( bDownloadAvailable )
+ setUIState( UPDATESTATE_DOWNLOAD_AVAIL );
+ else
+ setUIState(getUIState(m_aUpdateInfo));
}
}
}
@@ -922,6 +946,10 @@ UpdateCheck::install()
aParameter += UNISTRING(" &");
#endif
+
+ rtl::Reference< UpdateCheckConfig > rModel = UpdateCheckConfig::get( m_xContext );
+ rModel->clearLocalFileName();
+
xShellExecute->execute(aInstallImage, aParameter, nFlags);
ShutdownThread *pShutdownThread = new ShutdownThread( m_xContext );
(void) pShutdownThread;
@@ -1087,6 +1115,23 @@ UpdateCheck::downloadTargetExists(const rtl::OUString& rFileName)
}
//------------------------------------------------------------------------------
+bool UpdateCheck::checkDownloadDestination( const rtl::OUString& rFileName )
+{
+ osl::ClearableMutexGuard aGuard(m_aMutex);
+
+ rtl::Reference< UpdateHandler > aUpdateHandler( getUpdateHandler() );
+
+ bool bReload = false;
+
+ if( aUpdateHandler->isVisible() )
+ {
+ bReload = aUpdateHandler->showOverwriteWarning( rFileName );
+ }
+
+ return bReload;
+}
+
+//------------------------------------------------------------------------------
void
UpdateCheck::downloadStalled(const rtl::OUString& rErrorMessage)
@@ -1138,9 +1183,6 @@ UpdateCheck::downloadFinished(const rtl::OUString& rLocalFileName)
// no more retries
m_pThread->terminate();
- rtl::Reference< UpdateCheckConfig > rModel = UpdateCheckConfig::get(m_xContext);
- rModel->clearLocalFileName();
-
m_aImageName = getImageFromFileName(rLocalFileName);
UpdateInfo aUpdateInfo(m_aUpdateInfo);
@@ -1148,6 +1190,7 @@ UpdateCheck::downloadFinished(const rtl::OUString& rLocalFileName)
setUIState(UPDATESTATE_DOWNLOAD_AVAIL);
// Bring-up release note for position 2 ..
+ rtl::Reference< UpdateCheckConfig > rModel = UpdateCheckConfig::get( m_xContext );
const rtl::OUString aURL(getReleaseNote(aUpdateInfo, 2, rModel->isAutoDownloadEnabled()));
if( aURL.getLength() > 0 )
showReleaseNote(aURL);
diff --git a/extensions/source/update/check/updatecheck.hxx b/extensions/source/update/check/updatecheck.hxx
index c3a088897860..ff16fc3ed95b 100644
--- a/extensions/source/update/check/updatecheck.hxx
+++ b/extensions/source/update/check/updatecheck.hxx
@@ -114,6 +114,8 @@ public:
virtual void downloadProgressAt(sal_Int8 nProcent);
virtual void downloadStarted(const rtl::OUString& rLocalFileName, sal_Int64 nFileSize);
virtual void downloadFinished(const rtl::OUString& rLocalFileName);
+ // checks if the download target already exists and asks user what to do next
+ virtual bool checkDownloadDestination( const rtl::OUString& rFile );
// Cancels the download action (and resumes checking if enabled)
void cancelDownload();
diff --git a/extensions/source/update/check/updatehdl.cxx b/extensions/source/update/check/updatehdl.cxx
index 19ca5588c09c..01a404465e12 100644
--- a/extensions/source/update/check/updatehdl.cxx
+++ b/extensions/source/update/check/updatehdl.cxx
@@ -54,6 +54,7 @@
#include "com/sun/star/awt/XThrobber.hpp"
#include "com/sun/star/awt/XTopWindow.hpp"
#include "com/sun/star/awt/XVclWindowPeer.hpp"
+#include "com/sun/star/awt/XVclContainer.hpp"
#include "com/sun/star/awt/XWindow.hpp"
#include "com/sun/star/awt/XWindow2.hpp"
@@ -230,6 +231,11 @@ void UpdateHandler::setVisible( bool bVisible )
//--------------------------------------------------------------------
void UpdateHandler::setProgress( sal_Int32 nPercent )
{
+ if ( nPercent > 100 )
+ nPercent = 100;
+ else if ( nPercent < 0 )
+ nPercent = 0;
+
if ( nPercent != mnPercent )
{
osl::MutexGuard aGuard( maMutex );
@@ -705,6 +711,9 @@ void UpdateHandler::loadStrings()
msInstallError = loadString( xBundle, RID_UPDATE_STR_INSTALL_ERROR );
msOverwriteWarning = loadString( xBundle, RID_UPDATE_STR_OVERWRITE_WARNING );
msPercent = loadString( xBundle, RID_UPDATE_STR_PERCENT );
+ msReloadWarning = loadString( xBundle, RID_UPDATE_STR_RELOAD_WARNING );
+ msReloadReload = loadString( xBundle, RID_UPDATE_STR_RELOAD_RELOAD );
+ msReloadContinue = loadString( xBundle, RID_UPDATE_STR_RELOAD_CONTINUE );
msStatusFL = loadString( xBundle, RID_UPDATE_FT_STATUS );
msDescription = loadString( xBundle, RID_UPDATE_FT_DESCRIPTION );
@@ -957,6 +966,83 @@ bool UpdateHandler::showWarning( const rtl::OUString &rWarningText ) const
}
//--------------------------------------------------------------------
+bool UpdateHandler::showWarning( const rtl::OUString &rWarningText,
+ const rtl::OUString &rBtnText_1,
+ const rtl::OUString &rBtnText_2 ) const
+{
+ bool bRet = false;
+
+ uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
+ if ( !xControl.is() ) return bRet;
+
+ uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
+ if ( !xPeer.is() ) return bRet;
+
+ uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
+ if ( !xToolkit.is() ) return bRet;
+
+ awt::WindowDescriptor aDescriptor;
+
+ sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
+ nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
+ nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
+
+ aDescriptor.Type = awt::WindowClass_MODALTOP;
+ aDescriptor.WindowServiceName = UNISTRING( "warningbox" );
+ aDescriptor.ParentIndex = -1;
+ aDescriptor.Parent = xPeer;
+ aDescriptor.Bounds = awt::Rectangle( 10, 10, 250, 150 );
+ aDescriptor.WindowAttributes = nWindowAttributes;
+
+ uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
+ if ( xMsgBox.is() )
+ {
+ uno::Reference< awt::XVclContainer > xMsgBoxCtrls( xMsgBox, uno::UNO_QUERY );
+ if ( xMsgBoxCtrls.is() )
+ {
+ uno::Sequence< uno::Reference< awt::XWindow > > xChildren = xMsgBoxCtrls->getWindows();
+
+ for ( long i=0; i < xChildren.getLength(); i++ )
+ {
+ uno::Reference< awt::XVclWindowPeer > xMsgBoxCtrl( xChildren[i], uno::UNO_QUERY );
+ if ( xMsgBoxCtrl.is() )
+ {
+ bool bIsDefault = true;
+ uno::Any aValue = xMsgBoxCtrl->getProperty( UNISTRING("DefaultButton") );
+ aValue >>= bIsDefault;
+ if ( bIsDefault )
+ xMsgBoxCtrl->setProperty( UNISTRING("Text"), uno::Any( rBtnText_1 ) );
+ else
+ xMsgBoxCtrl->setProperty( UNISTRING("Text"), uno::Any( rBtnText_2 ) );
+ }
+ }
+ }
+
+ sal_Int16 nRet;
+ // xMsgBox->setCaptionText( msCancelTitle );
+ xMsgBox->setMessageText( rWarningText );
+ nRet = xMsgBox->execute();
+ if ( nRet == 2 ) // RET_YES == 2
+ bRet = true;
+ }
+
+ uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
+ if ( xComponent.is() )
+ xComponent->dispose();
+
+ return bRet;
+}
+
+//--------------------------------------------------------------------
+bool UpdateHandler::showOverwriteWarning( const rtl::OUString& rFileName ) const
+{
+ rtl::OUString aMsg( msReloadWarning );
+ searchAndReplaceAll( aMsg, UNISTRING( "%FILENAME" ), rFileName );
+ searchAndReplaceAll( aMsg, UNISTRING( "%DOWNLOAD_PATH" ), msDownloadPath );
+ return showWarning( aMsg, msReloadContinue, msReloadReload );
+}
+
+//--------------------------------------------------------------------
bool UpdateHandler::showOverwriteWarning() const
{
return showWarning( msOverwriteWarning );
diff --git a/extensions/source/update/check/updatehdl.hrc b/extensions/source/update/check/updatehdl.hrc
index 906a2e2a5db7..567269f97e52 100644
--- a/extensions/source/update/check/updatehdl.hrc
+++ b/extensions/source/update/check/updatehdl.hrc
@@ -50,6 +50,9 @@
#define RID_UPDATE_STR_PERCENT RID_UPDATE_HDL_START + 18
#define RID_UPDATE_STR_DOWNLOAD_DESCR RID_UPDATE_HDL_START + 19
#define RID_UPDATE_STR_INSTALL_ERROR RID_UPDATE_HDL_START + 20
+ #define RID_UPDATE_STR_RELOAD_WARNING RID_UPDATE_HDL_START + 21
+ #define RID_UPDATE_STR_RELOAD_RELOAD RID_UPDATE_HDL_START + 22
+ #define RID_UPDATE_STR_RELOAD_CONTINUE RID_UPDATE_HDL_START + 23
#define RID_UPDATE_FT_DESCRIPTION RID_UPDATE_HDL_START + 25
#define RID_UPDATE_FT_STATUS RID_UPDATE_HDL_START + 26
diff --git a/extensions/source/update/check/updatehdl.hxx b/extensions/source/update/check/updatehdl.hxx
index 9b33098f30f1..f54eca5008b8 100644
--- a/extensions/source/update/check/updatehdl.hxx
+++ b/extensions/source/update/check/updatehdl.hxx
@@ -128,6 +128,9 @@ private:
rtl::OUString msInstallError; // RID_UPDATE_STR_INSTALL_ERROR
rtl::OUString msOverwriteWarning; // RID_UPDATE_STR_OVERWRITE_WARNING
rtl::OUString msPercent; // RID_UPDATE_STR_PERCENT
+ rtl::OUString msReloadWarning; // RID_UPDATE_STR_OVERWRITE_WARNING
+ rtl::OUString msReloadReload; // RID_UPDATE_STR_OVERWRITE_WARNING
+ rtl::OUString msReloadContinue; // RID_UPDATE_STR_OVERWRITE_WARNING
rtl::OUString msStatusFL; // RID_UPDATE_FT_STATUS
rtl::OUString msDescription; // RID_UPDATE_FT_DESCRIPTION
rtl::OUString msClose; // RID_UPDATE_BTN_CLOSE
@@ -187,6 +190,8 @@ public:
rtl::OUString getBubbleTitle( UpdateState eState );
rtl::OUString getDefaultInstErrMsg();
bool showWarning( const rtl::OUString &rWarning ) const;
+ bool showWarning( const rtl::OUString &rWarning, const rtl::OUString& rBtnText_1, const rtl::OUString& rBtnText_2 ) const;
+ bool showOverwriteWarning( const rtl::OUString &rFileName ) const;
bool showOverwriteWarning() const;
// Allows runtime exceptions to be thrown by const methods
diff --git a/extensions/source/update/check/updatehdl.src b/extensions/source/update/check/updatehdl.src
index 7e846d3d9185..99e4a6dcbf59 100644
--- a/extensions/source/update/check/updatehdl.src
+++ b/extensions/source/update/check/updatehdl.src
@@ -125,6 +125,21 @@ String RID_UPDATE_STR_OVERWRITE_WARNING
Text [ en-US ] = "A file with that name already exists! Do you want to overwrite the existing file?";
};
+String RID_UPDATE_STR_RELOAD_WARNING
+{
+ Text [ en-US ] = "A file with the name '%FILENAME' already exists in '%DOWNLOAD_PATH'! Do you want to continue with the download or delete and reload the file?";
+};
+
+String RID_UPDATE_STR_RELOAD_RELOAD
+{
+ Text [ en-US ] = "Reload File";
+};
+
+String RID_UPDATE_STR_RELOAD_CONTINUE
+{
+ Text [ en-US ] = "Continue";
+};
+
String RID_UPDATE_STR_PERCENT
{
Text [ en-US ] = "%PERCENT%";