diff --git a/components/esm4/reader.cpp b/components/esm4/reader.cpp index 93de160e5e..e041626c41 100644 --- a/components/esm4/reader.cpp +++ b/components/esm4/reader.cpp @@ -57,16 +57,16 @@ namespace ESM4 return header + ": code " + std::to_string(errorCode) + ", " + std::string(msg != nullptr ? msg : "(null)"); } - std::u8string_view getStringsSuffix(LocalizedStringType type) + std::string_view getStringsSuffix(LocalizedStringType type) { switch (type) { case LocalizedStringType::Strings: - return u8".STRINGS"; + return ".STRINGS"; case LocalizedStringType::ILStrings: - return u8".ILSTRINGS"; + return ".ILSTRINGS"; case LocalizedStringType::DLStrings: - return u8".DLSTRINGS"; + return ".DLSTRINGS"; } throw std::logic_error("Unsupported LocalizedStringType: " + std::to_string(static_cast(type))); @@ -304,29 +304,35 @@ namespace ESM4 if ((mHeader.mFlags & Rec_ESM) == 0 || (mHeader.mFlags & Rec_Localized) == 0) return; - const std::u8string prefix = mCtx.filename.stem().filename().u8string(); + const std::string prefix = Files::pathToUnicodeString(mCtx.filename.stem().filename()); buildLStringIndex(LocalizedStringType::Strings, prefix); buildLStringIndex(LocalizedStringType::ILStrings, prefix); buildLStringIndex(LocalizedStringType::DLStrings, prefix); } - void Reader::buildLStringIndex(LocalizedStringType stringType, const std::u8string& prefix) + void Reader::buildLStringIndex(LocalizedStringType stringType, std::string_view prefix) { - static const std::filesystem::path strings("Strings"); - const std::u8string language(u8"_En"); - const std::u8string altLanguage(u8"_English"); - const std::u8string suffix(getStringsSuffix(stringType)); - std::filesystem::path path = strings / (prefix + language + suffix); + const std::string_view suffix = getStringsSuffix(stringType); + constexpr std::string_view language("_En"); + constexpr std::string_view altLanguage("_English"); if (mVFS != nullptr) { - VFS::Path::Normalized vfsPath(Files::pathToUnicodeString(path)); + constexpr VFS::Path::NormalizedView strings("strings"); + std::string fileName(prefix); + fileName += language; + fileName += suffix; + VFS::Path::Normalized vfsPath(strings); + vfsPath /= fileName; Files::IStreamPtr stream = mVFS->find(vfsPath); if (stream == nullptr) { - path = strings / (prefix + altLanguage + suffix); - vfsPath = VFS::Path::Normalized(Files::pathToUnicodeString(path)); + fileName = prefix; + fileName += altLanguage; + fileName += suffix; + vfsPath = strings; + vfsPath /= fileName; stream = mVFS->find(vfsPath); } @@ -337,28 +343,33 @@ namespace ESM4 } if (mIgnoreMissingLocalizedStrings) - { Log(Debug::Warning) << "Ignore missing VFS strings file: " << vfsPath; + } + else + { + static const std::filesystem::path strings("Strings"); + std::string fileName(prefix); + fileName += language; + fileName += suffix; + std::filesystem::path fsPath = mCtx.filename.parent_path() / strings / fileName; + if (!std::filesystem::exists(fsPath)) + { + fileName = prefix; + fileName += altLanguage; + fileName += suffix; + fsPath = mCtx.filename.parent_path() / strings / fileName; + } + + if (std::filesystem::exists(fsPath)) + { + const Files::IStreamPtr stream = Files::openConstrainedFileStream(fsPath); + buildLStringIndex(stringType, *stream); return; } - } - std::filesystem::path fsPath = mCtx.filename.parent_path() / path; - if (!std::filesystem::exists(fsPath)) - { - path = strings / (prefix + altLanguage + suffix); - fsPath = mCtx.filename.parent_path() / path; + if (mIgnoreMissingLocalizedStrings) + Log(Debug::Warning) << "Ignore missing strings file: " << fsPath; } - - if (std::filesystem::exists(fsPath)) - { - const Files::IStreamPtr stream = Files::openConstrainedFileStream(fsPath); - buildLStringIndex(stringType, *stream); - return; - } - - if (mIgnoreMissingLocalizedStrings) - Log(Debug::Warning) << "Ignore missing strings file: " << fsPath; } void Reader::buildLStringIndex(LocalizedStringType stringType, std::istream& stream) diff --git a/components/esm4/reader.hpp b/components/esm4/reader.hpp index e8be484355..0f026e09b3 100644 --- a/components/esm4/reader.hpp +++ b/components/esm4/reader.hpp @@ -167,7 +167,7 @@ namespace ESM4 bool mIgnoreMissingLocalizedStrings = false; - void buildLStringIndex(LocalizedStringType stringType, const std::u8string& prefix); + void buildLStringIndex(LocalizedStringType stringType, std::string_view prefix); void buildLStringIndex(LocalizedStringType stringType, std::istream& stream);