#include <save_index.hpp>
Public Types | |
enum class | create_for_default_saves_dir { yes } |
Syntatic sugar for choosing which constructor to use. More... | |
Public Member Functions | |
save_index_class (const std::string &dir) | |
Constructor for a read-only instance. More... | |
save_index_class (create_for_default_saves_dir) | |
std::vector< save_info > | get_saves_list (const std::string *filter=nullptr) |
Get a list of available saves. More... | |
void | delete_game (const std::string &name) |
Delete a savegame, including deleting the underlying file. More... | |
void | rebuild (const std::string &name) |
void | rebuild (const std::string &name, const std::time_t &modified) |
void | remove (const std::string &name) |
Delete a savegame from the index, without deleting the underlying file. More... | |
void | set_modified (const std::string &name, const std::time_t &modified) |
config & | get (const std::string &name) |
const std::string & | dir () const |
void | delete_old_auto_saves (const int autosavemax, const int infinite_auto_saves) |
Delete autosaves that are no longer needed (according to the autosave policy in the preferences). More... | |
void | write_save_index () |
Sync to disk, no-op if read_only_ is set. More... | |
bool | read_only () |
If true, all of delete_game, delete_old_auto_saves and write_save_index will be no-ops. More... | |
Static Public Member Functions | |
static std::shared_ptr< save_index_class > | default_saves_dir () |
Returns an instance for managing saves in filesystem::get_saves_dir() More... | |
Private Member Functions | |
config & | data (const std::string &name) |
config & | data () |
void | clean_up_index () |
Deletes non-existent save files from the index. More... | |
Static Private Member Functions | |
static void | fix_leader_image_path (config &data) |
Private Attributes | |
bool | loaded_ |
config | data_ |
std::map< std::string, std::time_t > | modified_ |
const std::string | dir_ |
bool | read_only_ |
The instance for default_saves_dir() writes a cache file. More... | |
bool | clean_up_index_ |
Flag to only run the clean_up_index method once. More... | |
Definition at line 78 of file save_index.hpp.
Syntatic sugar for choosing which constructor to use.
Enumerator | |
---|---|
yes |
Definition at line 86 of file save_index.hpp.
|
explicit |
Constructor for a read-only instance.
To get a writable instance, call default_saves_dir().
Definition at line 143 of file save_index.cpp.
|
explicit |
Definition at line 153 of file save_index.cpp.
References read_only_.
|
private |
Deletes non-existent save files from the index.
Definition at line 99 of file save_index.cpp.
References config::all_children_count(), d, data(), dir(), filesystem::get_files_in_dir(), and config::remove_children().
Referenced by write_save_index().
|
private |
Definition at line 172 of file save_index.cpp.
References config::clear(), data_, e, ERR_SAVE, filesystem::file_exists(), filesystem::get_save_index_file(), filesystem::istream_file(), loaded_, read(), and read_gz().
Referenced by clean_up_index(), data(), fix_leader_image_path(), get(), rebuild(), remove(), and write_save_index().
|
private |
Definition at line 159 of file save_index.cpp.
References config::add_child(), data(), config::find_child(), and fix_leader_image_path().
|
static |
Returns an instance for managing saves in filesystem::get_saves_dir()
Definition at line 209 of file save_index.cpp.
References yes.
Referenced by savegame::autosave_savegame::autosave(), savegame::clean_saves(), gui2::dialogs::game_load::execute(), game_launcher::game_launcher(), gui2::dialogs::game_load::handle_dir_select(), play_controller::hotkey_handler::load_autosave(), game_launcher::load_game(), play_controller::load_game(), gui2::dialogs::mp_create_game::load_game_callback(), savegame::save_game_exists(), and game_launcher::single_unit_test().
void savegame::save_index_class::delete_game | ( | const std::string & | name | ) |
Delete a savegame, including deleting the underlying file.
Definition at line 376 of file save_index.cpp.
References filesystem::delete_file(), dir(), LOG_SAVE, log_scope, read_only_, and remove().
Referenced by delete_old_auto_saves().
void savegame::save_index_class::delete_old_auto_saves | ( | const int | autosavemax, |
const int | infinite_auto_saves | ||
) |
Delete autosaves that are no longer needed (according to the autosave policy in the preferences).
Definition at line 352 of file save_index.cpp.
References _(), delete_game(), get_saves_list(), i, LOG_SAVE, log_scope, and read_only_.
const std::string & savegame::save_index_class::dir | ( | ) | const |
Definition at line 94 of file save_index.cpp.
References dir_.
Referenced by clean_up_index(), delete_game(), and get_saves_list().
|
staticprivate |
Definition at line 199 of file save_index.cpp.
References config::child_range(), and data().
Referenced by data().
config & savegame::save_index_class::get | ( | const std::string & | name | ) |
Definition at line 81 of file save_index.cpp.
References data(), config_attribute_value::empty(), modified_, rebuild(), and config_attribute_value::to_time_t().
std::vector< save_info > savegame::save_index_class::get_saves_list | ( | const std::string * | filter = nullptr | ) |
Get a list of available saves.
Definition at line 216 of file save_index.cpp.
References dir(), utils::erase_if(), filename, and filesystem::get_files_in_dir().
Referenced by delete_old_auto_saves().
|
inline |
If true, all of delete_game, delete_old_auto_saves and write_save_index will be no-ops.
Definition at line 116 of file save_index.hpp.
References read_only_.
void savegame::save_index_class::rebuild | ( | const std::string & | name | ) |
Definition at line 43 of file save_index.cpp.
References dir_, and filesystem::file_modified_time().
Referenced by get().
void savegame::save_index_class::rebuild | ( | const std::string & | name, |
const std::time_t & | modified | ||
) |
Definition at line 49 of file save_index.cpp.
References data(), dir_, dummy, savegame::extract_summary_from_config(), log_scope, savegame::read_save_file(), and write_save_index().
void savegame::save_index_class::remove | ( | const std::string & | name | ) |
Delete a savegame from the index, without deleting the underlying file.
Definition at line 69 of file save_index.cpp.
References d, data(), config::remove_children(), and write_save_index().
Referenced by delete_game().
void savegame::save_index_class::set_modified | ( | const std::string & | name, |
const std::time_t & | modified | ||
) |
Definition at line 76 of file save_index.cpp.
References modified_.
void savegame::save_index_class::write_save_index | ( | ) |
Sync to disk, no-op if read_only_ is set.
Definition at line 115 of file save_index.cpp.
References clean_up_index(), clean_up_index_, data(), e, ERR_SAVE, prefs::get(), filesystem::get_save_index_file(), LOG_SAVE, log_scope, compression::none, filesystem::ostream_file(), read_only_, write(), and write_gz().
|
private |
Flag to only run the clean_up_index method once.
Definition at line 139 of file save_index.hpp.
Referenced by write_save_index().
|
private |
Definition at line 130 of file save_index.hpp.
Referenced by data().
|
private |
Definition at line 132 of file save_index.hpp.
|
private |
Definition at line 129 of file save_index.hpp.
Referenced by data().
|
private |
Definition at line 131 of file save_index.hpp.
Referenced by get(), and set_modified().
|
private |
The instance for default_saves_dir() writes a cache file.
For other instances, write_save_index() and delete() are no-ops.
Definition at line 137 of file save_index.hpp.
Referenced by delete_game(), delete_old_auto_saves(), read_only(), save_index_class(), and write_save_index().