aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2016-06-07 13:49:26 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit505d3764cb9c873b1dbefcb0d7b2cc7b587c6a42 (patch)
tree8cc195cecb86d8cfe19d74749f995ca229cf6c7c
parentd1d71afb0724c372143d2c303c70291ba43d2d68 (diff)
downloadscummvm-rg350-505d3764cb9c873b1dbefcb0d7b2cc7b587c6a42.tar.gz
scummvm-rg350-505d3764cb9c873b1dbefcb0d7b2cc7b587c6a42.tar.bz2
scummvm-rg350-505d3764cb9c873b1dbefcb0d7b2cc7b587c6a42.zip
CLOUD: Fix GoogleDriveStorage to work with root folder
Now it needs another scope and uses "root" instead of "appDataFolder".
-rw-r--r--backends/cloud/cloudmanager.cpp33
-rw-r--r--backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp2
-rw-r--r--backends/cloud/googledrive/googledrivecreatedirectoryrequest.h2
-rw-r--r--backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp20
-rw-r--r--backends/cloud/googledrive/googledriveresolveidrequest.cpp2
-rw-r--r--backends/cloud/googledrive/googledrivestorage.cpp4
6 files changed, 19 insertions, 44 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp
index 64fa19ceb9..7613b2cbbf 100644
--- a/backends/cloud/cloudmanager.cpp
+++ b/backends/cloud/cloudmanager.cpp
@@ -127,39 +127,6 @@ void CloudManager::testFeature() {
//if (storage) storage->info(nullptr, nullptr);
GoogleDrive::GoogleDriveStorage *gd = dynamic_cast<GoogleDrive::GoogleDriveStorage *>(storage);
if (gd) {
- //new folder in root: +
- //gd->createDirectory("newfolder1", nullptr, nullptr);
-
- //check it's there: +
- //gd->listDirectoryById("appDataFolder", nullptr, nullptr);
-
- //new folder in firstfolder: +
- //gd->createDirectory("firstfolder/newfolder2", nullptr, nullptr);
-
- //check it's there: +
- //gd->listDirectoryById("1LWq-r1IwegkJJ0eZpswGlyjj8nu6XyUmosvxD7L0F9X3", nullptr, nullptr);
-
- //create existing folder in firstfolder: +
- //gd->createDirectory("firstfolder/subfolder", nullptr, nullptr);
-
- //check no new folder there: +
- //gd->listDirectoryById("1LWq-r1IwegkJJ0eZpswGlyjj8nu6XyUmosvxD7L0F9X3", nullptr, nullptr);
-
- //create folder in subfolder: +
- //gd->createDirectory("firstfolder/subfolder/newfolder3", nullptr, nullptr);
-
- //check it's there: +
- //gd->listDirectoryById("1OysvorQlmGl2ObMGb1c-JnjfC5yFL-Zj7AsQQhNNBnrk", nullptr, nullptr);
-
- //one more time: +
- //gd->createDirectory("firstfolder/subfolder/newfolder3/megafolder", nullptr, nullptr);
-
- //check it's there: +
- //gd->listDirectoryById("1OXWPtfNgnmR_1K7SDm2v5J923bbAWrTdVDj-zRppLZDw", nullptr, nullptr);
-
- //gd->listDirectory("", nullptr, nullptr);
- //gd->listDirectory("firstfolder", nullptr, nullptr);
- gd->listDirectory("firstfolder/subfolder", nullptr, nullptr, true);
}
//gd->resolveFileId("firstfolder/subfolder", nullptr, nullptr);
//gd->listDirectoryById("appDataFolder", nullptr, nullptr);
diff --git a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp b/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp
index 213f030c26..1554fef200 100644
--- a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp
+++ b/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp
@@ -45,8 +45,6 @@ void GoogleDriveCreateDirectoryRequest::start() {
_ignoreCallback = true;
if (_workingRequest) _workingRequest->finish();
_workingRequest = nullptr;
- _currentDirectory = "";
- _currentDirectoryId = "appDataFolder";
_ignoreCallback = false;
//find out the parent id
diff --git a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h b/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h
index 0ac178e8a6..6c5ccddf6c 100644
--- a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h
+++ b/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h
@@ -37,8 +37,6 @@ class GoogleDriveCreateDirectoryRequest: public Networking::Request {
Common::String _requestedDirectoryName;
GoogleDriveStorage *_storage;
Storage::BoolCallback _boolCallback;
- Common::String _currentDirectory;
- Common::String _currentDirectoryId;
Request *_workingRequest;
bool _ignoreCallback;
diff --git a/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp b/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp
index 0915b623f3..f7aa7a1c0c 100644
--- a/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp
+++ b/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp
@@ -55,7 +55,8 @@ void GoogleDriveListDirectoryByIdRequest::start() {
}
void GoogleDriveListDirectoryByIdRequest::makeRequest(Common::String pageToken) {
- Common::String url = "https://www.googleapis.com/drive/v3/files?spaces=appDataFolder";
+ Common::String url = "https://www.googleapis.com/drive/v3/files?spaces=drive&fields=files%28id,mimeType,modifiedTime,name,size%29,nextPageToken";
+ //files(id,mimeType,modifiedTime,name,size),nextPageToken
if (pageToken != "") url += "&pageToken=" + pageToken;
url += "&q=%27" + _requestedId + "%27+in+parents";
@@ -66,6 +67,17 @@ void GoogleDriveListDirectoryByIdRequest::makeRequest(Common::String pageToken)
_workingRequest = ConnMan.addRequest(request);
}
+namespace {
+uint64 atoull(Common::String s) {
+ uint64 result = 0;
+ for (uint32 i = 0; i < s.size(); ++i) {
+ if (s[i] < '0' || s[i] > '9') break;
+ result = result * 10L + (s[i] - '0');
+ }
+ return result;
+}
+}
+
void GoogleDriveListDirectoryByIdRequest::responseCallback(Networking::JsonResponse response) {
_workingRequest = nullptr;
if (_ignoreCallback) return;
@@ -100,10 +112,10 @@ void GoogleDriveListDirectoryByIdRequest::responseCallback(Networking::JsonRespo
Common::String name = item.getVal("name")->asString();
bool isDirectory = (item.getVal("mimeType")->asString() == "application/vnd.google-apps.folder");
uint32 size = 0, timestamp = 0;
- if (!isDirectory) {
- size = item.getVal("size")->asIntegerNumber();
+ if (item.contains("size") && item.getVal("size")->isString())
+ size = atoull(item.getVal("size")->asString());
+ if (item.contains("modifiedTime") && item.getVal("modifiedTime")->isString())
timestamp = ISO8601::convertToTimestamp(item.getVal("modifiedTime")->asString());
- }
_files.push_back(StorageFile(path, name, size, timestamp, isDirectory));
}
}
diff --git a/backends/cloud/googledrive/googledriveresolveidrequest.cpp b/backends/cloud/googledrive/googledriveresolveidrequest.cpp
index 0ef0cd982f..a9adb82969 100644
--- a/backends/cloud/googledrive/googledriveresolveidrequest.cpp
+++ b/backends/cloud/googledrive/googledriveresolveidrequest.cpp
@@ -50,7 +50,7 @@ void GoogleDriveResolveIdRequest::start() {
if (_workingRequest) _workingRequest->finish();
_workingRequest = nullptr;
_currentDirectory = "";
- _currentDirectoryId = "appDataFolder";
+ _currentDirectoryId = "root";
_ignoreCallback = false;
listNextDirectory(StorageFile(_currentDirectoryId, 0, 0, true));
diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp
index 3c85b1f074..dce35b5904 100644
--- a/backends/cloud/googledrive/googledrivestorage.cpp
+++ b/backends/cloud/googledrive/googledrivestorage.cpp
@@ -316,7 +316,7 @@ Networking::Request *GoogleDriveStorage::createDirectory(Common::String path, Bo
}
if (parentPath == "") {
- return createDirectoryWithParentId("appDataFolder", directoryName, callback, errorCallback);
+ return createDirectoryWithParentId("root", directoryName, callback, errorCallback);
}
return addRequest(new GoogleDriveCreateDirectoryRequest(this, parentPath, directoryName, callback, errorCallback));
@@ -379,7 +379,7 @@ Common::String GoogleDriveStorage::getAuthLink() {
url += "&redirect_uri=http://localhost"; //that's for copy-pasting
//url += "&redirect_uri=http%3A%2F%2Flocalhost"; //that's "http://localhost" for automatic opening
url += "&client_id="; url += KEY;
- url += "&scope=https://www.googleapis.com/auth/drive.appfolder"; //for copy-pasting
+ url += "&scope=https://www.googleapis.com/auth/drive"; //for copy-pasting
return url;
}