From ed87dc1ca9cbe8b43c5efd2943023ea94ea5ace3 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Mon, 2 Mar 2026 21:27:06 +0100 Subject: [PATCH] fixed moduleConfig.xml being case insesitive --- src/main.rs | 3 ++- src/utils.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 86976ad..f800781 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use crate::{ linker::{create_plugins_txt, link_game_to_target, link_instance_to_target}, load_order::LoadOrder, mod_config_installer::FomodInstaller, + utils::resolve_case_insensitive, }; mod basic_types; @@ -22,7 +23,7 @@ mod mod_config_installer; mod utils; pub fn load_mod_config(mod_root: impl AsRef) -> Result> { - let path = mod_root.as_ref().join("FOMod/ModuleConfig.xml"); + let path = resolve_case_insensitive(&mod_root, "fomod/ModuleConfig.xml")?; let mod_config = Config::load_from_file(path)?; Ok(mod_config) } diff --git a/src/utils.rs b/src/utils.rs index e0ffa47..2e89d8d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,6 @@ use std::{ fs::{self, DirEntry}, + io, path::{Path, PathBuf}, }; @@ -29,3 +30,39 @@ pub fn walk_files_recursive( pub fn path_to_lowercase(path: impl AsRef) -> PathBuf { PathBuf::from(path.as_ref().to_string_lossy().to_lowercase()) } + +pub fn resolve_case_insensitive( + base: impl AsRef, + rel: impl AsRef, +) -> io::Result { + let mut current = base.as_ref().to_path_buf(); + + for part in rel.as_ref().iter() { + let target = part.to_string_lossy(); + + let mut found = None; + + for entry in fs::read_dir(¤t)? { + let entry = entry?; + let name = entry.file_name(); + let name = name.to_string_lossy(); + + if name.eq_ignore_ascii_case(&target) { + found = Some(entry.path()); + break; + } + } + + match found { + Some(path) => current = path, + None => { + return Err(io::Error::new( + io::ErrorKind::NotFound, + format!("Path component not found: {}", target), + )); + } + } + } + + Ok(current) +}