diff options
author | Alexander Tkachev | 2016-05-23 11:23:33 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 41e65db7d0468b01f626c6ce21a1b8e6791f58fa (patch) | |
tree | b8ea4bbd60950c5f58e323b4c504b4be13b07493 /backends/cloud/dropbox | |
parent | c4b1fdc72752516a81b83490035d8f71357d045b (diff) | |
download | scummvm-rg350-41e65db7d0468b01f626c6ce21a1b8e6791f58fa.tar.gz scummvm-rg350-41e65db7d0468b01f626c6ce21a1b8e6791f58fa.tar.bz2 scummvm-rg350-41e65db7d0468b01f626c6ce21a1b8e6791f58fa.zip |
CLOUD: Add Storage saving mechanism
In this commit CloudManager starts supporting multiple Storage. Now, in
its init() it loads all the Storages and determines the current one.
It now also has save() method. In that method all Storages are saved
with their new saveConfig() method.
CloudManager::save() not called from anywhere, though. The only one
Storage that could be added is DropboxStorage in case you have no
cloud-related config keys or you have no storages connected.
Diffstat (limited to 'backends/cloud/dropbox')
-rw-r--r-- | backends/cloud/dropbox/dropboxstorage.cpp | 25 | ||||
-rw-r--r-- | backends/cloud/dropbox/dropboxstorage.h | 22 |
2 files changed, 36 insertions, 11 deletions
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index 49355fa845..d32d86567a 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -45,9 +45,12 @@ static void saveAccessTokenCallback(void *ptr) { if (!result.contains("access_token") || !result.contains("uid")) { warning("Bad response, no token/uid passed"); } else { - ConfMan.set("current_storage_type", "Dropbox", "cloud"); - ConfMan.set("current_storage_access_token", result.getVal("access_token")->asString(), "cloud"); - ConfMan.set("current_storage_user_id", result.getVal("uid")->asString(), "cloud"); + //we suppose that's the first storage + ConfMan.set("storages_number", "1", "cloud"); + ConfMan.set("current_storage", "1", "cloud"); + ConfMan.set("storage1_type", "Dropbox", "cloud"); + ConfMan.set("storage1_access_token", result.getVal("access_token")->asString(), "cloud"); + ConfMan.set("storage1_user_id", result.getVal("uid")->asString(), "cloud"); ConfMan.removeKey("dropbox_code", "cloud"); debug("Now please restart ScummVM to apply the changes."); } @@ -66,6 +69,12 @@ DropboxStorage::~DropboxStorage() { curl_global_cleanup(); } +void DropboxStorage::saveConfig(Common::String keyPrefix) { + ConfMan.set(keyPrefix + "type", "Dropbox", "cloud"); + ConfMan.set(keyPrefix + "access_token", _token, "cloud"); + ConfMan.set(keyPrefix + "user_id", _uid, "cloud"); +} + void DropboxStorage::syncSaves(BoolCallback callback) { //this is not the real syncSaves() implementation info(new Common::Callback<DropboxStorage, StorageInfo>(this, &DropboxStorage::infoMethodCallback)); @@ -106,22 +115,22 @@ void DropboxStorage::infoMethodCallback(StorageInfo storageInfo) { debug("info: %s", storageInfo.info().c_str()); } -DropboxStorage *DropboxStorage::loadFromConfig() { +DropboxStorage *DropboxStorage::loadFromConfig(Common::String keyPrefix) { KEY = ConfMan.get("DROPBOX_KEY", "cloud"); SECRET = ConfMan.get("DROPBOX_SECRET", "cloud"); - if (!ConfMan.hasKey("current_storage_access_token", "cloud")) { + if (!ConfMan.hasKey(keyPrefix + "access_token", "cloud")) { warning("No access_token found"); return 0; } - if (!ConfMan.hasKey("current_storage_user_id", "cloud")) { + if (!ConfMan.hasKey(keyPrefix + "user_id", "cloud")) { warning("No user_id found"); return 0; } - Common::String accessToken = ConfMan.get("current_storage_access_token", "cloud"); - Common::String userId = ConfMan.get("current_storage_user_id", "cloud"); + Common::String accessToken = ConfMan.get(keyPrefix + "access_token", "cloud"); + Common::String userId = ConfMan.get(keyPrefix + "user_id", "cloud"); return new DropboxStorage(accessToken, userId); } diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h index 3fc38bc1bb..493fcdd25d 100644 --- a/backends/cloud/dropbox/dropboxstorage.h +++ b/backends/cloud/dropbox/dropboxstorage.h @@ -45,7 +45,23 @@ class DropboxStorage: public Cloud::Storage { public: virtual ~DropboxStorage(); - /** Returns pointer to Common::Array<StorageFile>. */ + /** + * Storage methods, which are used by CloudManager to save + * storage in configuration file. + */ + + /** + * Save storage data using ConfMan. + * @param keyPrefix all saved keys must start with this prefix. + * @note every Storage must write keyPrefix + "type" key + * with common value (e.g. "Dropbox"). + */ + + virtual void saveConfig(Common::String keyPrefix); + + /** Public Cloud API comes down there. */ + + /** Returns Common::Array<StorageFile>. */ virtual void listDirectory(Common::String path, FileArrayCallback callback) {} //TODO /** Calls the callback when finished. */ @@ -66,7 +82,7 @@ public: /** Calls the callback when finished. */ virtual void touch(Common::String path, BoolCallback callback) {} //TODO - /** Returns pointer to the StorageInfo struct. */ + /** Returns the StorageInfo struct. */ virtual void info(StorageInfoCallback callback); /** This method is passed into info(). (Temporary) */ @@ -82,7 +98,7 @@ public: * Load token and user id from configs and return DropboxStorage for those. * @return pointer to the newly created DropboxStorage or 0 if some problem occured. */ - static DropboxStorage *loadFromConfig(); + static DropboxStorage *loadFromConfig(Common::String keyPrefix); /** * Returns Dropbox auth link. |