From 1348065be36074b8b3dc2c13353b1b90dfe1e0ef Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 29 Aug 2025 22:43:13 +0200 Subject: [PATCH] Use normalized path in Lua vfs bindings --- apps/openmw/mwlua/vfsbindings.cpp | 23 +++++++++++------------ components/vfs/manager.hpp | 10 +++++----- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwlua/vfsbindings.cpp b/apps/openmw/mwlua/vfsbindings.cpp index 8a07d69e08..ccee5aa0d5 100644 --- a/apps/openmw/mwlua/vfsbindings.cpp +++ b/apps/openmw/mwlua/vfsbindings.cpp @@ -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(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); diff --git a/components/vfs/manager.hpp b/components/vfs/manager.hpp index 3d10b3f355..bbe03d25ca 100644 --- a/components/vfs/manager.hpp +++ b/components/vfs/manager.hpp @@ -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; }; }