diff options
Diffstat (limited to 'backends')
-rw-r--r-- | backends/cloud/cloudmanager.cpp | 10 | ||||
-rw-r--r-- | backends/cloud/cloudmanager.h | 12 | ||||
-rw-r--r-- | backends/cloud/savessyncrequest.cpp | 10 | ||||
-rw-r--r-- | backends/cloud/storage.cpp | 14 | ||||
-rw-r--r-- | backends/cloud/storage.h | 12 |
5 files changed, 57 insertions, 1 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp index b4598d7a97..f5d60e025c 100644 --- a/backends/cloud/cloudmanager.cpp +++ b/backends/cloud/cloudmanager.cpp @@ -151,4 +151,14 @@ Common::Array<Common::String> CloudManager::getSyncingFiles() { return Common::Array<Common::String>(); } +void CloudManager::cancelSync() { + Storage *storage = getCurrentStorage(); + if (storage) storage->cancelSync(); +} + +void CloudManager::setSyncTarget(GUI::CommandReceiver *target) { + Storage *storage = getCurrentStorage(); + if (storage) storage->setSyncTarget(target); +} + } // End of namespace Common diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h index a02dc90008..c7351dab2e 100644 --- a/backends/cloud/cloudmanager.h +++ b/backends/cloud/cloudmanager.h @@ -27,6 +27,12 @@ #include "common/array.h" #include "common/singleton.h" +namespace GUI { + +class CommandReceiver; + +} + namespace Cloud { class CloudManager : public Common::Singleton<CloudManager> { @@ -89,6 +95,12 @@ public: /** Returns an array of saves names which are not yet synced (thus cannot be used). */ Common::Array<Common::String> getSyncingFiles(); + + /** Cancels running sync. */ + void cancelSync(); + + /** Sets SavesSyncRequest's target to given CommandReceiver. */ + void setSyncTarget(GUI::CommandReceiver *target); }; /** Shortcut for accessing the connection manager. */ diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp index a99c229925..e066c53a92 100644 --- a/backends/cloud/savessyncrequest.cpp +++ b/backends/cloud/savessyncrequest.cpp @@ -24,14 +24,19 @@ #include "common/config-manager.h" #include "common/debug.h" #include "common/file.h" +#include "common/json.h" #include "common/savefile.h" #include "common/system.h" -#include <common/json.h> namespace Cloud { const char *SavesSyncRequest::TIMESTAMPS_FILENAME = "timestamps"; +enum { + kSavesSyncProgressCmd = 'SSPR', + kSavesSyncEndedCmd = 'SSEN' +}; + SavesSyncRequest::SavesSyncRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb): Request(nullptr, ecb), CommandSender(nullptr), _storage(storage), _boolCallback(callback), _workingRequest(nullptr), _ignoreCallback(false) { @@ -203,10 +208,13 @@ void SavesSyncRequest::directoryCreatedErrorCallback(Networking::ErrorResponse e void SavesSyncRequest::downloadNextFile() { if (_filesToDownload.empty()) { + sendCommand(kSavesSyncEndedCmd, 0); uploadNextFile(); return; } + sendCommand(kSavesSyncProgressCmd, (int)(getProgress() * 100)); + _currentDownloadingFile = _filesToDownload.back(); _filesToDownload.pop_back(); diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp index 19f0845c47..c98310d3dd 100644 --- a/backends/cloud/storage.cpp +++ b/backends/cloud/storage.cpp @@ -142,5 +142,19 @@ Common::Array<Common::String> Storage::getSyncingFiles() { return result; } +void Storage::cancelSync() { + _runningRequestsMutex.lock(); + if (_savesSyncRequest) + _savesSyncRequest->finish(); + _runningRequestsMutex.unlock(); +} + +void Storage::setSyncTarget(GUI::CommandReceiver *target) { + _runningRequestsMutex.lock(); + if (_savesSyncRequest) + _savesSyncRequest->setTarget(target); + _runningRequestsMutex.unlock(); +} + } // End of namespace Cloud diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h index 5941fe4a32..40ea14a3a1 100644 --- a/backends/cloud/storage.h +++ b/backends/cloud/storage.h @@ -33,6 +33,12 @@ #include "common/stream.h" #include "common/str.h" +namespace GUI { + +class CommandReceiver; + +} + namespace Cloud { class SavesSyncRequest; @@ -146,6 +152,12 @@ public: /** Returns an array of saves names which are not yet synced (thus cannot be used). */ virtual Common::Array<Common::String> getSyncingFiles(); + + /** Cancels running sync. */ + virtual void cancelSync(); + + /** Sets SavesSyncRequest's target to given CommandReceiver. */ + virtual void setSyncTarget(GUI::CommandReceiver *target); }; } // End of namespace Cloud |