[Scummvm-git-logs] scummvm master -> 873ba580fb51ae38c9768ac04dd9202ee2bc0b09
sev-
sev at scummvm.org
Mon Aug 23 23:37:08 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
873ba580fb GUI: Warn when enabling autosave on options
Commit: 873ba580fb51ae38c9768ac04dd9202ee2bc0b09
https://github.com/scummvm/scummvm/commit/873ba580fb51ae38c9768ac04dd9202ee2bc0b09
Author: Orgad Shaneh (orgads at gmail.com)
Date: 2021-08-24T01:37:06+02:00
Commit Message:
GUI: Warn when enabling autosave on options
...if non-autosave games are stored in autosave slot
Changed paths:
gui/options.cpp
gui/options.h
diff --git a/gui/options.cpp b/gui/options.cpp
index 2dd7cc7628..90be14d544 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -38,6 +38,7 @@
#include "common/config-manager.h"
#include "common/gui_options.h"
#include "common/rendermode.h"
+#include "common/savefile.h"
#include "common/system.h"
#include "common/textconsole.h"
#include "common/translation.h"
@@ -2476,6 +2477,91 @@ void GlobalOptionsDialog::addAccessibilityControls(GuiObject *boss, const Common
}
#endif // USE_TTS
+struct ExistingSave {
+ MetaEngine *metaEngine;
+ Common::String target;
+ SaveStateDescriptor desc;
+
+ ExistingSave(MetaEngine *_metaEngine, const Common::String &_target, const SaveStateDescriptor &_desc) :
+ metaEngine(_metaEngine),
+ target(_target),
+ desc(_desc)
+ {}
+};
+
+bool GlobalOptionsDialog::updateAutosavePeriod(int newValue) {
+ const int oldAutosavePeriod = ConfMan.getInt("autosave_period");
+ if (oldAutosavePeriod != 0 || newValue <= 0)
+ return true;
+ typedef Common::Array<ExistingSave> ExistingSaveList;
+ ExistingSaveList saveList;
+ using Common::ConfigManager;
+ const int maxListSize = 10;
+ bool hasMore = false;
+ const ConfigManager::DomainMap &domains = ConfMan.getGameDomains();
+ for (ConfigManager::DomainMap::const_iterator it = domains.begin(), end = domains.end(); it != end; ++it) {
+ const Common::String target = it->_key;
+ const ConfigManager::Domain domain = it->_value;
+ const Common::String engine = domain["engineid"];
+ if (const Plugin *detectionPlugin = EngineMan.findPlugin(engine)) {
+ if (const Plugin *plugin = PluginMan.getEngineFromMetaEngine(detectionPlugin)) {
+ MetaEngine &metaEngine = plugin->get<MetaEngine>();
+ const int autoSaveSlot = metaEngine.getAutosaveSlot();
+ if (autoSaveSlot < 0)
+ continue;
+ SaveStateDescriptor desc = metaEngine.querySaveMetaInfos(target.c_str(), autoSaveSlot);
+ if (desc.getSaveSlot() != -1 && !desc.getDescription().empty() && !desc.hasAutosaveName()) {
+ if (saveList.size() >= maxListSize) {
+ hasMore = true;
+ break;
+ }
+ saveList.push_back(ExistingSave(&metaEngine, target, desc));
+ }
+ }
+ }
+ }
+ Common::U32StringArray altButtons;
+ altButtons.push_back(_("Ignore"));
+ altButtons.push_back(_("Disable autosave"));
+ Common::U32String message = _("WARNING: Autosave was enabled. Some of your games have existing "
+ "saved games on the autosave slot. You can either move the "
+ "existing saves to new slots, disable autosave, or ignore (you "
+ "will be prompted when autosave is about to overwrite a save).\n"
+ "List of games:\n");
+ for (ExistingSaveList::const_iterator it = saveList.begin(), end = saveList.end(); it != end; ++it)
+ message += Common::U32String(it->target) + Common::U32String(": ") + it->desc.getDescription() + "\n";
+ message.deleteLastChar();
+ if (hasMore)
+ message += _("\nAnd more...");
+ GUI::MessageDialog warn(message, _("Move"), altButtons);
+ switch (warn.runModal()) {
+ case GUI::kMessageOK: {
+ ExistingSaveList failedSaves;
+ for (ExistingSaveList::const_iterator it = saveList.begin(), end = saveList.end(); it != end; ++it) {
+ if (it->metaEngine->copySaveFileToFreeSlot(it->target.c_str(), it->desc.getSaveSlot())) {
+ g_system->getSavefileManager()->removeSavefile(
+ it->metaEngine->getSavegameFile(it->desc.getSaveSlot(), it->target.c_str()));
+ } else {
+ failedSaves.push_back(*it);
+ }
+ }
+ if (!failedSaves.empty()) {
+ Common::U32String failMessage = _("ERROR: Failed to move the following saved games:\n");
+ for (ExistingSaveList::const_iterator it = failedSaves.begin(), end = failedSaves.end(); it != end; ++it)
+ failMessage += Common::U32String(it->target) + Common::U32String(": ") + it->desc.getDescription() + "\n";
+ failMessage.deleteLastChar();
+ GUI::MessageDialog(failMessage).runModal();
+ }
+ break;
+ }
+ case GUI::kMessageAlt:
+ break;
+ case GUI::kMessageAlt + 1:
+ return false;
+ }
+ return true;
+}
+
void GlobalOptionsDialog::apply() {
OptionsDialog::apply();
@@ -2522,7 +2608,11 @@ void GlobalOptionsDialog::apply() {
if (oldGuiScale != (int)_guiBasePopUp->getSelectedTag())
g_gui.computeScaleFactor();
- ConfMan.setInt("autosave_period", _autosavePeriodPopUp->getSelectedTag(), _domain);
+ const int autosavePeriod = _autosavePeriodPopUp->getSelectedTag();
+ if (updateAutosavePeriod(autosavePeriod))
+ ConfMan.setInt("autosave_period", autosavePeriod, _domain);
+ else
+ _autosavePeriodPopUp->setSelected(0);
#ifdef USE_UPDATES
ConfMan.setInt("updates_check", _updatesPopUp->getSelectedTag());
diff --git a/gui/options.h b/gui/options.h
index 4112a0adbd..959300fc24 100644
--- a/gui/options.h
+++ b/gui/options.h
@@ -317,6 +317,7 @@ protected:
PopUpWidget *_updatesPopUp;
#endif
+ bool updateAutosavePeriod(int newValue);
void addMiscControls(GuiObject *boss, const Common::String &prefix, bool lowres);
#ifdef USE_CLOUD
More information about the Scummvm-git-logs
mailing list