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() {
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");
if (_activeStorage)
_activeStorage->saveConfig("storage_" + getStorageConfigName(_currentStorageIndex) + "_");
@ -179,13 +187,34 @@ Common::String CloudManager::getStorageLastSync(uint32 index) {
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 {
debug("bool = %s", (response.value ? "true" : "false"));
}
SavesSyncRequest *CloudManager::syncSaves(Storage::BoolCallback callback, Networking::ErrorCallback errorCallback) {
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;
}

View File

@ -143,6 +143,33 @@ public:
*/
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.
*/

View File

@ -25,6 +25,7 @@
#include "backends/cloud/dropbox/dropboxcreatedirectoryrequest.h"
#include "backends/cloud/dropbox/dropboxlistdirectoryrequest.h"
#include "backends/cloud/dropbox/dropboxuploadrequest.h"
#include "backends/cloud/cloudmanager.h"
#include "backends/networking/curl/connectionmanager.h"
#include "backends/networking/curl/curljsonrequest.h"
#include "common/config-manager.h"
@ -171,6 +172,10 @@ void DropboxStorage::infoInnerCallback(StorageInfoCallback outerCallback, Networ
uint64 quotaNormal = quota.getVal("normal")->asIntegerNumber();
uint64 quotaShared = quota.getVal("shared")->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)));
delete outerCallback;
}

View File

@ -180,6 +180,9 @@ void GoogleDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Ne
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)));
delete outerCallback;
}

View File

@ -159,6 +159,8 @@ void OneDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Netwo
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)));
delete outerCallback;
}