From 1f0a0fefe220574808ff3fb22c77326c2f2064c1 Mon Sep 17 00:00:00 2001 From: Afonso Pereia Date: Tue, 24 Nov 2026 13:21:44 +0000 Subject: [PATCH] VFS: preserve equivalent user mount overrides Merge missing default mounts using the same ASCII-case and trailing-separator equivalence as VFS construction. Otherwise default G: sorts before a configured g: and silently shadows it. Keep persistent storage drive detection consistent with separator-normalized prefixes. A file-backed configuration-to-VFS regression failed before the fix; Windows configuration tests afterward: 8 passed, 0 failed, 0 ignored. --- README.md | 2 ++ crates/xcl/src/config.rs | 46 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0710608d4d..134f6087ed 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,8 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder - Title data: `%LOCALAPPDATA%\XCL\\` (`%XCL_DATA_ROOT%`): `xcl.toml`, `overlay\`, `saves\`, `pls\` (the title's `S:\`), `temp\` (`T:\`), `cache\`, `logs\xcl.log`, `logs\report.json` (the previous run's: `xcl.prev.log`, `report.prev.json`). +- Custom mount prefixes in `xcl.toml` override defaults regardless of ASCII case or trailing + separators: `g:`, `G:\`, and `g:/` all override the default `G:` mount. ## Tests diff --git a/crates/xcl/src/config.rs b/crates/xcl/src/config.rs index 1503e550a6..b20d8ee651 100644 --- a/crates/xcl/src/config.rs +++ b/crates/xcl/src/config.rs @@ -139,6 +139,7 @@ impl Config { /// the drive-letter mount onto `{data}\pls`. None when the mounts have no such drive. pub fn pls_drive(&self) -> Option<String> { self.mounts.iter().find_map(|(prefix, target)| { + let prefix = prefix.trim_end_matches(['\\', '/']); let b = prefix.as_bytes(); let target = target.replace('/', "\\"); let is_drive = b.len() == 2 && b[0].is_ascii_alphabetic() && b[1] == b':'; @@ -210,7 +211,9 @@ impl Config { let mut c: Config = toml::from_str(&s).map_err(|e| format!("{}: {e}", path.display()))?; // default mounts added since the file was written for (k, v) in Config::default().mounts { - c.mounts.entry(k).or_insert(v); + if !c.mounts.keys().any(|prefix| prefix.trim_end_matches(['\\', '/']).eq_ignore_ascii_case(&k)) { + c.mounts.insert(k, v); + } } // the old default console id, written into every xcl.toml created before if c.console_id == OLD_CONSOLE_ID { @@ -289,6 +292,39 @@ impl Boot { mod tests { use super::*; + #[test] + fn default_mounts_do_not_shadow_equivalent_user_prefixes() { + use crate::vfs::{Target, Vfs}; + + let dir = std::env::temp_dir().join(format!("xcl_cfg_mount_overrides_{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let path = dir.join("xcl.toml"); + for prefix in ["G:", "g:", "G:\\", "g:/", "GaMe:"] { + std::fs::write(&path, format!("[mounts]\n'{prefix}' = 'C:\\custom'\n")).unwrap(); + let boot = Boot { + title: "MountOverride".into(), + exe_path: PathBuf::from("C:\\game\\game.exe"), + game_root: PathBuf::from("C:\\game"), + data_dir: dir.clone(), + config: Config::load_or_create(&path).unwrap(), + }; + let mounts = boot.config.mounts.iter().map(|(k, v)| (k.clone(), boot.expand(v))).collect(); + let vfs = Vfs::new(&boot.game_root, &boot.data_dir, mounts); + let input = format!("{}\\asset.bin", prefix.trim_end_matches(['\\', '/'])); + assert_eq!( + vfs.classify_with(&input, |p| Some(p.to_string())), + Target::Translated("C:\\custom\\asset.bin".into()), + "{prefix}" + ); + assert_eq!( + vfs.classify_with("D:\\asset.bin", |p| Some(p.to_string())), + Target::Game { rel: "asset.bin".into() } + ); + } + std::fs::remove_file(path).unwrap(); + std::fs::remove_dir(dir).unwrap(); + } + #[test] fn default_roundtrips_through_toml() { let c = Config::default(); @@ -328,10 +364,12 @@ mod tests { // a user-moved drive (any spelling of the target) is followed c.mounts.remove("S:"); assert_eq!(c.pls_drive(), None); - c.mounts.insert("p:".into(), "{data}/PLS\\".into()); - assert_eq!(c.pls_drive().as_deref(), Some("P:\\")); + for prefix in ["p:", "P:\\", "p:/"] { + c.mounts.insert(prefix.into(), "{data}/PLS\\".into()); + assert_eq!(c.pls_drive().as_deref(), Some("P:\\")); + c.mounts.remove(prefix); + } // directory-style prefixes are not drives - c.mounts.remove("p:"); c.mounts.insert("PLS:".into(), PLS_MOUNT_TARGET.into()); assert_eq!(c.pls_drive(), None); }