aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-14 15:29:47 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit0ca791709329c3e7f24f68fa2da7c86c87dac557 (patch)
tree17ef63035c6226d45c758f3f59b580c174b32d63 /backends
parentca33c0a0a8ce31b13137f74ba15e226b3855b75a (diff)
downloadscummvm-rg350-0ca791709329c3e7f24f68fa2da7c86c87dac557.tar.gz
scummvm-rg350-0ca791709329c3e7f24f68fa2da7c86c87dac557.tar.bz2
scummvm-rg350-0ca791709329c3e7f24f68fa2da7c86c87dac557.zip
CLOUD: Update FolderDownloadRequest
It now keeps track of downloaded bytes.
Diffstat (limited to 'backends')
-rw-r--r--backends/cloud/cloudmanager.cpp12
-rw-r--r--backends/cloud/cloudmanager.h6
-rw-r--r--backends/cloud/folderdownloadrequest.cpp24
-rw-r--r--backends/cloud/folderdownloadrequest.h7
-rw-r--r--backends/cloud/storage.cpp18
-rw-r--r--backends/cloud/storage.h6
6 files changed, 72 insertions, 1 deletions
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp
index e5b2c2a69d..80ee24808c 100644
--- a/backends/cloud/cloudmanager.cpp
+++ b/backends/cloud/cloudmanager.cpp
@@ -346,6 +346,18 @@ double CloudManager::getDownloadingProgress() {
return 1;
}
+uint64 CloudManager::getDownloadBytesNumber() {
+ Storage *storage = getCurrentStorage();
+ if (storage) return storage->getDownloadBytesNumber();
+ return 1;
+}
+
+uint64 CloudManager::getDownloadTotalBytesNumber() {
+ Storage *storage = getCurrentStorage();
+ if (storage) return storage->getDownloadTotalBytesNumber();
+ return 1;
+}
+
Common::String CloudManager::getDownloadRemoteDirectory() {
Storage *storage = getCurrentStorage();
if (storage) return storage->getDownloadRemoteDirectory();
diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h
index 1098bddaa6..0baede7fe9 100644
--- a/backends/cloud/cloudmanager.h
+++ b/backends/cloud/cloudmanager.h
@@ -244,6 +244,12 @@ public:
/** Returns a number in [0, 1] range which represents current download progress (1 = complete). */
double getDownloadingProgress();
+ /** Returns a number of bytes that is downloaded in current download progress. */
+ uint64 getDownloadBytesNumber();
+
+ /** Returns a total number of bytes to be downloaded in current download progress. */
+ uint64 getDownloadTotalBytesNumber();
+
/** Returns remote directory path. */
virtual Common::String getDownloadRemoteDirectory();
diff --git a/backends/cloud/folderdownloadrequest.cpp b/backends/cloud/folderdownloadrequest.cpp
index f5c872b461..ca3f9a1c99 100644
--- a/backends/cloud/folderdownloadrequest.cpp
+++ b/backends/cloud/folderdownloadrequest.cpp
@@ -51,6 +51,7 @@ void FolderDownloadRequest::start() {
_failedFiles.clear();
_ignoreCallback = false;
_totalFiles = 0;
+ _downloadedBytes = _totalBytes = 0;
//list directory first
_workingRequest = _storage->listDirectory(
@@ -70,8 +71,10 @@ void FolderDownloadRequest::directoryListedCallback(Storage::ListDirectoryRespon
for (Common::Array<StorageFile>::iterator i = _pendingFiles.begin(); i != _pendingFiles.end(); )
if (i->isDirectory())
_pendingFiles.erase(i);
- else
+ else {
+ _totalBytes += i->size();
++i;
+ }
_totalFiles = _pendingFiles.size();
downloadNextFile();
@@ -87,6 +90,7 @@ void FolderDownloadRequest::fileDownloadedCallback(Storage::BoolResponse respons
_workingRequest = nullptr;
if (_ignoreCallback) return;
if (!response.value) _failedFiles.push_back(_currentFile);
+ _downloadedBytes += _currentFile.size();
downloadNextFile();
}
@@ -159,4 +163,22 @@ double FolderDownloadRequest::getProgress() const {
return (double)(uploadedFiles + currentFileProgress) / (double)(_totalFiles);
}
+uint64 FolderDownloadRequest::getDownloadedBytes() const {
+ if (_totalFiles == 0) return 0;
+
+ double currentFileProgress = 0;
+ DownloadRequest *downloadRequest = dynamic_cast<DownloadRequest *>(_workingRequest);
+ if (downloadRequest != nullptr) currentFileProgress = downloadRequest->getProgress();
+ else {
+ Id::IdDownloadRequest *idDownloadRequest = dynamic_cast<Id::IdDownloadRequest *>(_workingRequest);
+ if (idDownloadRequest != nullptr) currentFileProgress = idDownloadRequest->getProgress();
+ }
+
+ return _downloadedBytes + (uint64)(currentFileProgress * _currentFile.size());
+}
+
+uint64 FolderDownloadRequest::getTotalBytesToDownload() const {
+ return _totalBytes;
+}
+
} // End of namespace Cloud
diff --git a/backends/cloud/folderdownloadrequest.h b/backends/cloud/folderdownloadrequest.h
index ee17de08dc..1a67f32165 100644
--- a/backends/cloud/folderdownloadrequest.h
+++ b/backends/cloud/folderdownloadrequest.h
@@ -40,6 +40,7 @@ class FolderDownloadRequest: public Networking::Request, public GUI::CommandSend
Request *_workingRequest;
bool _ignoreCallback;
uint32 _totalFiles;
+ uint64 _downloadedBytes, _totalBytes;
void start();
void directoryListedCallback(Storage::ListDirectoryResponse response);
@@ -58,6 +59,12 @@ public:
/** Returns a number in range [0, 1], where 1 is "complete". */
double getProgress() const;
+ /** Returns a number of downloaded bytes. */
+ uint64 getDownloadedBytes() const;
+
+ /** Returns a total number of bytes to download. */
+ uint64 getTotalBytesToDownload() const;
+
/** Returns remote directory path. */
Common::String getRemotePath() { return _remoteDirectoryPath; }
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index 110c97ad9c..c9843d6188 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -241,6 +241,24 @@ double Storage::getDownloadingProgress() {
return result;
}
+uint64 Storage::getDownloadBytesNumber() {
+ uint64 result = 0;
+ _runningRequestsMutex.lock();
+ if (_downloadFolderRequest)
+ result = _downloadFolderRequest->getDownloadedBytes();
+ _runningRequestsMutex.unlock();
+ return result;
+}
+
+uint64 Storage::getDownloadTotalBytesNumber() {
+ uint64 result = 0;
+ _runningRequestsMutex.lock();
+ if (_downloadFolderRequest)
+ result = _downloadFolderRequest->getTotalBytesToDownload();
+ _runningRequestsMutex.unlock();
+ return result;
+}
+
Common::String Storage::getDownloadRemoteDirectory() {
Common::String result = "";
_runningRequestsMutex.lock();
diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h
index 414a722c64..6d9db33bc6 100644
--- a/backends/cloud/storage.h
+++ b/backends/cloud/storage.h
@@ -198,6 +198,12 @@ public:
/** Returns a number in [0, 1] range which represents current download progress (1 = complete). */
virtual double getDownloadingProgress();
+ /** Returns a number of bytes that is downloaded in current download progress. */
+ virtual uint64 getDownloadBytesNumber();
+
+ /** Returns a total number of bytes to be downloaded in current download progress. */
+ virtual uint64 getDownloadTotalBytesNumber();
+
/** Returns remote directory path. */
virtual Common::String getDownloadRemoteDirectory();