#include "registerarchives.hpp" #include #include #include #include #include #include #include namespace VFS { void registerArchives(VFS::Manager* vfs, const Files::Collections& collections, const std::vector& archives, bool useLooseFiles) { const Files::PathContainer& dataDirs = collections.getPaths(); for (std::vector::const_iterator archive = archives.begin(); archive != archives.end(); ++archive) { if (collections.doesExist(*archive)) { // Last BSA has the highest priority const auto archivePath = collections.getPath(*archive); Log(Debug::Info) << "Adding BSA archive " << archivePath; Bsa::BsaVersion bsaVersion = Bsa::BSAFile::detectVersion(archivePath); if (bsaVersion == Bsa::BSAVER_COMPRESSED) vfs->addArchive(std::make_unique::type>(archivePath)); else if (bsaVersion == Bsa::BSAVER_BA2_GNRL) vfs->addArchive(std::make_unique::type>(archivePath)); else if (bsaVersion == Bsa::BSAVER_BA2_DX10) vfs->addArchive(std::make_unique::type>(archivePath)); else if (bsaVersion == Bsa::BSAVER_UNCOMPRESSED) vfs->addArchive(std::make_unique::type>(archivePath)); else throw std::runtime_error("Unknown archive type '" + *archive + "'"); } else { throw std::runtime_error("Archive '" + *archive + "' not found"); } } if (useLooseFiles) { std::set seen; for (const auto& dataDir : dataDirs) { if (seen.insert(dataDir).second) { Log(Debug::Info) << "Adding data directory " << dataDir; // Last data dir has the highest priority vfs->addArchive(std::make_unique(dataDir)); } else Log(Debug::Info) << "Ignoring duplicate data directory " << dataDir; } } vfs->buildIndex(); } }