mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-13 21:31:53 +00:00
CLOUD: Update FolderDownloadRequest
It now keeps track of downloaded bytes.
This commit is contained in:
parent
ca33c0a0a8
commit
0ca7917093
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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 %%", progress));
|
||||
_percentLabel->setLabel(Common::String::format("%u %% (%u bytes out of %u)", progress, CloudMan.getDownloadBytesNumber(), CloudMan.getDownloadTotalBytesNumber()));
|
||||
_progressBar->setValue(progress);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user