mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-07 10:21:31 +00:00
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).
This commit is contained in:
parent
f6e69b6276
commit
7e6a89c141
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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("");
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user