[Scummvm-git-logs] scummvm master -> 09639e7f230bf51974492dcdcaf58066dd5db40d
sev-
noreply at scummvm.org
Tue Aug 2 20:08:24 UTC 2022
This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
6901e941aa CLOUD: Fix #11244: Crash when loading a save from the launcher
dbbdf28482 COMMON: Redraw Save/Load dialog while syncing
645e1a0c83 CLOUD: Make cloud sync load timestamps less
85739018fe GUI: Show bytes sizes in saves sync dialog
09639e7f23 GUI: Add files amount to SaveLoadCloudSyncProgressDialog
Commit: 6901e941aa26700001b6763c5250ad89661e7575
https://github.com/scummvm/scummvm/commit/6901e941aa26700001b6763c5250ad89661e7575
Author: Alexander Tkachev (alexander at tkachov.ru)
Date: 2022-08-02T22:08:19+02:00
Commit Message:
CLOUD: Fix #11244: Crash when loading a save from the launcher
Removing GUI::CommandSender from SavesSyncRequest, so it doesn't update SaveLoadCloudSyncProgressDialog or SaveLoadChooserDialog from another thread.
Instead, these two are now polling CloudMan once per second themselves.
Changed paths:
backends/cloud/cloudmanager.cpp
backends/cloud/cloudmanager.h
backends/cloud/savessyncrequest.cpp
backends/cloud/savessyncrequest.h
backends/cloud/storage.cpp
backends/cloud/storage.h
gui/saveload-dialog.cpp
gui/saveload-dialog.h
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp
index 4eb514f9bb4..b7dafb05e4f 100644
--- a/backends/cloud/cloudmanager.cpp
+++ b/backends/cloud/cloudmanager.cpp
@@ -441,12 +441,6 @@ void CloudManager::cancelSync() const {
storage->cancelSync();
}
-void CloudManager::setSyncTarget(GUI::CommandReceiver *target) const {
- Storage *storage = getCurrentStorage();
- if (storage)
- storage->setSyncTarget(target);
-}
-
void CloudManager::showCloudDisabledIcon() {
_icon.show(CloudIcon::kDisabled, 3000);
}
diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h
index f5a57fc2d51..7bb80e72fe4 100644
--- a/backends/cloud/cloudmanager.h
+++ b/backends/cloud/cloudmanager.h
@@ -260,9 +260,6 @@ public:
/** Cancels running sync. */
void cancelSync() const;
- /** Sets SavesSyncRequest's target to given CommandReceiver. */
- void setSyncTarget(GUI::CommandReceiver *target) const;
-
/** Shows a "cloud disabled" icon for three seconds. */
void showCloudDisabledIcon();
diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp
index 8af8e25411d..3cc9342b443 100644
--- a/backends/cloud/savessyncrequest.cpp
+++ b/backends/cloud/savessyncrequest.cpp
@@ -34,7 +34,7 @@
namespace Cloud {
SavesSyncRequest::SavesSyncRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb):
- Request(nullptr, ecb), CommandSender(nullptr), _storage(storage), _boolCallback(callback),
+ Request(nullptr, ecb), _storage(storage), _boolCallback(callback),
_workingRequest(nullptr), _ignoreCallback(false) {
start();
}
@@ -269,7 +269,6 @@ void SavesSyncRequest::directoryCreatedErrorCallback(Networking::ErrorResponse e
void SavesSyncRequest::downloadNextFile() {
if (_filesToDownload.empty()) {
_currentDownloadingFile = StorageFile("", 0, 0, false); //so getFilesToDownload() would return an empty array
- sendCommand(GUI::kSavesSyncEndedCmd, 0);
uploadNextFile();
return;
}
@@ -277,8 +276,6 @@ void SavesSyncRequest::downloadNextFile() {
_currentDownloadingFile = _filesToDownload.back();
_filesToDownload.pop_back();
- sendCommand(GUI::kSavesSyncProgressCmd, (int)(getDownloadingProgress() * 100));
-
debug(9, "\nSavesSyncRequest: downloading %s (%d %%)", _currentDownloadingFile.name().c_str(), (int)(getProgress() * 100));
_workingRequest = _storage->downloadById(
_currentDownloadingFile.id(),
diff --git a/backends/cloud/savessyncrequest.h b/backends/cloud/savessyncrequest.h
index 37c41eea8ee..f648c12d88c 100644
--- a/backends/cloud/savessyncrequest.h
+++ b/backends/cloud/savessyncrequest.h
@@ -26,11 +26,10 @@
#include "backends/cloud/storage.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
-#include "gui/object.h"
namespace Cloud {
-class SavesSyncRequest: public Networking::Request, public GUI::CommandSender {
+class SavesSyncRequest: public Networking::Request {
Storage *_storage;
Storage::BoolCallback _boolCallback;
Common::HashMap<Common::String, uint32> _localFilesTimestamps;
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index 534189e24f1..1760c3d3b1c 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -214,13 +214,6 @@ void Storage::cancelSync() {
_runningRequestsMutex.unlock();
}
-void Storage::setSyncTarget(GUI::CommandReceiver *target) {
- _runningRequestsMutex.lock();
- if (_savesSyncRequest)
- _savesSyncRequest->setTarget(target);
- _runningRequestsMutex.unlock();
-}
-
void Storage::savesSyncDefaultCallback(BoolResponse response) {
_runningRequestsMutex.lock();
_savesSyncRequest = nullptr;
diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h
index 3e77e6e6cea..ef2d8896f76 100644
--- a/backends/cloud/storage.h
+++ b/backends/cloud/storage.h
@@ -194,9 +194,6 @@ public:
/** Cancels running sync. */
virtual void cancelSync();
- /** Sets SavesSyncRequest's target to given CommandReceiver. */
- virtual void setSyncTarget(GUI::CommandReceiver *target);
-
protected:
/** Finishes the sync. Shows an OSD message. */
virtual void savesSyncDefaultCallback(BoolResponse response);
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index 32b803da822..0b598ce5123 100644
--- a/gui/saveload-dialog.cpp
+++ b/gui/saveload-dialog.cpp
@@ -50,7 +50,7 @@ enum {
kBackgroundSyncCmd = 'PDBS'
};
-SaveLoadCloudSyncProgressDialog::SaveLoadCloudSyncProgressDialog(bool canRunInBackground): Dialog("SaveLoadCloudSyncProgress"), _close(false) {
+SaveLoadCloudSyncProgressDialog::SaveLoadCloudSyncProgressDialog(bool canRunInBackground): Dialog("SaveLoadCloudSyncProgress"), _close(false), _pollFrame(0) {
_label = new StaticTextWidget(this, "SaveLoadCloudSyncProgress.TitleText", _("Downloading saves..."));
uint32 progress = (uint32)(100 * CloudMan.getSyncDownloadingProgress());
_progressBar = new SliderWidget(this, "SaveLoadCloudSyncProgress.ProgressBar");
@@ -66,23 +66,15 @@ SaveLoadCloudSyncProgressDialog::SaveLoadCloudSyncProgressDialog(bool canRunInBa
}
SaveLoadCloudSyncProgressDialog::~SaveLoadCloudSyncProgressDialog() {
- CloudMan.setSyncTarget(nullptr); //not that dialog, at least
}
void SaveLoadCloudSyncProgressDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch(cmd) {
- case kSavesSyncProgressCmd:
- _percentLabel->setLabel(Common::String::format("%u%%", data));
- _progressBar->setValue(data);
- _progressBar->markAsDirty();
- break;
-
case kCancelSyncCmd:
setResult(kCancelSyncCmd);
close();
break;
- case kSavesSyncEndedCmd:
case kBackgroundSyncCmd:
_close = true;
break;
@@ -95,6 +87,8 @@ void SaveLoadCloudSyncProgressDialog::handleCommand(CommandSender *sender, uint3
}
void SaveLoadCloudSyncProgressDialog::handleTickle() {
+ pollCloudMan();
+
if (_close) {
setResult(kBackgroundSyncCmd);
close();
@@ -102,6 +96,22 @@ void SaveLoadCloudSyncProgressDialog::handleTickle() {
Dialog::handleTickle();
}
+
+void SaveLoadCloudSyncProgressDialog::pollCloudMan() {
+ _pollFrame = (_pollFrame + 1) % 60;
+ if (_pollFrame != 0) return;
+
+ const bool syncing = CloudMan.isSyncing();
+ const uint32 progress = (uint32)(100 * CloudMan.getSyncDownloadingProgress());
+
+ if (!syncing || progress == 100) {
+ _close = true;
+ }
+
+ _percentLabel->setLabel(Common::String::format("%u %%", progress));
+ _progressBar->setValue(progress);
+ _progressBar->markAsDirty();
+}
#endif
#ifndef DISABLE_SAVELOADCHOOSER_GRID
@@ -142,6 +152,9 @@ SaveLoadChooserDialog::SaveLoadChooserDialog(const Common::String &dialogName, c
#ifndef DISABLE_SAVELOADCHOOSER_GRID
, _listButton(nullptr), _gridButton(nullptr)
#endif // !DISABLE_SAVELOADCHOOSER_GRID
+#if defined(USE_CLOUD) && defined(USE_LIBCURL)
+ , _pollFrame(0), _didUpdateAfterSync(true)
+#endif
{
#ifndef DISABLE_SAVELOADCHOOSER_GRID
addChooserButtons();
@@ -155,6 +168,9 @@ SaveLoadChooserDialog::SaveLoadChooserDialog(int x, int y, int w, int h, const b
#ifndef DISABLE_SAVELOADCHOOSER_GRID
, _listButton(nullptr), _gridButton(nullptr)
#endif // !DISABLE_SAVELOADCHOOSER_GRID
+#if defined(USE_CLOUD) && defined(USE_LIBCURL)
+ , _pollFrame(0), _didUpdateAfterSync(true)
+#endif
{
#ifndef DISABLE_SAVELOADCHOOSER_GRID
addChooserButtons();
@@ -162,9 +178,6 @@ SaveLoadChooserDialog::SaveLoadChooserDialog(int x, int y, int w, int h, const b
}
SaveLoadChooserDialog::~SaveLoadChooserDialog() {
-#if defined(USE_CLOUD) && defined(USE_LIBCURL)
- CloudMan.setSyncTarget(nullptr); //not that dialog, at least
-#endif
}
void SaveLoadChooserDialog::open() {
@@ -178,9 +191,6 @@ void SaveLoadChooserDialog::open() {
}
void SaveLoadChooserDialog::close() {
-#if defined(USE_CLOUD) && defined(USE_LIBCURL)
- CloudMan.setSyncTarget(nullptr); //not that dialog, at least
-#endif
Dialog::close();
}
@@ -220,13 +230,6 @@ void SaveLoadChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uin
}
#endif // !DISABLE_SAVELOADCHOOSER_GRID
-#if defined(USE_CLOUD) && defined(USE_LIBCURL)
- if (cmd == kSavesSyncProgressCmd || cmd == kSavesSyncEndedCmd) {
- //this dialog only gets these commands if the progress dialog was shown and user clicked "run in background"
- return updateSaveList();
- }
-#endif
-
return Dialog::handleCommand(sender, cmd, data);
}
@@ -237,8 +240,6 @@ void SaveLoadChooserDialog::runSaveSync(bool hasSavepathOverride) {
CloudMan.showCloudDisabledIcon();
} else {
Cloud::SavesSyncRequest *request = CloudMan.syncSaves();
- if (request)
- request->setTarget(this);
}
}
}
@@ -251,18 +252,17 @@ void SaveLoadChooserDialog::handleTickle() {
if (!files.empty()) {
{
SaveLoadCloudSyncProgressDialog dialog(_metaEngine ? _metaEngine->hasFeature(MetaEngine::kSimpleSavesNames) : false);
- CloudMan.setSyncTarget(&dialog);
int result = dialog.runModal();
if (result == kCancelSyncCmd) {
CloudMan.cancelSync();
}
}
- //dialog changes syncTarget to nullptr after that }
- CloudMan.setSyncTarget(this);
_dialogWasShown = true;
updateSaveList();
}
}
+
+ pollCloudMan();
#endif
Dialog::handleTickle();
}
@@ -376,6 +376,29 @@ ButtonWidget *SaveLoadChooserDialog::createSwitchButton(const Common::String &na
}
#endif // !DISABLE_SAVELOADCHOOSER_GRID
+#if defined(USE_CLOUD) && defined(USE_LIBCURL)
+void SaveLoadChooserDialog::pollCloudMan() {
+ _pollFrame = (_pollFrame + 1) % 60;
+ if (_pollFrame != 0) return;
+
+ const bool syncing = CloudMan.isSyncing();
+ const uint32 progress = (uint32)(100 * CloudMan.getSyncDownloadingProgress());
+
+ bool update = false;
+ if (syncing && progress < 100) {
+ update = true;
+ _didUpdateAfterSync = false;
+ } else {
+ if (!_didUpdateAfterSync) { // do one more update when sync is over
+ update = true;
+ _didUpdateAfterSync = true;
+ }
+ }
+
+ if (update) updateSaveList();
+}
+#endif
+
// SaveLoadChooserSimple implementation
enum {
diff --git a/gui/saveload-dialog.h b/gui/saveload-dialog.h
index 3569892ef3c..7c36923e1fe 100644
--- a/gui/saveload-dialog.h
+++ b/gui/saveload-dialog.h
@@ -30,21 +30,21 @@
namespace GUI {
#if defined(USE_CLOUD) && defined(USE_LIBCURL)
-enum SaveLoadCloudSyncProgress {
- kSavesSyncProgressCmd = 'SSPR',
- kSavesSyncEndedCmd = 'SSEN'
-};
-
class SaveLoadCloudSyncProgressDialog : public Dialog { //protected?
StaticTextWidget *_label, *_percentLabel;
SliderWidget *_progressBar;
bool _close;
+ int _pollFrame;
+
public:
SaveLoadCloudSyncProgressDialog(bool canRunInBackground);
~SaveLoadCloudSyncProgressDialog() override;
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
void handleTickle() override;
+
+private:
+ void pollCloudMan();
};
#endif
@@ -130,6 +130,14 @@ protected:
void addChooserButtons();
ButtonWidget *createSwitchButton(const Common::String &name, const Common::U32String &desc, const Common::U32String &tooltip, const char *image, uint32 cmd = 0);
#endif // !DISABLE_SAVELOADCHOOSER_GRID
+
+#if defined(USE_CLOUD) && defined(USE_LIBCURL)
+ int _pollFrame;
+ bool _didUpdateAfterSync;
+
+ /** If CloudMan is syncing, this will refresh the list of saves. */
+ void pollCloudMan();
+#endif
};
class SaveLoadChooserSimple : public SaveLoadChooserDialog {
Commit: dbbdf28482fd762e4ca0434c1f9373b2eedc0f29
https://github.com/scummvm/scummvm/commit/dbbdf28482fd762e4ca0434c1f9373b2eedc0f29
Author: Alexander Tkachev (alexander at tkachov.ru)
Date: 2022-08-02T22:08:19+02:00
Commit Message:
COMMON: Redraw Save/Load dialog while syncing
A bit hacky (uses `friend`), but now while SaveLoadCloudSyncProgressDialog is modal, SaveLoadChooserDialog is still redrawing in the background, so the not-yet-ready saves buttons are being replaced with ready ones while the sync is in progress.
Changed paths:
gui/saveload-dialog.cpp
gui/saveload-dialog.h
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index 0b598ce5123..db9ea746b8a 100644
--- a/gui/saveload-dialog.cpp
+++ b/gui/saveload-dialog.cpp
@@ -50,7 +50,9 @@ enum {
kBackgroundSyncCmd = 'PDBS'
};
-SaveLoadCloudSyncProgressDialog::SaveLoadCloudSyncProgressDialog(bool canRunInBackground): Dialog("SaveLoadCloudSyncProgress"), _close(false), _pollFrame(0) {
+SaveLoadCloudSyncProgressDialog::SaveLoadCloudSyncProgressDialog(bool canRunInBackground, SaveLoadChooserDialog *parent)
+ : Dialog("SaveLoadCloudSyncProgress"), _close(false), _pollFrame(0), _parent(parent)
+{
_label = new StaticTextWidget(this, "SaveLoadCloudSyncProgress.TitleText", _("Downloading saves..."));
uint32 progress = (uint32)(100 * CloudMan.getSyncDownloadingProgress());
_progressBar = new SliderWidget(this, "SaveLoadCloudSyncProgress.ProgressBar");
@@ -62,7 +64,6 @@ SaveLoadCloudSyncProgressDialog::SaveLoadCloudSyncProgressDialog(bool canRunInBa
new ButtonWidget(this, "SaveLoadCloudSyncProgress.Cancel", _("Cancel"), Common::U32String(), kCancelSyncCmd, Common::ASCII_ESCAPE); // Cancel dialog
ButtonWidget *backgroundButton = new ButtonWidget(this, "SaveLoadCloudSyncProgress.Background", _("Run in background"), Common::U32String(), kBackgroundSyncCmd, Common::ASCII_RETURN); // Confirm dialog
backgroundButton->setEnabled(canRunInBackground);
- g_gui.scheduleTopDialogRedraw();
}
SaveLoadCloudSyncProgressDialog::~SaveLoadCloudSyncProgressDialog() {
@@ -99,7 +100,7 @@ void SaveLoadCloudSyncProgressDialog::handleTickle() {
void SaveLoadCloudSyncProgressDialog::pollCloudMan() {
_pollFrame = (_pollFrame + 1) % 60;
- if (_pollFrame != 0) return;
+ if (_pollFrame != 1) return;
const bool syncing = CloudMan.isSyncing();
const uint32 progress = (uint32)(100 * CloudMan.getSyncDownloadingProgress());
@@ -111,6 +112,11 @@ void SaveLoadCloudSyncProgressDialog::pollCloudMan() {
_percentLabel->setLabel(Common::String::format("%u %%", progress));
_progressBar->setValue(progress);
_progressBar->markAsDirty();
+
+ if (_parent) {
+ _parent->updateSaveList();
+ _parent->reflowLayout();
+ }
}
#endif
@@ -251,7 +257,7 @@ void SaveLoadChooserDialog::handleTickle() {
Common::Array<Common::String> files = CloudMan.getSyncingFiles();
if (!files.empty()) {
{
- SaveLoadCloudSyncProgressDialog dialog(_metaEngine ? _metaEngine->hasFeature(MetaEngine::kSimpleSavesNames) : false);
+ SaveLoadCloudSyncProgressDialog dialog(_metaEngine ? _metaEngine->hasFeature(MetaEngine::kSimpleSavesNames) : false, this);
int result = dialog.runModal();
if (result == kCancelSyncCmd) {
CloudMan.cancelSync();
@@ -379,7 +385,7 @@ ButtonWidget *SaveLoadChooserDialog::createSwitchButton(const Common::String &na
#if defined(USE_CLOUD) && defined(USE_LIBCURL)
void SaveLoadChooserDialog::pollCloudMan() {
_pollFrame = (_pollFrame + 1) % 60;
- if (_pollFrame != 0) return;
+ if (_pollFrame != 1) return;
const bool syncing = CloudMan.isSyncing();
const uint32 progress = (uint32)(100 * CloudMan.getSyncDownloadingProgress());
diff --git a/gui/saveload-dialog.h b/gui/saveload-dialog.h
index 7c36923e1fe..47a0612e38e 100644
--- a/gui/saveload-dialog.h
+++ b/gui/saveload-dialog.h
@@ -30,14 +30,17 @@
namespace GUI {
#if defined(USE_CLOUD) && defined(USE_LIBCURL)
+class SaveLoadChooserDialog;
+
class SaveLoadCloudSyncProgressDialog : public Dialog { //protected?
StaticTextWidget *_label, *_percentLabel;
SliderWidget *_progressBar;
+ SaveLoadChooserDialog *_parent;
bool _close;
int _pollFrame;
public:
- SaveLoadCloudSyncProgressDialog(bool canRunInBackground);
+ SaveLoadCloudSyncProgressDialog(bool canRunInBackground, SaveLoadChooserDialog *parent);
~SaveLoadCloudSyncProgressDialog() override;
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
@@ -137,6 +140,8 @@ protected:
/** If CloudMan is syncing, this will refresh the list of saves. */
void pollCloudMan();
+
+ friend class SaveLoadCloudSyncProgressDialog;
#endif
};
Commit: 645e1a0c838ffff3710235d8f59f107fee74d0ba
https://github.com/scummvm/scummvm/commit/645e1a0c838ffff3710235d8f59f107fee74d0ba
Author: Alexander Tkachev (alexander at tkachov.ru)
Date: 2022-08-02T22:08:19+02:00
Commit Message:
CLOUD: Make cloud sync load timestamps less
No need to reload the timestamps file all time (invalidating save file manager's cache) -- it's loaded once in the beginning of a sync and then is updated one file at a time.
Changed paths:
backends/cloud/savessyncrequest.cpp
diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp
index 3cc9342b443..df941aecb4e 100644
--- a/backends/cloud/savessyncrequest.cpp
+++ b/backends/cloud/savessyncrequest.cpp
@@ -301,7 +301,6 @@ void SavesSyncRequest::fileDownloadedCallback(Storage::BoolResponse response) {
}
//update local timestamp for downloaded file
- _localFilesTimestamps = DefaultSaveFileManager::loadTimestamps();
_localFilesTimestamps[_currentDownloadingFile.name()] = _currentDownloadingFile.timestamp();
DefaultSaveFileManager::saveTimestamps(_localFilesTimestamps);
@@ -352,7 +351,6 @@ void SavesSyncRequest::fileUploadedCallback(Storage::UploadResponse response) {
return;
//update local timestamp for the uploaded file
- _localFilesTimestamps = DefaultSaveFileManager::loadTimestamps();
_localFilesTimestamps[_currentUploadingFile] = response.value.timestamp();
DefaultSaveFileManager::saveTimestamps(_localFilesTimestamps);
Commit: 85739018fe54eda2158b0421c7f832a0cfd8b0c6
https://github.com/scummvm/scummvm/commit/85739018fe54eda2158b0421c7f832a0cfd8b0c6
Author: Alexander Tkachev (alexander at tkachov.ru)
Date: 2022-08-02T22:08:19+02:00
Commit Message:
GUI: Show bytes sizes in saves sync dialog
And also makes percentage calculated based on bytes sizes, not files count.
Changed paths:
backends/cloud/cloudmanager.cpp
backends/cloud/cloudmanager.h
backends/cloud/savessyncrequest.cpp
backends/cloud/savessyncrequest.h
backends/cloud/storage.cpp
backends/cloud/storage.h
gui/saveload-dialog.cpp
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp
index b7dafb05e4f..dce237683db 100644
--- a/backends/cloud/cloudmanager.cpp
+++ b/backends/cloud/cloudmanager.cpp
@@ -421,6 +421,20 @@ double CloudManager::getSyncDownloadingProgress() const {
return 1;
}
+uint64 CloudManager::getSyncDownloadBytesNumber() 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;
+}
+
double CloudManager::getSyncProgress() const {
Storage *storage = getCurrentStorage();
if (storage)
diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h
index 7bb80e72fe4..6fe12d85546 100644
--- a/backends/cloud/cloudmanager.h
+++ b/backends/cloud/cloudmanager.h
@@ -251,6 +251,12 @@ 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;
+
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
double getSyncProgress() const;
diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp
index df941aecb4e..bc0734c26e7 100644
--- a/backends/cloud/savessyncrequest.cpp
+++ b/backends/cloud/savessyncrequest.cpp
@@ -21,6 +21,8 @@
#include "backends/cloud/savessyncrequest.h"
#include "backends/cloud/cloudmanager.h"
+#include "backends/cloud/downloadrequest.h"
+#include "backends/cloud/id/iddownloadrequest.h"
#include "backends/networking/curl/curljsonrequest.h"
#include "backends/saves/default/default-saves.h"
#include "common/config-manager.h"
@@ -35,7 +37,7 @@ namespace Cloud {
SavesSyncRequest::SavesSyncRequest(Storage *storage, Storage::BoolCallback callback, Networking::ErrorCallback ecb):
Request(nullptr, ecb), _storage(storage), _boolCallback(callback),
- _workingRequest(nullptr), _ignoreCallback(false) {
+ _workingRequest(nullptr), _ignoreCallback(false), _bytesToDownload(0), _bytesDownloaded(0) {
start();
}
@@ -136,11 +138,14 @@ void SavesSyncRequest::directoryListedCallback(Storage::ListDirectoryResponse re
}
}
+ _bytesToDownload = 0;
+ _bytesDownloaded = 0;
debug(9, "\nSavesSyncRequest: ");
if (_filesToDownload.size() > 0) {
debug(9, "download files:");
for (uint32 i = 0; i < _filesToDownload.size(); ++i) {
debug(9, " %s", _filesToDownload[i].name().c_str());
+ _bytesToDownload += _filesToDownload[i].size();
}
debug(9, "%s", "");
} else {
@@ -303,6 +308,7 @@ void SavesSyncRequest::fileDownloadedCallback(Storage::BoolResponse response) {
//update local timestamp for downloaded file
_localFilesTimestamps[_currentDownloadingFile.name()] = _currentDownloadingFile.timestamp();
DefaultSaveFileManager::saveTimestamps(_localFilesTimestamps);
+ _bytesDownloaded += _currentDownloadingFile.size();
//continue downloading files
downloadNextFile();
@@ -381,6 +387,11 @@ double SavesSyncRequest::getDownloadingProgress() const {
if (_totalFilesToHandle == _filesToUpload.size())
return 1; //nothing to download => download complete
+ if (_bytesToDownload > 0) {
+ // can calculate more precise progress
+ return (double)(getDownloadedBytes()) / (double)(_bytesToDownload);
+ }
+
uint32 totalFilesToDownload = _totalFilesToHandle - _filesToUpload.size();
uint32 filesLeftToDownload = _filesToDownload.size() + (_currentDownloadingFile.name() != "" ? 1 : 0);
return (double)(totalFilesToDownload - filesLeftToDownload) / (double)(totalFilesToDownload);
@@ -405,6 +416,20 @@ Common::Array<Common::String> SavesSyncRequest::getFilesToDownload() {
return result;
}
+uint32 SavesSyncRequest::getDownloadedBytes() const {
+ double currentFileProgress = 0;
+ if (const DownloadRequest *downloadRequest = dynamic_cast<DownloadRequest *>(_workingRequest))
+ currentFileProgress = downloadRequest->getProgress();
+ else if (const Id::IdDownloadRequest *idDownloadRequest = dynamic_cast<Id::IdDownloadRequest *>(_workingRequest))
+ currentFileProgress = idDownloadRequest->getProgress();
+
+ return _bytesDownloaded + currentFileProgress * _currentDownloadingFile.size();
+}
+
+uint32 SavesSyncRequest::getBytesToDownload() const {
+ return _bytesToDownload;
+}
+
void SavesSyncRequest::finishError(Networking::ErrorResponse error, Networking::RequestState state) {
debug(9, "SavesSync::finishError");
//if we were downloading a file - remember the name
diff --git a/backends/cloud/savessyncrequest.h b/backends/cloud/savessyncrequest.h
index f648c12d88c..44bf7457c7f 100644
--- a/backends/cloud/savessyncrequest.h
+++ b/backends/cloud/savessyncrequest.h
@@ -41,6 +41,7 @@ class SavesSyncRequest: public Networking::Request {
bool _ignoreCallback;
uint32 _totalFilesToHandle;
Common::String _date;
+ uint32 _bytesToDownload, _bytesDownloaded;
void start();
void directoryListedCallback(Storage::ListDirectoryResponse response);
@@ -71,6 +72,9 @@ public:
/** 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
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index 1760c3d3b1c..70cc9247bb8 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -189,6 +189,24 @@ double Storage::getSyncDownloadingProgress() {
return result;
}
+uint64 Storage::getSyncDownloadBytesNumber() {
+ uint64 result = 0;
+ _runningRequestsMutex.lock();
+ if (_savesSyncRequest)
+ result = _savesSyncRequest->getDownloadedBytes();
+ _runningRequestsMutex.unlock();
+ return result;
+}
+
+uint64 Storage::getSyncDownloadTotalBytesNumber() {
+ uint64 result = 0;
+ _runningRequestsMutex.lock();
+ if (_savesSyncRequest)
+ result = _savesSyncRequest->getBytesToDownload();
+ _runningRequestsMutex.unlock();
+ return result;
+}
+
double Storage::getSyncProgress() {
double result = 1;
_runningRequestsMutex.lock();
diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h
index ef2d8896f76..9ebdd6e5215 100644
--- a/backends/cloud/storage.h
+++ b/backends/cloud/storage.h
@@ -182,9 +182,15 @@ public:
/** Returns whether there is a SavesSyncRequest running. */
virtual bool isSyncing();
- /** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
+ /** 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();
+
+ /** Returns a total number of bytes to be downloaded in current sync download progress. */
+ virtual uint64 getSyncDownloadTotalBytesNumber();
+
/** Returns a number in [0, 1] range which represents current sync progress (1 = complete). */
virtual double getSyncProgress();
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index db9ea746b8a..62e5a8dbedc 100644
--- a/gui/saveload-dialog.cpp
+++ b/gui/saveload-dialog.cpp
@@ -109,7 +109,11 @@ void SaveLoadCloudSyncProgressDialog::pollCloudMan() {
_close = true;
}
- _percentLabel->setLabel(Common::String::format("%u %%", progress));
+ Common::String downloaded, downloadedUnits, total, totalUnits;
+ downloaded = getHumanReadableBytes(CloudMan.getSyncDownloadBytesNumber(), downloadedUnits);
+ total = getHumanReadableBytes(CloudMan.getSyncDownloadTotalBytesNumber(), totalUnits);
+
+ _percentLabel->setLabel(Common::String::format("%u %% (%s %S / %s %S)", progress, downloaded.c_str(), _(downloadedUnits).c_str(), total.c_str(), _(totalUnits).c_str()));
_progressBar->setValue(progress);
_progressBar->markAsDirty();
Commit: 09639e7f230bf51974492dcdcaf58066dd5db40d
https://github.com/scummvm/scummvm/commit/09639e7f230bf51974492dcdcaf58066dd5db40d
Author: Alexander Tkachev (alexander at tkachov.ru)
Date: 2022-08-02T22:08:19+02:00
Commit Message:
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).
Changed paths:
backends/cloud/cloudmanager.cpp
backends/cloud/cloudmanager.h
backends/cloud/savessyncrequest.cpp
backends/cloud/savessyncrequest.h
backends/cloud/storage.cpp
backends/cloud/storage.h
gui/saveload-dialog.cpp
diff --git a/backends/cloud/cloudmanager.cpp b/backends/cloud/cloudmanager.cpp
index dce237683db..251674174ec 100644
--- a/backends/cloud/cloudmanager.cpp
+++ b/backends/cloud/cloudmanager.cpp
@@ -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 {
diff --git a/backends/cloud/cloudmanager.h b/backends/cloud/cloudmanager.h
index 6fe12d85546..a0d36b87602 100644
--- a/backends/cloud/cloudmanager.h
+++ b/backends/cloud/cloudmanager.h
@@ -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;
diff --git a/backends/cloud/savessyncrequest.cpp b/backends/cloud/savessyncrequest.cpp
index bc0734c26e7..6f7646ea4e9 100644
--- a/backends/cloud/savessyncrequest.cpp
+++ b/backends/cloud/savessyncrequest.cpp
@@ -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)
diff --git a/backends/cloud/savessyncrequest.h b/backends/cloud/savessyncrequest.h
index 44bf7457c7f..1a8bcc0a20a 100644
--- a/backends/cloud/savessyncrequest.h
+++ b/backends/cloud/savessyncrequest.h
@@ -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
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index 70cc9247bb8..ae8c09bcff7 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -189,22 +189,12 @@ double Storage::getSyncDownloadingProgress() {
return result;
}
-uint64 Storage::getSyncDownloadBytesNumber() {
- uint64 result = 0;
- _runningRequestsMutex.lock();
- if (_savesSyncRequest)
- result = _savesSyncRequest->getDownloadedBytes();
- _runningRequestsMutex.unlock();
- return result;
-}
-
-uint64 Storage::getSyncDownloadTotalBytesNumber() {
- uint64 result = 0;
+void Storage::getSyncDownloadingInfo(SyncDownloadingInfo& info) {
_runningRequestsMutex.lock();
- if (_savesSyncRequest)
- result = _savesSyncRequest->getBytesToDownload();
+ if (_savesSyncRequest) {
+ _savesSyncRequest->getDownloadingInfo(info);
+ }
_runningRequestsMutex.unlock();
- return result;
}
double Storage::getSyncProgress() {
diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h
index 9ebdd6e5215..a802e403c36 100644
--- a/backends/cloud/storage.h
+++ b/backends/cloud/storage.h
@@ -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();
-
- /** Returns a total number of bytes to be downloaded in current sync download progress. */
- virtual uint64 getSyncDownloadTotalBytesNumber();
+ struct SyncDownloadingInfo {
+ uint64 bytesDownloaded = 0, bytesToDownload = 0;
+ uint64 filesDownloaded = 0, filesToDownload = 0;
+ bool inProgress = false;
+ };
+
+ /** 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();
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index 62e5a8dbedc..cde42c93a77 100644
--- a/gui/saveload-dialog.cpp
+++ b/gui/saveload-dialog.cpp
@@ -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
More information about the Scummvm-git-logs
mailing list