diff --git a/src/basic_types.rs b/src/basic_types.rs index 08bbed9..cac73ff 100644 --- a/src/basic_types.rs +++ b/src/basic_types.rs @@ -13,6 +13,41 @@ use crate::{ 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, dst: impl AsRef) -> 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 for (PathBuf, PathBuf) { + fn from(value: Link) -> Self { + (value.src, value.dst) + } +} + #[derive(Debug, Clone, Deserialize, PartialEq)] pub struct RootConfig { /// Available games @@ -70,6 +105,16 @@ pub struct Game { 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)] pub struct InstancePointer { pub id: String, @@ -168,8 +213,9 @@ impl ModdedInstance { let mut already_installed_files: Vec<(ModFile, &InstalledMod)> = Vec::new(); for installed_mod in &self.mods { - for (src, dst) in &installed_mod.files { - already_installed_files.push((ModFile::new(src, dst, 0), installed_mod)); + for link in &installed_mod.files { + 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)] pub struct InstalledMod { id: String, - files: Vec<(PathBuf, PathBuf)>, + files: Vec, priority: isize, } @@ -223,7 +269,7 @@ impl InstalledMod { } 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 @@ -237,8 +283,8 @@ impl InstalledMod { } /// The selected files - pub fn files(&self) -> Vec<(PathBuf, PathBuf)> { - self.files.clone() + pub fn files(&self) -> &[Link] { + &self.files } } diff --git a/src/linker.rs b/src/linker.rs index ec7ee99..24e60e7 100644 --- a/src/linker.rs +++ b/src/linker.rs @@ -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_source_root = root_config.get_mod_location(&mod_config); - for (src, dst) in installed_mod.files() { - let link_target = mod_source_root.join(src); - let link_name = target.as_ref().join(dst); + for link in installed_mod.files() { + let link_target = mod_source_root.join(&link.src); + let link_name = target.as_ref().join(&link.dst); link_file(&link_target, &link_name)?; } } diff --git a/src/load_order.rs b/src/load_order.rs index 1a64e82..826be0d 100644 --- a/src/load_order.rs +++ b/src/load_order.rs @@ -44,8 +44,8 @@ impl LoadOrder { let mod_plugins: Vec = installed_mod .files() .iter() - .filter(|f| Self::is_plugin_file(&f.0)) - .map(|(from, _)| mod_source_root.join(from)) + .filter(|f| Self::is_plugin_file(&f.dst)) + .map(|link| mod_source_root.join(&link.src)) .collect(); let refs: Vec<_> = mod_plugins.iter().map(|e| e.as_path()).collect();