From 96dda41c46d4803e79089a73d0c483dbcf0b46a8 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Wed, 11 Mar 2026 00:30:50 +0100 Subject: [PATCH] pass active plugins to fomod installer --- src/instance.rs | 15 +++++++++++---- src/load_order.rs | 9 +-------- src/types/installed_mod.rs | 15 ++++++++++++++- src/types/modded_instance.rs | 5 +++++ src/utils.rs | 7 +++++++ 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/instance.rs b/src/instance.rs index 6fbf9f5..ad08a5d 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -5,7 +5,7 @@ use std::{ }; use globset::{Glob, GlobSet, GlobSetBuilder}; -use log::warn; +use log::{debug, trace, warn}; use thiserror::Error; use crate::{ @@ -114,14 +114,21 @@ fn determain_mod_kind( } fn install_fomod( - _instance: &ModdedInstance, + instance: &ModdedInstance, module_config_path: impl AsRef, mod_root: impl AsRef, ) -> anyhow::Result> { + debug!("Running FOmod installer"); let module_config = fomod::Config::load_from_file(module_config_path)?; - // TODO: add active plugins from instance config - let files = run_fomod_installer(module_config, &[], install_prompt::prompt) + let active_plugins: Vec<_> = instance + .active_plugins() + .map(|e| e.to_string_lossy()) + .map(|e| e.to_string()) + .collect(); + + trace!("Current loded plugins: {:?}", active_plugins); + let files = run_fomod_installer(module_config, &active_plugins, install_prompt::prompt) .map_err(|_| InststanceError::FomodRunInstaller)?; let mod_files: Vec<_> = files diff --git a/src/load_order.rs b/src/load_order.rs index 6bba889..769af27 100644 --- a/src/load_order.rs +++ b/src/load_order.rs @@ -10,7 +10,7 @@ use std::{ use thiserror::Error; use walkdir::WalkDir; -use crate::types::{self, ModdedInstance, RootConfig}; +use crate::{types::{self, ModdedInstance, RootConfig}, utils::is_plugin_file}; pub fn create_loadorder( root_config: &RootConfig, @@ -76,13 +76,6 @@ pub fn create_loadorder( Ok(sorted) } -fn is_plugin_file(filename: impl AsRef) -> bool { - filename - .as_ref() - .extension() - .is_some_and(|ext| ext == "esp" || ext == "esm" || ext == "esl") -} - #[derive(Error, Debug)] pub enum LoadOrderError { #[error("Failed to read game directory")] diff --git a/src/types/installed_mod.rs b/src/types/installed_mod.rs index fa2d8b5..eced8c6 100644 --- a/src/types/installed_mod.rs +++ b/src/types/installed_mod.rs @@ -1,6 +1,11 @@ +use std::ffi::OsStr; + use serde::{Deserialize, Serialize}; -use crate::types::{link::Link, mod_file::ModFile}; +use crate::{ + types::{link::Link, mod_file::ModFile}, + utils::is_plugin_file, +}; #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub struct InstalledMod { @@ -36,4 +41,12 @@ impl InstalledMod { pub fn files(&self) -> &[Link] { &self.files } + + pub fn active_plugins(&self) -> impl Iterator { + self.files + .iter() + .filter(|e| is_plugin_file(e.dst())) + .map(|e| e.dst()) + .flat_map(|e| e.file_name()) + } } diff --git a/src/types/modded_instance.rs b/src/types/modded_instance.rs index 3ee6834..1ef0b37 100644 --- a/src/types/modded_instance.rs +++ b/src/types/modded_instance.rs @@ -1,4 +1,5 @@ use std::{ + ffi::OsStr, fs::{self, read_to_string}, io::Write, path::{Path, PathBuf}, @@ -88,4 +89,8 @@ impl ModdedInstance { pub fn mods(&self) -> &[InstalledMod] { &self.mods } + + pub fn active_plugins(&self) -> impl Iterator { + self.mods.iter().flat_map(|e| e.active_plugins()) + } } diff --git a/src/utils.rs b/src/utils.rs index 3a49d98..f787797 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -56,3 +56,10 @@ pub fn walk_all_files( Ok(a) } + +pub fn is_plugin_file(filename: impl AsRef) -> bool { + filename + .as_ref() + .extension() + .is_some_and(|ext| ext == "esp" || ext == "esm" || ext == "esl") +}