Compare commits

..

3 Commits

Author SHA1 Message Date
6c634824a8 added custom debug impl for Link 2026-03-16 23:00:42 +01:00
b6b3759446 add install_root in instance 2026-03-16 23:00:18 +01:00
fa93cf9a6b deny unknown fields in config 2026-03-16 22:59:30 +01:00
4 changed files with 31 additions and 6 deletions

View File

@@ -82,10 +82,8 @@ pub fn files_to_install_mod(
let files = match determain_mod_kind(mod_to_install, &mod_location)? {
ModKind::Fomod(xml_path) => install_fomod(instance, xml_path, &mod_location)?,
ModKind::EmbeddedData(data_path) => {
install_from_dir(mod_to_install, mod_location.join(data_path))?
}
ModKind::Root => install_from_dir(mod_to_install, mod_location)?,
ModKind::EmbeddedData(_data_path) => install_from_dir(mod_to_install, mod_location)?,
ModKind::Root => install_root(mod_to_install, mod_location)?,
ModKind::Unkown => install_from_dir_to_data(mod_to_install, mod_location)?,
};
@@ -149,6 +147,22 @@ fn install_from_dir(
) -> anyhow::Result<Vec<ModFile>> {
let glob_filter = create_glob_filter(mod_config.ignore())?;
let files: Vec<_> = walk_all_files(&mod_location)?
.map(|entry| entry.path().strip_prefix(&mod_location).unwrap().to_owned())
.filter(|rel_path| !glob_filter.is_match(rel_path))
.filter(|rel_path| should_be_included(rel_path))
.map(|rel_path| ModFile::new(&rel_path, &rel_path, 0))
.collect();
Ok(files)
}
fn install_root(
mod_config: &ModConfig,
mod_location: impl AsRef<Path>,
) -> anyhow::Result<Vec<ModFile>> {
let glob_filter = create_glob_filter(mod_config.ignore())?;
let files: Vec<_> = walk_all_files(&mod_location)?
.map(|entry| entry.path().strip_prefix(&mod_location).unwrap().to_owned())
.filter(|rel_path| !glob_filter.is_match(rel_path))

View File

@@ -1,11 +1,14 @@
use std::path::{Path, PathBuf};
use std::{
fmt::Debug,
path::{Path, PathBuf},
};
use serde::{Deserialize, Serialize};
use crate::types::mod_file::ModFile;
/// A link between a file from a mod and a destination in a ModdedInstance
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[derive(Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
#[serde(from = "(PathBuf, PathBuf)", into = "(PathBuf,PathBuf)")]
pub struct Link {
src: PathBuf,
@@ -53,3 +56,9 @@ impl From<ModFile> for Link {
Self::new(value.src(), value.dst())
}
}
impl Debug for Link {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Link{{{:?} -> {:?}}}", self.src, self.dst,)
}
}

View File

@@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
/// Config for an available mod
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct ModConfig {
/// ID of the mod
#[serde(skip)]

View File

@@ -11,6 +11,7 @@ use serde::{Deserialize, Serialize};
use crate::types::{ConfigReadWriteError, ModConfig, game::Game, modded_instance::ModdedInstance};
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct RootConfig {
#[serde(default)]
games: HashMap<String, Game>,