From 8d233edfe44836171c937fac6e283df96f2aa0e9 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 23 Sep 2023 11:48:58 +0100 Subject: [PATCH] Support .nam files for Fallout: New Vegas If a .nam file is present in the Data folder, any .esp or .esm file with the (case-insensitively) same basename will be activated by the game. Only Fallout NV uses .nam files like this. --- src/game_settings.rs | 83 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/src/game_settings.rs b/src/game_settings.rs index 61e0e63..f003234 100644 --- a/src/game_settings.rs +++ b/src/game_settings.rs @@ -349,6 +349,44 @@ fn hardcoded_plugins(game_id: GameId) -> &'static [&'static str] { } } +fn find_nam_plugins(plugins_path: &Path) -> Result, Error> { + // Scan the path for .nam files. Each .nam file can activate a .esm or .esp + // plugin with the same basename, so return those filenames. + let mut plugin_names = Vec::new(); + + if !plugins_path.exists() { + return Ok(plugin_names); + } + + let dir_iter = plugins_path + .read_dir()? + .into_iter() + .filter_map(Result::ok) + .filter(|e| e.file_type().map(|f| f.is_file()).unwrap_or(false)) + .filter(|e| { + e.path() + .extension() + .unwrap_or_default() + .eq_ignore_ascii_case("nam") + }); + + for entry in dir_iter { + let file_name = entry.file_name(); + + let esp = Path::new(&file_name).with_extension("esp"); + if let Some(esp) = esp.to_str() { + plugin_names.push(esp.to_string()); + } + + let esm = Path::new(&file_name).with_extension("esm"); + if let Some(esm) = esm.to_str() { + plugin_names.push(esm.to_string()); + } + } + + Ok(plugin_names) +} + fn implicitly_active_plugins(game_id: GameId, game_path: &Path) -> Result, Error> { let mut plugin_names: Vec = hardcoded_plugins(game_id) .iter() @@ -367,6 +405,15 @@ fn implicitly_active_plugins(game_id: GameId, game_path: &Path) -> Result Result