From f6a17e679f4fac2fda21dc7f64565a0dc4a10ca1 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sat, 27 Jul 2019 22:44:15 +0700 Subject: CLOUD: Ask user to manually enable Storage For more security, newly connected Storage only gets username/used space information and is disabled until user manually presses the button. --- backends/cloud/storage.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'backends/cloud/storage.cpp') diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp index 3a9ae53a43..ed7f8f0ae7 100644 --- a/backends/cloud/storage.cpp +++ b/backends/cloud/storage.cpp @@ -34,10 +34,18 @@ namespace Cloud { Storage::Storage(): _runningRequestsCount(0), _savesSyncRequest(nullptr), _syncRestartRequestsed(false), - _downloadFolderRequest(nullptr) {} + _downloadFolderRequest(nullptr), _isEnabled(false) {} Storage::~Storage() {} +bool Storage::isEnabled() const { + return _isEnabled; +} + +void Storage::enable() { + _isEnabled = true; +} + Networking::ErrorCallback Storage::getErrorPrintingCallback() { return new Common::Callback(this, &Storage::printErrorResponse); } @@ -121,6 +129,12 @@ Networking::Request *Storage::downloadById(Common::String remoteId, Common::Stri } Networking::Request *Storage::downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive) { + if (!_isEnabled) { + warning("Storage::downloadFolder: cannot be run while Storage is disabled"); + if (errorCallback) + (*errorCallback)(Networking::ErrorResponse(nullptr, false, true, "Storage is disabled.", -1)); + return nullptr; + } if (!errorCallback) errorCallback = getErrorPrintingCallback(); return addRequest(new FolderDownloadRequest(this, callback, errorCallback, remotePath, localPath, recursive)); @@ -128,6 +142,13 @@ Networking::Request *Storage::downloadFolder(Common::String remotePath, Common:: SavesSyncRequest *Storage::syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) { _runningRequestsMutex.lock(); + if (!_isEnabled) { + warning("Storage::syncSaves: cannot be run while Storage is disabled"); + if (errorCallback) + (*errorCallback)(Networking::ErrorResponse(nullptr, false, true, "Storage is disabled.", -1)); + _runningRequestsMutex.unlock(); + return nullptr; + } if (_savesSyncRequest) { warning("Storage::syncSaves: there is a sync in progress already"); _syncRestartRequestsed = true; -- cgit v1.2.3