From 7dc5626af3eb924fa381c46491cd49178a78cd73 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sun, 2 Jul 2017 16:47:03 +0200 Subject: Move directory scanners to new get_filenames(...) calls --- src/io/resource.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/io/resource.cpp') diff --git a/src/io/resource.cpp b/src/io/resource.cpp index 6a388c1ac..aa13de683 100644 --- a/src/io/resource.cpp +++ b/src/io/resource.cpp @@ -205,7 +205,7 @@ std::vector get_filenames(Domain domain, Type type, std::vector &files, Glib::ustring path, std::vector extensions, std::vector exclusions) @@ -217,15 +217,23 @@ void get_filenames_from_path(std::vector &files, Glib::ustring pa Glib::Dir dir(path); std::string file = dir.read_name(); while (!file.empty()){ - bool reject = false; + // If not extensions are specified, don't reject ANY files. + bool reject = !extensions.empty(); + + // Unreject any file which has one of the extensions. for (auto &ext: extensions) { - reject |= !Glib::str_has_suffix(file, ext); + reject ^= Glib::str_has_suffix(file, ext); } + + // Reject any file which matches the exclusions. for (auto &exc: exclusions) { reject |= Glib::str_has_prefix(file, exc); } + + // Reject any filename which isn't a regular file Glib::ustring filename = Glib::build_filename(path, file); reject |= !Glib::file_test(filename, Glib::FILE_TEST_IS_REGULAR); + if(!reject) { files.push_back(filename); } -- cgit v1.2.3