aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud/storage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backends/cloud/storage.cpp')
-rw-r--r--backends/cloud/storage.cpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index f035c93368..95786c2cba 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -30,7 +30,7 @@
namespace Cloud {
-Storage::Storage(): _runningRequestsCount(0) {}
+Storage::Storage(): _runningRequestsCount(0), _savesSyncRequest(nullptr) {}
Storage::~Storage() {}
@@ -53,6 +53,8 @@ Networking::Request *Storage::addRequest(Networking::Request *request) {
void Storage::requestFinishedCallback(Networking::Request *invalidRequestPointer) {
_runningRequestsMutex.lock();
+ if (invalidRequestPointer == _savesSyncRequest)
+ _savesSyncRequest = nullptr;
--_runningRequestsCount;
if (_runningRequestsCount == 0) debug("Storage is not working now");
_runningRequestsMutex.unlock();
@@ -96,8 +98,16 @@ Networking::Request *Storage::downloadFolder(Common::String remotePath, Common::
}
Networking::Request *Storage::syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) {
+ _runningRequestsMutex.lock();
+ if (_savesSyncRequest) {
+ warning("Storage::syncSaves: there is a sync in progress already");
+ _runningRequestsMutex.unlock();
+ return _savesSyncRequest;
+ }
if (!errorCallback) errorCallback = getErrorPrintingCallback();
- return addRequest(new SavesSyncRequest(this, callback, errorCallback));
+ _savesSyncRequest = new SavesSyncRequest(this, callback, errorCallback);
+ _runningRequestsMutex.unlock();
+ return addRequest(_savesSyncRequest);
}
bool Storage::isWorking() {
@@ -107,5 +117,30 @@ bool Storage::isWorking() {
return working;
}
+bool Storage::isSyncing() {
+ _runningRequestsMutex.lock();
+ bool syncing = _savesSyncRequest != nullptr;
+ _runningRequestsMutex.unlock();
+ return syncing;
+}
+
+double Storage::getSyncProgress() {
+ double result = 1;
+ _runningRequestsMutex.lock();
+ if (_savesSyncRequest)
+ result = _savesSyncRequest->getProgress();
+ _runningRequestsMutex.unlock();
+ return result;
+}
+
+Common::Array<Common::String> Storage::getSyncingFiles() {
+ Common::Array<Common::String> result;
+ _runningRequestsMutex.lock();
+ if (_savesSyncRequest)
+ result = _savesSyncRequest->getFilesToUpload();
+ _runningRequestsMutex.unlock();
+ return result;
+}
+
} // End of namespace Cloud