1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00
openmw/components/vfs/bsaarchive.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
2.7 KiB
C++
Raw Normal View History

2015-09-24 13:21:42 +00:00
#ifndef VFS_BSAARCHIVE_HPP_
#define VFS_BSAARCHIVE_HPP_
#include "archive.hpp"
#include "file.hpp"
2023-05-31 21:11:03 +00:00
#include "pathutil.hpp"
#include <components/bsa/ba2dx10file.hpp>
#include <components/bsa/ba2gnrlfile.hpp>
#include <components/bsa/bsa_file.hpp>
#include <components/bsa/compressedbsafile.hpp>
#include <algorithm>
namespace VFS
{
template <typename FileType>
class BsaArchiveFile : public File
{
public:
BsaArchiveFile(const Bsa::BSAFile::FileStruct* info, FileType* bsa)
: mInfo(info)
, mFile(bsa)
{
}
Files::IStreamPtr open() override { return mFile->getFile(mInfo); }
std::filesystem::path getPath() override { return mInfo->name(); }
2022-05-14 01:58:00 +00:00
const Bsa::BSAFile::FileStruct* mInfo;
FileType* mFile;
};
template <typename BSAFileType>
class BsaArchive : public Archive
{
public:
BsaArchive(const std::filesystem::path& filename)
: Archive()
{
mFile = std::make_unique<BSAFileType>();
mFile->open(filename);
const Bsa::BSAFile::FileList& filelist = mFile->getList();
for (Bsa::BSAFile::FileList::const_iterator it = filelist.begin(); it != filelist.end(); ++it)
{
mResources.emplace_back(&*it, mFile.get());
mFiles.emplace_back(it->name());
}
std::sort(mFiles.begin(), mFiles.end());
}
virtual ~BsaArchive() {}
2023-12-17 14:20:48 +00:00
void listResources(FileMap& out) override
{
for (auto& resource : mResources)
out[VFS::Path::Normalized(resource.mInfo->name())] = &resource;
}
bool contains(Path::NormalizedView file) const override
{
return std::binary_search(mFiles.begin(), mFiles.end(), file);
}
std::string getDescription() const override { return std::string{ "BSA: " } + mFile->getFilename(); }
private:
std::unique_ptr<BSAFileType> mFile;
std::vector<BsaArchiveFile<BSAFileType>> mResources;
std::vector<VFS::Path::Normalized> mFiles;
};
2022-05-14 01:58:00 +00:00
template <Bsa::BsaVersion>
struct ArchiveSelector
{
};
template <>
struct ArchiveSelector<Bsa::BSAVER_UNCOMPRESSED>
{
using type = BsaArchive<Bsa::BSAFile>;
};
template <>
struct ArchiveSelector<Bsa::BSAVER_COMPRESSED>
{
using type = BsaArchive<Bsa::CompressedBSAFile>;
};
template <>
struct ArchiveSelector<Bsa::BSAVER_BA2_GNRL>
{
using type = BsaArchive<Bsa::BA2GNRLFile>;
};
template <>
struct ArchiveSelector<Bsa::BSAVER_BA2_DX10>
{
using type = BsaArchive<Bsa::BA2DX10File>;
};
}
2015-09-24 13:21:42 +00:00
2016-02-16 18:17:04 +00:00
#endif