mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-13 21:31:53 +00:00
CLOUD: Calculate FolderDownload download speed
This commit is contained in:
parent
85adefdb86
commit
c431ae6d84
@ -349,13 +349,19 @@ double CloudManager::getDownloadingProgress() {
|
||||
uint64 CloudManager::getDownloadBytesNumber() {
|
||||
Storage *storage = getCurrentStorage();
|
||||
if (storage) return storage->getDownloadBytesNumber();
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64 CloudManager::getDownloadTotalBytesNumber() {
|
||||
Storage *storage = getCurrentStorage();
|
||||
if (storage) return storage->getDownloadTotalBytesNumber();
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64 CloudManager::getDownloadSpeed() {
|
||||
Storage *storage = getCurrentStorage();
|
||||
if (storage) return storage->getDownloadSpeed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Common::String CloudManager::getDownloadRemoteDirectory() {
|
||||
|
@ -250,6 +250,9 @@ public:
|
||||
/** Returns a total number of bytes to be downloaded in current download progress. */
|
||||
uint64 getDownloadTotalBytesNumber();
|
||||
|
||||
/** Returns download speed of current download progress. */
|
||||
uint64 getDownloadSpeed();
|
||||
|
||||
/** Returns remote directory path. */
|
||||
virtual Common::String getDownloadRemoteDirectory();
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "backends/cloud/id/iddownloadrequest.h"
|
||||
#include "common/debug.h"
|
||||
#include "gui/downloaddialog.h"
|
||||
#include <backends/networking/curl/connectionmanager.h>
|
||||
|
||||
namespace Cloud {
|
||||
|
||||
@ -51,7 +52,7 @@ void FolderDownloadRequest::start() {
|
||||
_failedFiles.clear();
|
||||
_ignoreCallback = false;
|
||||
_totalFiles = 0;
|
||||
_downloadedBytes = _totalBytes = 0;
|
||||
_downloadedBytes = _totalBytes = _wasDownloadedBytes = _currentDownloadSpeed = 0;
|
||||
|
||||
//list directory first
|
||||
_workingRequest = _storage->listDirectory(
|
||||
@ -139,7 +140,13 @@ void FolderDownloadRequest::downloadNextFile() {
|
||||
);
|
||||
}
|
||||
|
||||
void FolderDownloadRequest::handle() {}
|
||||
void FolderDownloadRequest::handle() {
|
||||
uint32 microsecondsPassed = Networking::ConnectionManager::getCloudRequestsPeriodInMicroseconds();
|
||||
uint64 currentDownloadedBytes = getDownloadedBytes();
|
||||
uint64 downloadedThisPeriod = currentDownloadedBytes - _wasDownloadedBytes;
|
||||
_currentDownloadSpeed = downloadedThisPeriod * (1000000L / microsecondsPassed);
|
||||
_wasDownloadedBytes = currentDownloadedBytes;
|
||||
}
|
||||
|
||||
void FolderDownloadRequest::restart() { start(); }
|
||||
|
||||
@ -171,4 +178,8 @@ uint64 FolderDownloadRequest::getTotalBytesToDownload() const {
|
||||
return _totalBytes;
|
||||
}
|
||||
|
||||
uint64 FolderDownloadRequest::getDownloadSpeed() const {
|
||||
return _currentDownloadSpeed;
|
||||
}
|
||||
|
||||
} // End of namespace Cloud
|
||||
|
@ -40,7 +40,7 @@ class FolderDownloadRequest: public Networking::Request, public GUI::CommandSend
|
||||
Request *_workingRequest;
|
||||
bool _ignoreCallback;
|
||||
uint32 _totalFiles;
|
||||
uint64 _downloadedBytes, _totalBytes;
|
||||
uint64 _downloadedBytes, _totalBytes, _wasDownloadedBytes, _currentDownloadSpeed;
|
||||
|
||||
void start();
|
||||
void directoryListedCallback(Storage::ListDirectoryResponse response);
|
||||
@ -65,6 +65,9 @@ public:
|
||||
/** Returns a total number of bytes to download. */
|
||||
uint64 getTotalBytesToDownload() const;
|
||||
|
||||
/** Returns average download speed for the last second. */
|
||||
uint64 getDownloadSpeed() const;
|
||||
|
||||
/** Returns remote directory path. */
|
||||
Common::String getRemotePath() { return _remoteDirectoryPath; }
|
||||
|
||||
|
@ -259,6 +259,15 @@ uint64 Storage::getDownloadTotalBytesNumber() {
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64 Storage::getDownloadSpeed() {
|
||||
uint64 result = 0;
|
||||
_runningRequestsMutex.lock();
|
||||
if (_downloadFolderRequest)
|
||||
result = _downloadFolderRequest->getDownloadSpeed();
|
||||
_runningRequestsMutex.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
Common::String Storage::getDownloadRemoteDirectory() {
|
||||
Common::String result = "";
|
||||
_runningRequestsMutex.lock();
|
||||
|
@ -204,6 +204,9 @@ public:
|
||||
/** Returns a total number of bytes to be downloaded in current download progress. */
|
||||
virtual uint64 getDownloadTotalBytesNumber();
|
||||
|
||||
/** Returns download speed of current download progress. */
|
||||
virtual uint64 getDownloadSpeed();
|
||||
|
||||
/** Returns remote directory path. */
|
||||
virtual Common::String getDownloadRemoteDirectory();
|
||||
|
||||
|
@ -91,6 +91,10 @@ Common::String ConnectionManager::urlEncode(Common::String s) {
|
||||
return "";
|
||||
}
|
||||
|
||||
uint32 ConnectionManager::getCloudRequestsPeriodInMicroseconds() {
|
||||
return TIMER_INTERVAL * FRAMES_PER_SECOND / CLOUD_PERIOD;
|
||||
}
|
||||
|
||||
//private goes here:
|
||||
|
||||
void connectionsThread(void *ignored) {
|
||||
|
@ -120,6 +120,8 @@ public:
|
||||
|
||||
/** Return URL-encoded version of given string. */
|
||||
Common::String urlEncode(Common::String s);
|
||||
|
||||
static uint32 getCloudRequestsPeriodInMicroseconds();
|
||||
};
|
||||
|
||||
/** Shortcut for accessing the connection manager. */
|
||||
|
@ -192,7 +192,7 @@ void DownloadDialog::refreshWidgets() {
|
||||
_remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory());
|
||||
_localDirectoryLabel->setLabel(_("To: ") + _localDirectory);
|
||||
uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress());
|
||||
_percentLabel->setLabel(Common::String::format("%u %% (%u bytes out of %u)", progress, CloudMan.getDownloadBytesNumber(), CloudMan.getDownloadTotalBytesNumber()));
|
||||
_percentLabel->setLabel(Common::String::format("%u %% (%u bytes out of %u - %u bytes per second)", progress, CloudMan.getDownloadBytesNumber(), CloudMan.getDownloadTotalBytesNumber(), CloudMan.getDownloadSpeed()));
|
||||
_progressBar->setValue(progress);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user