1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include "bsaarchive.hpp"
#include <components/bsa/compressedbsafile.hpp>
#include <memory>
namespace VFS
{
BsaArchive::BsaArchive(const std::string &filename)
{
Bsa::BsaVersion bsaVersion = Bsa::CompressedBSAFile::detectVersion(filename);
if (bsaVersion == Bsa::BSAVER_COMPRESSED) {
mFile = std::make_unique<Bsa::CompressedBSAFile>(Bsa::CompressedBSAFile());
}
else {
mFile = std::make_unique<Bsa::BSAFile>(Bsa::BSAFile());
}
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());
}
}
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)
{
std::string ent = it->mInfo->name();
std::transform(ent.begin(), ent.end(), ent.begin(), normalize_function);
out[ent] = &*it;
}
}
bool BsaArchive::contains(const std::string& file, char (*normalize_function)(char)) const
{
for (const auto& it : mResources)
{
std::string ent = it.mInfo->name();
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();
}
// ------------------------------------------------------------------------------
BsaArchiveFile::BsaArchiveFile(const Bsa::BSAFile::FileStruct *info, Bsa::BSAFile* bsa)
: mInfo(info)
, mFile(bsa)
{
}
Files::IStreamPtr BsaArchiveFile::open()
{
return mFile->getFile(mInfo);
}
}
|