1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-29 09:32:45 +00:00
OpenMW/components/vfs/bsaarchive.cpp

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

121 lines
3.6 KiB
C++
Raw Normal View History

#include "bsaarchive.hpp"
#include <algorithm>
#include <memory>
namespace VFS
{
BsaArchive::BsaArchive(const std::filesystem::path& filename)
{
mFile = std::make_unique<Bsa::BSAFile>();
mFile->open(filename);
2022-09-22 21:26:05 +03:00
const Bsa::BSAFile::FileList& filelist = mFile->getList();
for (Bsa::BSAFile::FileList::const_iterator it = filelist.begin(); it != filelist.end(); ++it)
2022-09-22 21:26:05 +03:00
{
2020-10-17 12:26:35 +04:00
mResources.emplace_back(&*it, mFile.get());
2022-09-22 21:26:05 +03:00
}
}
BsaArchive::BsaArchive() {}
BsaArchive::~BsaArchive() {}
void BsaArchive::listResources(std::map<std::string, File*>& out, char (*normalize_function)(char))
{
for (std::vector<BsaArchiveFile>::iterator it = mResources.begin(); it != mResources.end(); ++it)
2022-09-22 21:26:05 +03:00
{
2021-04-07 18:58:46 +02:00
std::string ent = it->mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
out[ent] = &*it;
2022-09-22 21:26:05 +03:00
}
}
2020-12-29 21:45:59 +01:00
bool BsaArchive::contains(const std::string& file, char (*normalize_function)(char)) const
{
for (const auto& it : mResources)
2022-09-22 21:26:05 +03:00
{
2021-04-07 18:58:46 +02:00
std::string ent = it.mInfo->name();
2020-12-29 21:45:59 +01:00
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
if (file == ent)
return true;
2022-09-22 21:26:05 +03:00
}
2020-12-29 21:45:59 +01:00
return false;
}
std::string BsaArchive::getDescription() const
{
return std::string{ "BSA: " } + mFile->getFilename();
}
// ------------------------------------------------------------------------------
BsaArchiveFile::BsaArchiveFile(const Bsa::BSAFile::FileStruct* info, Bsa::BSAFile* bsa)
: mInfo(info)
, mFile(bsa)
{
}
Files::IStreamPtr BsaArchiveFile::open()
{
return mFile->getFile(mInfo);
}
CompressedBsaArchive::CompressedBsaArchive(const std::filesystem::path& filename)
: Archive()
{
mCompressedFile = std::make_unique<Bsa::CompressedBSAFile>();
mCompressedFile->open(filename);
2022-09-22 21:26:05 +03:00
const Bsa::BSAFile::FileList& filelist = mCompressedFile->getList();
for (Bsa::BSAFile::FileList::const_iterator it = filelist.begin(); it != filelist.end(); ++it)
2022-09-22 21:26:05 +03:00
{
mCompressedResources.emplace_back(&*it, mCompressedFile.get());
2022-09-22 21:26:05 +03:00
}
}
void CompressedBsaArchive::listResources(std::map<std::string, File*>& out, char (*normalize_function)(char))
{
for (std::vector<CompressedBsaArchiveFile>::iterator it = mCompressedResources.begin();
it != mCompressedResources.end(); ++it)
2022-09-22 21:26:05 +03:00
{
std::string ent = it->mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
2022-09-22 21:26:05 +03:00
out[ent] = &*it;
}
2022-09-22 21:26:05 +03:00
}
bool CompressedBsaArchive::contains(const std::string& file, char (*normalize_function)(char)) const
2022-09-22 21:26:05 +03:00
{
for (const auto& it : mCompressedResources)
2022-09-22 21:26:05 +03:00
{
std::string ent = it.mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
if (file == ent)
2022-09-22 21:26:05 +03:00
return true;
}
return false;
2022-09-22 21:26:05 +03:00
}
std::string CompressedBsaArchive::getDescription() const
2022-09-22 21:26:05 +03:00
{
return std::string{ "BSA: " } + mCompressedFile->getFilename();
2022-09-22 21:26:05 +03:00
}
CompressedBsaArchiveFile::CompressedBsaArchiveFile(
const Bsa::BSAFile::FileStruct* info, Bsa::CompressedBSAFile* bsa)
: mInfo(info)
, mCompressedFile(bsa)
2022-09-22 21:26:05 +03:00
{
}
Files::IStreamPtr CompressedBsaArchiveFile::open()
{
return mCompressedFile->getFile(mInfo);
}
}