mirror of https://github.com/OpenMW/openmw
Don't use filesystem::path while looking for vfs files
This commit is contained in:
parent
a6097d06b6
commit
6e8b6ef48e
|
|
@ -57,16 +57,16 @@ namespace ESM4
|
||||||
return header + ": code " + std::to_string(errorCode) + ", " + std::string(msg != nullptr ? msg : "(null)");
|
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)
|
switch (type)
|
||||||
{
|
{
|
||||||
case LocalizedStringType::Strings:
|
case LocalizedStringType::Strings:
|
||||||
return u8".STRINGS";
|
return ".STRINGS";
|
||||||
case LocalizedStringType::ILStrings:
|
case LocalizedStringType::ILStrings:
|
||||||
return u8".ILSTRINGS";
|
return ".ILSTRINGS";
|
||||||
case LocalizedStringType::DLStrings:
|
case LocalizedStringType::DLStrings:
|
||||||
return u8".DLSTRINGS";
|
return ".DLSTRINGS";
|
||||||
}
|
}
|
||||||
|
|
||||||
throw std::logic_error("Unsupported LocalizedStringType: " + std::to_string(static_cast<int>(type)));
|
throw std::logic_error("Unsupported LocalizedStringType: " + std::to_string(static_cast<int>(type)));
|
||||||
|
|
@ -304,29 +304,35 @@ namespace ESM4
|
||||||
if ((mHeader.mFlags & Rec_ESM) == 0 || (mHeader.mFlags & Rec_Localized) == 0)
|
if ((mHeader.mFlags & Rec_ESM) == 0 || (mHeader.mFlags & Rec_Localized) == 0)
|
||||||
return;
|
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::Strings, prefix);
|
||||||
buildLStringIndex(LocalizedStringType::ILStrings, prefix);
|
buildLStringIndex(LocalizedStringType::ILStrings, prefix);
|
||||||
buildLStringIndex(LocalizedStringType::DLStrings, 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::string_view suffix = getStringsSuffix(stringType);
|
||||||
const std::u8string language(u8"_En");
|
constexpr std::string_view language("_En");
|
||||||
const std::u8string altLanguage(u8"_English");
|
constexpr std::string_view altLanguage("_English");
|
||||||
const std::u8string suffix(getStringsSuffix(stringType));
|
|
||||||
std::filesystem::path path = strings / (prefix + language + suffix);
|
|
||||||
if (mVFS != nullptr)
|
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);
|
Files::IStreamPtr stream = mVFS->find(vfsPath);
|
||||||
|
|
||||||
if (stream == nullptr)
|
if (stream == nullptr)
|
||||||
{
|
{
|
||||||
path = strings / (prefix + altLanguage + suffix);
|
fileName = prefix;
|
||||||
vfsPath = VFS::Path::Normalized(Files::pathToUnicodeString(path));
|
fileName += altLanguage;
|
||||||
|
fileName += suffix;
|
||||||
|
vfsPath = strings;
|
||||||
|
vfsPath /= fileName;
|
||||||
stream = mVFS->find(vfsPath);
|
stream = mVFS->find(vfsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,28 +343,33 @@ namespace ESM4
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mIgnoreMissingLocalizedStrings)
|
if (mIgnoreMissingLocalizedStrings)
|
||||||
{
|
|
||||||
Log(Debug::Warning) << "Ignore missing VFS strings file: " << vfsPath;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::path fsPath = mCtx.filename.parent_path() / path;
|
if (mIgnoreMissingLocalizedStrings)
|
||||||
if (!std::filesystem::exists(fsPath))
|
Log(Debug::Warning) << "Ignore missing strings file: " << fsPath;
|
||||||
{
|
|
||||||
path = strings / (prefix + altLanguage + suffix);
|
|
||||||
fsPath = mCtx.filename.parent_path() / path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
void Reader::buildLStringIndex(LocalizedStringType stringType, std::istream& stream)
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ namespace ESM4
|
||||||
|
|
||||||
bool mIgnoreMissingLocalizedStrings = false;
|
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);
|
void buildLStringIndex(LocalizedStringType stringType, std::istream& stream);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue