aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-13 14:57:01 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit2b3caf1efadd2a68384978e77cfceab158c703f3 (patch)
treee694877b876d6fdf578f1c9e9a73ea6b2ebbfe75
parente0a6b2135de6a83f2ed4177c96fabf216412e5fb (diff)
downloadscummvm-rg350-2b3caf1efadd2a68384978e77cfceab158c703f3.tar.gz
scummvm-rg350-2b3caf1efadd2a68384978e77cfceab158c703f3.tar.bz2
scummvm-rg350-2b3caf1efadd2a68384978e77cfceab158c703f3.zip
CLOUD: Add IdStorage
This is a special base class for Storages which are using ids instead of paths in their APIs, like Box or Google Drive. This commit makes Box derived from IdStorage.
-rw-r--r--backends/cloud/box/boxstorage.cpp49
-rw-r--r--backends/cloud/box/boxstorage.h15
-rw-r--r--backends/cloud/id/idlistdirectoryrequest.cpp (renamed from backends/cloud/box/boxlistdirectoryrequest.cpp)40
-rw-r--r--backends/cloud/id/idlistdirectoryrequest.h (renamed from backends/cloud/box/boxlistdirectoryrequest.h)18
-rw-r--r--backends/cloud/id/idresolveidrequest.cpp (renamed from backends/cloud/box/boxresolveidrequest.cpp)32
-rw-r--r--backends/cloud/id/idresolveidrequest.h (renamed from backends/cloud/box/boxresolveidrequest.h)18
-rw-r--r--backends/cloud/id/idstorage.cpp86
-rw-r--r--backends/cloud/id/idstorage.h73
-rw-r--r--backends/module.mk5
9 files changed, 225 insertions, 111 deletions
diff --git a/backends/cloud/box/boxstorage.cpp b/backends/cloud/box/boxstorage.cpp
index 65f90a51d2..3681cbfaa8 100644
--- a/backends/cloud/box/boxstorage.cpp
+++ b/backends/cloud/box/boxstorage.cpp
@@ -23,8 +23,6 @@
#include "backends/cloud/box/boxstorage.h"
#include "backends/cloud/box/boxlistdirectorybyidrequest.h"
-#include "backends/cloud/box/boxlistdirectoryrequest.h"
-#include "backends/cloud/box/boxresolveidrequest.h"
#include "backends/cloud/box/boxtokenrefresher.h"
#include "backends/cloud/cloudmanager.h"
#include "backends/networking/curl/connectionmanager.h"
@@ -178,17 +176,6 @@ void BoxStorage::infoInnerCallback(StorageInfoCallback outerCallback, Networking
delete json;
}
-void BoxStorage::printJson(Networking::JsonResponse response) {
- Common::JSONValue *json = response.value;
- if (!json) {
- warning("printJson: NULL");
- return;
- }
-
- debug("%s", json->stringify().c_str());
- delete json;
-}
-
void BoxStorage::fileInfoCallback(Networking::NetworkReadStreamCallback outerCallback, Networking::JsonResponse response) {
if (!response.value) {
warning("fileInfoCallback: NULL");
@@ -212,21 +199,9 @@ void BoxStorage::fileInfoCallback(Networking::NetworkReadStreamCallback outerCal
delete response.value;
}
-Networking::Request *BoxStorage::resolveFileId(Common::String path, UploadCallback callback, Networking::ErrorCallback errorCallback) {
- if (!errorCallback) errorCallback = getErrorPrintingCallback();
- if (!callback) callback = new Common::Callback<BoxStorage, UploadResponse>(this, &BoxStorage::printFile);
- return addRequest(new BoxResolveIdRequest(this, path, callback, errorCallback));
-}
-
-Networking::Request *BoxStorage::listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive) {
- if (!errorCallback) errorCallback = getErrorPrintingCallback();
- if (!callback) callback = new Common::Callback<BoxStorage, FileArrayResponse>(this, &BoxStorage::printFiles);
- return addRequest(new BoxListDirectoryRequest(this, path, callback, errorCallback, recursive));
-}
-
Networking::Request *BoxStorage::listDirectoryById(Common::String id, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback) {
if (!errorCallback) errorCallback = getErrorPrintingCallback();
- if (!callback) callback = new Common::Callback<BoxStorage, FileArrayResponse>(this, &BoxStorage::printFiles);
+ if (!callback) callback = getPrintFilesCallback();
return addRequest(new BoxListDirectoryByIdRequest(this, id, callback, errorCallback));
}
@@ -251,24 +226,6 @@ void BoxStorage::fileDownloaded(BoolResponse response) {
else debug("download failed!");
}
-void BoxStorage::printFiles(FileArrayResponse response) {
- debug("files:");
- Common::Array<StorageFile> &files = response.value;
- for (uint32 i = 0; i < files.size(); ++i)
- debug("\t%s", files[i].path().c_str());
-}
-
-void BoxStorage::printBool(BoolResponse response) {
- debug("bool: %s", response.value ? "true" : "false");
-}
-
-void BoxStorage::printFile(UploadResponse response) {
- debug("\nuploaded file info:");
- debug("\tpath: %s", response.value.path().c_str());
- debug("\tsize: %u", response.value.size());
- debug("\ttimestamp: %u", response.value.timestamp());
-}
-
Networking::Request *BoxStorage::createDirectory(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) {
if (!errorCallback) errorCallback = getErrorPrintingCallback();
//return addRequest(new BoxCreateDirectoryRequest(this, path, callback, errorCallback));
@@ -307,5 +264,9 @@ Common::String BoxStorage::getAuthLink() {
return "";
}
+Common::String BoxStorage::getRootDirectoryId() {
+ return "0";
+}
+
} // End of namespace Box
} // End of namespace Cloud
diff --git a/backends/cloud/box/boxstorage.h b/backends/cloud/box/boxstorage.h
index d0b4d1aa84..865358c845 100644
--- a/backends/cloud/box/boxstorage.h
+++ b/backends/cloud/box/boxstorage.h
@@ -23,14 +23,14 @@
#ifndef BACKENDS_CLOUD_BOX_BOXSTORAGE_H
#define BACKENDS_CLOUD_BOX_BOXSTORAGE_H
-#include "backends/cloud/storage.h"
+#include "backends/cloud/id/idstorage.h"
#include "common/callback.h"
#include "backends/networking/curl/curljsonrequest.h"
namespace Cloud {
namespace Box {
-class BoxStorage: public Cloud::Storage {
+class BoxStorage: public Id::IdStorage {
static char *KEY, *SECRET;
static void loadKeyAndSecret();
@@ -46,11 +46,7 @@ class BoxStorage: public Cloud::Storage {
/** Constructs StorageInfo based on JSON response from cloud. */
void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json);
- void printJson(Networking::JsonResponse response);
void fileDownloaded(BoolResponse response);
- void printFiles(FileArrayResponse response);
- void printBool(BoolResponse response);
- void printFile(UploadResponse response);
void fileInfoCallback(Networking::NetworkReadStreamCallback outerCallback, Networking::JsonResponse response);
public:
@@ -79,11 +75,6 @@ public:
/** Public Cloud API comes down there. */
- /** Returns StorageFile with the resolved file's id. */
- virtual Networking::Request *resolveFileId(Common::String path, UploadCallback callback, Networking::ErrorCallback errorCallback);
-
- /** Returns ListDirectoryStatus struct with list of files. */
- virtual Networking::Request *listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
virtual Networking::Request *listDirectoryById(Common::String id, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback);
/** Returns UploadStatus struct with info about uploaded file. */
@@ -115,6 +106,8 @@ public:
*/
static Common::String getAuthLink();
+ virtual Common::String getRootDirectoryId();
+
/**
* Gets new access_token. If <code> passed is "", refresh_token is used.
* Use "" in order to refresh token and pass a callback, so you could
diff --git a/backends/cloud/box/boxlistdirectoryrequest.cpp b/backends/cloud/id/idlistdirectoryrequest.cpp
index b35c8c80d5..012065dc77 100644
--- a/backends/cloud/box/boxlistdirectoryrequest.cpp
+++ b/backends/cloud/id/idlistdirectoryrequest.cpp
@@ -20,26 +20,26 @@
*
*/
-#include "backends/cloud/box/boxlistdirectoryrequest.h"
-#include "backends/cloud/box/boxstorage.h"
+#include "backends/cloud/id/idlistdirectoryrequest.h"
+#include "backends/cloud/id/idstorage.h"
namespace Cloud {
-namespace Box {
+namespace Id {
-BoxListDirectoryRequest::BoxListDirectoryRequest(BoxStorage *storage, Common::String path, Storage::ListDirectoryCallback cb, Networking::ErrorCallback ecb, bool recursive):
+IdListDirectoryRequest::IdListDirectoryRequest(IdStorage *storage, Common::String path, Storage::ListDirectoryCallback cb, Networking::ErrorCallback ecb, bool recursive):
Networking::Request(nullptr, ecb),
_requestedPath(path), _requestedRecursive(recursive), _storage(storage), _listDirectoryCallback(cb),
_workingRequest(nullptr), _ignoreCallback(false) {
start();
}
-BoxListDirectoryRequest::~BoxListDirectoryRequest() {
+IdListDirectoryRequest::~IdListDirectoryRequest() {
_ignoreCallback = true;
if (_workingRequest) _workingRequest->finish();
delete _listDirectoryCallback;
}
-void BoxListDirectoryRequest::start() {
+void IdListDirectoryRequest::start() {
//cleanup
_ignoreCallback = true;
if (_workingRequest) _workingRequest->finish();
@@ -50,12 +50,12 @@ void BoxListDirectoryRequest::start() {
_ignoreCallback = false;
//find out that directory's id
- Storage::UploadCallback innerCallback = new Common::Callback<BoxListDirectoryRequest, Storage::UploadResponse>(this, &BoxListDirectoryRequest::idResolvedCallback);
- Networking::ErrorCallback innerErrorCallback = new Common::Callback<BoxListDirectoryRequest, Networking::ErrorResponse>(this, &BoxListDirectoryRequest::idResolveErrorCallback);
+ Storage::UploadCallback innerCallback = new Common::Callback<IdListDirectoryRequest, Storage::UploadResponse>(this, &IdListDirectoryRequest::idResolvedCallback);
+ Networking::ErrorCallback innerErrorCallback = new Common::Callback<IdListDirectoryRequest, Networking::ErrorResponse>(this, &IdListDirectoryRequest::idResolveErrorCallback);
_workingRequest = _storage->resolveFileId(_requestedPath, innerCallback, innerErrorCallback);
}
-void BoxListDirectoryRequest::idResolvedCallback(Storage::UploadResponse response) {
+void IdListDirectoryRequest::idResolvedCallback(Storage::UploadResponse response) {
_workingRequest = nullptr;
if (_ignoreCallback) return;
if (response.request) _date = response.request->date();
@@ -66,14 +66,14 @@ void BoxListDirectoryRequest::idResolvedCallback(Storage::UploadResponse respons
listNextDirectory();
}
-void BoxListDirectoryRequest::idResolveErrorCallback(Networking::ErrorResponse error) {
+void IdListDirectoryRequest::idResolveErrorCallback(Networking::ErrorResponse error) {
_workingRequest = nullptr;
if (_ignoreCallback) return;
if (error.request) _date = error.request->date();
finishError(error);
}
-void BoxListDirectoryRequest::listNextDirectory() {
+void IdListDirectoryRequest::listNextDirectory() {
if (_directoriesQueue.empty()) {
finishListing(_files);
return;
@@ -82,12 +82,12 @@ void BoxListDirectoryRequest::listNextDirectory() {
_currentDirectory = _directoriesQueue.back();
_directoriesQueue.pop_back();
- Storage::FileArrayCallback callback = new Common::Callback<BoxListDirectoryRequest, Storage::FileArrayResponse>(this, &BoxListDirectoryRequest::listedDirectoryCallback);
- Networking::ErrorCallback failureCallback = new Common::Callback<BoxListDirectoryRequest, Networking::ErrorResponse>(this, &BoxListDirectoryRequest::listedDirectoryErrorCallback);
+ Storage::FileArrayCallback callback = new Common::Callback<IdListDirectoryRequest, Storage::FileArrayResponse>(this, &IdListDirectoryRequest::listedDirectoryCallback);
+ Networking::ErrorCallback failureCallback = new Common::Callback<IdListDirectoryRequest, Networking::ErrorResponse>(this, &IdListDirectoryRequest::listedDirectoryErrorCallback);
_workingRequest = _storage->listDirectoryById(_currentDirectory.id(), callback, failureCallback);
}
-void BoxListDirectoryRequest::listedDirectoryCallback(Storage::FileArrayResponse response) {
+void IdListDirectoryRequest::listedDirectoryCallback(Storage::FileArrayResponse response) {
_workingRequest = nullptr;
if (_ignoreCallback) return;
if (response.request) _date = response.request->date();
@@ -107,23 +107,23 @@ void BoxListDirectoryRequest::listedDirectoryCallback(Storage::FileArrayResponse
listNextDirectory();
}
-void BoxListDirectoryRequest::listedDirectoryErrorCallback(Networking::ErrorResponse error) {
+void IdListDirectoryRequest::listedDirectoryErrorCallback(Networking::ErrorResponse error) {
_workingRequest = nullptr;
if (_ignoreCallback) return;
if (error.request) _date = error.request->date();
finishError(error);
}
-void BoxListDirectoryRequest::handle() {}
+void IdListDirectoryRequest::handle() {}
-void BoxListDirectoryRequest::restart() { start(); }
+void IdListDirectoryRequest::restart() { start(); }
-Common::String BoxListDirectoryRequest::date() const { return _date; }
+Common::String IdListDirectoryRequest::date() const { return _date; }
-void BoxListDirectoryRequest::finishListing(Common::Array<StorageFile> &files) {
+void IdListDirectoryRequest::finishListing(Common::Array<StorageFile> &files) {
Request::finishSuccess();
if (_listDirectoryCallback) (*_listDirectoryCallback)(Storage::ListDirectoryResponse(this, files));
}
-} // End of namespace Box
+} // End of namespace Id
} // End of namespace Cloud
diff --git a/backends/cloud/box/boxlistdirectoryrequest.h b/backends/cloud/id/idlistdirectoryrequest.h
index 7392cdd84c..58c5d2c864 100644
--- a/backends/cloud/box/boxlistdirectoryrequest.h
+++ b/backends/cloud/id/idlistdirectoryrequest.h
@@ -20,22 +20,22 @@
*
*/
-#ifndef BACKENDS_CLOUD_BOX_BOXLISTDIRECTORYREQUEST_H
-#define BACKENDS_CLOUD_BOX_BOXLISTDIRECTORYREQUEST_H
+#ifndef BACKENDS_CLOUD_ID_IDLISTDIRECTORYREQUEST_H
+#define BACKENDS_CLOUD_ID_IDLISTDIRECTORYREQUEST_H
#include "backends/cloud/storage.h"
#include "backends/networking/curl/request.h"
#include "common/callback.h"
namespace Cloud {
-namespace Box {
+namespace Id {
-class BoxStorage;
+class IdStorage;
-class BoxListDirectoryRequest: public Networking::Request {
+class IdListDirectoryRequest: public Networking::Request {
Common::String _requestedPath;
bool _requestedRecursive;
- BoxStorage *_storage;
+ IdStorage *_storage;
Storage::ListDirectoryCallback _listDirectoryCallback;
Common::Array<StorageFile> _files;
Common::Array<StorageFile> _directoriesQueue;
@@ -52,15 +52,15 @@ class BoxListDirectoryRequest: public Networking::Request {
void listedDirectoryErrorCallback(Networking::ErrorResponse error);
void finishListing(Common::Array<StorageFile> &files);
public:
- BoxListDirectoryRequest(BoxStorage *storage, Common::String path, Storage::ListDirectoryCallback cb, Networking::ErrorCallback ecb, bool recursive = false);
- virtual ~BoxListDirectoryRequest();
+ IdListDirectoryRequest(IdStorage *storage, Common::String path, Storage::ListDirectoryCallback cb, Networking::ErrorCallback ecb, bool recursive = false);
+ virtual ~IdListDirectoryRequest();
virtual void handle();
virtual void restart();
virtual Common::String date() const;
};
-} // End of namespace Box
+} // End of namespace Id
} // End of namespace Cloud
#endif
diff --git a/backends/cloud/box/boxresolveidrequest.cpp b/backends/cloud/id/idresolveidrequest.cpp
index f07a94b92b..fc61137088 100644
--- a/backends/cloud/box/boxresolveidrequest.cpp
+++ b/backends/cloud/id/idresolveidrequest.cpp
@@ -20,49 +20,49 @@
*
*/
-#include "backends/cloud/box/boxresolveidrequest.h"
-#include "backends/cloud/box/boxstorage.h"
+#include "backends/cloud/id/idresolveidrequest.h"
+#include "backends/cloud/id/idstorage.h"
namespace Cloud {
-namespace Box {
+namespace Id {
-BoxResolveIdRequest::BoxResolveIdRequest(BoxStorage *storage, Common::String path, Storage::UploadCallback cb, Networking::ErrorCallback ecb, bool recursive):
+IdResolveIdRequest::IdResolveIdRequest(IdStorage *storage, Common::String path, Storage::UploadCallback cb, Networking::ErrorCallback ecb, bool recursive):
Networking::Request(nullptr, ecb),
_requestedPath(path), _storage(storage), _uploadCallback(cb),
_workingRequest(nullptr), _ignoreCallback(false) {
start();
}
-BoxResolveIdRequest::~BoxResolveIdRequest() {
+IdResolveIdRequest::~IdResolveIdRequest() {
_ignoreCallback = true;
if (_workingRequest) _workingRequest->finish();
delete _uploadCallback;
}
-void BoxResolveIdRequest::start() {
+void IdResolveIdRequest::start() {
//cleanup
_ignoreCallback = true;
if (_workingRequest) _workingRequest->finish();
_workingRequest = nullptr;
_currentDirectory = "";
- _currentDirectoryId = "0";
+ _currentDirectoryId = _storage->getRootDirectoryId();
_ignoreCallback = false;
listNextDirectory(StorageFile(_currentDirectoryId, 0, 0, true));
}
-void BoxResolveIdRequest::listNextDirectory(StorageFile fileToReturn) {
+void IdResolveIdRequest::listNextDirectory(StorageFile fileToReturn) {
if (_currentDirectory.equalsIgnoreCase(_requestedPath)) {
finishFile(fileToReturn);
return;
}
- Storage::FileArrayCallback callback = new Common::Callback<BoxResolveIdRequest, Storage::FileArrayResponse>(this, &BoxResolveIdRequest::listedDirectoryCallback);
- Networking::ErrorCallback failureCallback = new Common::Callback<BoxResolveIdRequest, Networking::ErrorResponse>(this, &BoxResolveIdRequest::listedDirectoryErrorCallback);
+ Storage::FileArrayCallback callback = new Common::Callback<IdResolveIdRequest, Storage::FileArrayResponse>(this, &IdResolveIdRequest::listedDirectoryCallback);
+ Networking::ErrorCallback failureCallback = new Common::Callback<IdResolveIdRequest, Networking::ErrorResponse>(this, &IdResolveIdRequest::listedDirectoryErrorCallback);
_workingRequest = _storage->listDirectoryById(_currentDirectoryId, callback, failureCallback);
}
-void BoxResolveIdRequest::listedDirectoryCallback(Storage::FileArrayResponse response) {
+void IdResolveIdRequest::listedDirectoryCallback(Storage::FileArrayResponse response) {
_workingRequest = nullptr;
if (_ignoreCallback) return;
@@ -106,20 +106,20 @@ void BoxResolveIdRequest::listedDirectoryCallback(Storage::FileArrayResponse res
}
}
-void BoxResolveIdRequest::listedDirectoryErrorCallback(Networking::ErrorResponse error) {
+void IdResolveIdRequest::listedDirectoryErrorCallback(Networking::ErrorResponse error) {
_workingRequest = nullptr;
if (_ignoreCallback) return;
finishError(error);
}
-void BoxResolveIdRequest::handle() {}
+void IdResolveIdRequest::handle() {}
-void BoxResolveIdRequest::restart() { start(); }
+void IdResolveIdRequest::restart() { start(); }
-void BoxResolveIdRequest::finishFile(StorageFile file) {
+void IdResolveIdRequest::finishFile(StorageFile file) {
Request::finishSuccess();
if (_uploadCallback) (*_uploadCallback)(Storage::UploadResponse(this, file));
}
-} // End of namespace Box
+} // End of namespace Id
} // End of namespace Cloud
diff --git a/backends/cloud/box/boxresolveidrequest.h b/backends/cloud/id/idresolveidrequest.h
index 3807549002..94d4af5030 100644
--- a/backends/cloud/box/boxresolveidrequest.h
+++ b/backends/cloud/id/idresolveidrequest.h
@@ -20,21 +20,21 @@
*
*/
-#ifndef BACKENDS_CLOUD_BOX_BOXRESOLVEIDREQUEST_H
-#define BACKENDS_CLOUD_BOX_BOXRESOLVEIDREQUEST_H
+#ifndef BACKENDS_CLOUD_ID_IDRESOLVEIDREQUEST_H
+#define BACKENDS_CLOUD_ID_IDRESOLVEIDREQUEST_H
#include "backends/cloud/storage.h"
#include "backends/networking/curl/request.h"
#include "common/callback.h"
namespace Cloud {
-namespace Box {
+namespace Id {
-class BoxStorage;
+class IdStorage;
-class BoxResolveIdRequest: public Networking::Request {
+class IdResolveIdRequest: public Networking::Request {
Common::String _requestedPath;
- BoxStorage *_storage;
+ IdStorage *_storage;
Storage::UploadCallback _uploadCallback;
Common::String _currentDirectory;
Common::String _currentDirectoryId;
@@ -47,14 +47,14 @@ class BoxResolveIdRequest: public Networking::Request {
void listedDirectoryErrorCallback(Networking::ErrorResponse error);
void finishFile(StorageFile file);
public:
- BoxResolveIdRequest(BoxStorage *storage, Common::String path, Storage::UploadCallback cb, Networking::ErrorCallback ecb, bool recursive = false); //TODO: why upload?
- virtual ~BoxResolveIdRequest();
+ IdResolveIdRequest(IdStorage *storage, Common::String path, Storage::UploadCallback cb, Networking::ErrorCallback ecb, bool recursive = false); //TODO: why upload?
+ virtual ~IdResolveIdRequest();
virtual void handle();
virtual void restart();
};
-} // End of namespace Box
+} // End of namespace Id
} // End of namespace Cloud
#endif
diff --git a/backends/cloud/id/idstorage.cpp b/backends/cloud/id/idstorage.cpp
new file mode 100644
index 0000000000..aed1738d4f
--- /dev/null
+++ b/backends/cloud/id/idstorage.cpp
@@ -0,0 +1,86 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
+#include "backends/cloud/id/idstorage.h"
+#include "backends/cloud/id/idlistdirectoryrequest.h"
+#include "backends/cloud/id/idresolveidrequest.h"
+#include "common/debug.h"
+#include "common/json.h"
+
+namespace Cloud {
+namespace Id {
+
+IdStorage::~IdStorage() {}
+
+void IdStorage::printJson(Networking::JsonResponse response) {
+ Common::JSONValue *json = response.value;
+ if (!json) {
+ warning("printJson: NULL");
+ return;
+ }
+
+ debug("%s", json->stringify().c_str());
+ delete json;
+}
+
+void IdStorage::printFiles(FileArrayResponse response) {
+ debug("files:");
+ Common::Array<StorageFile> &files = response.value;
+ 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(" ");
+ }
+}
+
+void IdStorage::printBool(BoolResponse response) {
+ debug("bool: %s", response.value ? "true" : "false");
+}
+
+void IdStorage::printFile(UploadResponse response) {
+ debug("\nuploaded file info:");
+ debug("\tid: %s", response.value.path().c_str());
+ debug("\tname: %s", response.value.name().c_str());
+ debug("\tsize: %u", response.value.size());
+ debug("\ttimestamp: %u", response.value.timestamp());
+}
+
+Storage::ListDirectoryCallback IdStorage::getPrintFilesCallback() {
+ return new Common::Callback<IdStorage, FileArrayResponse>(this, &IdStorage::printFiles);
+}
+
+Networking::Request *IdStorage::resolveFileId(Common::String path, UploadCallback callback, Networking::ErrorCallback errorCallback) {
+ if (!errorCallback) errorCallback = getErrorPrintingCallback();
+ if (!callback) callback = new Common::Callback<IdStorage, UploadResponse>(this, &IdStorage::printFile);
+ return addRequest(new IdResolveIdRequest(this, path, callback, errorCallback));
+}
+
+Networking::Request *IdStorage::listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive) {
+ if (!errorCallback) errorCallback = getErrorPrintingCallback();
+ if (!callback) callback = new Common::Callback<IdStorage, FileArrayResponse>(this, &IdStorage::printFiles);
+ return addRequest(new IdListDirectoryRequest(this, path, callback, errorCallback, recursive));
+}
+
+} // End of namespace Id
+} // End of namespace Cloud
diff --git a/backends/cloud/id/idstorage.h b/backends/cloud/id/idstorage.h
new file mode 100644
index 0000000000..a5e1c1e22c
--- /dev/null
+++ b/backends/cloud/id/idstorage.h
@@ -0,0 +1,73 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+
+#ifndef BACKENDS_CLOUD_ID_IDSTORAGE_H
+#define BACKENDS_CLOUD_ID_IDSTORAGE_H
+
+#include "backends/cloud/storage.h"
+#include "backends/networking/curl/curljsonrequest.h"
+
+/*
+ * Id::IdStorage is a special base class, which is created
+ * to simplify adding new storages which use ids instead of
+ * paths in their API.
+ *
+ * Some Requests are already implemented, and Storage based
+ * on IdStorage needs to override/implement a few basic things.
+ *
+ * For example, ListDirectoryRequest and ResolveIdRequests are
+ * based on listDirectoryById() and getRootDirectoryId() methods.
+ * Implementing these you'll get id resolving and directory
+ * listing by path.
+ */
+
+namespace Cloud {
+namespace Id {
+
+class IdStorage: public Cloud::Storage {
+protected:
+ void printJson(Networking::JsonResponse response);
+ void printFiles(FileArrayResponse response);
+ void printBool(BoolResponse response);
+ void printFile(UploadResponse response);
+
+ ListDirectoryCallback getPrintFilesCallback();
+
+public:
+ virtual ~IdStorage();
+
+ /** Public Cloud API comes down there. */
+
+ /** Returns StorageFile with the resolved file's id. */
+ virtual Networking::Request *resolveFileId(Common::String path, UploadCallback callback, Networking::ErrorCallback errorCallback);
+
+ /** Returns ListDirectoryStatus struct with list of files. */
+ virtual Networking::Request *listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
+ virtual Networking::Request *listDirectoryById(Common::String id, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback) = 0;
+
+ virtual Common::String getRootDirectoryId() = 0;
+};
+
+} // End of namespace Id
+} // End of namespace Cloud
+
+#endif
diff --git a/backends/module.mk b/backends/module.mk
index 53eca87131..3c3b343e98 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -30,8 +30,6 @@ MODULE_OBJS += \
cloud/savessyncrequest.o \
cloud/box/boxstorage.o \
cloud/box/boxlistdirectorybyidrequest.o \
- cloud/box/boxlistdirectoryrequest.o \
- cloud/box/boxresolveidrequest.o \
cloud/box/boxtokenrefresher.o \
cloud/dropbox/dropboxstorage.o \
cloud/dropbox/dropboxcreatedirectoryrequest.o \
@@ -46,6 +44,9 @@ MODULE_OBJS += \
cloud/googledrive/googledrivestreamfilerequest.o \
cloud/googledrive/googledrivetokenrefresher.o \
cloud/googledrive/googledriveuploadrequest.o \
+ cloud/id/idstorage.o \
+ cloud/id/idlistdirectoryrequest.o \
+ cloud/id/idresolveidrequest.o \
cloud/onedrive/onedrivestorage.o \
cloud/onedrive/onedrivecreatedirectoryrequest.o \
cloud/onedrive/onedrivetokenrefresher.o \