fixed moduleConfig.xml being case insesitive
This commit is contained in:
@@ -9,6 +9,7 @@ use crate::{
|
|||||||
linker::{create_plugins_txt, link_game_to_target, link_instance_to_target},
|
linker::{create_plugins_txt, link_game_to_target, link_instance_to_target},
|
||||||
load_order::LoadOrder,
|
load_order::LoadOrder,
|
||||||
mod_config_installer::FomodInstaller,
|
mod_config_installer::FomodInstaller,
|
||||||
|
utils::resolve_case_insensitive,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod basic_types;
|
mod basic_types;
|
||||||
@@ -22,7 +23,7 @@ mod mod_config_installer;
|
|||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
pub fn load_mod_config(mod_root: impl AsRef<Path>) -> Result<fomod::Config, Box<dyn Error>> {
|
pub fn load_mod_config(mod_root: impl AsRef<Path>) -> Result<fomod::Config, Box<dyn Error>> {
|
||||||
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)?;
|
let mod_config = Config::load_from_file(path)?;
|
||||||
Ok(mod_config)
|
Ok(mod_config)
|
||||||
}
|
}
|
||||||
|
|||||||
37
src/utils.rs
37
src/utils.rs
@@ -1,5 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{self, DirEntry},
|
fs::{self, DirEntry},
|
||||||
|
io,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -29,3 +30,39 @@ pub fn walk_files_recursive(
|
|||||||
pub fn path_to_lowercase(path: impl AsRef<Path>) -> PathBuf {
|
pub fn path_to_lowercase(path: impl AsRef<Path>) -> PathBuf {
|
||||||
PathBuf::from(path.as_ref().to_string_lossy().to_lowercase())
|
PathBuf::from(path.as_ref().to_string_lossy().to_lowercase())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn resolve_case_insensitive(
|
||||||
|
base: impl AsRef<Path>,
|
||||||
|
rel: impl AsRef<Path>,
|
||||||
|
) -> io::Result<PathBuf> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user