diff options
author | Alexander Tkachev | 2016-06-07 16:27:04 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | bf71ba9a1c98b39647edb248e913322ee38a0af5 (patch) | |
tree | 0451db33ffbe35dab7428a13b0db0dc6ba02c95b /backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp | |
parent | c968f0143c5e36cc9fc429832622eb180732caf8 (diff) | |
download | scummvm-rg350-bf71ba9a1c98b39647edb248e913322ee38a0af5.tar.gz scummvm-rg350-bf71ba9a1c98b39647edb248e913322ee38a0af5.tar.bz2 scummvm-rg350-bf71ba9a1c98b39647edb248e913322ee38a0af5.zip |
CLOUD: Update GoogleDriveCreateDirectoryRequest
Now it also creates the "base" ScummVM directory if there is no such
directory yet. This way SavesSyncRequest works fine when no "ScummVM" or
"ScummVM/Saves" folder exist in the Google Drive.
Diffstat (limited to 'backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp')
-rw-r--r-- | backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp b/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp index 1554fef200..54eff3d6ad 100644 --- a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp +++ b/backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp @@ -46,12 +46,38 @@ void GoogleDriveCreateDirectoryRequest::start() { if (_workingRequest) _workingRequest->finish(); _workingRequest = nullptr; _ignoreCallback = false; + + //the only exception when we create parent folder - is when it's ScummVM/ base folder + Common::String prefix = _requestedParentPath; + if (prefix.size() > 7) prefix.erase(7); + if (prefix.equalsIgnoreCase("ScummVM")) { + Storage::BoolCallback callback = new Common::Callback<GoogleDriveCreateDirectoryRequest, Storage::BoolResponse>(this, &GoogleDriveCreateDirectoryRequest::createdBaseDirectoryCallback); + Networking::ErrorCallback failureCallback = new Common::Callback<GoogleDriveCreateDirectoryRequest, Networking::ErrorResponse>(this, &GoogleDriveCreateDirectoryRequest::createdBaseDirectoryErrorCallback); + _workingRequest = _storage->createDirectory("ScummVM", callback, failureCallback); + return; + } - //find out the parent id + resolveId(); +} + +void GoogleDriveCreateDirectoryRequest::createdBaseDirectoryCallback(Storage::BoolResponse response) { + _workingRequest = nullptr; + if (_ignoreCallback) return; + resolveId(); +} + +void GoogleDriveCreateDirectoryRequest::createdBaseDirectoryErrorCallback(Networking::ErrorResponse error) { + _workingRequest = nullptr; + if (_ignoreCallback) return; + finishError(error); +} + +void GoogleDriveCreateDirectoryRequest::resolveId() { + //check whether such folder already exists Storage::UploadCallback innerCallback = new Common::Callback<GoogleDriveCreateDirectoryRequest, Storage::UploadResponse>(this, &GoogleDriveCreateDirectoryRequest::idResolvedCallback); Networking::ErrorCallback innerErrorCallback = new Common::Callback<GoogleDriveCreateDirectoryRequest, Networking::ErrorResponse>(this, &GoogleDriveCreateDirectoryRequest::idResolveFailedCallback); Common::String path = _requestedParentPath; - path += "/"; + if (_requestedParentPath != "") path += "/"; path += _requestedDirectoryName; _workingRequest = _storage->resolveFileId(path, innerCallback, innerErrorCallback); } |