diff options
author | Alexander Tkachev | 2016-06-08 13:02:49 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | f0d61084daf7292d157e451c7bfc5485757eac43 (patch) | |
tree | d99da13cfaa971c3dc81f3977b7f018a6ea3d127 /backends/cloud | |
parent | 60add0df1b63dbd31b88edcabf0769eb675efab0 (diff) | |
download | scummvm-rg350-f0d61084daf7292d157e451c7bfc5485757eac43.tar.gz scummvm-rg350-f0d61084daf7292d157e451c7bfc5485757eac43.tar.bz2 scummvm-rg350-f0d61084daf7292d157e451c7bfc5485757eac43.zip |
CLOUD: Update downloading in Storages
Id should be used everywhere.
Diffstat (limited to 'backends/cloud')
-rw-r--r-- | backends/cloud/downloadrequest.cpp | 8 | ||||
-rw-r--r-- | backends/cloud/downloadrequest.h | 4 | ||||
-rw-r--r-- | backends/cloud/dropbox/dropboxstorage.cpp | 2 | ||||
-rw-r--r-- | backends/cloud/dropbox/dropboxstorage.h | 2 | ||||
-rw-r--r-- | backends/cloud/googledrive/googledrivestorage.cpp | 12 | ||||
-rw-r--r-- | backends/cloud/googledrive/googledrivestorage.h | 4 | ||||
-rw-r--r-- | backends/cloud/onedrive/onedrivestorage.cpp | 2 | ||||
-rw-r--r-- | backends/cloud/onedrive/onedrivestorage.h | 2 | ||||
-rw-r--r-- | backends/cloud/storage.cpp | 17 | ||||
-rw-r--r-- | backends/cloud/storage.h | 3 |
10 files changed, 39 insertions, 17 deletions
diff --git a/backends/cloud/downloadrequest.cpp b/backends/cloud/downloadrequest.cpp index 7dde74f88d..307ea00aa2 100644 --- a/backends/cloud/downloadrequest.cpp +++ b/backends/cloud/downloadrequest.cpp @@ -27,8 +27,8 @@ namespace Cloud { -DownloadRequest::DownloadRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb, Common::String remoteFile, Common::DumpFile *dumpFile): - Request(nullptr, ecb), _boolCallback(callback), _localFile(dumpFile), _remoteFileName(remoteFile), _storage(storage), +DownloadRequest::DownloadRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb, Common::String remoteFileId, Common::DumpFile *dumpFile): + Request(nullptr, ecb), _boolCallback(callback), _localFile(dumpFile), _remoteFileId(remoteFileId), _storage(storage), _remoteFileStream(nullptr), _workingRequest(nullptr), _ignoreCallback(false) { start(); } @@ -47,8 +47,8 @@ void DownloadRequest::start() { //TODO: reopen DumpFile _ignoreCallback = false; - _workingRequest = _storage->streamFile( - _remoteFileName, + _workingRequest = _storage->streamFileById( + _remoteFileId, new Common::Callback<DownloadRequest, Networking::NetworkReadStreamResponse>(this, &DownloadRequest::streamCallback), new Common::Callback<DownloadRequest, Networking::ErrorResponse>(this, &DownloadRequest::streamErrorCallback) ); diff --git a/backends/cloud/downloadrequest.h b/backends/cloud/downloadrequest.h index 9e3421d777..def69d47de 100644 --- a/backends/cloud/downloadrequest.h +++ b/backends/cloud/downloadrequest.h @@ -33,7 +33,7 @@ namespace Cloud { class DownloadRequest: public Networking::Request { Storage::BoolCallback _boolCallback; Common::DumpFile *_localFile; - Common::String _remoteFileName; + Common::String _remoteFileId; Storage *_storage; Networking::NetworkReadStream *_remoteFileStream; Request *_workingRequest; @@ -44,7 +44,7 @@ class DownloadRequest: public Networking::Request { void streamErrorCallback(Networking::ErrorResponse error); void finishSuccess(bool success); public: - DownloadRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb, Common::String remoteFile, Common::DumpFile *dumpFile); + DownloadRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb, Common::String remoteFileId, Common::DumpFile *dumpFile); virtual ~DownloadRequest(); virtual void handle(); diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index 861a58db4b..038a1683bf 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -117,7 +117,7 @@ Networking::Request *DropboxStorage::upload(Common::String path, Common::Seekabl return addRequest(new DropboxUploadRequest(_token, path, contents, callback, errorCallback)); } -Networking::Request *DropboxStorage::streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) { +Networking::Request *DropboxStorage::streamFileById(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) { Common::JSONObject jsonRequestParameters; jsonRequestParameters.setVal("path", new Common::JSONValue(path)); Common::JSONValue value(jsonRequestParameters); diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h index c186d1e5d6..9ac0ffb166 100644 --- a/backends/cloud/dropbox/dropboxstorage.h +++ b/backends/cloud/dropbox/dropboxstorage.h @@ -74,7 +74,7 @@ public: virtual Networking::Request *upload(Common::String path, Common::SeekableReadStream *contents, UploadCallback callback, Networking::ErrorCallback errorCallback); /** Returns pointer to Networking::NetworkReadStream. */ - virtual Networking::Request *streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback); + virtual Networking::Request *streamFileById(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback); /** Calls the callback when finished. */ virtual Networking::Request *remove(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp index 6b5c437fd7..c6e423e00d 100644 --- a/backends/cloud/googledrive/googledrivestorage.cpp +++ b/backends/cloud/googledrive/googledrivestorage.cpp @@ -263,6 +263,18 @@ Networking::Request *GoogleDriveStorage::streamFile(Common::String path, Network request->addHeader("Authorization: Bearer " + _token); return addRequest(request); */ + //TODO: resolve id + //TODO: then call streamFileById() + return nullptr; //TODO +} + +Networking::Request *GoogleDriveStorage::streamFileById(Common::String id, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) { + return nullptr; //TODO +} + +Networking::Request *GoogleDriveStorage::download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) { + //TODO: resolve id + //TODO: then call downloadById() return nullptr; //TODO } diff --git a/backends/cloud/googledrive/googledrivestorage.h b/backends/cloud/googledrive/googledrivestorage.h index 274bc78401..a456030369 100644 --- a/backends/cloud/googledrive/googledrivestorage.h +++ b/backends/cloud/googledrive/googledrivestorage.h @@ -95,6 +95,10 @@ public: /** Returns pointer to Networking::NetworkReadStream. */ virtual Networking::Request *streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback); + virtual Networking::Request *streamFileById(Common::String id, 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); /** Calls the callback when finished. */ virtual Networking::Request *remove(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp index ca8a2346ad..c494f38a6c 100644 --- a/backends/cloud/onedrive/onedrivestorage.cpp +++ b/backends/cloud/onedrive/onedrivestorage.cpp @@ -204,7 +204,7 @@ Networking::Request *OneDriveStorage::upload(Common::String path, Common::Seekab return addRequest(new OneDriveUploadRequest(this, path, contents, callback, errorCallback)); } -Networking::Request *OneDriveStorage::streamFile(Common::String path, Networking::NetworkReadStreamCallback outerCallback, Networking::ErrorCallback errorCallback) { +Networking::Request *OneDriveStorage::streamFileById(Common::String path, Networking::NetworkReadStreamCallback outerCallback, Networking::ErrorCallback errorCallback) { Common::String url = "https://api.onedrive.com/v1.0/drive/special/approot:/" + path; Networking::JsonCallback innerCallback = new Common::CallbackBridge<OneDriveStorage, Networking::NetworkReadStreamResponse, Networking::JsonResponse>(this, &OneDriveStorage::fileInfoCallback, outerCallback); Networking::CurlJsonRequest *request = new OneDriveTokenRefresher(this, innerCallback, errorCallback, url.c_str()); diff --git a/backends/cloud/onedrive/onedrivestorage.h b/backends/cloud/onedrive/onedrivestorage.h index a09d68b6fd..8afdac8b0f 100644 --- a/backends/cloud/onedrive/onedrivestorage.h +++ b/backends/cloud/onedrive/onedrivestorage.h @@ -84,7 +84,7 @@ public: virtual Networking::Request *upload(Common::String path, Common::SeekableReadStream *contents, UploadCallback callback, Networking::ErrorCallback errorCallback); /** Returns pointer to Networking::NetworkReadStream. */ - virtual Networking::Request *streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback); + virtual Networking::Request *streamFileById(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback); /** Calls the callback when finished. */ virtual Networking::Request *remove(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp index f0c1319846..08ab9e9c90 100644 --- a/backends/cloud/storage.cpp +++ b/backends/cloud/storage.cpp @@ -76,7 +76,17 @@ Networking::Request *Storage::upload(Common::String remotePath, Common::String l return upload(remotePath, f, callback, errorCallback); } +Networking::Request *Storage::streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) { + //most Storages use paths instead of ids, so this should work + return streamFile(path, callback, errorCallback); +} + Networking::Request *Storage::download(Common::String remotePath, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) { + //most Storages use paths instead of ids, so this should work + return downloadById(remotePath, localPath, callback, errorCallback); +} + +Networking::Request *Storage::downloadById(Common::String remoteId, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) { if (!errorCallback) errorCallback = getErrorPrintingCallback(); Common::DumpFile *f = new Common::DumpFile(); @@ -89,12 +99,7 @@ Networking::Request *Storage::download(Common::String remotePath, Common::String return nullptr; } - return addRequest(new DownloadRequest(this, callback, errorCallback, remotePath, f)); -} - -Networking::Request *Storage::downloadById(Common::String remoteId, Common::String localPath, BoolCallback callback, Networking::ErrorCallback errorCallback) { - //most Storages use paths instead of ids, so this should work - return download(remoteId, localPath, callback, errorCallback); + return addRequest(new DownloadRequest(this, callback, errorCallback, remoteId, f)); } Networking::Request *Storage::downloadFolder(Common::String remotePath, Common::String localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive) { diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h index 3cf8fb55ff..4a5e1236b7 100644 --- a/backends/cloud/storage.h +++ b/backends/cloud/storage.h @@ -118,7 +118,8 @@ public: virtual Networking::Request *upload(Common::String remotePath, Common::String localPath, UploadCallback callback, Networking::ErrorCallback errorCallback); /** Returns pointer to Networking::NetworkReadStream. */ - virtual Networking::Request *streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) = 0; + virtual Networking::Request *streamFile(Common::String path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback); + virtual Networking::Request *streamFileById(Common::String id, 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); |