added abilty to ignore files in a mod
This commit is contained in:
@@ -84,6 +84,14 @@ pub struct ModConfig {
|
||||
|
||||
/// Relative to the mod_location from root config
|
||||
pub path: PathBuf,
|
||||
|
||||
/// If the files should be included on the root
|
||||
#[serde(default)]
|
||||
root_mod: bool,
|
||||
|
||||
/// Globs of what files to ignore
|
||||
#[serde(default)]
|
||||
ignore: Vec<String>,
|
||||
}
|
||||
|
||||
impl ModConfig {
|
||||
@@ -91,8 +99,18 @@ impl ModConfig {
|
||||
Self {
|
||||
id: id.to_owned(),
|
||||
path: source.as_ref().to_owned(),
|
||||
root_mod: false,
|
||||
ignore: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_root_mod(&self) -> bool {
|
||||
self.root_mod
|
||||
}
|
||||
|
||||
pub fn ignore(&self) -> &[String] {
|
||||
&self.ignore
|
||||
}
|
||||
}
|
||||
|
||||
/// An modded game with all plugins and files
|
||||
|
||||
32
src/main.rs
32
src/main.rs
@@ -1,8 +1,8 @@
|
||||
use clap::Parser;
|
||||
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||
use log::debug;
|
||||
use std::{
|
||||
error::Error,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
@@ -32,6 +32,10 @@ pub fn gen_filelist_for_mod(
|
||||
) -> Result<Vec<ModFile>, Box<dyn Error>> {
|
||||
let mod_location = root_config.get_mod_location(mod_config);
|
||||
|
||||
if mod_config.is_root_mod() {
|
||||
return gen_filelist_for_root_mod(mod_config, mod_location);
|
||||
}
|
||||
|
||||
let module_config_path = resolve_case_insensitive(&mod_location, "fomod/ModuleConfig.xml")?;
|
||||
|
||||
let files: Vec<ModFile> = match module_config_path {
|
||||
@@ -48,6 +52,32 @@ pub fn gen_filelist_for_mod(
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
fn create_glob_filter(rules: &[String]) -> Result<GlobSet, Box<dyn Error>> {
|
||||
let mut builder = GlobSetBuilder::new();
|
||||
|
||||
for p in rules {
|
||||
builder.add(Glob::new(p)?);
|
||||
}
|
||||
|
||||
let set = builder.build()?;
|
||||
Ok(set)
|
||||
}
|
||||
|
||||
fn gen_filelist_for_root_mod(
|
||||
mod_config: &ModConfig,
|
||||
mod_location: impl AsRef<Path>,
|
||||
) -> Result<Vec<ModFile>, Box<dyn Error>> {
|
||||
let glob_filter = create_glob_filter(mod_config.ignore())?;
|
||||
let files: Vec<_> = walk_files_recursive(&mod_location)?
|
||||
.map(|entry| entry.path())
|
||||
.map(|path| path.strip_prefix(&mod_location).unwrap().to_owned())
|
||||
.filter(|rel_path| !glob_filter.is_match(rel_path))
|
||||
.map(|rel_path| ModFile::new(&rel_path, &rel_path, 0))
|
||||
.collect();
|
||||
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
pub fn gen_filelist_from_mod_dir(
|
||||
mod_location: impl AsRef<Path>,
|
||||
) -> Result<Vec<ModFile>, Box<dyn Error>> {
|
||||
|
||||
Reference in New Issue
Block a user