aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud
diff options
context:
space:
mode:
Diffstat (limited to 'backends/cloud')
-rw-r--r--backends/cloud/cloudmanager.cpp6
-rw-r--r--backends/cloud/cloudmanager.h3
-rw-r--r--backends/cloud/savessyncrequest.cpp16
-rw-r--r--backends/cloud/savessyncrequest.h3
-rw-r--r--backends/cloud/storage.cpp9
-rw-r--r--backends/cloud/storage.h3
6 files changed, 39 insertions, 1 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). */