From 58505aeebc1bb5250d3b026f5a2cd8309be8bd88 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Thu, 26 Feb 2026 18:04:30 +0100 Subject: [PATCH] added link_plugin_files to linker --- src/linker.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/linker.rs b/src/linker.rs index e0b5397..a665019 100644 --- a/src/linker.rs +++ b/src/linker.rs @@ -4,6 +4,8 @@ use std::{ path::{Path, PathBuf}, }; +use crate::fomod::FileTypeEnum; + pub struct Linker { target: PathBuf, } @@ -85,6 +87,35 @@ impl Linker { Ok(()) } + + pub fn link_plugin_files( + &self, + entries: &[FileTypeEnum], + mod_dir: &Path, + ) -> Result<(), LinkerError> { + let mut sorted_entries = entries.to_owned(); + sorted_entries.sort_by_cached_key(|e| match e { + FileTypeEnum::File(file_type) => file_type.priority.unwrap_or(0), + FileTypeEnum::Folder(file_type) => file_type.priority.unwrap_or(0), + }); + + for entry in sorted_entries { + match entry { + FileTypeEnum::File(file) => { + let from = mod_dir.join(file.source); + let to = Path::new("Data").join(file.destination.unwrap_or("".to_owned())); + self.link_file(&from, &to)?; + } + FileTypeEnum::Folder(folder) => { + let from = mod_dir.join(folder.source); + let to = Path::new("Data").join(folder.destination.unwrap_or("".to_owned())); + self.link_recursive(&from, &to)?; + } + } + } + + Ok(()) + } } #[derive(Debug)]