1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-07 15:30:58 +00:00

Use normalized path in Lua vfs bindings

This commit is contained in:
elsid 2025-08-29 22:43:13 +02:00
parent 5b01ca99f8
commit 1348065be3
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
2 changed files with 16 additions and 17 deletions

View file

@ -200,16 +200,15 @@ namespace MWLua
};
api["lines"] = [vfs](sol::this_main_state lua, std::string_view fileName) {
auto normalizedName = VFS::Path::normalizeFilename(fileName);
return sol::as_function(
[lua, file = FileHandle(vfs->getNormalized(normalizedName), normalizedName)]() mutable {
validateFile(file);
auto result = readLineFromFile(lua, file);
if (result == sol::nil)
file.mFilePtr.reset();
const VFS::Path::Normalized normalizedName(fileName);
return sol::as_function([lua, file = FileHandle(vfs->get(normalizedName), normalizedName)]() mutable {
validateFile(file);
auto result = readLineFromFile(lua, file);
if (result == sol::nil)
file.mFilePtr.reset();
return result;
});
return result;
});
};
fileHandle["close"] = [](sol::this_state lua, FileHandle& self) {
@ -314,11 +313,11 @@ namespace MWLua
sol::variadic_results values;
try
{
auto normalizedName = VFS::Path::normalizeFilename(fileName);
auto handle = FileHandle(vfs->getNormalized(normalizedName), normalizedName);
const VFS::Path::Normalized normalizedName(fileName);
FileHandle handle(vfs->get(normalizedName), normalizedName);
values.push_back(sol::make_object<FileHandle>(lua, std::move(handle)));
}
catch (std::exception& e)
catch (const std::exception& e)
{
auto msg = "Can not open file: " + std::string(e.what());
values.push_back(sol::nil);

View file

@ -55,11 +55,6 @@ namespace VFS
Files::IStreamPtr get(Path::NormalizedView name) const;
/// Retrieve a file by name (name is already normalized).
/// @note Throws an exception if the file can not be found.
/// @note May be called from any thread once the index has been built.
Files::IStreamPtr getNormalized(std::string_view normalizedName) const;
std::string getArchive(const Path::Normalized& name) const;
/// Recursively iterate over the elements of the given path
@ -82,6 +77,11 @@ namespace VFS
FileMap mIndex;
inline Files::IStreamPtr findNormalized(std::string_view normalizedPath) const;
/// Retrieve a file by name (name is already normalized).
/// @note Throws an exception if the file can not be found.
/// @note May be called from any thread once the index has been built.
Files::IStreamPtr getNormalized(std::string_view normalizedName) const;
};
}