aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud/downloadrequest.cpp
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-24 12:31:27 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commitcaaa4c5a5d0bce7582cc6611d8bde53fbdb1f2d1 (patch)
tree4550fc9f3dbdba4feeeb68aeceb82a5146b9e542 /backends/cloud/downloadrequest.cpp
parent826a2a921cd0b0a72f71dd6f323097a2f449fab0 (diff)
downloadscummvm-rg350-caaa4c5a5d0bce7582cc6611d8bde53fbdb1f2d1.tar.gz
scummvm-rg350-caaa4c5a5d0bce7582cc6611d8bde53fbdb1f2d1.tar.bz2
scummvm-rg350-caaa4c5a5d0bce7582cc6611d8bde53fbdb1f2d1.zip
CLOUD: Make DownloadRequest write to local file
Tested with .jpg file. Transfer complete, CRC-32 is the same.
Diffstat (limited to 'backends/cloud/downloadrequest.cpp')
-rw-r--r--backends/cloud/downloadrequest.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/backends/cloud/downloadrequest.cpp b/backends/cloud/downloadrequest.cpp
index ed84d4f0e5..8124fd67d7 100644
--- a/backends/cloud/downloadrequest.cpp
+++ b/backends/cloud/downloadrequest.cpp
@@ -26,38 +26,45 @@
namespace Cloud {
-DownloadRequest::DownloadRequest(Storage::BoolCallback callback, Networking::NetworkReadStream *stream):
- Request(0), _boolCallback(callback), _stream(stream) {}
+DownloadRequest::DownloadRequest(Storage::BoolCallback callback, Networking::NetworkReadStream *stream, Common::DumpFile *dumpFile):
+ Request(0), _boolCallback(callback), _remoteFileStream(stream), _localFile(dumpFile) {}
bool DownloadRequest::handle() {
- if (!_stream) {
+ if (!_remoteFileStream) {
warning("DownloadRequest: no stream to read");
return true;
}
+ if (!_localFile) {
+ warning("DownloadRequest: no file to write");
+ return true;
+ }
+
+ if (!_localFile->isOpen()) {
+ warning("DownloadRequest: failed to open file to write");
+ return true;
+ }
+
const int kBufSize = 16 * 1024;
char buf[kBufSize];
- uint32 readBytes = _stream->read(buf, kBufSize);
+ uint32 readBytes = _remoteFileStream->read(buf, kBufSize);
- //TODO: save into file
- /*
if (readBytes != 0)
- if (_outputStream.write(buf, readBytes) != readBytes)
- warning("DropboxDownloadRequest: unable to write all received bytes into output stream");
- */
-
- buf[readBytes] = 0;
- debug("%s", buf); //TODO: remove
+ if (_localFile->write(buf, readBytes) != readBytes) {
+ warning("DownloadRequest: unable to write all received bytes into output file");
+ if (_boolCallback) (*_boolCallback)(false);
+ return true;
+ }
- if (_stream->eos()) {
- if (_stream->httpResponseCode() != 200) {
- warning("HTTP response code is not 200 OK (it's %ld)", _stream->httpResponseCode());
+ if (_remoteFileStream->eos()) {
+ if (_remoteFileStream->httpResponseCode() != 200) {
+ warning("HTTP response code is not 200 OK (it's %ld)", _remoteFileStream->httpResponseCode());
//TODO: do something about it actually
}
- if (_boolCallback) (*_boolCallback)(_stream->httpResponseCode() == 200);
+ if (_boolCallback) (*_boolCallback)(_remoteFileStream->httpResponseCode() == 200);
- //TODO: close file stream
+ _localFile->close(); //yes, I know it's closed automatically in ~DumpFile()
return true;
}