diff --git a/SystemToolkit.cpp b/SystemToolkit.cpp index 2b27e87..d7346d1 100644 --- a/SystemToolkit.cpp +++ b/SystemToolkit.cpp @@ -43,6 +43,7 @@ using namespace std; #include #include #include +#include #define PATH_SEP '/' #endif @@ -298,7 +299,7 @@ std::string SystemToolkit::path_directory(const std::string& path) return directorypath; } -list SystemToolkit::list_directory(const string& path, const list& extensions) +list SystemToolkit::list_directory(const string& path, const list& patterns) { list ls; @@ -309,10 +310,12 @@ list SystemToolkit::list_directory(const string& path, const listd_type == DT_REG) { - string filename = string(ent->d_name); - string ext = extension_filename(filename); - if ( extensions.empty() || find(extensions.cbegin(), extensions.cend(), ext) != extensions.cend()) - ls.push_back( full_filename(path, filename) ); + int found = FNM_NOMATCH; + for (auto it = patterns.cbegin(); it != patterns.cend() && found == FNM_NOMATCH; ++it) + // test pattern in CASE insensitive + found = fnmatch( it->c_str(), ent->d_name, FNM_CASEFOLD ); + if (found != FNM_NOMATCH) + ls.push_back( full_filename(path, ent->d_name) ); } } closedir (dir); diff --git a/SystemToolkit.h b/SystemToolkit.h index 4c9b35a..b7bb44b 100644 --- a/SystemToolkit.h +++ b/SystemToolkit.h @@ -49,7 +49,7 @@ namespace SystemToolkit std::string path_directory(const std::string& path); // list all files of a directory mathing the given filter extension (if any) - std::list list_directory(const std::string& path, const std::list &extensions); + std::list list_directory(const std::string& path, const std::list &patterns); // builds a path relative to 'relativeTo' to reach file at 'absolutePath' (e.g. /a/b/c/d rel to /a/b/e -> ../c/d) std::string path_relative_to_path(const std::string& absolutePath, const std::string& relativeTo); diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index b05f265..46604f6 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -4415,7 +4415,7 @@ void Navigator::RenderMainPannelVimix() // selection MODE 1 : LIST FOLDER else if ( selection_session_mode == 1) { // show list of vimix files in folder - sessions_list = SystemToolkit::list_directory( Settings::application.recentFolders.path, {"mix", "MIX"}); + sessions_list = SystemToolkit::list_directory( Settings::application.recentFolders.path, { VIMIX_FILES_PATTERN }); } // indicate the list changed (do not change at every frame) selection_session_mode_changed = false;