aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2016-06-07 16:27:04 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commitbf71ba9a1c98b39647edb248e913322ee38a0af5 (patch)
tree0451db33ffbe35dab7428a13b0db0dc6ba02c95b
parentc968f0143c5e36cc9fc429832622eb180732caf8 (diff)
downloadscummvm-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.
-rw-r--r--backends/cloud/googledrive/googledrivecreatedirectoryrequest.cpp30
-rw-r--r--backends/cloud/googledrive/googledrivecreatedirectoryrequest.h3
-rw-r--r--backends/cloud/googledrive/googledrivestorage.cpp6
-rw-r--r--backends/cloud/savessyncrequest.cpp9
4 files changed, 41 insertions, 7 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);
}
diff --git a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h b/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h
index 6c5ccddf6c..ede84277de 100644
--- a/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h
+++ b/backends/cloud/googledrive/googledrivecreatedirectoryrequest.h
@@ -41,6 +41,9 @@ class GoogleDriveCreateDirectoryRequest: public Networking::Request {
bool _ignoreCallback;
void start();
+ void createdBaseDirectoryCallback(Storage::BoolResponse response);
+ void createdBaseDirectoryErrorCallback(Networking::ErrorResponse error);
+ void resolveId();
void idResolvedCallback(Storage::UploadResponse response);
void idResolveFailedCallback(Networking::ErrorResponse error);
void createdDirectoryCallback(Storage::BoolResponse response);
diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp
index dce35b5904..d7dbd529e5 100644
--- a/backends/cloud/googledrive/googledrivestorage.cpp
+++ b/backends/cloud/googledrive/googledrivestorage.cpp
@@ -315,10 +315,6 @@ Networking::Request *GoogleDriveStorage::createDirectory(Common::String path, Bo
}
}
- if (parentPath == "") {
- return createDirectoryWithParentId("root", directoryName, callback, errorCallback);
- }
-
return addRequest(new GoogleDriveCreateDirectoryRequest(this, parentPath, directoryName, callback, errorCallback));
}
@@ -353,7 +349,7 @@ Networking::Request *GoogleDriveStorage::info(StorageInfoCallback callback, Netw
return addRequest(request);
}
-Common::String GoogleDriveStorage::savesDirectoryPath() { return "saves/"; }
+Common::String GoogleDriveStorage::savesDirectoryPath() { return "scummvm/saves/"; }
GoogleDriveStorage *GoogleDriveStorage::loadFromConfig(Common::String keyPrefix) {
loadKeyAndSecret();
diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp
index 3c41c005e4..1d4ec4c2ee 100644
--- a/backends/cloud/savessyncrequest.cpp
+++ b/backends/cloud/savessyncrequest.cpp
@@ -158,9 +158,18 @@ void SavesSyncRequest::directoryListedErrorCallback(Networking::ErrorResponse er
}
}
}
+
+ //TODO: Google Drive-related JSON error
}
delete value;
}
+
+ //Google Drive-related ScummVM-based error
+ if (error.response.contains("subdirectory not found")) {
+ irrecoverable = false; //base "/ScummVM/" folder not found
+ } else if (error.response.contains("no such file found in its parent directory")) {
+ irrecoverable = false; //"Saves" folder within "/ScummVM/" not found
+ }
}
if (irrecoverable) {