aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
Diffstat (limited to 'backends')
-rw-r--r--backends/cloud/cloudmanager.cpp (renamed from backends/cloud/manager.cpp)51
-rw-r--r--backends/cloud/cloudmanager.h87
-rw-r--r--backends/cloud/manager.h53
-rw-r--r--backends/cloud/onedrive/onedrivestorage.cpp9
-rw-r--r--backends/module.mk2
-rw-r--r--backends/platform/sdl/sdl.cpp6
6 files changed, 114 insertions, 94 deletions
diff --git a/backends/cloud/manager.cpp b/backends/cloud/cloudmanager.cpp
index 13424ba8c6..d18bb6ff9a 100644
--- a/backends/cloud/manager.cpp
+++ b/backends/cloud/cloudmanager.cpp
@@ -20,37 +20,33 @@
*
*/
-#include "backends/cloud/manager.h"
+#include "backends/cloud/cloudmanager.h"
#include "backends/cloud/dropbox/dropboxstorage.h"
#include "backends/cloud/onedrive/onedrivestorage.h"
#include "common/config-manager.h"
-#include "common/random.h"
#include "common/debug.h"
+namespace Common {
+
+DECLARE_SINGLETON(Cloud::CloudManager);
+
+}
+
namespace Cloud {
-Manager::Manager(): _currentStorageIndex(0), _deviceId(0) {}
+CloudManager::CloudManager() : _currentStorageIndex(0) {}
-Manager::~Manager() {
+CloudManager::~CloudManager() {
//TODO: do we have to save storages on manager destruction?
for (uint32 i = 0; i < _storages.size(); ++i)
delete _storages[i];
- _storages.clear();
+ _storages.clear();
}
-void Manager::init() {
+void CloudManager::init() {
bool offerDropbox = false;
bool offerOneDrive = true;
-
- if (!ConfMan.hasKey("device_id", "cloud")) {
- Common::RandomSource source("Cloud Random Source");
- _deviceId = source.getRandomNumber(UINT_MAX - 1);
- ConfMan.setInt("device_id", _deviceId, "cloud");
- ConfMan.flushToDisk();
- } else {
- _deviceId = ConfMan.getInt("device_id", "cloud");
- }
-
+
if (ConfMan.hasKey("storages_number", "cloud")) {
int storages = ConfMan.getInt("storages_number", "cloud");
for (int i = 1; i <= storages; ++i) {
@@ -80,50 +76,47 @@ void Manager::init() {
} else {
offerDropbox = true;
}
-
if (offerDropbox) {
//this is temporary console offer to auth with Dropbox
Dropbox::DropboxStorage::authThroughConsole();
- } else if(offerOneDrive) {
+ } else if (offerOneDrive) {
//OneDrive time
OneDrive::OneDriveStorage::authThroughConsole();
}
}
-void Manager::save() {
+void CloudManager::save() {
ConfMan.set("storages_number", Common::String::format("%d", _storages.size()), "cloud");
ConfMan.set("current_storage", Common::String::format("%d", _currentStorageIndex + 1), "cloud");
for (uint32 i = 0; i < _storages.size(); ++i)
- _storages[i]->saveConfig(Common::String::format("storage%d_", i+1));
+ _storages[i]->saveConfig(Common::String::format("storage%d_", i + 1));
ConfMan.flushToDisk();
}
-void Manager::addStorage(Cloud::Storage *storage, bool makeCurrent, bool saveConfig) {
- if (!storage) error("Cloud::Manager: NULL storage passed");
+void CloudManager::addStorage(Storage *storage, bool makeCurrent, bool saveConfig) {
+ if (!storage) error("Cloud::CloudManager: NULL storage passed");
_storages.push_back(storage);
if (makeCurrent) _currentStorageIndex = _storages.size() - 1;
if (saveConfig) save();
}
-Storage *Manager::getCurrentStorage() {
+Storage *CloudManager::getCurrentStorage() {
if (_currentStorageIndex < _storages.size())
return _storages[_currentStorageIndex];
return nullptr;
}
-void Manager::printBool(Storage::BoolResponse response) {
+void CloudManager::printBool(Storage::BoolResponse response) const {
debug("bool = %s", (response.value ? "true" : "false"));
}
-void Manager::syncSaves(Storage::BoolCallback callback, Networking::ErrorCallback errorCallback) {
+void CloudManager::syncSaves(Storage::BoolCallback callback, Networking::ErrorCallback errorCallback) {
Storage *storage = getCurrentStorage();
if (storage) storage->syncSaves(callback, errorCallback);
}
-void Manager::testFeature() {
+void CloudManager::testFeature() {
Storage *storage = getCurrentStorage();
- if (storage) storage->createDirectory("base/belong_to_us",
- new Common::Callback<Manager, Storage::BoolResponse>(this, &Manager::printBool), nullptr);
}
-} // End of namespace Cloud
+} // End of namespace Common
diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h
new file mode 100644
index 0000000000..a13eeebb94
--- /dev/null
+++ b/backends/cloud/cloudmanager.h
@@ -0,0 +1,87 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+
+#ifndef CLOUD_CLOUDMANAGER_H
+#define CLOUD_CLOUDMANAGER_H
+
+#include "backends/cloud/storage.h"
+#include "common/array.h"
+#include "common/singleton.h"
+
+namespace Cloud {
+
+class CloudManager : public Common::Singleton<CloudManager> {
+ Common::Array<Cloud::Storage *> _storages;
+ uint _currentStorageIndex;
+
+ void printBool(Cloud::Storage::BoolResponse response) const;
+
+public:
+ CloudManager();
+ virtual ~CloudManager();
+
+ /**
+ * Loads all information from configs and creates current Storage instance.
+ *
+ * @note It's called once on startup in scummvm_main().
+ */
+ void init();
+
+ /**
+ * Saves all information into configuration file.
+ */
+ void save();
+
+ /**
+ * Adds new Storage into list.
+ *
+ * @param storage Cloud::Storage to add.
+ * @param makeCurrent whether added storage should be the new current storage.
+ * @param saveConfig whether save() should be called to update configuration file.
+ */
+ void addStorage(Cloud::Storage *storage, bool makeCurrent = true, bool saveConfig = true);
+
+ /**
+ * Returns active Storage, which could be used to interact
+ * with cloud storage.
+ *
+ * @return active Cloud::Storage or null, if there is no active Storage.
+ */
+ Cloud::Storage *getCurrentStorage();
+
+ /**
+ * Starts saves syncing process in currently active storage if there is any.
+ */
+ void syncSaves(Cloud::Storage::BoolCallback callback = nullptr, Networking::ErrorCallback errorCallback = nullptr);
+
+ /**
+ * Starts feature testing (the one I'm working on currently). (Temporary)
+ */
+ void testFeature();
+};
+
+/** Shortcut for accessing the connection manager. */
+#define CloudMan Cloud::CloudManager::instance()
+
+} // End of namespace Cloud
+
+#endif
diff --git a/backends/cloud/manager.h b/backends/cloud/manager.h
deleted file mode 100644
index f68b33517d..0000000000
--- a/backends/cloud/manager.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
-*
-* ScummVM is the legal property of its developers, whose names
-* are too numerous to list here. Please refer to the COPYRIGHT
-* file distributed with this source distribution.
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*
-*/
-
-#ifndef BACKENDS_CLOUD_MANAGER_H
-#define BACKENDS_CLOUD_MANAGER_H
-
-#include "common/cloudmanager.h"
-#include "common/str.h"
-
-namespace Cloud {
-
-class Manager: public Common::CloudManager {
- Common::Array<Storage *> _storages;
- uint _currentStorageIndex;
- uint _deviceId;
-
- void printBool(Storage::BoolResponse response);
-
-public:
- Manager();
- virtual ~Manager();
-
- virtual void init();
- virtual void save();
- virtual void addStorage(Cloud::Storage *storage, bool makeCurrent = true, bool saveConfig = true);
-
- virtual Storage *getCurrentStorage();
- virtual void syncSaves(Storage::BoolCallback callback, Networking::ErrorCallback errorCallback);
- virtual void testFeature();
-};
-
-} // End of namespace Cloud
-
-#endif
diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp
index 98f0ac5a4d..ca8a2346ad 100644
--- a/backends/cloud/onedrive/onedrivestorage.cpp
+++ b/backends/cloud/onedrive/onedrivestorage.cpp
@@ -22,6 +22,7 @@
#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include "backends/cloud/onedrive/onedrivestorage.h"
+#include "backends/cloud/cloudmanager.h"
#include "backends/cloud/onedrive/onedrivecreatedirectoryrequest.h"
#include "backends/cloud/onedrive/onedrivetokenrefresher.h"
#include "backends/cloud/onedrive/onedrivelistdirectoryrequest.h"
@@ -29,11 +30,9 @@
#include "backends/networking/curl/connectionmanager.h"
#include "backends/networking/curl/curljsonrequest.h"
#include "backends/networking/curl/networkreadstream.h"
-#include "common/cloudmanager.h"
#include "common/config-manager.h"
#include "common/debug.h"
#include "common/json.h"
-#include "common/system.h"
#include <curl/curl.h>
namespace Cloud {
@@ -104,7 +103,7 @@ void OneDriveStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResp
_token = result.getVal("access_token")->asString();
_uid = result.getVal("user_id")->asString();
_refreshToken = result.getVal("refresh_token")->asString();
- g_system->getCloudManager()->save(); //ask CloudManager to save our new refreshToken
+ CloudMan.save(); //ask CloudManager to save our new refreshToken
if (callback) (*callback)(BoolResponse(nullptr, true));
}
delete json;
@@ -116,10 +115,10 @@ void OneDriveStorage::codeFlowComplete(BoolResponse response) {
return;
}
- g_system->getCloudManager()->addStorage(this);
+ CloudMan.addStorage(this);
ConfMan.removeKey("onedrive_code", "cloud");
debug("Done! You can use OneDrive now! Look:");
- g_system->getCloudManager()->syncSaves();
+ CloudMan.syncSaves();
}
void OneDriveStorage::saveConfig(Common::String keyPrefix) {
diff --git a/backends/module.mk b/backends/module.mk
index 4733509f24..40ccd17c78 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -21,8 +21,8 @@ MODULE_OBJS := \
ifdef USE_CLOUD
MODULE_OBJS += \
+ cloud/cloudmanager.o \
cloud/iso8601.o \
- cloud/manager.o \
cloud/storage.o \
cloud/storagefile.o \
cloud/downloadrequest.o \
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index acb4d999c3..dca6891fef 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -33,7 +33,6 @@
#include "gui/EventRecorder.h"
#include "common/taskbar.h"
#include "common/textconsole.h"
-#include "backends/cloud/manager.h"
#include "backends/saves/default/default-saves.h"
@@ -159,11 +158,6 @@ void OSystem_SDL::init() {
_taskbarManager = new Common::TaskbarManager();
#endif
-#if defined(USE_CLOUD)
- if (_cloudManager == 0)
- _cloudManager = new Cloud::Manager();
-#endif
-
}
void OSystem_SDL::initBackend() {