Skip to content

Commit

Permalink
Begin removal of exceptions from savegame code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Dec 8, 2014
1 parent 6102ff4 commit ddbd2b4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
9 changes: 2 additions & 7 deletions src/game_initialization/multiplayer_create.cpp
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/play_controller.cpp
Expand Up @@ -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(){
Expand Down
28 changes: 14 additions & 14 deletions src/savegame.cpp
Expand Up @@ -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
Expand All @@ -195,7 +195,7 @@ void loadgame::load_game(
}

if (filename_.empty())
throw load_game_cancelled_exception();
return false;

if (select_difficulty_)
show_difficulty_dialog();
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -285,7 +285,7 @@ void loadgame::check_version_compatibility()
}

if(res == gui2::twindow::CANCEL) {
throw load_game_cancelled_exception();
return false;
}
}

Expand All @@ -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;
{
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/savegame.hpp
Expand Up @@ -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();

Expand All @@ -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);

Expand Down

0 comments on commit ddbd2b4

Please sign in to comment.