aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud/googledrive
diff options
context:
space:
mode:
authorAlexander Tkachev2016-06-08 12:34:13 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit7e6a89c141d621b5caf8c66a58ecbcf60b2d52c1 (patch)
tree8d5dcb25bd8fb981b49a07600ce07416152387c8 /backends/cloud/googledrive
parentf6e69b62765482d290b7673e97fb7cf6a03fc943 (diff)
downloadscummvm-rg350-7e6a89c141d621b5caf8c66a58ecbcf60b2d52c1.tar.gz
scummvm-rg350-7e6a89c141d621b5caf8c66a58ecbcf60b2d52c1.tar.bz2
scummvm-rg350-7e6a89c141d621b5caf8c66a58ecbcf60b2d52c1.zip
CLOUD: Update GoogleDriveStorage and StorageFile
Because of the Google Drive StorageFile now contains yet another field, `id`. For other storages `id` == `path`, and thus all common Requests (such as SavesSyncRequest, DownloadFolderRequest, etc) must be using id() instead of path(). That way these Requests won't cause id resolving which could be quite slow (when you call it for all files in the folder, for example).
Diffstat (limited to 'backends/cloud/googledrive')
-rw-r--r--backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp6
-rw-r--r--backends/cloud/googledrive/googledrivelistdirectoryrequest.cpp14
-rw-r--r--backends/cloud/googledrive/googledrivelistdirectoryrequest.h4
-rw-r--r--backends/cloud/googledrive/googledriveresolveidrequest.cpp2
-rw-r--r--backends/cloud/googledrive/googledrivestorage.cpp1
5 files changed, 18 insertions, 9 deletions
diff --git a/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp b/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp
index f7aa7a1c0c..f9af363254 100644
--- a/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp
+++ b/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp
@@ -108,7 +108,7 @@ void GoogleDriveListDirectoryByIdRequest::responseCallback(Networking::JsonRespo
Common::JSONArray items = responseObject.getVal("files")->asArray();
for (uint32 i = 0; i < items.size(); ++i) {
Common::JSONObject item = items[i]->asObject();
- Common::String path = item.getVal("id")->asString();
+ Common::String id = item.getVal("id")->asString();
Common::String name = item.getVal("name")->asString();
bool isDirectory = (item.getVal("mimeType")->asString() == "application/vnd.google-apps.folder");
uint32 size = 0, timestamp = 0;
@@ -116,7 +116,9 @@ void GoogleDriveListDirectoryByIdRequest::responseCallback(Networking::JsonRespo
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));
+
+ //as we list directory by id, we can't determine full path for the file, so we leave it empty
+ _files.push_back(StorageFile(id, "", name, size, timestamp, isDirectory));
}
}
diff --git a/backends/cloud/googledrive/googledrivelistdirectoryrequest.cpp b/backends/cloud/googledrive/googledrivelistdirectoryrequest.cpp
index 803682b684..8811ffc938 100644
--- a/backends/cloud/googledrive/googledrivelistdirectoryrequest.cpp
+++ b/backends/cloud/googledrive/googledrivelistdirectoryrequest.cpp
@@ -46,7 +46,7 @@ void GoogleDriveListDirectoryRequest::start() {
_workingRequest = nullptr;
_files.clear();
_directoriesQueue.clear();
- _currentDirectory = "";
+ _currentDirectory = StorageFile();
_ignoreCallback = false;
//find out that directory's id
@@ -59,7 +59,9 @@ void GoogleDriveListDirectoryRequest::idResolvedCallback(Storage::UploadResponse
_workingRequest = nullptr;
if (_ignoreCallback) return;
- _directoriesQueue.push_back(response.value.path());
+ StorageFile directory = response.value;
+ directory.setPath(_requestedPath);
+ _directoriesQueue.push_back(directory);
listNextDirectory();
}
@@ -80,7 +82,7 @@ void GoogleDriveListDirectoryRequest::listNextDirectory() {
Storage::FileArrayCallback callback = new Common::Callback<GoogleDriveListDirectoryRequest, Storage::FileArrayResponse>(this, &GoogleDriveListDirectoryRequest::listedDirectoryCallback);
Networking::ErrorCallback failureCallback = new Common::Callback<GoogleDriveListDirectoryRequest, Networking::ErrorResponse>(this, &GoogleDriveListDirectoryRequest::listedDirectoryErrorCallback);
- _workingRequest = _storage->listDirectoryById(_currentDirectory, callback, failureCallback);
+ _workingRequest = _storage->listDirectoryById(_currentDirectory.id(), callback, failureCallback);
}
void GoogleDriveListDirectoryRequest::listedDirectoryCallback(Storage::FileArrayResponse response) {
@@ -89,9 +91,13 @@ void GoogleDriveListDirectoryRequest::listedDirectoryCallback(Storage::FileArray
for (uint32 i = 0; i < response.value.size(); ++i) {
StorageFile &file = response.value[i];
+ Common::String path = _currentDirectory.path();
+ if (path.size() && path.lastChar() != '/' && path.lastChar() != '\\') path += '/';
+ path += file.name();
+ file.setPath(path);
_files.push_back(file);
if (_requestedRecursive && file.isDirectory()) {
- _directoriesQueue.push_back(file.path());
+ _directoriesQueue.push_back(file);
}
}
diff --git a/backends/cloud/googledrive/googledrivelistdirectoryrequest.h b/backends/cloud/googledrive/googledrivelistdirectoryrequest.h
index 3eee83fed1..bea195f70a 100644
--- a/backends/cloud/googledrive/googledrivelistdirectoryrequest.h
+++ b/backends/cloud/googledrive/googledrivelistdirectoryrequest.h
@@ -39,8 +39,8 @@ class GoogleDriveListDirectoryRequest: public Networking::Request {
GoogleDriveStorage *_storage;
Storage::ListDirectoryCallback _listDirectoryCallback;
Common::Array<StorageFile> _files;
- Common::Array<Common::String> _directoriesQueue;
- Common::String _currentDirectory;
+ Common::Array<StorageFile> _directoriesQueue;
+ StorageFile _currentDirectory;
Request *_workingRequest;
bool _ignoreCallback;
diff --git a/backends/cloud/googledrive/googledriveresolveidrequest.cpp b/backends/cloud/googledrive/googledriveresolveidrequest.cpp
index 9cd13a78a6..e3ab97ea6c 100644
--- a/backends/cloud/googledrive/googledriveresolveidrequest.cpp
+++ b/backends/cloud/googledrive/googledriveresolveidrequest.cpp
@@ -92,7 +92,7 @@ void GoogleDriveResolveIdRequest::listedDirectoryCallback(Storage::FileArrayResp
if (files[i].isDirectory() && files[i].name().equalsIgnoreCase(currentLevelName)) {
if (_currentDirectory != "") _currentDirectory += "/";
_currentDirectory += files[i].name();
- _currentDirectoryId = files[i].path();
+ _currentDirectoryId = files[i].id();
///debug("found it! new directory and its id: '%s', '%s'", _currentDirectory.c_str(), _currentDirectoryId.c_str());
listNextDirectory(files[i]);
found = true;
diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp
index d7dbd529e5..6b5c437fd7 100644
--- a/backends/cloud/googledrive/googledrivestorage.cpp
+++ b/backends/cloud/googledrive/googledrivestorage.cpp
@@ -277,6 +277,7 @@ void GoogleDriveStorage::printFiles(FileArrayResponse response) {
for (uint32 i = 0; i < files.size(); ++i) {
debug("\t%s%s", files[i].name().c_str(), files[i].isDirectory() ? " (directory)" : "");
debug("\t%s", files[i].path().c_str());
+ debug("\t%s", files[i].id().c_str());
debug("");
}
}