Use normalized path for file archives indices

pull/3234/head
elsid 12 months ago
parent 062d3e9c00
commit a6657c18cc
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -51,25 +51,21 @@ namespace TestingOpenMW
struct VFSTestData : public VFS::Archive
{
std::map<std::string, VFS::File*, VFS::Path::PathLess> mFiles;
VFS::FileMap mFiles;
VFSTestData(std::map<std::string, VFS::File*, VFS::Path::PathLess> files)
explicit VFSTestData(VFS::FileMap&& files)
: mFiles(std::move(files))
{
}
void listResources(VFS::FileMap& out) override
{
for (const auto& [key, value] : mFiles)
out.emplace(key, value);
}
void listResources(VFS::FileMap& out) override { out = mFiles; }
bool contains(std::string_view file) const override { return mFiles.contains(file); }
bool contains(VFS::Path::NormalizedView file) const override { return mFiles.contains(file); }
std::string getDescription() const override { return "TestData"; }
};
inline std::unique_ptr<VFS::Manager> createTestVFS(std::map<std::string, VFS::File*, VFS::Path::PathLess> files)
inline std::unique_ptr<VFS::Manager> createTestVFS(VFS::FileMap&& files)
{
auto vfs = std::make_unique<VFS::Manager>();
vfs->addArchive(std::make_unique<VFSTestData>(std::move(files)));

@ -2,9 +2,9 @@
#define OPENMW_COMPONENTS_VFS_ARCHIVE_H
#include <string>
#include <string_view>
#include "filemap.hpp"
#include "pathutil.hpp"
namespace VFS
{
@ -17,7 +17,7 @@ namespace VFS
virtual void listResources(FileMap& out) = 0;
/// True if this archive contains the provided normalized file.
virtual bool contains(std::string_view file) const = 0;
virtual bool contains(Path::NormalizedView file) const = 0;
virtual std::string getDescription() const = 0;
};

@ -52,19 +52,14 @@ namespace VFS
void listResources(FileMap& out) override
{
for (auto& resource : mResources)
{
std::string ent = resource.mInfo->name();
Path::normalizeFilenameInPlace(ent);
out[ent] = &resource;
}
out[VFS::Path::Normalized(resource.mInfo->name())] = &resource;
}
bool contains(std::string_view file) const override
bool contains(Path::NormalizedView file) const override
{
for (const auto& it : mResources)
{
if (Path::pathEqual(file, it.mInfo->name()))
if (Path::pathEqual(file.value(), it.mInfo->name()))
return true;
}
return false;

@ -37,9 +37,9 @@ namespace VFS
FileSystemArchiveFile file(path);
std::string searchable = Path::normalizeFilename(std::string_view{ proper }.substr(prefix));
VFS::Path::Normalized searchable(std::string_view{ proper }.substr(prefix));
const auto inserted = mIndex.emplace(searchable, file);
const auto inserted = mIndex.emplace(std::move(searchable), std::move(file));
if (!inserted.second)
Log(Debug::Warning)
<< "Warning: found duplicate file for '" << proper
@ -56,7 +56,7 @@ namespace VFS
}
}
bool FileSystemArchive::contains(std::string_view file) const
bool FileSystemArchive::contains(Path::NormalizedView file) const
{
return mIndex.find(file) != mIndex.end();
}

@ -30,12 +30,12 @@ namespace VFS
void listResources(FileMap& out) override;
bool contains(std::string_view file) const override;
bool contains(Path::NormalizedView file) const override;
std::string getDescription() const override;
private:
std::map<std::string, FileSystemArchiveFile, std::less<>> mIndex;
std::map<VFS::Path::Normalized, FileSystemArchiveFile, std::less<>> mIndex;
bool mBuiltIndex;
std::filesystem::path mPath;
};

Loading…
Cancel
Save