2015-03-17 21:59:39 +01:00
|
|
|
#include "bsaarchive.hpp"
|
2021-10-11 08:09:48 +00:00
|
|
|
|
2019-01-17 09:56:11 +01:00
|
|
|
#include <memory>
|
2021-10-14 12:46:44 +00:00
|
|
|
#include <algorithm>
|
2015-03-17 21:59:39 +01:00
|
|
|
|
|
|
|
namespace VFS
|
|
|
|
{
|
|
|
|
|
|
|
|
BsaArchive::BsaArchive(const std::string &filename)
|
|
|
|
{
|
2021-10-11 08:09:48 +00:00
|
|
|
mFile = std::make_unique<Bsa::BSAFile>(Bsa::BSAFile());
|
2019-01-16 20:19:15 +01:00
|
|
|
mFile->open(filename);
|
|
|
|
|
|
|
|
const Bsa::BSAFile::FileList &filelist = mFile->getList();
|
2015-03-17 21:59:39 +01:00
|
|
|
for(Bsa::BSAFile::FileList::const_iterator it = filelist.begin();it != filelist.end();++it)
|
|
|
|
{
|
2020-10-17 12:26:35 +04:00
|
|
|
mResources.emplace_back(&*it, mFile.get());
|
2015-03-17 21:59:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 08:09:48 +00:00
|
|
|
BsaArchive::BsaArchive()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:19:15 +01:00
|
|
|
BsaArchive::~BsaArchive() {
|
|
|
|
}
|
|
|
|
|
2015-03-17 21:59:39 +01:00
|
|
|
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)
|
|
|
|
{
|
2021-04-07 18:58:46 +02:00
|
|
|
std::string ent = it->mInfo->name();
|
2015-03-17 21:59:39 +01:00
|
|
|
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
|
|
|
|
|
|
|
|
out[ent] = &*it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string BsaArchive::getDescription() const
|
|
|
|
{
|
|
|
|
return std::string{"BSA: "} + mFile->getFilename();
|
|
|
|
}
|
|
|
|
|
2021-10-11 08:09:48 +00:00
|
|
|
CompressedBsaArchive::CompressedBsaArchive(const std::string &filename)
|
|
|
|
: BsaArchive()
|
|
|
|
{
|
|
|
|
mFile = std::make_unique<Bsa::BSAFile>(Bsa::CompressedBSAFile());
|
|
|
|
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());
|
|
|
|
mCompressedResources.emplace_back(&*it, static_cast<Bsa::CompressedBSAFile*>(mFile.get()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
std::string ent = it->mInfo->name();
|
|
|
|
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
|
|
|
|
|
|
|
|
out[ent] = &*it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 21:59:39 +01:00
|
|
|
// ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BsaArchiveFile::BsaArchiveFile(const Bsa::BSAFile::FileStruct *info, Bsa::BSAFile* bsa)
|
|
|
|
: mInfo(info)
|
|
|
|
, mFile(bsa)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Files::IStreamPtr BsaArchiveFile::open()
|
|
|
|
{
|
|
|
|
return mFile->getFile(mInfo);
|
|
|
|
}
|
|
|
|
|
2021-10-11 08:09:48 +00:00
|
|
|
CompressedBsaArchiveFile::CompressedBsaArchiveFile(const Bsa::BSAFile::FileStruct *info, Bsa::CompressedBSAFile* bsa)
|
|
|
|
: BsaArchiveFile(info, bsa)
|
|
|
|
, mCompressedFile(bsa)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Files::IStreamPtr CompressedBsaArchiveFile::open()
|
|
|
|
{
|
|
|
|
return mCompressedFile->getFile(mInfo);
|
|
|
|
}
|
|
|
|
|
2015-03-17 21:59:39 +01:00
|
|
|
}
|