The Battle for Wesnoth  1.15.1+dev
save_index.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by Jörg Hinrichs, refactored from various
3  places formerly created by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "config.hpp"
20 
21 namespace savegame
22 {
23 /** Filename and modification date for a file list */
24 class save_info
25 {
26 private:
27  friend class create_save_info;
28 
29  save_info(const std::string& name, const std::time_t& modified)
30  : name_(name)
31  , modified_(modified)
32  {
33  }
34 
35 public:
36  const std::string& name() const
37  {
38  return name_;
39  }
40 
41  const std::time_t& modified() const
42  {
43  return modified_;
44  }
45 
46  std::string format_time_summary() const;
47  std::string format_time_local() const;
48  const config& summary() const;
49 
50 private:
51  std::string name_;
52  std::time_t modified_;
53 };
54 
55 /**
56  * A structure for comparing to save_info objects based on their modified time.
57  * If the times are equal, will order based on the name.
58  */
60 {
61  bool operator()(const save_info& a, const save_info& b) const;
62 };
63 
64 std::vector<save_info> get_saves_list(const std::string* dir = nullptr, const std::string* filter = nullptr);
65 
66 /** Read the complete config information out of a savefile. */
67 void read_save_file(const std::string& name, config& cfg, std::string* error_log);
68 
69 /** Remove autosaves that are no longer needed (according to the autosave policy in the preferences). */
70 void remove_old_auto_saves(const int autosavemax, const int infinite_auto_saves);
71 
72 /** Delete a savegame. */
73 void delete_game(const std::string& name);
74 
76 {
77 public:
78  create_save_info(const std::string* d = nullptr);
79  save_info operator()(const std::string& filename) const;
80  const std::string dir;
81 };
82 
84 {
85 public:
87 
88  void rebuild(const std::string& name);
89  void rebuild(const std::string& name, const std::time_t& modified);
90 
91  void remove(const std::string& name);
92  void set_modified(const std::string& name, const std::time_t& modified);
93 
94  config& get(const std::string& name);
95 
96  void write_save_index();
97 
98 private:
99  config& data(const std::string& name);
100  config& data();
101 
102  static void fix_leader_image_path(config& data);
103 
104  bool loaded_;
106  std::map<std::string, std::time_t> modified_;
107 };
108 
110 } // end of namespace savegame
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)...
Definition: save_index.cpp:312
int autosavemax()
Definition: game.cpp:822
void read_save_file(const std::string &name, config &cfg, std::string *error_log)
Read the complete config information out of a savefile.
Definition: save_index.cpp:271
friend class create_save_info
Definition: save_index.hpp:27
#define a
std::vector< save_info > get_saves_list(const std::string *dir, const std::string *filter)
Get a list of available saves.
Definition: save_index.cpp:190
#define d
Definitions for the interface to Wesnoth Markup Language (WML).
const std::string dir
Definition: save_index.hpp:80
const config & summary() const
Definition: save_index.cpp:209
#define b
std::string format_time_local() const
Definition: save_index.cpp:214
save_info(const std::string &name, const std::time_t &modified)
Definition: save_index.hpp:29
void delete_game(const std::string &name)
Delete a savegame.
Definition: save_index.cpp:330
save_index_class save_index_manager
Definition: save_index.cpp:170
std::string name_
Definition: save_index.hpp:51
const std::string & name() const
Definition: save_index.hpp:36
const std::time_t & modified() const
Definition: save_index.hpp:41
Filename and modification date for a file list.
Definition: save_index.hpp:24
std::map< std::string, std::time_t > modified_
Definition: save_index.hpp:106
std::string format_time_summary() const
Definition: save_index.cpp:228
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
A structure for comparing to save_info objects based on their modified time.
Definition: save_index.hpp:59
std::time_t modified_
Definition: save_index.hpp:52