Merge branch 'vfs_normalized_path_23' into 'master'

Use normalized path in Lua vfs bindings (#8138)

See merge request OpenMW/openmw!4903
This commit is contained in:
Alexei Kotov 2025-09-01 15:06:27 +03:00
commit ea3240ce03
2 changed files with 16 additions and 17 deletions

View File

@ -200,9 +200,8 @@ namespace MWLua
}; };
api["lines"] = [vfs](sol::this_main_state lua, std::string_view fileName) { api["lines"] = [vfs](sol::this_main_state lua, std::string_view fileName) {
auto normalizedName = VFS::Path::normalizeFilename(fileName); const VFS::Path::Normalized normalizedName(fileName);
return sol::as_function( return sol::as_function([lua, file = FileHandle(vfs->get(normalizedName), normalizedName)]() mutable {
[lua, file = FileHandle(vfs->getNormalized(normalizedName), normalizedName)]() mutable {
validateFile(file); validateFile(file);
auto result = readLineFromFile(lua, file); auto result = readLineFromFile(lua, file);
if (result == sol::nil) if (result == sol::nil)
@ -314,11 +313,11 @@ namespace MWLua
sol::variadic_results values; sol::variadic_results values;
try try
{ {
auto normalizedName = VFS::Path::normalizeFilename(fileName); const VFS::Path::Normalized normalizedName(fileName);
auto handle = FileHandle(vfs->getNormalized(normalizedName), normalizedName); FileHandle handle(vfs->get(normalizedName), normalizedName);
values.push_back(sol::make_object<FileHandle>(lua, std::move(handle))); 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()); auto msg = "Can not open file: " + std::string(e.what());
values.push_back(sol::nil); values.push_back(sol::nil);

View File

@ -55,11 +55,6 @@ namespace VFS
Files::IStreamPtr get(Path::NormalizedView name) const; 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; std::string getArchive(const Path::Normalized& name) const;
/// Recursively iterate over the elements of the given path /// Recursively iterate over the elements of the given path
@ -82,6 +77,11 @@ namespace VFS
FileMap mIndex; FileMap mIndex;
inline Files::IStreamPtr findNormalized(std::string_view normalizedPath) const; 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;
}; };
} }