16 #include <boost/iostreams/filter/gzip.hpp>
34 #define LOG_SAVE LOG_STREAM(info, log_engine)
35 #define ERR_SAVE LOG_STREAM(err, log_engine)
38 #define LOG_RG LOG_STREAM(info, log_enginerefac)
67 summary[
"corrupt"] =
true;
69 summary[
"mod_time"] = std::to_string(static_cast<int>(modified));
87 if (mod_time.
empty() ||
static_cast<time_t
>(mod_time.
to_int()) != m) {
104 ERR_SAVE <<
"error writing to save index file: '" << e.
what() <<
"'" << std::endl;
131 }
catch (boost::iostreams::gzip_error&) {
136 ERR_SAVE <<
"error reading save index: '" << e.
what() <<
"'" << std::endl;
138 ERR_SAVE <<
"error parsing save index config file:\n" << e.
message << std::endl;
153 return filename.end() == std::search(filename.begin(), filename.end(),
165 std::vector<std::string> filenames;
171 std::string filter_replaced(filter->begin(), filter->end());
174 filenames.erase(std::remove_if(filenames.begin(), filenames.end(),
179 std::vector<save_info>
result;
181 std::back_inserter(result), creator);
188 return save_index_manager.
get(
name());
193 char time_buf[256] = {0};
197 const size_t res =
strftime(time_buf,
sizeof(time_buf),
198 format.c_str(), tm_l);
225 }
else if (a.
name().find(
_(
" replay"))==std::string::npos && b.
name().find(
_(
" replay"))!=std::string::npos) {
227 }
else if (a.
name().find(
_(
" replay"))!=std::string::npos && b.
name().find(
_(
" replay"))==std::string::npos) {
237 if (file_stream->fail()) {
241 if (!file_stream->fail())
246 LOG_SAVE <<
"Could not open supplied filename '" << name <<
"'\n";
255 static const std::vector<std::string> suffixes = {
"",
".gz",
".bz2"};
269 read(cfg, *file_stream);
271 }
catch(
const std::ios_base::failure&
e) {
274 *error_log += e.what();
286 LOG_SAVE <<
"Could not parse file data into config\n";
295 if (countdown == infinite_auto_saves)
298 std::vector<save_info> games =
get_saves_list(
nullptr, &auto_save);
300 if (countdown-- <= 0) {
301 LOG_SAVE <<
"Deleting savegame '" <<
i->name() <<
"'\n";
315 save_index_manager.
remove(name);
336 const config &cfg_snapshot = cfg_save.
child(
"snapshot");
338 const config &cfg_replay_start = cfg_save.
child(
"replay_start") ? cfg_save.
child(
"replay_start") : cfg_save.
child(
"scenario") ;
340 const config &cfg_replay = cfg_save.
child(
"replay");
341 const bool has_replay = cfg_replay && !cfg_replay.
empty();
342 const bool has_snapshot = cfg_snapshot && cfg_snapshot.
child(
"side");
344 cfg_summary[
"replay"] = has_replay;
345 cfg_summary[
"snapshot"] = has_snapshot;
347 cfg_summary[
"label"] = cfg_save[
"label"];
348 cfg_summary[
"campaign_type"] = cfg_save[
"campaign_type"];
350 if(cfg_save.
has_child(
"carryover_sides_start")){
351 cfg_summary[
"scenario"] = cfg_save.
child(
"carryover_sides_start")[
"next_scenario"];
353 cfg_summary[
"scenario"] = cfg_save[
"scenario"];
356 cfg_summary[
"difficulty"] = cfg_save[
"difficulty"];
357 cfg_summary[
"random_mode"] = cfg_save[
"random_mode"];
360 cfg_summary[
"campaign"] = cfg_save[
"campaign"];
361 cfg_summary[
"version"] = cfg_save[
"version"];
362 cfg_summary[
"corrupt"] =
"";
365 cfg_summary[
"turn"] = cfg_snapshot[
"turn_at"];
366 if (cfg_snapshot[
"turns"] !=
"-1") {
367 cfg_summary[
"turn"] = cfg_summary[
"turn"].str() +
"/" + cfg_snapshot[
"turns"].str();
385 bool shrouded =
false;
389 if (
const config &snapshot = *(has_snapshot ? &cfg_snapshot : &cfg_replay_start))
393 if (side[
"controller"] != team::CONTROLLER::enum_to_string(team::CONTROLLER::HUMAN)) {
397 if (side[
"shroud"].to_bool()) {
401 if (side[
"canrecruit"].to_bool())
403 leader = side[
"id"].str();
404 leader_image = side[
"image"].str();
405 leader_image_tc_modifier =
"~RC(magenta>" + side[
"color"].str() +
")";
411 if (u[
"canrecruit"].to_bool()) {
412 leader = u[
"id"].str();
413 leader_image = u[
"image"].str();
414 leader_image_tc_modifier =
"~RC(" + u[
"flag_rgb"].str() +
">" + u[
"side"].str() +
")";
425 cfg_summary[
"leader"] = leader;
431 cfg_summary[
"leader_image"] = cfg_summary[
"leader_image"].str() + leader_image_tc_modifier;
436 cfg_summary[
"map_data"] = cfg_snapshot[
"map_data"].str();
438 ERR_SAVE <<
"Not saving map because there is shroud" << std::endl;
440 }
else if(has_replay) {
441 if (!cfg_replay_start.find_child(
"side",
"shroud",
"yes") && cfg_replay_start.has_attribute(
"map_data")) {
442 cfg_summary[
"map_data"] = cfg_replay_start[
"map_data"];
444 ERR_SAVE <<
"Not saving map because there is shroud" << std::endl;
child_itors child_range(const std::string &key)
void write_gz(std::ostream &out, configr_of const &cfg)
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)...
size_t strftime(char *str, size_t count, const std::string &format, const std::tm *time)
void remove_attribute(const std::string &key)
void rebuild(const std::string &name)
void read_save_file(const std::string &name, config &cfg, std::string *error_log)
Read the complete config information out of a savefile.
bool delete_file(const std::string &filename)
const char * what() const
void extract_summary_from_config(config &, config &)
bool operator()(const std::string &filename) const
Error used when game loading fails.
void remove(const std::string &name)
std::vector< save_info > get_saves_list(const std::string *dir, const std::string *filter)
Get a list of available saves.
static lg::log_domain log_engine("engine")
std::string format_time_summary(time_t t)
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
bool empty() const
Tests for an attribute that either was never set or was set to "".
std::string get_saves_dir()
Definitions for the interface to Wesnoth Markup Language (WML).
void replace_underbar2space(std::string &name)
std::string format_time_summary() const
Variant for storing WML attributes.
void read_gz(config &cfg, std::istream &file, abstract_validator *validator)
might throw a std::ios_base::failure especially a gzip_error
GLdouble GLdouble GLdouble b
GLuint GLenum GLenum transform
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
static UNUSEDNOWARN std::string _(const char *str)
const config & summary() const
std::istream * istream_file(const std::string &fname, bool treat_failure_as_error=true)
void delete_game(const std::string &name)
Delete a savegame.
GLboolean GLboolean GLboolean GLboolean a
static std::istream * find_save_file(const std::string &name, const std::string &alt_name, const std::vector< std::string > &suffixes)
std::ostream * ostream_file(std::string const &fname, bool create_directory=true)
std::string format_time_local() const
config & add_child(const std::string &key)
void read_bz2(config &cfg, std::istream &file, abstract_validator *validator)
might throw a std::ios_base::failure especially bzip2_error
save_index_class save_index_manager
std::string get_independent_image_path(const std::string &filename)
Returns an image path to filename for binary path-independent use in saved games. ...
void replace_space2underbar(std::string &name)
bool is_gzip_file(const std::string &filename)
Returns true if the file ends with '.gz'.
time_t file_modified_time(const std::string &fname)
Get the modification time of a file.
config & get(const std::string &name)
void get_files_in_dir(const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs=nullptr, file_name_option mode=FILE_NAME_ONLY, file_filter_option filter=NO_FILTER, file_reorder_option reorder=DONT_REORDER, file_tree_checksum *checksum=nullptr)
Populates 'files' with all the files and 'dirs' with all the directories in dir.
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
An exception object used when an IO error occurs.
#define log_scope(description)
std::map< std::string, time_t > modified_
Declarations for File-IO.
void read(config &cfg, std::istream &in, abstract_validator *validator)
bool operator()(const save_info &a, const save_info &b) const
static int sort(lua_State *L)
void set_modified(const std::string &name, const time_t &modified)
std::string replace(std::string str, const std::string &src, const std::string &dst)
Replace all instances of src in str with dst.
GLuint const GLchar * name
compression::format save_compression_format()
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
bool is_bzip2_file(const std::string &filename)
Returns true if the file ends with '.bz2'.
Filename and modification date for a file list.
create_save_info(const std::string *d=nullptr)
bool has_attribute(const std::string &key) const
const std::string & name() const
const time_t & modified() const
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...
filename_filter(const std::string &filter)
config & find_child(const std::string &key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
Standard logging facilities (interface).
save_info operator()(const std::string &filename) const
int to_int(int def=0) const
A config object defines a single node in a WML file, with access to child nodes.
static lg::log_domain log_enginerefac("enginerefac")
std::string get_save_index_file()
A structure for comparing to save_info objects based on their modified time.
void write(std::ostream &out, configr_of const &cfg, unsigned int level)
GLsizei const GLcharARB ** string
bool use_twelve_hour_clock_format()