Skip to content

Commit

Permalink
Merge pull request #381 from cbeck88/fixup_saves
Browse files Browse the repository at this point in the history
Fixup time to load saves selected from in-game menu (bug #23359)
  • Loading branch information
cbeck88 committed Mar 6, 2015
2 parents b7a8dba + b007b5a commit 00385f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
35 changes: 17 additions & 18 deletions src/savegame.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -268,19 +263,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;
}

Expand All @@ -303,15 +302,15 @@ 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;
}

if(preferences::confirm_load_save_from_different_version()) {
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;
}
Expand Down
6 changes: 5 additions & 1 deletion src/savegame.hpp
Expand Up @@ -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);
Expand Down

0 comments on commit 00385f5

Please sign in to comment.