made use of walkdir

This commit is contained in:
2026-03-04 19:56:33 +01:00
parent d263d487b1
commit b6efa0a818
6 changed files with 124 additions and 66 deletions

View File

@@ -1,18 +1,19 @@
use std::{
collections::{HashMap, HashSet},
collections::HashMap,
io,
path::{Path, PathBuf},
};
use globset::{Glob, GlobSet, GlobSetBuilder};
use log::warn;
use walkdir::WalkDir;
use crate::{
basic_types::{InstalledMod, Link, ModConfig, ModFile, ModdedInstance, RootConfig},
basic_types::{InstalledMod, ModConfig, ModFile, ModdedInstance, RootConfig},
file_conflict_solver::ConflictSolver,
fomod, install_prompt,
mod_config_installer::run_fomod_installer,
utils::{resolve_case_insensitive, walk_files_recursive},
utils::resolve_case_insensitive,
};
pub fn insert_mod_to_instance(
@@ -129,12 +130,23 @@ fn install_from_dir(
path: impl AsRef<Path>,
) -> anyhow::Result<Vec<ModFile>> {
let glob_filter = create_glob_filter(mod_config.ignore())?;
let files: Vec<_> = walk_files_recursive(&path)?
.map(|entry| entry.path())
.map(|file_path| file_path.strip_prefix(&path).unwrap().to_owned())
.filter(|rel_path| !glob_filter.is_match(rel_path))
.map(|rel_path| ModFile::new(&rel_path, &rel_path, 0))
.collect();
let files: Vec<_> = WalkDir::new(path)
.into_iter()
.map(|entry| {
let entry = entry?;
let path = entry.path();
let rel_path = path.strip_prefix(&path).unwrap();
if !glob_filter.is_match(rel_path) {
Ok(Some(ModFile::new(&rel_path, &rel_path, 0)))
} else {
Ok(None)
}
})
.filter_map(|r| r.transpose())
.collect::<Result<_, io::Error>>()?;
Ok(files)
}
@@ -144,13 +156,26 @@ fn install_from_dir_to_data(
) -> anyhow::Result<Vec<ModFile>> {
let glob_filter = create_glob_filter(mod_config.ignore())?;
let data = PathBuf::from("Data");
let files: Vec<_> = walk_files_recursive(&path)?
.map(|entry| entry.path())
.map(|file_path| file_path.strip_prefix(&path).unwrap().to_owned())
.filter(|rel_path| should_be_included(rel_path))
.filter(|rel_path| !glob_filter.is_match(rel_path))
.map(|rel_path| ModFile::new(&rel_path, data.join(&rel_path), 0))
.collect();
let files: Vec<_> = WalkDir::new(&path)
.into_iter()
.map(|entry| {
let entry = entry?;
let path = entry.path();
let rel_path = path.strip_prefix(&path).unwrap();
if !should_be_included(rel_path) {
return Ok(None);
}
if glob_filter.is_match(rel_path) {
return Ok(None);
}
Ok(Some(ModFile::new(rel_path, data.join(rel_path), 0)))
})
.filter_map(|r| r.transpose())
.collect::<Result<_, io::Error>>()?;
Ok(files)
}