Singleton class to manage game config file caching. More...
#include <config_cache.hpp>
Public Member Functions | |
config_cache (const config_cache &)=delete | |
config_cache & | operator= (const config_cache &)=delete |
const preproc_map & | get_preproc_map () const |
config | get_config (const std::string &path, abstract_validator *validator=nullptr) |
Gets a config object from given path. More... | |
void | clear_defines () |
Clear stored defines map to default values. More... | |
void | add_define (const std::string &define) |
Add a entry to preproc defines map. More... | |
void | remove_define (const std::string &define) |
Remove a entry to preproc defines map. More... | |
void | set_use_cache (bool use) |
Enable/disable caching. More... | |
void | set_force_valid_cache (bool force) |
Enable/disable cache validation. More... | |
void | recheck_filetree_checksum () |
Force cache checksum validation. More... | |
bool | clean_cache () |
Deletes stale cache files not in use by the game. More... | |
bool | purge_cache () |
Deletes all cache files. More... | |
Static Public Member Functions | |
static config_cache & | instance () |
Get reference to the singleton object. More... | |
Protected Member Functions | |
config_cache () | |
void | set_force_invalid_cache (bool) |
Private Member Functions | |
config | read_file (const std::string &file) |
void | write_file (const std::string &file, const config &cfg) |
void | write_file (const std::string &file, const preproc_map &defines) |
config | read_cache (const std::string &path, abstract_validator *validator=nullptr) |
std::pair< config, preproc_map > | read_configs (const std::string &path, abstract_validator *validator) |
config | read_configs (const std::string &path, preproc_map &defines, abstract_validator *validator=nullptr) |
config | load_configs (const std::string &path, abstract_validator *validator=nullptr) |
void | read_defines_queue () |
void | read_defines_file (const std::string &path) |
preproc_map & | make_copy_map () |
void | add_defines_map_diff (preproc_map &) |
bool | delete_cache_files (const std::vector< std::string > &paths, const std::string &exclude_pattern="") |
Private Attributes | |
bool | force_valid_cache_ |
bool | use_cache_ |
bool | fake_invalid_cache_ |
preproc_map | defines_map_ |
std::string | cache_file_prefix_ |
Singleton class to manage game config file caching.
It uses paths to config files as key to find correct cache
Make smarter filetree checksum caching so only required parts of tree are checked at startup. Trees are overlapping so have to split trees to subtrees to only do check once per file.
Make cache system easily allow validation of in memory cache objects using hash checksum of preproc_map.
Definition at line 92 of file config_cache.hpp.
|
delete |
|
protected |
Definition at line 67 of file config_cache.cpp.
References clear_defines().
void game_config::config_cache::add_define | ( | const std::string & | define | ) |
Add a entry to preproc defines map.
Definition at line 314 of file config_cache.cpp.
References DBG_CACHE, defines_map_, game_config::config_cache_transaction::get_active_map(), game_config::config_cache_transaction::instance(), and game_config::config_cache_transaction::is_active().
Referenced by BOOST_AUTO_TEST_CASE(), and test_utils::game_config_manager::game_config_manager().
|
private |
Definition at line 139 of file config_cache.cpp.
References game_config::config_cache_transaction::add_defines_map_diff(), and game_config::config_cache_transaction::instance().
Referenced by load_configs(), and read_cache().
bool game_config::config_cache::clean_cache | ( | ) |
Deletes stale cache files not in use by the game.
Definition at line 336 of file config_cache.cpp.
References cache_file_prefix_, delete_cache_files(), filesystem::ENTIRE_FILE_PATH, filesystem::get_cache_dir(), filesystem::get_files_in_dir(), and LOG_CACHE.
Referenced by gui2::dialogs::game_cache_options::clean_cache(), and game_config_manager::game_config_manager().
void game_config::config_cache::clear_defines | ( | ) |
Clear stored defines map to default values.
Definition at line 83 of file config_cache.cpp.
References defines_map_, and LOG_CACHE.
Referenced by BOOST_AUTO_TEST_CASE(), config_cache(), game_config_manager::load_game_config_for_create(), and game_config_manager::load_game_config_for_game().
|
private |
Definition at line 373 of file config_cache.cpp.
References filesystem::base_name(), filesystem::delete_directory(), ERR_CACHE, LOG_CACHE, and utils::wildcard_string_match().
Referenced by clean_cache(), and purge_cache().
config game_config::config_cache::get_config | ( | const std::string & | path, |
abstract_validator * | validator = nullptr |
||
) |
Gets a config object from given path.
path | file to load. Should be _main.cfg. |
validator | the WML schema validator, if provided. |
Definition at line 95 of file config_cache.cpp.
References load_configs(), and validator.
Referenced by ad_hoc_addon_fetch_session(), BOOST_AUTO_TEST_CASE(), test_utils::game_config_manager::game_config_manager(), game_config_manager::load_addons_cfg(), and game_config_manager::load_game_config().
const preproc_map & game_config::config_cache::get_preproc_map | ( | ) | const |
Definition at line 78 of file config_cache.cpp.
References defines_map_.
Referenced by BOOST_AUTO_TEST_CASE(), game_config_manager::load_game_config(), game_config_manager::load_game_config_for_create(), and game_config_manager::load_game_config_with_loadscreen().
|
static |
Get reference to the singleton object.
Definition at line 61 of file config_cache.cpp.
Referenced by ad_hoc_addon_fetch_session(), BOOST_AUTO_TEST_CASE(), gui2::dialogs::game_cache_options::clean_cache(), test_utils::game_config_manager::game_config_manager(), gui2::dialogs::game_cache_options::purge_cache(), and schema_validation::schema_validator::read_config_file().
|
private |
Definition at line 280 of file config_cache.cpp.
References add_defines_map_diff(), cfg, read_cache(), read_configs(), use_cache_, and validator.
Referenced by get_config().
|
private |
Definition at line 130 of file config_cache.cpp.
References defines_map_, game_config::config_cache_transaction::get_active_map(), and game_config::config_cache_transaction::instance().
Referenced by read_configs().
|
delete |
bool game_config::config_cache::purge_cache | ( | ) |
Deletes all cache files.
Definition at line 356 of file config_cache.cpp.
References delete_cache_files(), filesystem::ENTIRE_FILE_PATH, filesystem::get_cache_dir(), filesystem::get_files_in_dir(), and LOG_CACHE.
Referenced by gui2::dialogs::game_cache_options::purge_cache().
|
private |
Definition at line 156 of file config_cache.cpp.
References game_config::config_cache_transaction::add_define_file(), add_defines_map_diff(), cache_file_prefix_, cfg, filesystem::data_tree_checksum(), DBG_CACHE, defines_map_, e, ERR_CACHE, fake_invalid_cache_, filesystem::file_exists(), force_valid_cache_, filesystem::get_cache_dir(), utils::md5::hex_digest(), game_config::config_cache_transaction::instance(), LOG_CACHE, log_scope, read_configs(), read_defines_queue(), read_file(), validator, filesystem::file_tree_checksum::write(), and write_file().
Referenced by load_configs().
|
private |
Definition at line 144 of file config_cache.cpp.
References cfg, make_copy_map(), and validator.
Referenced by load_configs(), and read_cache().
|
private |
Definition at line 151 of file config_cache.cpp.
References preprocess_file(), io::read(), and validator.
|
private |
Definition at line 263 of file config_cache.cpp.
References config::all_children_view(), cfg, DBG_CACHE, defines_map_, preproc_define::insert(), game_config::config_cache_transaction::instance(), and read_file().
Referenced by read_defines_queue().
|
private |
Definition at line 273 of file config_cache.cpp.
References game_config::config_cache_transaction::instance(), p, and read_defines_file().
Referenced by read_cache().
|
private |
Definition at line 125 of file config_cache.cpp.
References filesystem::istream_file(), and io::read_gz().
Referenced by read_cache(), and read_defines_file().
void game_config::config_cache::recheck_filetree_checksum | ( | ) |
Force cache checksum validation.
Definition at line 309 of file config_cache.cpp.
References filesystem::data_tree_checksum().
Referenced by game_config_manager::reload_changed_game_config().
void game_config::config_cache::remove_define | ( | const std::string & | define | ) |
Remove a entry to preproc defines map.
Definition at line 325 of file config_cache.cpp.
References DBG_CACHE, defines_map_, game_config::config_cache_transaction::get_active_map(), game_config::config_cache_transaction::instance(), and game_config::config_cache_transaction::is_active().
Referenced by BOOST_AUTO_TEST_CASE().
|
protected |
Definition at line 294 of file config_cache.cpp.
References fake_invalid_cache_.
Referenced by test_config_cache::set_force_invalid_cache().
void game_config::config_cache::set_force_valid_cache | ( | bool | force | ) |
Enable/disable cache validation.
Definition at line 304 of file config_cache.cpp.
References force_valid_cache_.
Referenced by game_config_manager::game_config_manager().
void game_config::config_cache::set_use_cache | ( | bool | use | ) |
Enable/disable caching.
Definition at line 299 of file config_cache.cpp.
References use_cache_.
Referenced by game_config_manager::game_config_manager().
|
private |
Definition at line 100 of file config_cache.cpp.
References game_config::cache_compression_level, cfg, filesystem::ostream_file(), and config_writer::write().
Referenced by read_cache().
|
private |
Definition at line 107 of file config_cache.cpp.
References game_config::cache_compression_level, filesystem::delete_directory(), filesystem::file_exists(), and filesystem::ostream_file().
|
private |
Definition at line 159 of file config_cache.hpp.
Referenced by clean_cache(), and read_cache().
|
private |
Definition at line 157 of file config_cache.hpp.
Referenced by add_define(), clear_defines(), get_preproc_map(), make_copy_map(), read_cache(), read_defines_file(), and remove_define().
|
private |
Definition at line 155 of file config_cache.hpp.
Referenced by read_cache(), and set_force_invalid_cache().
|
private |
Definition at line 153 of file config_cache.hpp.
Referenced by read_cache(), and set_force_valid_cache().
|
private |
Definition at line 154 of file config_cache.hpp.
Referenced by load_configs(), and set_use_cache().