diff --git a/src/saved_game.cpp b/src/saved_game.cpp index fb16d006fb2e..cfe2855a26da 100644 --- a/src/saved_game.cpp +++ b/src/saved_game.cpp @@ -85,6 +85,38 @@ static lg::log_domain log_engine("engine"); #define LOG_NG LOG_STREAM(info, log_engine) #define DBG_NG LOG_STREAM(debug, log_engine) +namespace +{ +bool variable_to_bool(const config& vars, const std::string& expression) +{ + std::string res = utils::interpolate_variables_into_string(expression, config_variable_set(vars)); + return res == "true" || res == "yes" || res == "1"; +} + +// helper objects for saved_game::expand_mp_events() +struct modevents_entry +{ + modevents_entry(const std::string& _type, const std::string& _id) + : type(_type) + , id(_id) + { + } + + std::string type; + std::string id; +}; + +bool is_illegal_file_char(char c) +{ + return c == '/' || c == '\\' || c == ':' || (c >= 0x00 && c < 0x20) +#ifdef _WIN32 + || c == '?' || c == '|' || c == '<' || c == '>' || c == '*' || c == '"' +#endif + ; +} + +} // end anon namespace + saved_game::saved_game() : has_carryover_expanded_(false) , carryover_(carryover_info().to_config()) @@ -275,29 +307,6 @@ void saved_game::check_require_scenario() mp_settings_.update_addon_requirements(required_scenario); } -namespace -{ -bool variable_to_bool(const config& vars, const std::string& expression) -{ - std::string res = utils::interpolate_variables_into_string(expression, config_variable_set(vars)); - return res == "true" || res == "yes" || res == "1"; -} - -// helper objects for saved_game::expand_mp_events() -struct modevents_entry -{ - modevents_entry(const std::string& _type, const std::string& _id) - : type(_type) - , id(_id) - { - } - - std::string type; - std::string id; -}; - -} // end anon namespace - void saved_game::load_mod(const std::string& type, const std::string& id, size_t pos) { if(const config& cfg = game_config_manager::get()->game_config().find_child(type, "id", id)) { @@ -620,11 +629,16 @@ bool saved_game::not_corrupt() const void saved_game::update_label() { + std::string& label = classification().label; + if(classification().abbrev.empty()) { - classification().label = starting_point_["name"].str(); + label = starting_point_["name"].str(); } else { - classification().label = classification().abbrev + "-" + starting_point_["name"]; + label = classification().abbrev + "-" + starting_point_["name"]; } + + label.erase(std::remove_if(label.begin(), label.end(), is_illegal_file_char), label.end()); + std::replace(label.begin(), label.end(), '_', ' '); } void saved_game::cancel_orders() diff --git a/src/savegame.cpp b/src/savegame.cpp index 3b60741d2235..f985bd9eb097 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -414,22 +414,9 @@ bool savegame::check_filename(const std::string& filename) return true; } -bool savegame::is_illegal_file_char(char c) -{ - return c == '/' || c == '\\' || c == ':' || (c >= 0x00 && c < 0x20) -#ifdef _WIN32 - || c == '?' || c == '|' || c == '<' || c == '>' || c == '*' || c == '"' -#endif - ; -} - std::string savegame::create_filename(unsigned int turn_number) const { - std::string filename = create_initial_filename(turn_number); - filename.erase(std::remove_if(filename.begin(), filename.end(), - is_illegal_file_char), filename.end()); - std::replace(filename.begin(), filename.end(), '_', ' '); - return filename; + return create_initial_filename(turn_number); } void savegame::before_save() diff --git a/src/savegame.hpp b/src/savegame.hpp index a7959b8a97e0..3b1de6e45315 100644 --- a/src/savegame.hpp +++ b/src/savegame.hpp @@ -208,9 +208,6 @@ class savegame std::string title_; private: - /** Checks if a certain character is allowed in a savefile name. */ - static bool is_illegal_file_char(char c); - /** Subclass-specific part of filename building. */ virtual std::string create_initial_filename(unsigned int turn_number) const = 0; /** Display the save game dialog. */