GUI: Add files amount to SaveLoadCloudSyncProgressDialog

Also adds Cloud::Storage::SyncDownloadingInfo struct to pass around a bunch of numbers instead of having 3 methods for each number (in CloudManager, Storage and SavesSyncRequest).
This commit is contained in:
Alexander Tkachev 2022-08-02 01:42:08 +03:00 committed by Eugene Sandulenko
parent 85739018fe
commit 09639e7f23
7 changed files with 62 additions and 43 deletions

View File

@ -421,18 +421,10 @@ double CloudManager::getSyncDownloadingProgress() const {
return 1;
}
uint64 CloudManager::getSyncDownloadBytesNumber() const {
void CloudManager::getSyncDownloadingInfo(Storage::SyncDownloadingInfo &info) const {
Storage *storage = getCurrentStorage();
if (storage)
return storage->getSyncDownloadBytesNumber();
return 0;
}
uint64 CloudManager::getSyncDownloadTotalBytesNumber() const {
Storage *storage = getCurrentStorage();
if (storage)
return storage->getSyncDownloadTotalBytesNumber();
return 0;
storage->getSyncDownloadingInfo(info);
}
double CloudManager::getSyncProgress() const {

View File

@ -251,11 +251,8 @@ public:
/** Returns a number in [0, 1] range which represents current sync downloading progress (1 = complete). */
double getSyncDownloadingProgress() const;
/** Returns a number of bytes that is downloaded in current sync downloading progress. */
uint64 getSyncDownloadBytesNumber() const;
/** Returns a total number of bytes to be downloaded in current sync downloading progress. */
uint64 getSyncDownloadTotalBytesNumber() const;
/** Fills a struct with numbers about current sync downloading progress. */
void getSyncDownloadingInfo(Storage::SyncDownloadingInfo &info) const;
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
double getSyncProgress() const;

View File

@ -394,9 +394,25 @@ double SavesSyncRequest::getDownloadingProgress() const {
uint32 totalFilesToDownload = _totalFilesToHandle - _filesToUpload.size();
uint32 filesLeftToDownload = _filesToDownload.size() + (_currentDownloadingFile.name() != "" ? 1 : 0);
if (filesLeftToDownload > totalFilesToDownload)
filesLeftToDownload = totalFilesToDownload;
return (double)(totalFilesToDownload - filesLeftToDownload) / (double)(totalFilesToDownload);
}
void SavesSyncRequest::getDownloadingInfo(Storage::SyncDownloadingInfo &info) const {
info.bytesDownloaded = getDownloadedBytes();
info.bytesToDownload = getBytesToDownload();
uint32 totalFilesToDownload = _totalFilesToHandle - _filesToUpload.size();
uint32 filesLeftToDownload = _filesToDownload.size() + (_currentDownloadingFile.name() != "" ? 1 : 0);
if (filesLeftToDownload > totalFilesToDownload)
filesLeftToDownload = totalFilesToDownload;
info.filesDownloaded = totalFilesToDownload - filesLeftToDownload;
info.filesToDownload = totalFilesToDownload;
info.inProgress = (totalFilesToDownload > 0 && filesLeftToDownload > 0);
}
double SavesSyncRequest::getProgress() const {
if (_totalFilesToHandle == 0) {
if (_state == Networking::FINISHED)

View File

@ -57,6 +57,9 @@ class SavesSyncRequest: public Networking::Request {
virtual void finishError(Networking::ErrorResponse error, Networking::RequestState state = Networking::FINISHED);
void finishSync(bool success);
uint32 getDownloadedBytes() const;
uint32 getBytesToDownload() const;
public:
SavesSyncRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb);
virtual ~SavesSyncRequest();
@ -67,14 +70,14 @@ public:
/** Returns a number in range [0, 1], where 1 is "complete". */
double getDownloadingProgress() const;
/** Fills a struct with numbers about current sync downloading progress. */
void getDownloadingInfo(Storage::SyncDownloadingInfo &info) const;
/** Returns a number in range [0, 1], where 1 is "complete". */
double getProgress() const;
/** Returns an array of saves names which are not downloaded yet. */
Common::Array<Common::String> getFilesToDownload();
uint32 getDownloadedBytes() const;
uint32 getBytesToDownload() const;
};
} // End of namespace Cloud

View File

@ -189,22 +189,12 @@ double Storage::getSyncDownloadingProgress() {
return result;
}
uint64 Storage::getSyncDownloadBytesNumber() {
uint64 result = 0;
void Storage::getSyncDownloadingInfo(SyncDownloadingInfo& info) {
_runningRequestsMutex.lock();
if (_savesSyncRequest)
result = _savesSyncRequest->getDownloadedBytes();
_runningRequestsMutex.unlock();
return result;
if (_savesSyncRequest) {
_savesSyncRequest->getDownloadingInfo(info);
}
uint64 Storage::getSyncDownloadTotalBytesNumber() {
uint64 result = 0;
_runningRequestsMutex.lock();
if (_savesSyncRequest)
result = _savesSyncRequest->getBytesToDownload();
_runningRequestsMutex.unlock();
return result;
}
double Storage::getSyncProgress() {

View File

@ -185,11 +185,14 @@ public:
/** Returns a number in [0, 1] range which represents current sync downloading progress (1 = complete). */
virtual double getSyncDownloadingProgress();
/** Returns a number of bytes that is downloaded in current sync downloading progress. */
virtual uint64 getSyncDownloadBytesNumber();
struct SyncDownloadingInfo {
uint64 bytesDownloaded = 0, bytesToDownload = 0;
uint64 filesDownloaded = 0, filesToDownload = 0;
bool inProgress = false;
};
/** Returns a total number of bytes to be downloaded in current sync download progress. */
virtual uint64 getSyncDownloadTotalBytesNumber();
/** Fills a struct with numbers about current sync downloading progress. */
virtual void getSyncDownloadingInfo(SyncDownloadingInfo &info);
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
virtual double getSyncProgress();

View File

@ -100,7 +100,8 @@ void SaveLoadCloudSyncProgressDialog::handleTickle() {
void SaveLoadCloudSyncProgressDialog::pollCloudMan() {
_pollFrame = (_pollFrame + 1) % 60;
if (_pollFrame != 1) return;
if (_pollFrame != 1)
return;
const bool syncing = CloudMan.isSyncing();
const uint32 progress = (uint32)(100 * CloudMan.getSyncDownloadingProgress());
@ -109,11 +110,26 @@ void SaveLoadCloudSyncProgressDialog::pollCloudMan() {
_close = true;
}
Common::String downloaded, downloadedUnits, total, totalUnits;
downloaded = getHumanReadableBytes(CloudMan.getSyncDownloadBytesNumber(), downloadedUnits);
total = getHumanReadableBytes(CloudMan.getSyncDownloadTotalBytesNumber(), totalUnits);
Cloud::Storage::SyncDownloadingInfo info;
CloudMan.getSyncDownloadingInfo(info);
_percentLabel->setLabel(Common::String::format("%u %% (%s %S / %s %S)", progress, downloaded.c_str(), _(downloadedUnits).c_str(), total.c_str(), _(totalUnits).c_str()));
Common::String downloaded, downloadedUnits, total, totalUnits;
downloaded = getHumanReadableBytes(info.bytesDownloaded, downloadedUnits);
total = getHumanReadableBytes(info.bytesToDownload, totalUnits);
Common::String progressPercent = Common::String::format("%u %%", progress);
Common::String filesDownloaded = Common::String::format("%llu", info.filesDownloaded);
Common::String filesToDownload = Common::String::format("%llu", info.filesToDownload);
_percentLabel->setLabel(
Common::U32String::format(
_("%s (%s %S / %s %S, %s / %s files)"),
progressPercent.c_str(),
downloaded.c_str(), _(downloadedUnits).c_str(),
total.c_str(), _(totalUnits).c_str(),
filesDownloaded.c_str(), filesToDownload.c_str()
)
);
_progressBar->setValue(progress);
_progressBar->markAsDirty();
@ -389,7 +405,8 @@ ButtonWidget *SaveLoadChooserDialog::createSwitchButton(const Common::String &na
#if defined(USE_CLOUD) && defined(USE_LIBCURL)
void SaveLoadChooserDialog::pollCloudMan() {
_pollFrame = (_pollFrame + 1) % 60;
if (_pollFrame != 1) return;
if (_pollFrame != 1)
return;
const bool syncing = CloudMan.isSyncing();
const uint32 progress = (uint32)(100 * CloudMan.getSyncDownloadingProgress());
@ -405,7 +422,8 @@ void SaveLoadChooserDialog::pollCloudMan() {
}
}
if (update) updateSaveList();
if (update)
updateSaveList();
}
#endif