CLOUD: Update CloudManager

It now has methods to update Storage's information.
This commit is contained in:
Alexander Tkachev 2016-06-09 14:23:14 +06:00
parent af9930482e
commit 9b15ec9989
5 changed files with 67 additions and 1 deletions

View file

@ -114,6 +114,14 @@ void CloudManager::init() {
} }
void CloudManager::save() { void CloudManager::save() {
for (uint32 i = 0; i < _storages.size(); ++i) {
if (i == kStorageNoneId) continue;
Common::String name = getStorageConfigName(i);
ConfMan.set("storage_" + name + "_username", _storages[i].username, "cloud");
ConfMan.set("storage_" + name + "_lastSync", _storages[i].lastSyncDate, "cloud");
ConfMan.set("storage_" + name + "_usedBytes", Common::String::format("%llu", _storages[i].usedBytes), "cloud");
}
ConfMan.set("current_storage", Common::String::format("%d", _currentStorageIndex), "cloud"); ConfMan.set("current_storage", Common::String::format("%d", _currentStorageIndex), "cloud");
if (_activeStorage) if (_activeStorage)
_activeStorage->saveConfig("storage_" + getStorageConfigName(_currentStorageIndex) + "_"); _activeStorage->saveConfig("storage_" + getStorageConfigName(_currentStorageIndex) + "_");
@ -179,13 +187,34 @@ Common::String CloudManager::getStorageLastSync(uint32 index) {
return _storages[index].lastSyncDate; return _storages[index].lastSyncDate;
} }
void CloudManager::setStorageUsername(uint32 index, Common::String name) {
if (index >= _storages.size()) return;
_storages[index].username = name;
save();
}
void CloudManager::setStorageUsedSpace(uint32 index, uint64 used) {
if (index >= _storages.size()) return;
_storages[index].usedBytes = used;
save();
}
void CloudManager::setStorageLastSync(uint32 index, Common::String date) {
if (index >= _storages.size()) return;
_storages[index].lastSyncDate = date;
save();
}
void CloudManager::printBool(Storage::BoolResponse response) const { void CloudManager::printBool(Storage::BoolResponse response) const {
debug("bool = %s", (response.value ? "true" : "false")); debug("bool = %s", (response.value ? "true" : "false"));
} }
SavesSyncRequest *CloudManager::syncSaves(Storage::BoolCallback callback, Networking::ErrorCallback errorCallback) { SavesSyncRequest *CloudManager::syncSaves(Storage::BoolCallback callback, Networking::ErrorCallback errorCallback) {
Storage *storage = getCurrentStorage(); Storage *storage = getCurrentStorage();
if (storage) return storage->syncSaves(callback, errorCallback); if (storage) {
setStorageLastSync(_currentStorageIndex, "???"); //TODO get the date
return storage->syncSaves(callback, errorCallback);
}
return nullptr; return nullptr;
} }

View file

@ -143,6 +143,33 @@ public:
*/ */
Common::String getStorageLastSync(uint32 index); Common::String getStorageLastSync(uint32 index);
/**
* Set Storage's username.
* Automatically saves changes to the config.
*
* @param index Storage's index.
* @param name username to set
*/
void setStorageUsername(uint32 index, Common::String name);
/**
* Set Storage's used space field.
* Automatically saves changes to the config.
*
* @param index Storage's index.
* @param used value to set
*/
void setStorageUsedSpace(uint32 index, uint64 used);
/**
* Set Storage's last sync date.
* Automatically saves changes to the config.
*
* @param index Storage's index.
* @param date date to set
*/
void setStorageLastSync(uint32 index, Common::String date);
/** /**
* Starts saves syncing process in currently active storage if there is any. * Starts saves syncing process in currently active storage if there is any.
*/ */

View file

@ -25,6 +25,7 @@
#include "backends/cloud/dropbox/dropboxcreatedirectoryrequest.h" #include "backends/cloud/dropbox/dropboxcreatedirectoryrequest.h"
#include "backends/cloud/dropbox/dropboxlistdirectoryrequest.h" #include "backends/cloud/dropbox/dropboxlistdirectoryrequest.h"
#include "backends/cloud/dropbox/dropboxuploadrequest.h" #include "backends/cloud/dropbox/dropboxuploadrequest.h"
#include "backends/cloud/cloudmanager.h"
#include "backends/networking/curl/connectionmanager.h" #include "backends/networking/curl/connectionmanager.h"
#include "backends/networking/curl/curljsonrequest.h" #include "backends/networking/curl/curljsonrequest.h"
#include "common/config-manager.h" #include "common/config-manager.h"
@ -171,6 +172,10 @@ void DropboxStorage::infoInnerCallback(StorageInfoCallback outerCallback, Networ
uint64 quotaNormal = quota.getVal("normal")->asIntegerNumber(); uint64 quotaNormal = quota.getVal("normal")->asIntegerNumber();
uint64 quotaShared = quota.getVal("shared")->asIntegerNumber(); uint64 quotaShared = quota.getVal("shared")->asIntegerNumber();
uint64 quotaAllocated = quota.getVal("quota")->asIntegerNumber(); uint64 quotaAllocated = quota.getVal("quota")->asIntegerNumber();
CloudMan.setStorageUsedSpace(kStorageDropboxId, quotaNormal + quotaShared); //TODO that's not ScummVM's actually
CloudMan.setStorageUsername(kStorageDropboxId, email);
(*outerCallback)(StorageInfoResponse(nullptr, StorageInfo(uid, name, email, quotaNormal+quotaShared, quotaAllocated))); (*outerCallback)(StorageInfoResponse(nullptr, StorageInfo(uid, name, email, quotaNormal+quotaShared, quotaAllocated)));
delete outerCallback; delete outerCallback;
} }

View file

@ -180,6 +180,9 @@ void GoogleDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Ne
quotaAllocated = atoull(limit); quotaAllocated = atoull(limit);
} }
CloudMan.setStorageUsedSpace(kStorageGoogleDriveId, quotaUsed); //TODO that's not ScummVM's actually
CloudMan.setStorageUsername(kStorageGoogleDriveId, email);
(*outerCallback)(StorageInfoResponse(nullptr, StorageInfo(uid, name, email, quotaUsed, quotaAllocated))); (*outerCallback)(StorageInfoResponse(nullptr, StorageInfo(uid, name, email, quotaUsed, quotaAllocated)));
delete outerCallback; delete outerCallback;
} }

View file

@ -159,6 +159,8 @@ void OneDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Netwo
quotaUsed = info.getVal("size")->asIntegerNumber(); quotaUsed = info.getVal("size")->asIntegerNumber();
} }
CloudMan.setStorageUsedSpace(kStorageOneDriveId, quotaUsed); //TODO that's not ScummVM's actually
CloudMan.setStorageUsername(kStorageOneDriveId, email);
(*outerCallback)(StorageInfoResponse(nullptr, StorageInfo(uid, name, email, quotaUsed, quotaAllocated))); (*outerCallback)(StorageInfoResponse(nullptr, StorageInfo(uid, name, email, quotaUsed, quotaAllocated)));
delete outerCallback; delete outerCallback;
} }