Re-index BSAs

pull/280/head
Kyle Cooley 7 years ago
parent d7744e8b16
commit 7914fd5c9c

@ -21,8 +21,8 @@ namespace VFS
public: public:
virtual ~Archive() {} virtual ~Archive() {}
/// Clears cached data for archives that may change. /// Clears cached data.
virtual void resetIfNotStatic(){}; virtual void reset() = 0;
/// List all resources contained in this archive, and run the resource names through the given normalize function. /// List all resources contained in this archive, and run the resource names through the given normalize function.
virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char)) = 0; virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char)) = 0;

@ -5,14 +5,15 @@ namespace VFS
BsaArchive::BsaArchive(const std::string &filename) BsaArchive::BsaArchive(const std::string &filename)
: mFileName(filename)
{ {
mFile.open(filename); load();
}
const Bsa::BSAFile::FileList &filelist = mFile.getList(); void BsaArchive::reset()
for(Bsa::BSAFile::FileList::const_iterator it = filelist.begin();it != filelist.end();++it)
{ {
mResources.push_back(BsaArchiveFile(&*it, &mFile)); mResources.clear();
} load();
} }
void BsaArchive::listResources(std::map<std::string, File *> &out, char (*normalize_function)(char)) void BsaArchive::listResources(std::map<std::string, File *> &out, char (*normalize_function)(char))
@ -26,6 +27,17 @@ void BsaArchive::listResources(std::map<std::string, File *> &out, char (*normal
} }
} }
void BsaArchive::load()
{
mFile.open(mFileName);
const Bsa::BSAFile::FileList &filelist = mFile.getList();
for(Bsa::BSAFile::FileList::const_iterator it = filelist.begin();it != filelist.end();++it)
{
mResources.push_back(BsaArchiveFile(&*it, &mFile));
}
}
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
BsaArchiveFile::BsaArchiveFile(const Bsa::BSAFile::FileStruct *info, Bsa::BSAFile* bsa) BsaArchiveFile::BsaArchiveFile(const Bsa::BSAFile::FileStruct *info, Bsa::BSAFile* bsa)

@ -24,9 +24,14 @@ namespace VFS
public: public:
BsaArchive(const std::string& filename); BsaArchive(const std::string& filename);
virtual void reset();
virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char)); virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char));
private: private:
void load();
std::string mFileName;
Bsa::BSAFile mFile; Bsa::BSAFile mFile;
std::vector<BsaArchiveFile> mResources; std::vector<BsaArchiveFile> mResources;

@ -12,7 +12,7 @@ namespace VFS
} }
void FileSystemArchive::resetIfNotStatic() void FileSystemArchive::reset()
{ {
mIndex.clear(); mIndex.clear();
mBuiltIndex = false; mBuiltIndex = false;

@ -23,7 +23,7 @@ namespace VFS
public: public:
FileSystemArchive(const std::string& path); FileSystemArchive(const std::string& path);
virtual void resetIfNotStatic(); virtual void reset();
virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char)); virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char));

@ -60,7 +60,7 @@ namespace VFS
void Manager::rebuildIndex() void Manager::rebuildIndex()
{ {
for (std::vector<Archive*>::const_iterator it = mArchives.begin(); it != mArchives.end(); ++it) for (std::vector<Archive*>::const_iterator it = mArchives.begin(); it != mArchives.end(); ++it)
(*it)->resetIfNotStatic(); (*it)->reset();
buildIndex(); buildIndex();
} }

Loading…
Cancel
Save