From a8eebbe8517bf75131af4d7846592ebcc7e79d25 Mon Sep 17 00:00:00 2001 From: Peter Bozsó Date: Tue, 14 Jun 2016 20:47:03 +0200 Subject: CLOUD: Get rid of CloudConfigHelper, use kCloudDomain where approriate --- backends/cloud/cloudconfighelper.cpp | 58 ----------------------- backends/cloud/cloudconfighelper.h | 49 ------------------- backends/cloud/cloudmanager.cpp | 39 +++++++++------ backends/cloud/dropbox/dropboxstorage.cpp | 25 +++++----- backends/cloud/googledrive/googledrivestorage.cpp | 28 +++++------ backends/cloud/onedrive/onedrivestorage.cpp | 36 +++++++------- 6 files changed, 70 insertions(+), 165 deletions(-) delete mode 100644 backends/cloud/cloudconfighelper.cpp delete mode 100644 backends/cloud/cloudconfighelper.h (limited to 'backends/cloud') diff --git a/backends/cloud/cloudconfighelper.cpp b/backends/cloud/cloudconfighelper.cpp deleted file mode 100644 index 8c31b1c770..0000000000 --- a/backends/cloud/cloudconfighelper.cpp +++ /dev/null @@ -1,58 +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. -* -*/ - -#include "backends/cloud/cloudconfighelper.h" -#include "common/config-manager.h" - -namespace Common { - -DECLARE_SINGLETON(Cloud::CloudConfigHelper); - -} - -namespace Cloud { - -bool CloudConfigHelper::hasKey(const Common::String &key) const { - return ConfMan.hasKey(key, ConfMan.kCloudDomain); -} - -void CloudConfigHelper::removeKey(const Common::String &key) { - ConfMan.removeKey(key, ConfMan.kCloudDomain); -} - -const Common::String &CloudConfigHelper::get(const Common::String &key) const { - return ConfMan.get(key, ConfMan.kCloudDomain); -} - -int CloudConfigHelper::getInt(const Common::String &key) const { - return ConfMan.getInt(key, ConfMan.kCloudDomain); -} - -void CloudConfigHelper::set(const Common::String &key, const Common::String &value) { - ConfMan.set(key, value, ConfMan.kCloudDomain); -} - -void CloudConfigHelper::flushToDisk() { - ConfMan.flushToDisk(); -} - -} // End of namespace Cloud diff --git a/backends/cloud/cloudconfighelper.h b/backends/cloud/cloudconfighelper.h deleted file mode 100644 index efa8792190..0000000000 --- a/backends/cloud/cloudconfighelper.h +++ /dev/null @@ -1,49 +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 CLOUD_CLOUDCONFIGHELPER_H -#define CLOUD_CLOUDCONFIGHELPER_H - -#include "common/singleton.h" -#include "common/str.h" - -namespace Cloud { - -/** - * Convenience wrapper around ConfMan for the cloud backend. - */ -class CloudConfigHelper : public Common::Singleton { -public: - bool hasKey(const Common::String &key) const; - void removeKey(const Common::String &key); - const Common::String &get(const Common::String &key) const; - int getInt(const Common::String &key) const; - void set(const Common::String &key, const Common::String &value); - void flushToDisk(); -}; - -/** Shortcut for accessing the cloud configuration helper. */ -#define CloudConfig Cloud::CloudConfigHelper::instance() - -} // End of namespace Cloud - -#endif diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp index a6f5575b3a..19551213cd 100644 --- a/backends/cloud/cloudmanager.cpp +++ b/backends/cloud/cloudmanager.cpp @@ -26,7 +26,8 @@ #include "backends/cloud/googledrive/googledrivestorage.h" #include "common/debug.h" #include "common/translation.h" -#include "backends/cloud/cloudconfighelper.h" +#include "common/config-manager.h" +#include "common/str.h" namespace Common { @@ -77,6 +78,9 @@ void CloudManager::loadStorage() { } void CloudManager::init() { + Common::String oldDomain = ConfMan.getActiveDomainName(); + ConfMan.setActiveDomain(ConfMan.kCloudDomain); + //init configs structs for (uint32 i = 0; i < kStorageTotal; ++i) { Common::String name = getStorageConfigName(i); @@ -85,36 +89,43 @@ void CloudManager::init() { config.username = ""; config.lastSyncDate = ""; config.usedBytes = 0; - if (CloudConfig.hasKey(kStoragePrefix + name + "_username")) - config.username = CloudConfig.get(kStoragePrefix + name + "_username"); - if (CloudConfig.hasKey(kStoragePrefix + name + "_lastSync")) - config.lastSyncDate = CloudConfig.get(kStoragePrefix + name + "_lastSync"); - if (CloudConfig.hasKey(kStoragePrefix + name + "_usedBytes")) - config.usedBytes = CloudConfig.get(kStoragePrefix + name + "_usedBytes").asUint64(); + if (ConfMan.hasKey(kStoragePrefix + name + "_username")) + config.username = ConfMan.get(kStoragePrefix + name + "_username"); + if (ConfMan.hasKey(kStoragePrefix + name + "_lastSync")) + config.lastSyncDate = ConfMan.get(kStoragePrefix + name + "_lastSync"); + if (ConfMan.hasKey(kStoragePrefix + name + "_usedBytes")) + config.usedBytes = ConfMan.get(kStoragePrefix + name + "_usedBytes").asUint64(); _storages.push_back(config); } //load an active storage if there is any _currentStorageIndex = kStorageNoneId; - if (CloudConfig.hasKey("current_storage")) - _currentStorageIndex = CloudConfig.getInt("current_storage"); + if (ConfMan.hasKey("current_storage")) + _currentStorageIndex = ConfMan.getInt("current_storage"); loadStorage(); + + ConfMan.setActiveDomain(oldDomain); } void CloudManager::save() { + Common::String oldDomain = ConfMan.getActiveDomainName(); + ConfMan.setActiveDomain(ConfMan.kCloudDomain); + for (uint32 i = 0; i < _storages.size(); ++i) { if (i == kStorageNoneId) continue; Common::String name = getStorageConfigName(i); - CloudConfig.set(kStoragePrefix + name + "_username", _storages[i].username); - CloudConfig.set(kStoragePrefix + name + "_lastSync", _storages[i].lastSyncDate); - CloudConfig.set(kStoragePrefix + name + "_usedBytes", Common::String::format("%llu", _storages[i].usedBytes)); + ConfMan.set(kStoragePrefix + name + "_username", _storages[i].username); + ConfMan.set(kStoragePrefix + name + "_lastSync", _storages[i].lastSyncDate); + ConfMan.set(kStoragePrefix + name + "_usedBytes", Common::String::format("%llu", _storages[i].usedBytes)); } - CloudConfig.set("current_storage", Common::String::format("%d", _currentStorageIndex)); + ConfMan.set("current_storage", Common::String::format("%d", _currentStorageIndex)); if (_activeStorage) _activeStorage->saveConfig(kStoragePrefix + getStorageConfigName(_currentStorageIndex) + "_"); - CloudConfig.flushToDisk(); + ConfMan.flushToDisk(); + + ConfMan.setActiveDomain(oldDomain); } void CloudManager::replaceStorage(Storage *storage, uint32 index) { diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index d77e958da7..64425812db 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -31,7 +31,7 @@ #include "common/debug.h" #include "common/json.h" #include -#include "backends/cloud/cloudconfighelper.h" +#include "common/config-manager.h" namespace Cloud { namespace Dropbox { @@ -40,12 +40,12 @@ char *DropboxStorage::KEY = nullptr; //can't use CloudConfig there yet, loading char *DropboxStorage::SECRET = nullptr; //TODO: hide these secrets somehow void DropboxStorage::loadKeyAndSecret() { - Common::String k = CloudConfig.get("DROPBOX_KEY"); + Common::String k = ConfMan.get("DROPBOX_KEY", ConfMan.kCloudDomain); KEY = new char[k.size() + 1]; memcpy(KEY, k.c_str(), k.size()); KEY[k.size()] = 0; - k = CloudConfig.get("DROPBOX_SECRET"); + k = ConfMan.get("DROPBOX_SECRET", ConfMan.kCloudDomain); SECRET = new char[k.size() + 1]; memcpy(SECRET, k.c_str(), k.size()); SECRET[k.size()] = 0; @@ -81,9 +81,9 @@ void DropboxStorage::codeFlowComplete(Networking::JsonResponse response) { } else { _token = result.getVal("access_token")->asString(); _uid = result.getVal("uid")->asString(); - CloudConfig.removeKey("dropbox_code"); + ConfMan.removeKey("dropbox_code", ConfMan.kCloudDomain); CloudMan.replaceStorage(this, kStorageDropboxId); - CloudConfig.flushToDisk(); + ConfMan.flushToDisk(); } delete json; @@ -92,9 +92,9 @@ void DropboxStorage::codeFlowComplete(Networking::JsonResponse response) { } } -void DropboxStorage::saveConfig(Common::String keyPrefix) { - CloudConfig.set(keyPrefix + "access_token", _token); - CloudConfig.set(keyPrefix + "user_id", _uid); +void DropboxStorage::saveConfig(Common::String keyPrefix) { + ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain); + ConfMan.set(keyPrefix + "user_id", _uid, ConfMan.kCloudDomain); } Common::String DropboxStorage::name() const { @@ -198,18 +198,19 @@ void DropboxStorage::infoMethodCallback(StorageInfoResponse response) { DropboxStorage *DropboxStorage::loadFromConfig(Common::String keyPrefix) { loadKeyAndSecret(); - if (!CloudConfig.hasKey(keyPrefix + "access_token")) { + if (!ConfMan.hasKey(keyPrefix + "access_token", ConfMan.kCloudDomain)) { warning("No access_token found"); return 0; } - if (!CloudConfig.hasKey(keyPrefix + "user_id")) { + if (!ConfMan.hasKey(keyPrefix + "user_id", ConfMan.kCloudDomain)) { warning("No user_id found"); return 0; } - Common::String accessToken = CloudConfig.get(keyPrefix + "access_token"); - Common::String userId = CloudConfig.get(keyPrefix + "user_id"); + Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); + Common::String userId = ConfMan.get(keyPrefix + "user_id", ConfMan.kCloudDomain); + return new DropboxStorage(accessToken, userId); } diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp index 1e31121d6c..6d0a152938 100644 --- a/backends/cloud/googledrive/googledrivestorage.cpp +++ b/backends/cloud/googledrive/googledrivestorage.cpp @@ -37,7 +37,7 @@ #include "googledrivestreamfilerequest.h" #include "googledrivedownloadrequest.h" #include "googledriveuploadrequest.h" -#include "backends/cloud/cloudconfighelper.h" +#include "common/config-manager.h" namespace Cloud { namespace GoogleDrive { @@ -46,12 +46,12 @@ char *GoogleDriveStorage::KEY = nullptr; //can't use CloudConfig there yet, load char *GoogleDriveStorage::SECRET = nullptr; //TODO: hide these secrets somehow void GoogleDriveStorage::loadKeyAndSecret() { - Common::String k = CloudConfig.get("GOOGLE_DRIVE_KEY"); + Common::String k = ConfMan.get("GOOGLE_DRIVE_KEY", ConfMan.kCloudDomain); KEY = new char[k.size() + 1]; memcpy(KEY, k.c_str(), k.size()); KEY[k.size()] = 0; - k = CloudConfig.get("GOOGLE_DRIVE_SECRET"); + k = ConfMan.get("GOOGLE_DRIVE_SECRET", ConfMan.kCloudDomain); SECRET = new char[k.size() + 1]; memcpy(SECRET, k.c_str(), k.size()); SECRET[k.size()] = 0; @@ -122,14 +122,14 @@ void GoogleDriveStorage::codeFlowComplete(BoolResponse response) { return; } - CloudConfig.removeKey("googledrive_code"); + ConfMan.removeKey("googledrive_code", ConfMan.kCloudDomain); CloudMan.replaceStorage(this, kStorageGoogleDriveId); - CloudConfig.flushToDisk(); + ConfMan.flushToDisk(); } void GoogleDriveStorage::saveConfig(Common::String keyPrefix) { - CloudConfig.set(keyPrefix + "access_token", _token); - CloudConfig.set(keyPrefix + "refresh_token", _refreshToken); + ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain); + ConfMan.set(keyPrefix + "refresh_token", _refreshToken, ConfMan.kCloudDomain); } Common::String GoogleDriveStorage::name() const { @@ -337,18 +337,18 @@ Common::String GoogleDriveStorage::savesDirectoryPath() { return "scummvm/saves/ GoogleDriveStorage *GoogleDriveStorage::loadFromConfig(Common::String keyPrefix) { loadKeyAndSecret(); - if (!CloudConfig.hasKey(keyPrefix + "access_token")) { + if (!ConfMan.hasKey(keyPrefix + "access_token", ConfMan.kCloudDomain)) { warning("No access_token found"); return 0; } - if (!CloudConfig.hasKey(keyPrefix + "refresh_token")) { + if (!ConfMan.hasKey(keyPrefix + "refresh_token", ConfMan.kCloudDomain)) { warning("No refresh_token found"); return 0; } - Common::String accessToken = CloudConfig.get(keyPrefix + "access_token"); - Common::String refreshToken = CloudConfig.get(keyPrefix + "refresh_token"); + Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); + Common::String refreshToken = ConfMan.get(keyPrefix + "refresh_token", ConfMan.kCloudDomain); return new GoogleDriveStorage(accessToken, refreshToken); } @@ -363,16 +363,16 @@ Common::String GoogleDriveStorage::getAuthLink() { } void GoogleDriveStorage::authThroughConsole() { - if (!CloudConfig.hasKey("GOOGLE_DRIVE_KEY") || !CloudConfig.hasKey("GOOGLE_DRIVE_SECRET")) { + if (!ConfMan.hasKey("GOOGLE_DRIVE_KEY", ConfMan.kCloudDomain) || !ConfMan.hasKey("GOOGLE_DRIVE_SECRET", ConfMan.kCloudDomain)) { warning("No Google Drive keys available, cannot do auth"); return; } loadKeyAndSecret(); - if (CloudConfig.hasKey("googledrive_code")) { + if (ConfMan.hasKey("googledrive_code", ConfMan.kCloudDomain)) { //phase 2: get access_token using specified code - new GoogleDriveStorage(CloudConfig.get("googledrive_code")); + new GoogleDriveStorage(ConfMan.get("googledrive_code", ConfMan.kCloudDomain)); return; } diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp index b91d1cdce1..5c230366a8 100644 --- a/backends/cloud/onedrive/onedrivestorage.cpp +++ b/backends/cloud/onedrive/onedrivestorage.cpp @@ -33,7 +33,7 @@ #include "common/debug.h" #include "common/json.h" #include -#include "backends/cloud/cloudconfighelper.h" +#include "common/config-manager.h" namespace Cloud { namespace OneDrive { @@ -42,12 +42,12 @@ char *OneDriveStorage::KEY = nullptr; //can't use CloudConfig there yet, loading char *OneDriveStorage::SECRET = nullptr; //TODO: hide these secrets somehow void OneDriveStorage::loadKeyAndSecret() { - Common::String k = CloudConfig.get("ONEDRIVE_KEY"); + Common::String k = ConfMan.get("ONEDRIVE_KEY", ConfMan.kCloudDomain); KEY = new char[k.size() + 1]; memcpy(KEY, k.c_str(), k.size()); KEY[k.size()] = 0; - k = CloudConfig.get("ONEDRIVE_SECRET"); + k = ConfMan.get("ONEDRIVE_SECRET", ConfMan.kCloudDomain); SECRET = new char[k.size() + 1]; memcpy(SECRET, k.c_str(), k.size()); SECRET[k.size()] = 0; @@ -116,15 +116,15 @@ void OneDriveStorage::codeFlowComplete(BoolResponse response) { return; } - CloudConfig.removeKey("onedrive_code"); + ConfMan.removeKey("onedrive_code", ConfMan.kCloudDomain); CloudMan.replaceStorage(this, kStorageOneDriveId); - CloudConfig.flushToDisk(); + ConfMan.flushToDisk(); } -void OneDriveStorage::saveConfig(Common::String keyPrefix) { - CloudConfig.set(keyPrefix + "access_token", _token); - CloudConfig.set(keyPrefix + "user_id", _uid); - CloudConfig.set(keyPrefix + "refresh_token", _refreshToken); +void OneDriveStorage::saveConfig(Common::String keyPrefix) { + ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain); + ConfMan.set(keyPrefix + "user_id", _uid, ConfMan.kCloudDomain); + ConfMan.set(keyPrefix + "refresh_token", _refreshToken, ConfMan.kCloudDomain); } Common::String OneDriveStorage::name() const { @@ -260,24 +260,24 @@ Common::String OneDriveStorage::savesDirectoryPath() { return "saves/"; } OneDriveStorage *OneDriveStorage::loadFromConfig(Common::String keyPrefix) { loadKeyAndSecret(); - if (!CloudConfig.hasKey(keyPrefix + "access_token")) { + if (!ConfMan.hasKey(keyPrefix + "access_token", ConfMan.kCloudDomain)) { warning("No access_token found"); return 0; } - if (!CloudConfig.hasKey(keyPrefix + "user_id")) { + if (!ConfMan.hasKey(keyPrefix + "user_id", ConfMan.kCloudDomain)) { warning("No user_id found"); return 0; } - if (!CloudConfig.hasKey(keyPrefix + "refresh_token")) { + if (!ConfMan.hasKey(keyPrefix + "refresh_token", ConfMan.kCloudDomain)) { warning("No refresh_token found"); return 0; } - Common::String accessToken = CloudConfig.get(keyPrefix + "access_token"); - Common::String userId = CloudConfig.get(keyPrefix + "user_id"); - Common::String refreshToken = CloudConfig.get(keyPrefix + "refresh_token"); + Common::String accessToken = ConfMan.get(keyPrefix + "access_token", ConfMan.kCloudDomain); + Common::String userId = ConfMan.get(keyPrefix + "user_id", ConfMan.kCloudDomain); + Common::String refreshToken = ConfMan.get(keyPrefix + "refresh_token", ConfMan.kCloudDomain); return new OneDriveStorage(accessToken, userId, refreshToken); } @@ -292,16 +292,16 @@ Common::String OneDriveStorage::getAuthLink() { } void OneDriveStorage::authThroughConsole() { - if (!CloudConfig.hasKey("ONEDRIVE_KEY") || !CloudConfig.hasKey("ONEDRIVE_SECRET")) { + if (!ConfMan.hasKey("ONEDRIVE_KEY", ConfMan.kCloudDomain) || !ConfMan.hasKey("ONEDRIVE_SECRET", ConfMan.kCloudDomain)) { warning("No OneDrive keys available, cannot do auth"); return; } loadKeyAndSecret(); - if (CloudConfig.hasKey("onedrive_code")) { + if (ConfMan.hasKey("onedrive_code", ConfMan.kCloudDomain)) { //phase 2: get access_token using specified code - new OneDriveStorage(CloudConfig.get("onedrive_code")); + new OneDriveStorage(ConfMan.get("onedrive_code", ConfMan.kCloudDomain)); return; } -- cgit v1.2.3