diff --git a/apps/niftest/niftest.cpp b/apps/niftest/niftest.cpp index 4a13e56e80..219956cd75 100644 --- a/apps/niftest/niftest.cpp +++ b/apps/niftest/niftest.cpp @@ -34,12 +34,11 @@ bool isBSA(const std::string & filename) } /// Check all the nif files in a given VFS::Archive -/// \note Takes ownership! /// \note Can not read a bsa file inside of a bsa file. -void readVFS(VFS::Archive* anArchive,std::string archivePath = "") +void readVFS(std::unique_ptr&& anArchive, std::string archivePath = "") { VFS::Manager myManager(true); - myManager.addArchive(anArchive); + myManager.addArchive(std::move(anArchive)); myManager.buildIndex(); for(const auto& name : myManager.getRecursiveDirectoryIterator("")) @@ -55,7 +54,7 @@ void readVFS(VFS::Archive* anArchive,std::string archivePath = "") if(!archivePath.empty() && !isBSA(archivePath)) { // std::cout << "Reading BSA File: " << name << std::endl; - readVFS(new VFS::BsaArchive(archivePath+name),archivePath+name+"/"); + readVFS(std::make_unique(archivePath + name), archivePath + name + "/"); // std::cout << "Done with BSA File: " << name << std::endl; } } @@ -135,12 +134,12 @@ int main(int argc, char **argv) else if(isBSA(name)) { // std::cout << "Reading BSA File: " << name << std::endl; - readVFS(new VFS::BsaArchive(name)); + readVFS(std::make_unique(name)); } else if(std::filesystem::is_directory(std::filesystem::path(name))) { // std::cout << "Reading All Files in: " << name << std::endl; - readVFS(new VFS::FileSystemArchive(name),name); + readVFS(std::make_unique(name), name); } else { diff --git a/apps/openmw_test_suite/testing_util.hpp b/apps/openmw_test_suite/testing_util.hpp index e583552a21..125d2505ed 100644 --- a/apps/openmw_test_suite/testing_util.hpp +++ b/apps/openmw_test_suite/testing_util.hpp @@ -64,7 +64,7 @@ namespace TestingOpenMW inline std::unique_ptr createTestVFS(std::map files) { auto vfs = std::make_unique(true); - vfs->addArchive(new VFSTestData(std::move(files))); + vfs->addArchive(std::make_unique(std::move(files))); vfs->buildIndex(); return vfs; } diff --git a/components/vfs/manager.cpp b/components/vfs/manager.cpp index 8a43eda5ee..bd7418d4b5 100644 --- a/components/vfs/manager.cpp +++ b/components/vfs/manager.cpp @@ -36,30 +36,25 @@ namespace VFS } - Manager::~Manager() - { - reset(); - } + Manager::~Manager() {} void Manager::reset() { mIndex.clear(); - for (std::vector::iterator it = mArchives.begin(); it != mArchives.end(); ++it) - delete *it; mArchives.clear(); } - void Manager::addArchive(Archive *archive) + void Manager::addArchive(std::unique_ptr&& archive) { - mArchives.push_back(archive); + mArchives.push_back(std::move(archive)); } void Manager::buildIndex() { mIndex.clear(); - for (std::vector::const_iterator it = mArchives.begin(); it != mArchives.end(); ++it) - (*it)->listResources(mIndex, mStrict ? &strict_normalize_char : &nonstrict_normalize_char); + for (const auto& archive : mArchives) + archive->listResources(mIndex, mStrict ? &strict_normalize_char : &nonstrict_normalize_char); } Files::IStreamPtr Manager::get(const std::string &name) const diff --git a/components/vfs/manager.hpp b/components/vfs/manager.hpp index 98acfb7955..bb1ee6ad39 100644 --- a/components/vfs/manager.hpp +++ b/components/vfs/manager.hpp @@ -5,6 +5,7 @@ #include #include +#include namespace VFS { @@ -58,8 +59,7 @@ namespace VFS void reset(); /// Register the given archive. All files contained in it will be added to the index on the next buildIndex() call. - /// @note Takes ownership of the given pointer. - void addArchive(Archive* archive); + void addArchive(std::unique_ptr&& archive); /// Build the file index. Should be called when all archives have been registered. void buildIndex(); @@ -98,7 +98,7 @@ namespace VFS private: bool mStrict; - std::vector mArchives; + std::vector> mArchives; std::map mIndex; }; diff --git a/components/vfs/registerarchives.cpp b/components/vfs/registerarchives.cpp index ebe2683edd..25ee9e1f62 100644 --- a/components/vfs/registerarchives.cpp +++ b/components/vfs/registerarchives.cpp @@ -27,9 +27,9 @@ namespace VFS Bsa::BsaVersion bsaVersion = Bsa::CompressedBSAFile::detectVersion(archivePath); if (bsaVersion == Bsa::BSAVER_COMPRESSED) - vfs->addArchive(new CompressedBsaArchive(archivePath)); + vfs->addArchive(std::make_unique(archivePath)); else - vfs->addArchive(new BsaArchive(archivePath)); + vfs->addArchive(std::make_unique(archivePath)); } else { @@ -47,7 +47,7 @@ namespace VFS { Log(Debug::Info) << "Adding data directory " << iter->string(); // Last data dir has the highest priority - vfs->addArchive(new FileSystemArchive(iter->string())); + vfs->addArchive(std::make_unique(iter->string())); } else Log(Debug::Info) << "Ignoring duplicate data directory " << iter->string();