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 |
void | get_config (const std::string &path, config &cfg, 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 | |
void | read_file (const std::string &file, config &cfg) |
void | write_file (std::string file, const config &cfg) |
void | write_file (std::string file, const preproc_map &defines) |
void | read_cache (const std::string &path, config &cfg, abstract_validator *validator=nullptr) |
void | read_configs (const std::string &path, config &cfg, preproc_map &defines, abstract_validator *validator=nullptr) |
void | load_configs (const std::string &path, config &cfg, 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 63 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 321 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 137 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 344 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 79 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 381 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().
void game_config::config_cache::get_config | ( | const std::string & | path, |
config & | cfg, | ||
abstract_validator * | validator = nullptr |
||
) |
Gets a config object from given path.
path | file to load. Should be _main.cfg. |
cfg | config object that is written to. Should be empty on entry. |
validator | the WML schema validator, if provided. |
Definition at line 92 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 74 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 57 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::init(), gui2::dialogs::game_cache_options::purge_cache(), and schema_validation::schema_validator::read_config_file().
|
private |
Definition at line 287 of file config_cache.cpp.
References add_defines_map_diff(), make_copy_map(), read_cache(), read_configs(), use_cache_, and validator.
Referenced by get_config().
|
private |
Definition at line 128 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 load_configs(), and read_cache().
|
delete |
bool game_config::config_cache::purge_cache | ( | ) |
Deletes all cache files.
Definition at line 364 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 149 of file config_cache.cpp.
References game_config::config_cache_transaction::add_define_file(), add_defines_map_diff(), cache_file_prefix_, d, 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, make_copy_map(), read_configs(), read_defines_queue(), read_file(), validator, filesystem::file_tree_checksum::write(), and write_file().
Referenced by load_configs().
|
private |
Definition at line 142 of file config_cache.cpp.
References preprocess_file(), read(), and validator.
Referenced by load_configs(), and read_cache().
|
private |
Definition at line 264 of file config_cache.cpp.
References config::all_children_view(), DBG_CACHE, game_config::config_cache_transaction::insert_to_active(), game_config::config_cache_transaction::instance(), read_file(), and preproc_define::read_pair().
Referenced by read_defines_queue().
|
private |
Definition at line 278 of file config_cache.cpp.
References game_config::config_cache_transaction::get_define_files(), game_config::config_cache_transaction::instance(), p, and read_defines_file().
Referenced by read_cache().
|
private |
Definition at line 122 of file config_cache.cpp.
References filesystem::istream_file(), and 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 316 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 333 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 301 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 311 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 306 of file config_cache.cpp.
References use_cache_.
Referenced by game_config_manager::game_config_manager().
|
private |
Definition at line 97 of file config_cache.cpp.
References game_config::cache_compression_level, filesystem::ostream_file(), and config_writer::write().
Referenced by read_cache().
|
private |
Definition at line 104 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 160 of file config_cache.hpp.
Referenced by clean_cache(), and read_cache().
|
private |
Definition at line 158 of file config_cache.hpp.
Referenced by add_define(), clear_defines(), get_preproc_map(), make_copy_map(), read_cache(), and remove_define().
|
private |
Definition at line 156 of file config_cache.hpp.
Referenced by read_cache(), and set_force_invalid_cache().
|
private |
Definition at line 154 of file config_cache.hpp.
Referenced by read_cache(), and set_force_valid_cache().
|
private |
Definition at line 155 of file config_cache.hpp.
Referenced by load_configs(), and set_use_cache().