2015-03-19 17:49:41 +01:00
|
|
|
#include "registerarchives.hpp"
|
|
|
|
|
2018-01-14 00:25:20 +00:00
|
|
|
#include <set>
|
2015-05-10 00:36:04 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
2018-08-14 19:42:41 +04:00
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
|
2015-03-19 17:49:41 +01:00
|
|
|
#include <components/vfs/manager.hpp>
|
|
|
|
#include <components/vfs/bsaarchive.hpp>
|
|
|
|
#include <components/vfs/filesystemarchive.hpp>
|
|
|
|
|
|
|
|
namespace VFS
|
|
|
|
{
|
|
|
|
|
|
|
|
void registerArchives(VFS::Manager *vfs, const Files::Collections &collections, const std::vector<std::string> &archives, bool useLooseFiles)
|
|
|
|
{
|
|
|
|
const Files::PathContainer& dataDirs = collections.getPaths();
|
|
|
|
|
|
|
|
for (std::vector<std::string>::const_iterator archive = archives.begin(); archive != archives.end(); ++archive)
|
|
|
|
{
|
|
|
|
if (collections.doesExist(*archive))
|
|
|
|
{
|
|
|
|
// Last BSA has the highest priority
|
|
|
|
const std::string archivePath = collections.getPath(*archive).string();
|
2018-08-14 19:42:41 +04:00
|
|
|
Log(Debug::Info) << "Adding BSA archive " << archivePath;
|
2015-03-19 17:49:41 +01:00
|
|
|
|
|
|
|
vfs->addArchive(new BsaArchive(archivePath));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::stringstream message;
|
|
|
|
message << "Archive '" << *archive << "' not found";
|
|
|
|
throw std::runtime_error(message.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-30 17:11:15 +02:00
|
|
|
if (useLooseFiles)
|
2018-01-14 00:25:20 +00:00
|
|
|
{
|
|
|
|
std::set<boost::filesystem::path> seen;
|
2015-03-30 17:11:15 +02:00
|
|
|
for (Files::PathContainer::const_iterator iter = dataDirs.begin(); iter != dataDirs.end(); ++iter)
|
|
|
|
{
|
2018-01-14 00:25:20 +00:00
|
|
|
if (seen.insert(*iter).second)
|
|
|
|
{
|
2018-08-14 19:42:41 +04:00
|
|
|
Log(Debug::Info) << "Adding data directory " << iter->string();
|
2018-01-14 00:25:20 +00:00
|
|
|
// Last data dir has the highest priority
|
|
|
|
vfs->addArchive(new FileSystemArchive(iter->string()));
|
|
|
|
}
|
|
|
|
else
|
2018-08-14 19:42:41 +04:00
|
|
|
Log(Debug::Info) << "Ignoring duplicate data directory " << iter->string();
|
2015-03-30 17:11:15 +02:00
|
|
|
}
|
2018-01-14 00:25:20 +00:00
|
|
|
}
|
2015-03-30 17:11:15 +02:00
|
|
|
|
2015-03-19 17:49:41 +01:00
|
|
|
vfs->buildIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|