15 #define GETTEXT_DOMAIN "wesnoth-lib"
29 #include <boost/algorithm/string/replace.hpp>
30 #include <boost/iostreams/filter/gzip.hpp>
33 #define ERR_CACHE LOG_STREAM(err, log_cache)
34 #define LOG_CACHE LOG_STREAM(info, log_cache)
35 #define DBG_CACHE LOG_STREAM(debug, log_cache)
47 : force_valid_cache_(false)
49 , fake_invalid_cache_(false)
51 , cache_file_prefix_()
70 LOG_CACHE <<
"Clearing defines map!" << std::endl;
103 if(defines.empty()) {
114 for(
const preproc_map::value_type& define : defines) {
115 define.second.write(writer, define.first);
146 std::stringstream defines_string;
147 defines_string <<
path;
149 bool is_valid =
true;
155 if((!
d.second.value.empty() || !
d.second.arguments.empty()) &&
156 d.first !=
"WESNOTH_VERSION")
159 ERR_CACHE <<
"Invalid preprocessor define: " <<
d.first <<
'\n';
163 defines_string <<
" " <<
d.first;
170 if(is_valid && !cache_path.empty()) {
175 const std::string fname_checksum = fname +
".checksum" + extension;
184 DBG_CACHE <<
"Reading checksum: " << fname_checksum <<
"\n";
190 ERR_CACHE <<
"cache checksum is corrupt" << std::endl;
192 ERR_CACHE <<
"error reading cache checksum" << std::endl;
197 LOG_CACHE <<
"skipping cache validation (forced)\n";
201 LOG_CACHE <<
"found valid cache at '" << fname << extension <<
"' with defines_map " << defines_string.str() <<
"\n";
206 const std::string define_file = fname +
".define" + extension;
214 ERR_CACHE <<
"cache " << fname << extension <<
" is corrupt. Loading from files: "<< e.
message << std::endl;
216 ERR_CACHE <<
"error reading cache " << fname << extension <<
". Loading from files" << std::endl;
217 }
catch (boost::iostreams::gzip_error& e) {
219 ERR_CACHE <<
"cache " << fname << extension <<
" is corrupt. Error code: " << e.error() << std::endl;
223 LOG_CACHE <<
"no valid cache found. Writing cache to '" << fname << extension <<
" with defines_map "<< defines_string.str() <<
"'\n";
235 write_file(fname +
".define" + extension, copy_map);
242 ERR_CACHE <<
"could not write to cache '" << fname <<
"'" << std::endl;
248 LOG_CACHE <<
"Loading plain config instead of cache\n";
260 DBG_CACHE <<
"Reading cached defines from: " << path <<
"\n";
315 DBG_CACHE <<
"adding define: " << define <<
"\n";
328 DBG_CACHE <<
"removing define: " << define <<
"\n";
339 std::vector<std::string> files, dirs;
342 LOG_CACHE <<
"clean_cache(): " << files.size() <<
" files, "
343 << dirs.size() <<
" dirs to check\n";
359 std::vector<std::string> files, dirs;
362 LOG_CACHE <<
"purge_cache(): deleting " << files.size() <<
" files, "
363 << dirs.size() <<
" dirs\n";
377 const bool delete_everything = exclude_pattern.empty();
382 if(!delete_everything) {
387 <<
" excluded by '" << exclude_pattern <<
"'\n";
392 LOG_CACHE <<
"delete_cache_files(): deleting " <<
path <<
'\n';
394 ERR_CACHE <<
"delete_cache_files(): could not delete "
407 : define_filenames_()
439 active_map_.insert(defines_map.begin(), defines_map.end());
451 bool compare_define(
const preproc_map::value_type&
a,
const preproc_map::value_type&
b)
453 if(a.first < b.first) {
457 if(b.first < a.first) {
461 if(a.second < b.second) {
474 std::set_difference(new_map.begin(),
478 std::insert_iterator<preproc_map>(temp,temp.begin()),
481 for(
const preproc_map::value_type &def : temp) {
static config_cache & instance()
Get reference to the singleton object.
config_cache_transaction()
void write(const config &cfg)
void write_file(std::string file, const config &cfg)
void read_configs(const std::string &path, config &cfg, preproc_map &defines)
void read_file(const std::string &file, config &cfg)
void lock()
Lock the transaction so no more macros are added.
bool wildcard_string_match(const std::string &str, const std::string &match)
Match using '*' as any number of characters (including none), and '?' as any one character.
static config_cache_transaction * active_
void remove_define(const std::string &define)
Remove a entry to preproc defines map.
Holds a fake cache transaction if no real one is used.
~config_cache_transaction()
std::vector< std::string > define_filenames_
static config_cache_transaction & instance()
const std::vector< std::string > & get_define_files() const
std::map< std::string, preproc_define > preproc_map
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
GLsizei const char ** path
bool delete_cache_files(const std::vector< std::string > &paths, const std::string &exclude_pattern="")
Class for writing a config out to a file in pieces.
bool clean_cache()
Deletes stale cache files not in use by the game.
void read_defines_file(const std::string &path)
GLsizei const GLfloat * value
all_children_itors all_children_range() const
In-order iteration over all children.
std::string base_name(const std::string &file)
Returns the base filename of a file, with directory name stripped.
std::istream * istream_file(const std::string &fname, bool treat_failure_as_error=true)
const preproc_map & get_preproc_map() const
GLboolean GLboolean GLboolean GLboolean a
void get_config(const std::string &path, config &cfg)
Gets a config object from given path.
std::ostream * ostream_file(std::string const &fname, bool create_directory=true)
void add_define_file(const std::string &file)
void set_force_valid_cache(bool force)
Enable/disable cache validation.
static lg::log_domain log_cache("cache")
void set_use_cache(bool use)
Enable/disable caching.
void load_configs(const std::string &path, config &cfg)
std::string get_cache_dir()
void clear_defines()
Clear stored defines map to default values.
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.
const std::string revision
void add_defines_map_diff(preproc_map &)
Game configuration data as global variables.
An exception object used when an IO error occurs.
std::string cache_file_prefix_
preproc_map & get_active_map(const preproc_map &defines_map)
#define log_scope(description)
void write(config &cfg) const
void read_cache(const std::string &path, config &cfg)
void set_force_invalid_cache(bool)
Declarations for File-IO.
void read(config &cfg, std::istream &in, abstract_validator *validator)
static int writer(lua_State *L, const void *b, size_t size, void *B)
const version_info wesnoth_version(VERSION)
bool delete_directory(const std::string &dirname, const bool keep_pbl=false)
const file_tree_checksum & data_tree_checksum(bool reset=false)
Get the time at which the data/ tree was last modified at.
Used to share macros between cache objects You have to create transaction object to load all macros t...
void read_defines_queue()
std::istream * preprocess_file(std::string const &fname, preproc_map *defines)
void add_defines_map_diff(preproc_map &defines_map)
Standard logging facilities (interface).
void insert_to_active(const preproc_map::value_type &def)
Used to let std::for_each insert new defines to active_map map to active.
A config object defines a single node in a WML file, with access to child nodes.
static preproc_map::value_type read_pair(const config &)
preproc_map & make_copy_map()
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.
void add_define(const std::string &define)
Add a entry to preproc defines map.
GLsizei const GLcharARB ** string
void recheck_filetree_checksum()
Force cache checksum validation.
bool purge_cache()
Deletes all cache files.
Singleton class to manage game config file caching.
int cache_compression_level