develop #3

Merged
Fabel merged 12 commits from develop into main 2025-01-19 21:37:41 +00:00
1 changed files with 51 additions and 28 deletions
Showing only changes of commit 6d5610c05c - Show all commits

View File

@ -3,16 +3,23 @@
#include <filesystem> #include <filesystem>
namespace fs = std::filesystem; namespace fs = std::filesystem;
bool TreeStructurer::should_ignore_dir(const std::string& dirname) { bool TreeStructurer::should_ignore_dir(const std::string& dirname) {
static const std::vector<std::string> ignore_list = { static const std::vector<std::string> ignore_list = {
"build", "venv", "myenv", "dist", "node_modules", "CMakeFiles", "build", "venv", "myenv", "dist", "node_modules", "CMakeFiles",
".git", ".idea", ".vscode", "__pycache__" ".git", ".idea", ".vscode", "__pycache__"
}; };
return dirname[0] == '.' || // Ignore directories in the ignore list
dirname[0] == '_' || // This will catch __pycache__ and _directories if (std::find(ignore_list.begin(), ignore_list.end(), dirname) != ignore_list.end()) {
std::find(ignore_list.begin(), ignore_list.end(), dirname) != ignore_list.end(); return true;
}
// Ignore directories starting with '.' or '_'
if (!dirname.empty() && (dirname[0] == '.' || dirname[0] == '_')) {
return true;
}
return false;
} }
bool TreeStructurer::should_ignore_file(const std::string& filename) { bool TreeStructurer::should_ignore_file(const std::string& filename) {
@ -21,37 +28,51 @@ bool TreeStructurer::should_ignore_file(const std::string& filename) {
".o", ".obj", ".a", ".lib" ".o", ".obj", ".a", ".lib"
}; };
if (filename[0] == '.') return true; // Ignore files starting with '.' or '_'
if (!filename.empty() && (filename[0] == '.' || filename[0] == '_')) {
return true;
}
// Ignore files with specific extensions
fs::path path(filename); fs::path path(filename);
std::string ext = path.extension().string(); std::string ext = path.extension().string();
return std::find(ignore_extensions.begin(), ignore_extensions.end(), ext) != ignore_extensions.end(); if (std::find(ignore_extensions.begin(), ignore_extensions.end(), ext) != ignore_extensions.end()) {
return true;
}
return false;
} }
std::vector<fs::path> TreeStructurer::get_filtered_paths(const fs::path& start) { std::vector<fs::path> TreeStructurer::get_filtered_paths(const fs::path& start) {
std::vector<fs::path> paths; std::vector<fs::path> paths;
for(const auto& entry : fs::recursive_directory_iterator(start)) { for (const auto& entry : fs::recursive_directory_iterator(start)) {
const auto& path = entry.path(); const auto& path = entry.path();
bool should_include = true;
for(auto it = path.begin(); it != path.end(); ++it) { // Skip any path that contains an ignored directory
if(should_ignore_dir(it->string())) { bool contains_ignored_dir = false;
should_include = false; for (auto it = path.begin(); it != path.end(); ++it) {
if (should_ignore_dir(it->string())) {
contains_ignored_dir = true;
break; break;
} }
} }
if(should_include) { if (contains_ignored_dir) {
if(fs::is_directory(path)) { continue;
if(!should_ignore_dir(path.filename().string())) { }
// Handle directories
if (fs::is_directory(path)) {
if (!should_ignore_dir(path.filename().string())) {
paths.push_back(path); paths.push_back(path);
} }
} else { }
if(!should_ignore_file(path.filename().string())) { // Handle files
else {
if (!should_ignore_file(path.filename().string())) {
paths.push_back(path); paths.push_back(path);
} }
}
} }
} }
@ -59,6 +80,8 @@ std::vector<fs::path> TreeStructurer::get_filtered_paths(const fs::path& start)
return paths; return paths;
} }
std::string TreeStructurer::create_indent(int level) { std::string TreeStructurer::create_indent(int level) {
if (level == 0) return ""; if (level == 0) return "";