diff options
author | Alexander Tkachev | 2016-05-31 19:00:54 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 13351a730d79cc2f0d5b964226c69bb04e2c93c1 (patch) | |
tree | 9511d9aaf06ed78046ad1b1004dc7e95d0663246 | |
parent | 3638c8348d98273da5c4e2c5bd1afa8a985a2d0c (diff) | |
download | scummvm-rg350-13351a730d79cc2f0d5b964226c69bb04e2c93c1.tar.gz scummvm-rg350-13351a730d79cc2f0d5b964226c69bb04e2c93c1.tar.bz2 scummvm-rg350-13351a730d79cc2f0d5b964226c69bb04e2c93c1.zip |
CLOUD: Add OneDrive::info()
Unfortunately, OneDrive doesn't share quota information anymore because
of some reason. I had to get as much information as I could.
-rw-r--r-- | backends/cloud/onedrive/onedrivestorage.cpp | 45 | ||||
-rw-r--r-- | backends/cloud/onedrive/onedrivestorage.h | 5 |
2 files changed, 44 insertions, 6 deletions
diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp index 1e9a641e8a..a16a351690 100644 --- a/backends/cloud/onedrive/onedrivestorage.cpp +++ b/backends/cloud/onedrive/onedrivestorage.cpp @@ -131,6 +131,40 @@ void OneDriveStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "refresh_token", _refreshToken, "cloud"); } +void OneDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse response) { + Common::JSONValue *json = response.value; + if (!json) { + warning("NULL passed instead of JSON"); + delete outerCallback; + return; + } + + if (outerCallback) { + Common::JSONObject info = json->asObject(); + + Common::String uid, name, email; + uint32 quotaUsed = 0, quotaAllocated = 25 * 1024 * 1024 * 1024; // 25 GB, because I actually don't know any way to find out the real one + + if (info.contains("createdBy") && info.getVal("createdBy")->isObject()) { + Common::JSONObject createdBy = info.getVal("createdBy")->asObject(); + if (createdBy.contains("user") && createdBy.getVal("user")->isObject()) { + Common::JSONObject user = createdBy.getVal("user")->asObject(); + uid = user.getVal("id")->asString(); + name = user.getVal("displayName")->asString(); + } + } + + if (info.contains("size") && info.getVal("size")->isIntegerNumber()) { + quotaUsed = info.getVal("size")->asIntegerNumber(); + } + + (*outerCallback)(StorageInfoResponse(nullptr, StorageInfo(uid, name, email, quotaUsed, quotaAllocated))); + delete outerCallback; + } + + delete json; +} + void OneDriveStorage::printJson(Networking::JsonResponse response) { Common::JSONValue *json = response.value; if (!json) { @@ -232,13 +266,14 @@ Networking::ErrorCallback OneDriveStorage::getErrorPrintingCallback() { Networking::Request *OneDriveStorage::syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) { //this is not the real syncSaves() implementation - /* - Networking::JsonCallback innerCallback = new Common::Callback<OneDriveStorage, Networking::RequestJsonPair>(this, &OneDriveStorage::printJson); - Networking::CurlJsonRequest *request = new OneDriveTokenRefresher(this, innerCallback, "https://api.onedrive.com/v1.0/drive/special/approot"); + return ConnMan.addRequest(new SavesSyncRequest(this, new Common::Callback<OneDriveStorage, BoolResponse>(this, &OneDriveStorage::printBool), getErrorPrintingCallback())); //TODO +} + +Networking::Request *OneDriveStorage::info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback) { + Networking::JsonCallback innerCallback = new Common::CallbackBridge<OneDriveStorage, StorageInfoResponse, Networking::JsonResponse>(this, &OneDriveStorage::infoInnerCallback, callback); + Networking::CurlJsonRequest *request = new OneDriveTokenRefresher(this, innerCallback, errorCallback, "https://api.onedrive.com/v1.0/drive/special/approot"); request->addHeader("Authorization: bearer " + _token); return ConnMan.addRequest(request); - */ - return ConnMan.addRequest(new SavesSyncRequest(this, new Common::Callback<OneDriveStorage, BoolResponse>(this, &OneDriveStorage::printBool), getErrorPrintingCallback())); //TODO } Common::String OneDriveStorage::savesDirectoryPath() { return "saves/"; } diff --git a/backends/cloud/onedrive/onedrivestorage.h b/backends/cloud/onedrive/onedrivestorage.h index 45a8dca331..5741f8e20e 100644 --- a/backends/cloud/onedrive/onedrivestorage.h +++ b/backends/cloud/onedrive/onedrivestorage.h @@ -49,6 +49,9 @@ class OneDriveStorage: public Cloud::Storage { void tokenRefreshed(BoolCallback callback, Networking::JsonResponse response); void codeFlowComplete(BoolResponse response); + /** Constructs StorageInfo based on JSON response from cloud. */ + void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json); + void printJson(Networking::JsonResponse response); void fileDownloaded(BoolResponse response); void printFiles(FileArrayResponse response); @@ -105,7 +108,7 @@ public: virtual Networking::Request *touch(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO /** Returns the StorageInfo struct. */ - virtual Networking::Request *info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO + virtual Networking::Request *info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback); /** Returns storage's saves directory path with the trailing slash. */ virtual Common::String savesDirectoryPath(); |