From c47c92da22da45ca689fc1958f0de1c4f13de8d7 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Fri, 6 Mar 2015 17:55:12 -0500 Subject: [PATCH 1/2] savegame logic: make the version check GUI sequence a static fcn This allows it to be used just with the data from a save index record and not an entire loaded save. --- src/savegame.cpp | 16 ++++++++++------ src/savegame.hpp | 6 +++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/savegame.cpp b/src/savegame.cpp index 5c62f753eb70..88dd984dd209 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -268,19 +268,23 @@ bool loadgame::load_game( bool loadgame::check_version_compatibility() { - if (gamestate_.classification().version == game_config::version) { + return loadgame::check_version_compatibility(gamestate_.classification().version, gui_.video()); +} + +bool loadgame::check_version_compatibility(const version_info & save_version, CVideo & video) +{ + if (save_version == game_config::version) { return true; } - const version_info save_version = gamestate_.classification().version; const version_info &wesnoth_version = game_config::wesnoth_version; // If the version isn't good, it probably isn't a compatible stable one, // and the following comparisons would throw. if (!save_version.good()) { const std::string message = _("The save has corrupt version information ($version_number|) and cannot be loaded."); utils::string_map symbols; - symbols["version_number"] = gamestate_.classification().version; - gui2::show_error_message(gui_.video(), utils::interpolate_variables_into_string(message, &symbols)); + symbols["version_number"] = save_version.str(); + gui2::show_error_message(video, utils::interpolate_variables_into_string(message, &symbols)); return false; } @@ -303,7 +307,7 @@ bool loadgame::check_version_compatibility() const std::string message = _("This save is from an old, unsupported version ($version_number|) and cannot be loaded."); utils::string_map symbols; symbols["version_number"] = save_version.str(); - gui2::show_error_message(gui_.video(), utils::interpolate_variables_into_string(message, &symbols)); + gui2::show_error_message(video, utils::interpolate_variables_into_string(message, &symbols)); return false; } @@ -311,7 +315,7 @@ bool loadgame::check_version_compatibility() const std::string message = _("This save is from a different version of the game ($version_number|). Do you wish to try to load it?"); utils::string_map symbols; symbols["version_number"] = save_version.str(); - const int res = gui2::show_message(gui_.video(), _("Load Game"), utils::interpolate_variables_into_string(message, &symbols), + const int res = gui2::show_message(video, _("Load Game"), utils::interpolate_variables_into_string(message, &symbols), gui2::tmessage::yes_no_buttons); return res == gui2::twindow::OK; } diff --git a/src/savegame.hpp b/src/savegame.hpp index 58c56505ed71..79aeb344a182 100644 --- a/src/savegame.hpp +++ b/src/savegame.hpp @@ -61,12 +61,16 @@ class loadgame bool show_replay() const { return show_replay_; } bool cancel_orders() const { return cancel_orders_; } const std::string & filename() const { return filename_; } + + /** GUI Dialog sequence which confirms attempts to load saves from previous game versions. */ + static bool check_version_compatibility(const version_info & version, CVideo & video); + private: /** Display the load-game dialog. */ void show_dialog(bool show_replay, bool cancel_orders); /** Display the difficulty dialog. */ void show_difficulty_dialog(); - /** Check if the version of the savefile is compatible with the current version. */ + /** Call check_version_compatibility above, using the version of this savefile. */ bool check_version_compatibility(); /** Copy era information into the snapshot. */ void copy_era(config& cfg); From b007b5a8d09980e10c5e7192f5620319e0d88edf Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Fri, 6 Mar 2015 17:58:19 -0500 Subject: [PATCH 2/2] fix bug #23359: use save index for health, version checks of saves If we load the entire save for this purpose, then it means that we will sometimes load the entire save twice, which is reported to be significantly slower. --- src/savegame.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/savegame.cpp b/src/savegame.cpp index 88dd984dd209..cd8499f33174 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -42,6 +42,7 @@ #include "persist_manager.hpp" #include "replay.hpp" #include "resources.hpp" +#include "save_index.hpp" #include "serialization/binary_or_text.hpp" #include "serialization/parser.hpp" #include "statistics.hpp" @@ -178,24 +179,18 @@ bool loadgame::load_game() return false; } - std::string error_log; - { - cursor::setter cur(cursor::WAIT); - log_scope("load_game"); - - read_save_file(filename_, load_config_, &error_log); + // Confirm the integrity of the file before throwing the exception. + // Use the summary in the save_index for this. - gamestate_ = saved_game(load_config_); - } + const config & summary = save_index_manager.get(filename_); - if(!error_log.empty()) { + if (summary["corrupt"].to_bool(false)) { gui2::show_error_message(gui_.video(), - _("The file you have tried to load is corrupt: '") + - error_log); + _("The file you have tried to load is corrupt: '")); return false; } - if (!check_version_compatibility()) { + if (!loadgame::check_version_compatibility(summary["version"].str(), gui_.video())) { return false; }