mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-10 02:41:32 +00:00
Use normalized path for file archives indices
This commit is contained in:
parent
062d3e9c00
commit
a6657c18cc
5 changed files with 15 additions and 24 deletions
|
@ -51,25 +51,21 @@ namespace TestingOpenMW
|
||||||
|
|
||||||
struct VFSTestData : public VFS::Archive
|
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))
|
: mFiles(std::move(files))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void listResources(VFS::FileMap& out) override
|
void listResources(VFS::FileMap& out) override { out = mFiles; }
|
||||||
{
|
|
||||||
for (const auto& [key, value] : mFiles)
|
|
||||||
out.emplace(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
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"; }
|
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>();
|
auto vfs = std::make_unique<VFS::Manager>();
|
||||||
vfs->addArchive(std::make_unique<VFSTestData>(std::move(files)));
|
vfs->addArchive(std::make_unique<VFSTestData>(std::move(files)));
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
#define OPENMW_COMPONENTS_VFS_ARCHIVE_H
|
#define OPENMW_COMPONENTS_VFS_ARCHIVE_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
|
||||||
|
|
||||||
#include "filemap.hpp"
|
#include "filemap.hpp"
|
||||||
|
#include "pathutil.hpp"
|
||||||
|
|
||||||
namespace VFS
|
namespace VFS
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ namespace VFS
|
||||||
virtual void listResources(FileMap& out) = 0;
|
virtual void listResources(FileMap& out) = 0;
|
||||||
|
|
||||||
/// True if this archive contains the provided normalized file.
|
/// 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;
|
virtual std::string getDescription() const = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,19 +52,14 @@ namespace VFS
|
||||||
void listResources(FileMap& out) override
|
void listResources(FileMap& out) override
|
||||||
{
|
{
|
||||||
for (auto& resource : mResources)
|
for (auto& resource : mResources)
|
||||||
{
|
out[VFS::Path::Normalized(resource.mInfo->name())] = &resource;
|
||||||
std::string ent = resource.mInfo->name();
|
|
||||||
Path::normalizeFilenameInPlace(ent);
|
|
||||||
|
|
||||||
out[ent] = &resource;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool contains(std::string_view file) const override
|
bool contains(Path::NormalizedView file) const override
|
||||||
{
|
{
|
||||||
for (const auto& it : mResources)
|
for (const auto& it : mResources)
|
||||||
{
|
{
|
||||||
if (Path::pathEqual(file, it.mInfo->name()))
|
if (Path::pathEqual(file.value(), it.mInfo->name()))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -37,9 +37,9 @@ namespace VFS
|
||||||
|
|
||||||
FileSystemArchiveFile file(path);
|
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)
|
if (!inserted.second)
|
||||||
Log(Debug::Warning)
|
Log(Debug::Warning)
|
||||||
<< "Warning: found duplicate file for '" << proper
|
<< "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();
|
return mIndex.find(file) != mIndex.end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,12 @@ namespace VFS
|
||||||
|
|
||||||
void listResources(FileMap& out) override;
|
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;
|
std::string getDescription() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, FileSystemArchiveFile, std::less<>> mIndex;
|
std::map<VFS::Path::Normalized, FileSystemArchiveFile, std::less<>> mIndex;
|
||||||
bool mBuiltIndex;
|
bool mBuiltIndex;
|
||||||
std::filesystem::path mPath;
|
std::filesystem::path mPath;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue