mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-09-22 03:13:15 -04:00
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:
commit
ea3240ce03
@ -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);
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user