diff --git a/src/archive/find.rs b/src/archive/find.rs index ec535751..7896224e 100644 --- a/src/archive/find.rs +++ b/src/archive/find.rs @@ -29,9 +29,9 @@ pub fn find_associated_archives( // basename. GameType::TES4 => { if has_ascii_extension(plugin_path, "esp") { - Vec::new() - } else { find_associated_archives_with_arbitrary_suffixes(plugin_path, game_cache) + } else { + Vec::new() } }, @@ -92,6 +92,10 @@ fn find_associated_archives_with_arbitrary_suffixes( Some(s) => s.len(), None => return Vec::new(), }; + let plugin_extension = match plugin_path.extension() { + Some(e) => e, + None => return Vec::new(), + }; game_cache .archives() @@ -106,13 +110,19 @@ fn find_associated_archives_with_arbitrary_suffixes( }; // Can't just slice the archive filename to the same length as the plugin file stem directly because that might not slice on a character boundary, so truncate the byte slice and then check it's still valid UTF-8. + if archive_filename.len() < plugin_stem_len { + return false; + } + let filename = match std::str::from_utf8(&archive_filename.as_bytes()[..plugin_stem_len]) { Ok(f) => f, Err(_) => return false, }; - let archive_plugin_path = plugin_path.with_file_name(filename); + let archive_plugin_path = plugin_path + .with_file_name(filename) + .with_extension(plugin_extension); are_file_paths_equivalent(&archive_plugin_path, plugin_path) }) diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 5778d341..c77ac90c 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -85,7 +85,7 @@ impl Plugin { plugin_path: &Path, load_scope: LoadScope, ) -> Result { - let name = name_string(plugin_path)?; + let name = name_string(game_type, plugin_path)?; let (parse_options, crc) = if load_scope == LoadScope::HeaderOnly { (ParseOptions::header_only(), None) @@ -410,9 +410,10 @@ pub(crate) fn plugins_metadata( Ok(esplugin::plugins_metadata(&esplugins)?) } -fn name_string(path: &Path) -> Result { +fn name_string(game_type: GameType, path: &Path) -> Result { match path.file_name() { Some(f) => match f.to_str() { + Some(f) if game_type == GameType::OpenMW => Ok(f.to_string()), Some(f) => Ok(trim_dot_ghost(f).to_string()), None => Err(LoadPluginError::InvalidFilename( InvalidFilenameReason::NonUnicode,