FIlesystem: used scoped enums
This commit is contained in:
parent
351f7cafcc
commit
50ed04319d
11 changed files with 39 additions and 39 deletions
|
@ -344,7 +344,7 @@ void config_cache::remove_define(const std::string& define)
|
|||
bool config_cache::clean_cache()
|
||||
{
|
||||
std::vector<std::string> files, dirs;
|
||||
filesystem::get_files_in_dir(filesystem::get_cache_dir(), &files, &dirs, filesystem::ENTIRE_FILE_PATH);
|
||||
filesystem::get_files_in_dir(filesystem::get_cache_dir(), &files, &dirs, filesystem::name_mode::ENTIRE_FILE_PATH);
|
||||
|
||||
LOG_CACHE << "clean_cache(): " << files.size() << " files, "
|
||||
<< dirs.size() << " dirs to check\n";
|
||||
|
@ -364,7 +364,7 @@ bool config_cache::clean_cache()
|
|||
bool config_cache::purge_cache()
|
||||
{
|
||||
std::vector<std::string> files, dirs;
|
||||
filesystem::get_files_in_dir(filesystem::get_cache_dir(), &files, &dirs, filesystem::ENTIRE_FILE_PATH);
|
||||
filesystem::get_files_in_dir(filesystem::get_cache_dir(), &files, &dirs, filesystem::name_mode::ENTIRE_FILE_PATH);
|
||||
|
||||
LOG_CACHE << "purge_cache(): deleting " << files.size() << " files, "
|
||||
<< dirs.size() << " dirs\n";
|
||||
|
|
|
@ -354,9 +354,9 @@ static bool create_directory_if_missing_recursive(const bfs::path& dirpath)
|
|||
void get_files_in_dir(const std::string& dir,
|
||||
std::vector<std::string>* files,
|
||||
std::vector<std::string>* dirs,
|
||||
file_name_option mode,
|
||||
file_filter_option filter,
|
||||
file_reorder_option reorder,
|
||||
name_mode mode,
|
||||
filter_mode filter,
|
||||
reorder_mode reorder,
|
||||
file_tree_checksum* checksum)
|
||||
{
|
||||
if(bfs::path(dir).is_relative() && !game_config::path.empty()) {
|
||||
|
@ -371,13 +371,13 @@ void get_files_in_dir(const std::string& dir,
|
|||
|
||||
const bfs::path dirpath(dir);
|
||||
|
||||
if(reorder == DO_REORDER) {
|
||||
if(reorder == reorder_mode::DO_REORDER) {
|
||||
LOG_FS << "searching for _main.cfg in directory " << dir << '\n';
|
||||
const bfs::path maincfg = dirpath / maincfg_filename;
|
||||
|
||||
if(file_exists(maincfg)) {
|
||||
LOG_FS << "_main.cfg found : " << maincfg << '\n';
|
||||
push_if_exists(files, maincfg, mode == ENTIRE_FILE_PATH);
|
||||
push_if_exists(files, maincfg, mode == name_mode::ENTIRE_FILE_PATH);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -401,13 +401,13 @@ void get_files_in_dir(const std::string& dir,
|
|||
if(st.type() == bfs::regular_file) {
|
||||
{
|
||||
std::string basename = di->path().filename().string();
|
||||
if(filter == SKIP_PBL_FILES && looks_like_pbl(basename))
|
||||
if(filter == filter_mode::SKIP_PBL_FILES && looks_like_pbl(basename))
|
||||
continue;
|
||||
if(!basename.empty() && basename[0] == '.')
|
||||
continue;
|
||||
}
|
||||
|
||||
push_if_exists(files, di->path(), mode == ENTIRE_FILE_PATH);
|
||||
push_if_exists(files, di->path(), mode == name_mode::ENTIRE_FILE_PATH);
|
||||
|
||||
if(checksum != nullptr) {
|
||||
std::time_t mtime = bfs::last_write_time(di->path(), ec);
|
||||
|
@ -434,7 +434,7 @@ void get_files_in_dir(const std::string& dir,
|
|||
continue;
|
||||
}
|
||||
|
||||
if(filter == SKIP_MEDIA_DIR && (basename == "images" || basename == "sounds")) {
|
||||
if(filter == filter_mode::SKIP_MEDIA_DIR && (basename == "images" || basename == "sounds")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -443,12 +443,12 @@ void get_files_in_dir(const std::string& dir,
|
|||
|
||||
if(error_except_not_found(ec)) {
|
||||
LOG_FS << "Failed to get file status of " << inner_main.string() << ": " << ec.message() << '\n';
|
||||
} else if(reorder == DO_REORDER && main_st.type() == bfs::regular_file) {
|
||||
} else if(reorder == reorder_mode::DO_REORDER && main_st.type() == bfs::regular_file) {
|
||||
LOG_FS << "_main.cfg found : "
|
||||
<< (mode == ENTIRE_FILE_PATH ? inner_main.string() : inner_main.filename().string()) << '\n';
|
||||
push_if_exists(files, inner_main, mode == ENTIRE_FILE_PATH);
|
||||
<< (mode == name_mode::ENTIRE_FILE_PATH ? inner_main.string() : inner_main.filename().string()) << '\n';
|
||||
push_if_exists(files, inner_main, mode == name_mode::ENTIRE_FILE_PATH);
|
||||
} else {
|
||||
push_if_exists(dirs, di->path(), mode == ENTIRE_FILE_PATH);
|
||||
push_if_exists(dirs, di->path(), mode == name_mode::ENTIRE_FILE_PATH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ void get_files_in_dir(const std::string& dir,
|
|||
std::sort(dirs->begin(), dirs->end());
|
||||
}
|
||||
|
||||
if(files != nullptr && reorder == DO_REORDER) {
|
||||
if(files != nullptr && reorder == reorder_mode::DO_REORDER) {
|
||||
// move finalcfg_filename, if present, to the end of the vector
|
||||
for(unsigned int i = 0; i < files->size(); i++) {
|
||||
if(ends_with((*files)[i], "/" + finalcfg_filename)) {
|
||||
|
@ -956,7 +956,7 @@ bool delete_directory(const std::string& dirname, const bool keep_pbl)
|
|||
std::vector<std::string> dirs;
|
||||
error_code ec;
|
||||
|
||||
get_files_in_dir(dirname, &files, &dirs, ENTIRE_FILE_PATH, keep_pbl ? SKIP_PBL_FILES : NO_FILTER);
|
||||
get_files_in_dir(dirname, &files, &dirs, name_mode::ENTIRE_FILE_PATH, keep_pbl ? filter_mode::SKIP_PBL_FILES : filter_mode::NO_FILTER);
|
||||
|
||||
if(!files.empty()) {
|
||||
for(const std::string& f : files) {
|
||||
|
|
|
@ -49,9 +49,9 @@ struct io_exception : public game::error {
|
|||
|
||||
struct file_tree_checksum;
|
||||
|
||||
enum file_name_option { ENTIRE_FILE_PATH, FILE_NAME_ONLY };
|
||||
enum file_filter_option { NO_FILTER, SKIP_MEDIA_DIR, SKIP_PBL_FILES };
|
||||
enum file_reorder_option { DONT_REORDER, DO_REORDER };
|
||||
enum class name_mode { ENTIRE_FILE_PATH, FILE_NAME_ONLY };
|
||||
enum class filter_mode { NO_FILTER, SKIP_MEDIA_DIR, SKIP_PBL_FILES };
|
||||
enum class reorder_mode { DONT_REORDER, DO_REORDER };
|
||||
|
||||
// A list of file and directory blacklist patterns
|
||||
class blacklist_pattern_list
|
||||
|
@ -132,9 +132,9 @@ static const blacklist_pattern_list default_blacklist{
|
|||
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,
|
||||
name_mode mode = name_mode::FILE_NAME_ONLY,
|
||||
filter_mode filter = filter_mode::NO_FILTER,
|
||||
reorder_mode reorder = reorder_mode::DONT_REORDER,
|
||||
file_tree_checksum* checksum = nullptr);
|
||||
|
||||
std::string get_dir(const std::string &dir);
|
||||
|
|
|
@ -171,7 +171,7 @@ static void get_file_tree_checksum_internal(const std::string& path, file_tree_c
|
|||
{
|
||||
|
||||
std::vector<std::string> dirs;
|
||||
get_files_in_dir(path,nullptr,&dirs, ENTIRE_FILE_PATH, SKIP_MEDIA_DIR, DONT_REORDER, &res);
|
||||
get_files_in_dir(path,nullptr,&dirs, name_mode::ENTIRE_FILE_PATH, filter_mode::SKIP_MEDIA_DIR, reorder_mode::DONT_REORDER, &res);
|
||||
|
||||
for(std::vector<std::string>::const_iterator j = dirs.begin(); j != dirs.end(); ++j) {
|
||||
get_file_tree_checksum_internal(*j,res);
|
||||
|
|
|
@ -243,7 +243,7 @@ manager::manager()
|
|||
for(const std::string& path : filesystem::get_binary_paths("fonts")) {
|
||||
std::vector<std::string> files;
|
||||
if(filesystem::is_directory(path)) {
|
||||
filesystem::get_files_in_dir(path, &files, nullptr, filesystem::ENTIRE_FILE_PATH);
|
||||
filesystem::get_files_in_dir(path, &files, nullptr, filesystem::name_mode::ENTIRE_FILE_PATH);
|
||||
}
|
||||
for(const std::string& file : files) {
|
||||
if(is_valid_font_file(file))
|
||||
|
@ -266,7 +266,7 @@ manager::~manager()
|
|||
for(const std::string& path : filesystem::get_binary_paths("fonts")) {
|
||||
std::vector<std::string> files;
|
||||
if(filesystem::is_directory(path))
|
||||
filesystem::get_files_in_dir(path, &files, nullptr, filesystem::ENTIRE_FILE_PATH);
|
||||
filesystem::get_files_in_dir(path, &files, nullptr, filesystem::name_mode::ENTIRE_FILE_PATH);
|
||||
for(const std::string& file : files) {
|
||||
if(is_valid_font_file(file))
|
||||
{
|
||||
|
|
|
@ -213,7 +213,7 @@ void game_config_manager::load_game_config(bool reload_everything)
|
|||
const std::string user_campaign_dir = filesystem::get_addons_dir();
|
||||
std::vector<std::string> user_files;
|
||||
filesystem::get_files_in_dir(user_campaign_dir, &user_files, &user_dirs,
|
||||
filesystem::ENTIRE_FILE_PATH);
|
||||
filesystem::name_mode::ENTIRE_FILE_PATH);
|
||||
}
|
||||
for (const std::string& umc : user_dirs) {
|
||||
const std::string cores_file = umc + "/cores.cfg";
|
||||
|
@ -382,7 +382,7 @@ void game_config_manager::load_addons_cfg()
|
|||
std::vector<std::string> user_files;
|
||||
|
||||
filesystem::get_files_in_dir(user_campaign_dir, &user_files, &user_dirs,
|
||||
filesystem::ENTIRE_FILE_PATH);
|
||||
filesystem::name_mode::ENTIRE_FILE_PATH);
|
||||
|
||||
// Warn player about addons using the no-longer-supported single-file format.
|
||||
for(const std::string& file : user_files) {
|
||||
|
@ -410,7 +410,7 @@ void game_config_manager::load_addons_cfg()
|
|||
user_dirs.clear();
|
||||
|
||||
filesystem::get_files_in_dir(user_campaign_dir, nullptr, &user_dirs,
|
||||
filesystem::FILE_NAME_ONLY);
|
||||
filesystem::name_mode::FILE_NAME_ONLY);
|
||||
|
||||
// Load the addons.
|
||||
for(const std::string& addon_id : user_dirs) {
|
||||
|
|
|
@ -267,10 +267,10 @@ create_engine::create_engine(saved_game& state)
|
|||
|
||||
// TODO: the editor dir is already configurable, is the preferences value
|
||||
filesystem::get_files_in_dir(filesystem::get_user_data_dir() + "/editor/maps", &user_map_names_,
|
||||
nullptr, filesystem::FILE_NAME_ONLY);
|
||||
nullptr, filesystem::name_mode::FILE_NAME_ONLY);
|
||||
|
||||
filesystem::get_files_in_dir(filesystem::get_user_data_dir() + "/editor/scenarios", &user_scenario_names_,
|
||||
nullptr, filesystem::FILE_NAME_ONLY);
|
||||
nullptr, filesystem::name_mode::FILE_NAME_ONLY);
|
||||
|
||||
DBG_MP << "initializing all levels, eras and mods\n";
|
||||
|
||||
|
|
|
@ -484,7 +484,7 @@ void file_dialog::refresh_fileview()
|
|||
|
||||
// TODO: Need to detect and handle cases where we don't have search permission
|
||||
// on current_dir_, otherwise things may get weird.
|
||||
filesystem::get_files_in_dir(current_dir_, &dir_files_, &dir_subdirs_, filesystem::FILE_NAME_ONLY);
|
||||
filesystem::get_files_in_dir(current_dir_, &dir_files_, &dir_subdirs_, filesystem::name_mode::FILE_NAME_ONLY);
|
||||
isort_dir_entries(dir_files_);
|
||||
isort_dir_entries(dir_subdirs_);
|
||||
|
||||
|
|
|
@ -1050,8 +1050,8 @@ static void precache_file_existence_internal(const std::string& dir, const std::
|
|||
|
||||
std::vector<std::string> files_found;
|
||||
std::vector<std::string> dirs_found;
|
||||
filesystem::get_files_in_dir(checked_dir, &files_found, &dirs_found, filesystem::FILE_NAME_ONLY,
|
||||
filesystem::NO_FILTER, filesystem::DONT_REORDER);
|
||||
filesystem::get_files_in_dir(checked_dir, &files_found, &dirs_found, filesystem::name_mode::FILE_NAME_ONLY,
|
||||
filesystem::filter_mode::NO_FILTER, filesystem::reorder_mode::DONT_REORDER);
|
||||
|
||||
for(const auto& f : files_found) {
|
||||
image_existence_map[subdir + f] = true;
|
||||
|
|
|
@ -750,9 +750,9 @@ preprocessor_file::preprocessor_file(preprocessor_streambuf& t, const std::strin
|
|||
{
|
||||
if(is_directory_) {
|
||||
filesystem::get_files_in_dir(name, &files_, nullptr,
|
||||
filesystem::ENTIRE_FILE_PATH,
|
||||
filesystem::SKIP_MEDIA_DIR,
|
||||
filesystem::DO_REORDER
|
||||
filesystem::name_mode::ENTIRE_FILE_PATH,
|
||||
filesystem::filter_mode::SKIP_MEDIA_DIR,
|
||||
filesystem::reorder_mode::DO_REORDER
|
||||
);
|
||||
|
||||
for(const std::string& fname : files_) {
|
||||
|
@ -1722,8 +1722,8 @@ void preprocess_resource(const std::string& res_name,
|
|||
if(filesystem::is_directory(res_name)) {
|
||||
std::vector<std::string> dirs, files;
|
||||
|
||||
filesystem::get_files_in_dir(res_name, &files, &dirs, filesystem::ENTIRE_FILE_PATH, filesystem::SKIP_MEDIA_DIR,
|
||||
filesystem::DO_REORDER);
|
||||
filesystem::get_files_in_dir(res_name, &files, &dirs, filesystem::name_mode::ENTIRE_FILE_PATH, filesystem::filter_mode::SKIP_MEDIA_DIR,
|
||||
filesystem::reorder_mode::DO_REORDER);
|
||||
|
||||
// Subdirectories
|
||||
for(const std::string& dir : dirs) {
|
||||
|
|
|
@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE( test_fs_enum )
|
|||
// FIXME: get_files_in_dir with mode == FILE_NAME_ONLY will fail to reorder
|
||||
// entries because the sorting code looks for forward slashes.
|
||||
// This affects both the BFS-based and legacy implementations.
|
||||
get_files_in_dir(path, &files, &dirs, ENTIRE_FILE_PATH, NO_FILTER, DO_REORDER);
|
||||
get_files_in_dir(path, &files, &dirs, name_mode::ENTIRE_FILE_PATH, filter_mode::NO_FILTER, reorder_mode::DO_REORDER);
|
||||
|
||||
BOOST_CHECK( files == expected_filepaths );
|
||||
BOOST_CHECK( dirs == expected_dirpaths );
|
||||
|
|
Loading…
Add table
Reference in a new issue