From ddbd2b483c3ac8869c856c96fe84023b3458e99d Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Mon, 8 Dec 2014 15:14:33 +1100 Subject: [PATCH] Begin removal of exceptions from savegame code --- .../multiplayer_create.cpp | 9 ++---- src/play_controller.cpp | 6 ++-- src/savegame.cpp | 28 +++++++++---------- src/savegame.hpp | 6 ++-- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/game_initialization/multiplayer_create.cpp b/src/game_initialization/multiplayer_create.cpp index 663c33e4e6e5c..7e3468b13b886 100644 --- a/src/game_initialization/multiplayer_create.cpp +++ b/src/game_initialization/multiplayer_create.cpp @@ -272,13 +272,8 @@ void create::process_event() return; } - catch (load_game_cancelled_exception) - { - } - catch(config::error&) - { - } - + catch (load_game_cancelled_exception) {} + catch(config::error&) {} } bool update_mod_button_label = mod_selection_ != mods_menu_.selection(); diff --git a/src/play_controller.cpp b/src/play_controller.cpp index 3752b92f7fa9c..074bc1e04d6fc 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -318,8 +318,10 @@ void play_controller::save_map(){ } void play_controller::load_game(){ - savegame::loadgame load(*gui_, game_config_, saved_game_); - load.load_game(); + if (savegame::loadgame::load_game) { + savegame::loadgame load(*gui_, game_config_, saved_game_); + load.load_game(); + } } void play_controller::preferences(){ diff --git a/src/savegame.cpp b/src/savegame.cpp index adc21cce1c94e..3c6ac9f4f24b9 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -175,7 +175,7 @@ void loadgame::load_game() throw game::load_game_exception(filename_, show_replay_, cancel_orders_, select_difficulty_, difficulty_); } -void loadgame::load_game( +bool loadgame::load_game( const std::string& filename , const bool show_replay , const bool cancel_orders @@ -195,7 +195,7 @@ void loadgame::load_game( } if (filename_.empty()) - throw load_game_cancelled_exception(); + return false; if (select_difficulty_) show_difficulty_dialog(); @@ -230,14 +230,14 @@ void loadgame::load_game( // read classification to for loading the game_config config object. gamestate_.classification() = game_classification(load_config_); #endif - check_version_compatibility(); + return check_version_compatibility(); } -void loadgame::check_version_compatibility() +bool loadgame::check_version_compatibility() { if (gamestate_.classification().version == game_config::version) { - return; + return true; } const version_info save_version = gamestate_.classification().version; @@ -249,7 +249,7 @@ void loadgame::check_version_compatibility() utils::string_map symbols; symbols["version_number"] = gamestate_.classification().version; gui2::show_error_message(gui_.video(), utils::interpolate_variables_into_string(message, &symbols)); - throw load_game_cancelled_exception(); + return false; } // Even minor version numbers indicate stable releases which are @@ -258,7 +258,7 @@ void loadgame::check_version_compatibility() wesnoth_version.major_version() == save_version.major_version() && wesnoth_version.minor_version() == save_version.minor_version()) { - return; + return true; } // Do not load if too old. If either the savegame or the current @@ -272,7 +272,7 @@ void loadgame::check_version_compatibility() utils::string_map symbols; symbols["version_number"] = save_version.str(); gui2::show_error_message(gui_.video(), utils::interpolate_variables_into_string(message, &symbols)); - throw load_game_cancelled_exception(); + return false; } int res = gui2::twindow::OK; @@ -285,7 +285,7 @@ void loadgame::check_version_compatibility() } if(res == gui2::twindow::CANCEL) { - throw load_game_cancelled_exception(); + return false; } } @@ -294,12 +294,12 @@ void loadgame::set_gamestate() gamestate_ = saved_game(load_config_); } -void loadgame::load_multiplayer_game() +bool loadgame::load_multiplayer_game() { show_dialog(false, false); if (filename_.empty()) - throw load_game_cancelled_exception(); + return false; std::string error_log; { @@ -316,15 +316,15 @@ void loadgame::load_multiplayer_game() gui2::show_error_message(gui_.video(), _("The file you have tried to load is corrupt: '") + error_log); - throw load_game_cancelled_exception(); + return false; } if(gamestate_.classification().campaign_type != game_classification::MULTIPLAYER) { gui2::show_transient_error_message(gui_.video(), _("This is not a multiplayer save.")); - throw load_game_cancelled_exception(); + return false; } - check_version_compatibility(); + return check_version_compatibility(); } void loadgame::copy_era(config &cfg) diff --git a/src/savegame.hpp b/src/savegame.hpp index b934d3796218a..0fb499b0511e9 100644 --- a/src/savegame.hpp +++ b/src/savegame.hpp @@ -45,14 +45,14 @@ class loadgame /** Load a game without providing any information. */ void load_game(); /** Load a game with pre-setting information for the load-game dialog. */ - void load_game( + bool load_game( const std::string& filename , const bool show_replay , const bool cancel_orders , const bool select_difficulty , const std::string& difficulty); /** Loading a game from within the multiplayer-create dialog. */ - void load_multiplayer_game(); + bool load_multiplayer_game(); /** Generate the gamestate out of the loaded game config. */ void set_gamestate(); @@ -66,7 +66,7 @@ class loadgame /** Display the difficulty dialog. */ void show_difficulty_dialog(); /** Check if the version of the savefile is compatible with the current version. */ - void check_version_compatibility(); + bool check_version_compatibility(); /** Copy era information into the snapshot. */ void copy_era(config& cfg);