diff options
author | Alexander Tkachev | 2016-06-05 21:07:55 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 0ce7be17d3fec380f726c1ff16c559344b3e24c1 (patch) | |
tree | b815b220629a466e0286f02c91d36a529057f25e | |
parent | 3db80154d60c98fe27018dc78c875df52c20cfe9 (diff) | |
download | scummvm-rg350-0ce7be17d3fec380f726c1ff16c559344b3e24c1.tar.gz scummvm-rg350-0ce7be17d3fec380f726c1ff16c559344b3e24c1.tar.bz2 scummvm-rg350-0ce7be17d3fec380f726c1ff16c559344b3e24c1.zip |
CLOUD: Make ProgressDialog display downloading progress
-rw-r--r-- | backends/cloud/cloudmanager.cpp | 6 | ||||
-rw-r--r-- | backends/cloud/cloudmanager.h | 3 | ||||
-rw-r--r-- | backends/cloud/savessyncrequest.cpp | 16 | ||||
-rw-r--r-- | backends/cloud/savessyncrequest.h | 3 | ||||
-rw-r--r-- | backends/cloud/storage.cpp | 9 | ||||
-rw-r--r-- | backends/cloud/storage.h | 3 | ||||
-rw-r--r-- | gui/saveload-dialog.cpp | 2 |
7 files changed, 40 insertions, 2 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp index f5d60e025c..4230c1453b 100644 --- a/backends/cloud/cloudmanager.cpp +++ b/backends/cloud/cloudmanager.cpp @@ -139,6 +139,12 @@ bool CloudManager::isSyncing() { return false; } +double CloudManager::getSyncDownloadingProgress() { + Storage *storage = getCurrentStorage(); + if (storage) return storage->getSyncDownloadingProgress(); + return 1; +} + double CloudManager::getSyncProgress() { Storage *storage = getCurrentStorage(); if (storage) return storage->getSyncProgress(); diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h index c7351dab2e..dbff0184eb 100644 --- a/backends/cloud/cloudmanager.h +++ b/backends/cloud/cloudmanager.h @@ -90,6 +90,9 @@ public: /** Returns whether there is a SavesSyncRequest running. */ bool isSyncing(); + /** Returns a number in [0, 1] range which represents current sync downloading progress (1 = complete). */ + double getSyncDownloadingProgress(); + /** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */ double getSyncProgress(); diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp index e066c53a92..072685773e 100644 --- a/backends/cloud/savessyncrequest.cpp +++ b/backends/cloud/savessyncrequest.cpp @@ -208,12 +208,13 @@ void SavesSyncRequest::directoryCreatedErrorCallback(Networking::ErrorResponse e void SavesSyncRequest::downloadNextFile() { if (_filesToDownload.empty()) { + _currentDownloadingFile = StorageFile("", 0, 0, false); //so getFilesToDownload() would return an empty array sendCommand(kSavesSyncEndedCmd, 0); uploadNextFile(); return; } - sendCommand(kSavesSyncProgressCmd, (int)(getProgress() * 100)); + sendCommand(kSavesSyncProgressCmd, (int)(getDownloadingProgress() * 100)); _currentDownloadingFile = _filesToDownload.back(); _filesToDownload.pop_back(); @@ -295,6 +296,19 @@ void SavesSyncRequest::handle() {} void SavesSyncRequest::restart() { start(); } +double SavesSyncRequest::getDownloadingProgress() { + if (_totalFilesToHandle == 0) { + if (_state == Networking::FINISHED) return 1; //nothing to upload and download => Request ends soon + return 0; //directory not listed yet + } + + if (_totalFilesToHandle == _filesToUpload.size()) return 1; //nothing to download => download complete + + uint32 totalFilesToDownload = _totalFilesToHandle - _filesToUpload.size(); + uint32 filesLeftToDownload = _filesToDownload.size() + (_currentDownloadingFile.name() != "" ? 1 : 0); + return (double)(totalFilesToDownload - filesLeftToDownload) / (double)(totalFilesToDownload); +} + double SavesSyncRequest::getProgress() { if (_totalFilesToHandle == 0) { if (_state == Networking::FINISHED) return 1; //nothing to upload and download => Request ends soon diff --git a/backends/cloud/savessyncrequest.h b/backends/cloud/savessyncrequest.h index 397a8cbcac..569feb4e45 100644 --- a/backends/cloud/savessyncrequest.h +++ b/backends/cloud/savessyncrequest.h @@ -70,6 +70,9 @@ public: virtual void restart(); /** Returns a number in range [0, 1], where 1 is "complete". */ + double getDownloadingProgress(); + + /** Returns a number in range [0, 1], where 1 is "complete". */ double getProgress(); /** Returns an array of saves names which are not downloaded yet. */ diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp index c98310d3dd..5458276e39 100644 --- a/backends/cloud/storage.cpp +++ b/backends/cloud/storage.cpp @@ -124,6 +124,15 @@ bool Storage::isSyncing() { return syncing; } +double Storage::getSyncDownloadingProgress() { + double result = 1; + _runningRequestsMutex.lock(); + if (_savesSyncRequest) + result = _savesSyncRequest->getDownloadingProgress(); + _runningRequestsMutex.unlock(); + return result; +} + double Storage::getSyncProgress() { double result = 1; _runningRequestsMutex.lock(); diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h index 40ea14a3a1..058e831e5d 100644 --- a/backends/cloud/storage.h +++ b/backends/cloud/storage.h @@ -148,6 +148,9 @@ public: virtual bool isSyncing(); /** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */ + virtual double getSyncDownloadingProgress(); + + /** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */ virtual double getSyncProgress(); /** Returns an array of saves names which are not yet synced (thus cannot be used). */ diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp index bdae9efea4..6d343c88ed 100644 --- a/gui/saveload-dialog.cpp +++ b/gui/saveload-dialog.cpp @@ -52,7 +52,7 @@ SaveLoadCloudSyncProgressDialog::SaveLoadCloudSyncProgressDialog(): Dialog(10, 1 int buttonWidth = 140; int marginBottom = 8; - uint32 progress = (uint32)(100 * CloudMan.getSyncProgress()); + uint32 progress = (uint32)(100 * CloudMan.getSyncDownloadingProgress()); _label = new StaticTextWidget(this, 10, 10, 300, kLineHeight, Common::String::format("Downloading saves (%u%% complete)...", progress), Graphics::kTextAlignCenter); //if (defaultButton) |