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