The base class for all savegame stuff. More...
#include <savegame.hpp>
Public Member Functions | |
virtual | ~savegame () |
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. More... | |
bool | save_game_interactive (CVideo &video, const std::string &message, gui::DIALOG_TYPE dialog_type) |
Save a game interactively through the savegame dialog. More... | |
const std::string & | filename () const |
Protected Member Functions | |
savegame (saved_game &gamestate, const compression::format compress_saves, const std::string &title="Save") | |
The only constructor of savegame. More... | |
bool | save_game (CVideo *video=nullptr, const std::string &filename="") |
Save a game without any further user interaction. More... | |
void | set_filename (std::string filename) |
Sets the filename and removes invalid characters. More... | |
bool | check_filename (const std::string &filename, CVideo &video) |
Check, if the filename contains illegal constructs like ".gz". More... | |
void | set_error_message (const std::string &error_message) |
Customize the standard error message. More... | |
const std::string & | title () |
const saved_game & | gamestate () |
void | before_save () |
If there needs to be some data fiddling before saving the game, this is the place to go. More... | |
virtual void | write_game (config_writer &out) |
Writing the savegame config to a file. More... | |
Private Member Functions | |
virtual void | create_filename () |
Build the filename according to the specific savegame's needs. More... | |
virtual int | show_save_dialog (CVideo &video, const std::string &message, const gui::DIALOG_TYPE dialog_type) |
Display the save game dialog. More... | |
bool | check_overwrite (CVideo &video) |
Ask the user if an existing file should be overwritten. More... | |
void | write_game_to_disk (const std::string &filename) |
The actual method for saving the game to disk. More... | |
void | finish_save_game (const config_writer &out) |
Update the save_index. More... | |
filesystem::scoped_ostream | open_save_game (const std::string &label) |
Throws game::save_game_failed. More... | |
Static Private Member Functions | |
static bool | is_illegal_file_char (char c) |
Checks if a certain character is allowed in a savefile name. More... | |
Private Attributes | |
saved_game & | gamestate_ |
std::string | filename_ |
Filename of the savegame file on disk. More... | |
const std::string | title_ |
std::string | error_message_ |
Title of the savegame dialog. More... | |
bool | show_confirmation_ |
Error message to be displayed if the savefile could not be generated. More... | |
compression::format | compress_saves_ |
Determines if a confirmation of successful saving the game is shown. More... | |
Friends | |
class | save_info |
The base class for all savegame stuff.
This should not be used directly, as it does not directly produce usable saves. Instead, use one of the derived classes.
Definition at line 101 of file savegame.hpp.
|
protected |
The only constructor of savegame.
The title parameter is only necessary if you intend to do interactive saves.
Definition at line 341 of file savegame.cpp.
|
inlinevirtual |
Definition at line 109 of file savegame.hpp.
|
protected |
If there needs to be some data fiddling before saving the game, this is the place to go.
Definition at line 449 of file savegame.cpp.
|
protected |
Check, if the filename contains illegal constructs like ".gz".
Definition at line 422 of file savegame.cpp.
References _(), filesystem::is_compressed_file(), and gui2::show_error_message().
Referenced by savegame::oos_savegame::show_save_dialog().
|
private |
Ask the user if an existing file should be overwritten.
Definition at line 409 of file savegame.cpp.
References _(), filename_, gui2::twindow::OK, savegame::save_game_exists(), gui2::show_message(), and gui2::tmessage::yes_no_buttons.
|
inlineprivatevirtual |
Build the filename according to the specific savegame's needs.
Subclasses will have to override this to take effect.
Reimplemented in savegame::autosave_savegame, savegame::replay_savegame, and savegame::ingame_savegame.
Definition at line 157 of file savegame.hpp.
|
inline |
Definition at line 123 of file savegame.hpp.
References filename_.
Referenced by savegame::autosave_savegame::create_filename(), and savegame::oos_savegame::show_save_dialog().
|
private |
Update the save_index.
Definition at line 522 of file savegame.cpp.
References _(), e, config_writer::good(), savegame::save_index_class::remove(), savegame::save_index_manager, and game::error::what().
|
inlineprotected |
Definition at line 143 of file savegame.hpp.
Referenced by savegame::ingame_savegame::create_filename(), savegame::replay_savegame::create_filename(), savegame::autosave_savegame::create_filename(), savegame::ingame_savegame::write_game(), savegame::replay_savegame::write_game(), and savegame::scenariostart_savegame::write_game().
|
staticprivate |
Checks if a certain character is allowed in a savefile name.
Definition at line 433 of file savegame.cpp.
|
private |
Throws game::save_game_failed.
Definition at line 535 of file savegame.cpp.
References e, filesystem::get_saves_dir(), filesystem::ostream_file(), replace_space2underbar(), and game::error::what().
|
protected |
Save a game without any further user interaction.
If you want notifying messages or error messages to appear, you have to provide the gui parameter. The return value denotes, if the save was successful or not.
Definition at line 453 of file savegame.cpp.
References _(), e, persist_manager::end_transaction(), ERR_SAVE, filename_, LOG_SAVE, game::error::message, resources::persist, gui2::show_error_message(), gui2::show_transient_message(), and persist_manager::start_transaction().
bool savegame::savegame::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.
The return value denotes, if the save was successful or not. This is used by automatically generated replays, start-of-scenario saves, autosaves, and saves from the console (e.g. ":w").
Definition at line 350 of file savegame.cpp.
References filename_, and gui::OK_CANCEL.
Referenced by savegame::autosave_savegame::autosave(), play_controller::do_consolesave(), campaign_controller::play_game(), play_controller::save_game_auto(), play_controller::save_replay_auto(), and game_launcher::unit_test().
bool savegame::savegame::save_game_interactive | ( | CVideo & | video, |
const std::string & | message, | ||
gui::DIALOG_TYPE | dialog_type | ||
) |
Save a game interactively through the savegame dialog.
Used for manual midgame and replay saves. The return value denotes, if the save was successful or not.
Definition at line 366 of file savegame.cpp.
References gui2::twindow::OK, and throw_quit_game_exception().
Referenced by playsingle_controller::play_scenario(), playmp_controller::process_oos(), play_controller::process_oos(), play_controller::save_game(), and play_controller::save_replay().
|
inlineprotected |
Customize the standard error message.
Definition at line 140 of file savegame.hpp.
Referenced by savegame::autosave_savegame::autosave_savegame().
|
protected |
Sets the filename and removes invalid characters.
Don't set the filename directly but use this method instead.
Definition at line 442 of file savegame.cpp.
References filename_.
Referenced by savegame::ingame_savegame::create_filename(), savegame::replay_savegame::create_filename(), savegame::autosave_savegame::create_filename(), savegame::scenariostart_savegame::scenariostart_savegame(), and savegame::oos_savegame::show_save_dialog().
|
privatevirtual |
Display the save game dialog.
Reimplemented in savegame::oos_savegame.
Definition at line 385 of file savegame.cpp.
References gui2::twindow::CANCEL, filename_, gui2::tdialog::get_retval(), gui::OK_CANCEL, gui2::tdialog::show(), and gui::YES_NO.
|
inlineprotected |
Definition at line 142 of file savegame.hpp.
Referenced by savegame::oos_savegame::show_save_dialog().
|
protectedvirtual |
Writing the savegame config to a file.
Reimplemented in savegame::scenariostart_savegame, savegame::replay_savegame, and savegame::ingame_savegame.
Definition at line 510 of file savegame.cpp.
References config_writer::close_child(), log_scope, config_writer::open_child(), game_config::version, config_writer::write_key_val(), and statistics::write_stats().
Referenced by savegame::ingame_savegame::write_game(), savegame::replay_savegame::write_game(), and savegame::scenariostart_savegame::write_game().
|
private |
The actual method for saving the game to disk.
All interactive filename choosing and data manipulation has to happen before calling this method.
Definition at line 489 of file savegame.cpp.
References _(), filename_, compression::format_extension(), and LOG_SAVE.
|
friend |
Definition at line 171 of file savegame.hpp.
|
private |
Determines if a confirmation of successful saving the game is shown.
Definition at line 183 of file savegame.hpp.
|
private |
Title of the savegame dialog.
Definition at line 179 of file savegame.hpp.
|
private |
Filename of the savegame file on disk.
Definition at line 175 of file savegame.hpp.
|
private |
Definition at line 173 of file savegame.hpp.
|
private |
Error message to be displayed if the savefile could not be generated.
Definition at line 181 of file savegame.hpp.
|
private |
Definition at line 177 of file savegame.hpp.