diff options
author | Alexander Tkachev | 2016-06-08 12:34:13 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 7e6a89c141d621b5caf8c66a58ecbcf60b2d52c1 (patch) | |
tree | 8d5dcb25bd8fb981b49a07600ce07416152387c8 | |
parent | f6e69b62765482d290b7673e97fb7cf6a03fc943 (diff) | |
download | scummvm-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).
7 files changed, 36 insertions, 15 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(""); } } diff --git a/backends/cloud/storagefile.cpp b/backends/cloud/storagefile.cpp index 452cce3cf3..4bee92edce 100644 --- a/backends/cloud/storagefile.cpp +++ b/backends/cloud/storagefile.cpp @@ -25,6 +25,7 @@ namespace Cloud { StorageFile::StorageFile() { + _id = ""; _path = ""; _name = ""; _size = 0; @@ -33,6 +34,7 @@ StorageFile::StorageFile() { } StorageFile::StorageFile(Common::String pth, uint32 sz, uint32 ts, bool dir) { + _id = pth; _path = pth; _name = pth; @@ -53,8 +55,9 @@ StorageFile::StorageFile(Common::String pth, uint32 sz, uint32 ts, bool dir) { _isDirectory = dir; } -StorageFile::StorageFile(Common::String id, Common::String name, uint32 sz, uint32 ts, bool dir) { - _path = id; +StorageFile::StorageFile(Common::String id, Common::String path, Common::String name, uint32 sz, uint32 ts, bool dir) { + _id = id; + _path = path; _name = name; _size = sz; _timestamp = ts; diff --git a/backends/cloud/storagefile.h b/backends/cloud/storagefile.h index 7503653d6b..1324cafc93 100644 --- a/backends/cloud/storagefile.h +++ b/backends/cloud/storagefile.h @@ -31,24 +31,33 @@ namespace Cloud { * StorageFile represents a file storaged on remote cloud storage. * It contains basic information about a file, and might be used * when listing directories or syncing files. + * + * Some storages (Google Drive, for example) don't have an actual + * path notation to address files. Instead, they are using ids. + * As resolving id by path is not a fast operation, it's required + * to use ids if they are known, but user-friendly paths are + * necessary too, because these are used by Requests. + * + * If storage supports path notation, id would actually contain path. */ class StorageFile { - Common::String _path, _name; + Common::String _id, _path, _name; uint32 _size, _timestamp; bool _isDirectory; public: StorageFile(); //invalid empty file StorageFile(Common::String pth, uint32 sz, uint32 ts, bool dir); + StorageFile(Common::String id, Common::String path, Common::String name, uint32 sz, uint32 ts, bool dir); - /** In this constructor <path> is used to storage <id> (in Google Drive, for example) */ - StorageFile(Common::String id, Common::String name, uint32 sz, uint32 ts, bool dir); - + Common::String id() const { return _id; } Common::String path() const { return _path; } Common::String name() const { return _name; } uint32 size() const { return _size; } uint32 timestamp() const { return _timestamp; } bool isDirectory() const { return _isDirectory; } + + void setPath(Common::String path) { _path = path; } }; } // End of namespace Cloud |