aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-31 19:41:11 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit675e7a6ed1d19e64e2f80a4dd1f454e646cb52f5 (patch)
treecead5f18e92b5cfcf530b66dcd733c851acbfada
parentca85d4482af0b2e570565d5aa6d562ec86b10100 (diff)
downloadscummvm-rg350-675e7a6ed1d19e64e2f80a4dd1f454e646cb52f5.tar.gz
scummvm-rg350-675e7a6ed1d19e64e2f80a4dd1f454e646cb52f5.tar.bz2
scummvm-rg350-675e7a6ed1d19e64e2f80a4dd1f454e646cb52f5.zip
CLOUD: Move download methods into Storage
DownloadRequest and FolderDownloadRequest are using other Storage's methods. Thus, download() and downloadFolder() could be implemented in base Storage class.
-rw-r--r--backends/cloud/dropbox/dropboxstorage.cpp16
-rw-r--r--backends/cloud/dropbox/dropboxstorage.h6
-rw-r--r--backends/cloud/onedrive/onedrivestorage.cpp17
-rw-r--r--backends/cloud/onedrive/onedrivestorage.h6
-rw-r--r--backends/cloud/storage.cpp23
-rw-r--r--backends/cloud/storage.h4
6 files changed, 25 insertions, 47 deletions
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp
index 263c2c8132..acc96f9476 100644
--- a/backends/cloud/dropbox/dropboxstorage.cpp
+++ b/backends/cloud/dropbox/dropboxstorage.cpp
@@ -137,22 +137,6 @@ Networking::Request *DropboxStorage::streamFile(Common::String path, Networking:
return response.request;
}
-Networking::Request *DropboxStorage::download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) {
- Common::DumpFile *f = new Common::DumpFile();
- if (!f->open(localPath, true)) {
- warning("DropboxStorage: unable to open file to download into");
- if (errorCallback) (*errorCallback)(Networking::ErrorResponse(nullptr, false, true, "", -1));
- delete f;
- return nullptr;
- }
-
- return ConnMan.addRequest(new DownloadRequest(this, callback, errorCallback, remotePath, f));
-}
-
-Networking::Request *DropboxStorage::downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive) {
- return ConnMan.addRequest(new FolderDownloadRequest(this, callback, errorCallback, remotePath, localPath, recursive));
-}
-
Networking::Request *DropboxStorage::info(StorageInfoCallback outerCallback, Networking::ErrorCallback errorCallback) {
Networking::JsonCallback innerCallback = new Common::CallbackBridge<DropboxStorage, StorageInfoResponse, Networking::JsonResponse>(this, &DropboxStorage::infoInnerCallback, outerCallback);
Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(innerCallback, errorCallback, "https://api.dropboxapi.com/1/account/info");
diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h
index 7752dddf9b..5db2bb7ee3 100644
--- a/backends/cloud/dropbox/dropboxstorage.h
+++ b/backends/cloud/dropbox/dropboxstorage.h
@@ -77,12 +77,6 @@ public:
virtual Networking::Request *streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback);
/** Calls the callback when finished. */
- virtual Networking::Request *download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback);
-
- /** Returns Common::Array<StorageFile> with list of files, which were not downloaded. */
- virtual Networking::Request *downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
-
- /** Calls the callback when finished. */
virtual Networking::Request *remove(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO
/** Calls the callback when finished. */
diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp
index c64ed6bf72..e1c6861efd 100644
--- a/backends/cloud/onedrive/onedrivestorage.cpp
+++ b/backends/cloud/onedrive/onedrivestorage.cpp
@@ -215,23 +215,6 @@ Networking::Request *OneDriveStorage::streamFile(Common::String path, Networking
return ConnMan.addRequest(request);
}
-Networking::Request *OneDriveStorage::download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) {
- Common::DumpFile *f = new Common::DumpFile();
- if (!f->open(localPath, true)) {
- warning("OneDriveStorage: unable to open file to download into");
- if (errorCallback) (*errorCallback)(Networking::ErrorResponse(nullptr, false, true, "", -1));
- delete f;
- return nullptr;
- }
-
- return ConnMan.addRequest(new DownloadRequest(this, callback, errorCallback, remotePath, f));
-}
-
-/** Returns Common::Array<StorageFile> with list of files, which were not downloaded. */
-Networking::Request *OneDriveStorage::downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive) {
- return ConnMan.addRequest(new FolderDownloadRequest(this, callback, errorCallback, remotePath, localPath, recursive));
-}
-
void OneDriveStorage::fileDownloaded(BoolResponse response) {
if (response.value) debug("file downloaded!");
else debug("download failed!");
diff --git a/backends/cloud/onedrive/onedrivestorage.h b/backends/cloud/onedrive/onedrivestorage.h
index 241b6a8742..49d63b98a6 100644
--- a/backends/cloud/onedrive/onedrivestorage.h
+++ b/backends/cloud/onedrive/onedrivestorage.h
@@ -87,12 +87,6 @@ public:
virtual Networking::Request *streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback);
/** Calls the callback when finished. */
- virtual Networking::Request *download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback);
-
- /** Returns Common::Array<StorageFile> with list of files, which were not downloaded. */
- virtual Networking::Request *downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
-
- /** Calls the callback when finished. */
virtual Networking::Request *remove(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO
/** Calls the callback when finished. */
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index 2e13376fa8..90e095a146 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -21,6 +21,8 @@
*/
#include "backends/cloud/storage.h"
+#include "backends/cloud/downloadrequest.h"
+#include "backends/cloud/folderdownloadrequest.h"
#include "backends/cloud/savessyncrequest.h"
#include "backends/networking/curl/connectionmanager.h"
#include "common/debug.h"
@@ -53,6 +55,27 @@ Networking::Request *Storage::upload(Common::String remotePath, Common::String l
return upload(remotePath, f, callback, errorCallback);
}
+Networking::Request *Storage::download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) {
+ if (!errorCallback) errorCallback = getErrorPrintingCallback();
+
+ Common::DumpFile *f = new Common::DumpFile();
+ if (!f->open(localPath, true)) {
+ warning("Storage: unable to open file to download into");
+ if (errorCallback) (*errorCallback)(Networking::ErrorResponse(nullptr, false, true, "", -1));
+ delete errorCallback;
+ delete callback;
+ delete f;
+ return nullptr;
+ }
+
+ return ConnMan.addRequest(new DownloadRequest(this, callback, errorCallback, remotePath, f));
+}
+
+Networking::Request *Storage::downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive) {
+ if (!errorCallback) errorCallback = getErrorPrintingCallback();
+ return ConnMan.addRequest(new FolderDownloadRequest(this, callback, errorCallback, remotePath, localPath, recursive));
+}
+
Networking::Request *Storage::syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) {
if (!errorCallback) errorCallback = getErrorPrintingCallback();
return ConnMan.addRequest(new SavesSyncRequest(this, callback, errorCallback));
diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h
index b4d2680e31..4956d5f617 100644
--- a/backends/cloud/storage.h
+++ b/backends/cloud/storage.h
@@ -92,10 +92,10 @@ public:
virtual Networking::Request *streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) = 0;
/** Calls the callback when finished. */
- virtual Networking::Request *download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) = 0;
+ virtual Networking::Request *download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback);
/** Returns Common::Array<StorageFile> with list of files, which were not downloaded. */
- virtual Networking::Request *downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false) = 0;
+ virtual Networking::Request *downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
/** Calls the callback when finished. */
virtual Networking::Request *remove(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) = 0;