added type Link

This commit is contained in:
2026-03-03 20:59:37 +01:00
parent 63171acbe4
commit e9b7aedb6f
3 changed files with 57 additions and 11 deletions

View File

@@ -13,6 +13,41 @@ use crate::{
utils::walk_files_recursive, utils::walk_files_recursive,
}; };
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(from = "(PathBuf, PathBuf)", into = "(PathBuf,PathBuf)")]
pub struct Link {
pub src: PathBuf,
pub dst: PathBuf,
}
impl Link {
pub fn new(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Self {
Self {
src: src.as_ref().to_owned(),
dst: dst.as_ref().to_owned(),
}
}
pub fn from_mod_file(file: &ModFile) -> Self {
Self::new(&file.source, &file.dest)
}
}
impl From<(PathBuf, PathBuf)> for Link {
fn from(value: (PathBuf, PathBuf)) -> Self {
Self {
src: value.0,
dst: value.1,
}
}
}
impl From<Link> for (PathBuf, PathBuf) {
fn from(value: Link) -> Self {
(value.src, value.dst)
}
}
#[derive(Debug, Clone, Deserialize, PartialEq)] #[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct RootConfig { pub struct RootConfig {
/// Available games /// Available games
@@ -70,6 +105,16 @@ pub struct Game {
pub install_location: PathBuf, pub install_location: PathBuf,
} }
impl Game {
// pub fn export_links(&self) -> Result<, io::Error> {
// walk_files_recursive(&self.install_location)
// .unwrap()
// .map(|file| file.path())
// .map(|path| ());
// todo!()
// }
}
#[derive(Debug, Clone, Deserialize, PartialEq)] #[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct InstancePointer { pub struct InstancePointer {
pub id: String, pub id: String,
@@ -168,8 +213,9 @@ impl ModdedInstance {
let mut already_installed_files: Vec<(ModFile, &InstalledMod)> = Vec::new(); let mut already_installed_files: Vec<(ModFile, &InstalledMod)> = Vec::new();
for installed_mod in &self.mods { for installed_mod in &self.mods {
for (src, dst) in &installed_mod.files { for link in &installed_mod.files {
already_installed_files.push((ModFile::new(src, dst, 0), installed_mod)); already_installed_files
.push((ModFile::new(&link.src, &link.dst, 1), installed_mod));
} }
} }
@@ -209,7 +255,7 @@ impl ModdedInstance {
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct InstalledMod { pub struct InstalledMod {
id: String, id: String,
files: Vec<(PathBuf, PathBuf)>, files: Vec<Link>,
priority: isize, priority: isize,
} }
@@ -223,7 +269,7 @@ impl InstalledMod {
} }
pub fn add_file(&mut self, file: &ModFile) { pub fn add_file(&mut self, file: &ModFile) {
self.files.push((file.source.clone(), file.dest.clone())); self.files.push(Link::from_mod_file(file));
} }
/// Get the id of the mod /// Get the id of the mod
@@ -237,8 +283,8 @@ impl InstalledMod {
} }
/// The selected files /// The selected files
pub fn files(&self) -> Vec<(PathBuf, PathBuf)> { pub fn files(&self) -> &[Link] {
self.files.clone() &self.files
} }
} }

View File

@@ -17,9 +17,9 @@ pub fn link_instance_to_target(
let mod_config = root_config.get_mod_by_id(&installed_mod.mod_id()).unwrap(); let mod_config = root_config.get_mod_by_id(&installed_mod.mod_id()).unwrap();
let mod_source_root = root_config.get_mod_location(&mod_config); let mod_source_root = root_config.get_mod_location(&mod_config);
for (src, dst) in installed_mod.files() { for link in installed_mod.files() {
let link_target = mod_source_root.join(src); let link_target = mod_source_root.join(&link.src);
let link_name = target.as_ref().join(dst); let link_name = target.as_ref().join(&link.dst);
link_file(&link_target, &link_name)?; link_file(&link_target, &link_name)?;
} }
} }

View File

@@ -44,8 +44,8 @@ impl LoadOrder {
let mod_plugins: Vec<PathBuf> = installed_mod let mod_plugins: Vec<PathBuf> = installed_mod
.files() .files()
.iter() .iter()
.filter(|f| Self::is_plugin_file(&f.0)) .filter(|f| Self::is_plugin_file(&f.dst))
.map(|(from, _)| mod_source_root.join(from)) .map(|link| mod_source_root.join(&link.src))
.collect(); .collect();
let refs: Vec<_> = mod_plugins.iter().map(|e| e.as_path()).collect(); let refs: Vec<_> = mod_plugins.iter().map(|e| e.as_path()).collect();