16 #include <boost/iostreams/filter/gzip.hpp>
52 #define LOG_SAVE LOG_STREAM(info, log_engine)
53 #define ERR_SAVE LOG_STREAM(err, log_engine)
56 #define LOG_RG LOG_STREAM(info, log_enginerefac)
75 LOG_SAVE <<
"Cleaning saves with prefix '" << prefix <<
"'\n";
77 if (
i->name().compare(0, prefix.length(), prefix) == 0) {
78 LOG_SAVE <<
"Deleting savegame '" <<
i->name() <<
"'\n";
85 : game_config_(game_config)
87 , gamestate_(gamestate)
92 , cancel_orders_(false)
93 , select_difficulty_(false)
101 _(
"There are no save files to load"));
131 if(campaign[
"id"] != campaign_id) {
167 if (summary[
"corrupt"].to_bool(
false)) {
169 _(
"The file you have tried to load is corrupt: '"));
182 ,
const bool show_replay
183 ,
const bool cancel_orders
184 ,
const bool select_difficulty
186 ,
bool skip_version_check)
211 if(!error_log.empty()) {
214 _(
"Warning: The file you have tried to load is corrupt. Loading anyway.\n") +
218 _(
"Warning: The file you have tried to load is corrupt. Loading anyway.\n") +
229 if (skip_version_check) {
265 const std::string message =
_(
"This save is from an old, unsupported version ($version_number|) and cannot be loaded.");
267 symbols[
"version_number"] = save_version.
str();
273 const std::string message =
_(
"This save is from a different version of the game ($version_number|). Do you wish to try to load it?");
275 symbols[
"version_number"] = save_version.
str();
307 if(!error_log.empty()) {
309 _(
"The file you have tried to load is corrupt: '") +
329 const config &replay_start = cfg.
child(
"replay_start");
330 if (!replay_start)
return;
336 if (!snapshot)
return;
342 : gamestate_(gamestate)
345 , error_message_(
_(
"The game could not be saved: "))
346 , show_confirmation_(false)
347 , compress_saves_(compress_saves)
350 bool savegame::save_game_automatic(
CVideo& video,
bool ask_for_overwrite,
const std::string& filename)
357 if (ask_for_overwrite){
358 if (!check_overwrite(video)) {
363 return save_game(&video);
369 show_confirmation_ =
true;
372 const int res = show_save_dialog(video, message, dialog_type);
379 return save_game(&video);
409 bool savegame::check_overwrite(
CVideo& video)
416 message <<
_(
"Save already exists. Do you want to overwrite it?") <<
"\n" <<
_(
"Name: ") <<
filename_;
426 "Please remove the extension."));
433 bool savegame::is_illegal_file_char(
char c)
435 return c ==
'/' || c ==
'\\' || c ==
':'
437 || c ==
'?' || c ==
'|' || c ==
'<' || c ==
'>' || c ==
'*' || c ==
'"'
444 filename.erase(std::remove_if(filename.begin(), filename.end(),
445 is_illegal_file_char), filename.end());
449 void savegame::before_save()
458 start = SDL_GetTicks();
471 end = SDL_GetTicks();
472 LOG_SAVE <<
"Milliseconds to save " <<
filename_ <<
": " << end - start << std::endl;
474 if (video !=
nullptr && show_confirmation_)
479 if (video !=
nullptr){
491 LOG_SAVE <<
"savegame::save_game" << std::endl;
496 std::stringstream ss;
500 finish_save_game(out);
516 gamestate_.write_general_info(out);
548 :
savegame(gamestate, compress_saves)
559 :
savegame(gamestate, compress_saves,
_(
"Save Replay"))
600 filename =
_(
"Auto-Save");
635 :
savegame(gamestate, compress_saves,
_(
"Save Game")),
643 <<
" " <<
_(
"Turn") <<
" " <<
gamestate().get_starting_pos()[
"turn_at"]).str());
667 const config& replay_start = cfg.
child(
"replay_start");
673 carryover[
"random_seed"] = cfg[
"random_seed"];
674 carryover[
"random_calls"] = cfg[
"random_calls"];
676 carryover.
add_child(
"menu_item", menu_item);
678 carryover[
"difficulty"] = cfg[
"difficulty"];
679 carryover[
"random_mode"] = cfg[
"random_mode"];
681 carryover[
"next_scenario"] = cfg[
"scenario"];
683 config carryover_start = carryover;
686 if(!snapshot.
empty()){
702 }
else if (!replay_start.
empty()){
715 if(!snapshot.
empty()){
716 if(
const config& variables = snapshot.
child(
"variables")){
717 carryover.
add_child(
"variables", variables);
719 }
else if (
const config& variables = cfg.
child(
"variables")){
720 carryover.
add_child(
"variables", variables);
721 carryover_start.
add_child(
"variables", variables);
723 }
else if (!replay_start.
empty()){
724 if(
const config& variables = replay_start.
child(
"variables")){
725 carryover.
add_child(
"variables", variables);
726 carryover_start.
add_child(
"variables", variables);
733 cfg.
add_child(
"carryover_sides", carryover);
734 cfg.
add_child(
"carryover_sides_start", carryover_start);
739 LOG_RG<<
"removing replay_start \n";
745 LOG_RG<<
"removing replay \n";
749 if(snapshot.
empty()){
750 LOG_RG<<
"removing snapshot \n";
757 if(
config& carryover_sides_start = cfg.
child(
"carryover_sides_start"))
759 if(!carryover_sides_start.has_attribute(
"next_underlying_unit_id"))
761 carryover_sides_start[
"next_underlying_unit_id"] = cfg[
"next_underlying_unit_id"];
777 snapshot.add_child(
"end_level_data", end_level);
778 snapshot.clear_children(
"end_level");
781 if(cfg.
has_child(
"carryover_sides_start"))
793 (
"mp_era",
"era_blank")
794 (
"show_connect",
false)
795 (
"show_configure",
false)
796 (
"mp_use_map_settings",
true)
805 if(
config& multiplayer = cfg.
child(
"multiplayer")) {
806 if(multiplayer[
"mp_era"] ==
"era_blank") {
807 multiplayer[
"mp_era"] =
"era_default";
811 if(
config& carryover_sides_start = cfg.
child(
"carryover_sides_start"))
829 if (snapshot.has_attribute(
"used_items")) {
832 used_items[item] =
true;
835 snapshot.add_child(
"used_items", used_items);
857 LOG_RG<<
"cfg after conversion "<<cfg<<
"\n";
std::string difficulty_
Name of the savefile to be loaded.
void show_difficulty_dialog()
Display the difficulty dialog.
bool select_difficulty_
State of the "cancel_orders" checkbox in the load-game dialog.
child_itors child_range(const std::string &key)
void remove_old_auto_saves(const int autosavemax, const int infinite_auto_saves)
Remove autosaves that are no longer needed (according to the autosave policy in the preferences)...
void remove_attribute(const std::string &key)
bool load_game()
Load a game without providing any information.
void show_error_message(CVideo &video, const std::string &message, bool message_use_markup)
Shows an error message to the user.
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
static void convert_old_saves_1_13_1(config &cfg)
void read_save_file(const std::string &name, config &cfg, std::string *error_log)
Read the complete config information out of a savefile.
bool cancel_orders() const
std::string label
Name of the game (e.g.
void write_game(config_writer &out)
Writing the savegame config to a file.
game_classification * classification
virtual void write_game(config_writer &out)
Writing the savegame config to a file.
const char * what() const
static void convert_old_saves_1_13_0(config &cfg)
void set_gamestate()
Generate the gamestate out of the loaded game config.
replay_savegame(saved_game &gamestate, const compression::format compress_saves)
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
replay_recorder_base & get_replay()
void remove(const std::string &name)
ingame_savegame(saved_game &gamestate, game_display &gui, const compression::format compress_saves)
void show_transient_error_message(CVideo &video, const std::string &message, const std::string &image, const bool message_use_markup)
Shows a transient error message to the user.
void show_dialog()
Display the load-game dialog.
std::vector< save_info > get_saves_list(const std::string *dir, const std::string *filter)
Get a list of available saves.
Error used when game saving fails.
void show_transient_message(CVideo &video, const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup, const bool restore_background)
Shows a transient message to the user.
Class for "normal" midgame saves.
persist_manager * persist
bool confirm_load_save_from_different_version()
bool check_filename(const std::string &filename, CVideo &video)
Check, if the filename contains illegal constructs like ".gz".
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
const config & child_or_empty(const std::string &key) const
Returns the first child with the given key, or an empty config if there is none.
virtual void create_filename()
Create a filename for automatic saves.
void clear_children(const std::string &key)
std::string get_saves_dir()
bool cancel_orders() const
loadgame(CVideo &video, const config &game_config, saved_game &gamestate)
scenariostart_savegame(saved_game &gamestate, const compression::format compress_saves)
The base class for all savegame stuff.
void write_child(const std::string &key, const config &cfg)
void write_game(config_writer &out)
Writing the savegame config to a file.
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
static UNUSEDNOWARN std::string _(const char *str)
void throw_quit_game_exception()
void write_key_val(const std::string &key, const T &value)
This template function will work with any type that can be assigned to an attribute_value.
Dialog is closed with ok button.
std::map< std::string, t_string > string_map
const std::string & filename() const
virtual void create_filename()
Create a filename for automatic saves.
void close_child(const std::string &key)
config summary_
State of the "change_difficulty" checkbox in the load-game dialog.
Class for writing a config out to a file in pieces.
autosave_savegame(saved_game &gamestate, game_display &gui, const compression::format compress_saves)
Dialog is closed with the cancel button.
const version_info test_version("test")
void open_child(const std::string &key)
void show_message(CVideo &video, const std::string &title, const std::string &message, const std::string &button_caption, const bool auto_close, const bool message_use_markup)
Shows a message to the user.
void delete_game(const std::string &name)
Delete a savegame.
bool save_game_exists(const std::string &name, compression::format compressed)
Returns true if there is already a savegame with that name.
std::ostream * ostream_file(std::string const &fname, bool create_directory=true)
static bool is_replay_save(const config &cfg)
void write(config_writer &out) const
config & add_child(const std::string &key)
virtual int show_save_dialog(CVideo &video, const std::string &message, const gui::DIALOG_TYPE dialog_type)
Display the save game dialog.
save_index_class save_index_manager
Modify, read and display user preferences.
config & get_starting_pos()
void set_data(config &cfg)
destroys the passed config.
const config & game_config_
std::string str() const
Serializes the version number into string form.
std::string selected_difficulty() const
Returns the selected difficulty define after displaying.
void convert_old_saves(config &cfg)
converts saves from older versions of wesnoth
bool change_difficulty() const
void replace_space2underbar(std::string &name)
std::string format_extension(format compression_format)
config & get(const std::string &name)
void write_game(config_writer &out)
Writing the savegame config to a file.
Thrown by operations encountering invalid UTF-8 data.
void clean_saves(const std::string &label)
Delete all autosaves of a certain scenario.
Game configuration data as global variables.
An exception object used when an IO error occurs.
unsigned int minor_version() const
Retrieves the minor version number (x2 in "x1.x2.x3").
Exception used to signal that the user has decided to abort a game, and to load another game instead...
unsigned int major_version() const
Retrieves the major version number (x1 in "x1.x2.x3").
bool is_compressed_file(const std::string &filename)
#define log_scope(description)
const std::string & filename() const
virtual void create_filename()
Create a filename for automatic saves.
const version_info wesnoth_version(VERSION)
bool load_multiplayer_game()
Loading a game from within the multiplayer-create dialog.
void set_filename(std::string filename)
Sets the filename and removes invalid characters.
Represents version numbers.
const std::string & title()
GLuint const GLchar * name
void copy_era(config &cfg)
Copy era information into the snapshot.
void set_error_message(const std::string &error_message)
Customize the standard error message.
compression::format save_compression_format()
static lg::log_domain log_enginerefac("enginerefac")
std::string filename_
Primary output information.
const std::vector< std::string > & modifications(bool mp)
const saved_game & gamestate()
game_classification & classification()
static void convert_old_saves_1_11_0(config &cfg)
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Standard logging facilities (interface).
void autosave(const bool disable_autosave, const int autosave_max, const int infinite_autosaves)
CVideo & video()
Gets the underlying screen object.
GLsizei GLenum GLuint GLuint GLsizei char * message
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
const std::string & filename() const
A config object defines a single node in a WML file, with access to child nodes.
void write_carryover(config_writer &out) const
config load_config_
The difficulty the save is meant to be loaded with.
const version_info min_savegame_version(MIN_SAVEGAME_VERSION)
bool cancel_orders_
State of the "show_replay" checkbox in the load-game dialog.
bool check_version_compatibility()
Call check_version_compatibility above, using the version of this savefile.
Interfaces for manipulating version numbers of engine, add-ons, etc.
bool file_exists(const std::string &name)
Returns true if a file or directory with such name already exists.
const std::string version
static lg::log_domain log_engine("engine")
GLsizei const GLcharARB ** string
bool save_game_automatic(CVideo &video, bool ask_for_overwrite=false, const std::string &filename="")
Saves a game without user interaction, unless the file exists and it should be asked to overwrite it...
Shows a yes and no button.
bool show_replay_
Config information of the savefile to be loaded.
std::string version
Version game was created with.
oos_savegame(saved_game &gamestate, game_display &gui, bool &ignore)