From 05d93c7fa1be9245dd5211b7dc1bdf0961b39eea Mon Sep 17 00:00:00 2001 From: number Zero Date: Wed, 13 Sep 2017 23:03:18 +0300 Subject: Load files from subfolders in texturepacks Updated and rebased version of a PR by red-001 --- src/filesys.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/filesys.cpp') diff --git a/src/filesys.cpp b/src/filesys.cpp index d965384a2..694169d20 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -380,15 +380,36 @@ std::string TempPath() #endif -void GetRecursiveSubPaths(const std::string &path, std::vector &dst) +void GetRecursiveDirs(std::vector &dirs, const std::string &dir) +{ + static const std::set chars_to_ignore = { '_', '.' }; + if (dir.empty() || !IsDir(dir)) + return; + dirs.push_back(dir); + fs::GetRecursiveSubPaths(dir, dirs, false, chars_to_ignore); +} + +std::vector GetRecursiveDirs(const std::string &dir) +{ + std::vector result; + GetRecursiveDirs(result, dir); + return result; +} + +void GetRecursiveSubPaths(const std::string &path, + std::vector &dst, + bool list_files, + const std::set &ignore) { std::vector content = GetDirListing(path); for (const auto &n : content) { std::string fullpath = path + DIR_DELIM + n.name; - dst.push_back(fullpath); - if (n.dir) { - GetRecursiveSubPaths(fullpath, dst); - } + if (ignore.count(n.name[0])) + continue; + if (list_files || n.dir) + dst.push_back(fullpath); + if (n.dir) + GetRecursiveSubPaths(fullpath, dst, list_files, ignore); } } -- cgit v1.2.3