diff --git a/include/ifilesystem.h b/include/ifilesystem.h index e43fdb6fe3..b15be1850c 100644 --- a/include/ifilesystem.h +++ b/include/ifilesystem.h @@ -104,6 +104,11 @@ class FileInfo return _infoProvider ? _infoProvider->getFileSize(fullPath()) : 0; } + std::size_t getIsPhysicalFile() const + { + return _infoProvider ? _infoProvider->getIsPhysical(fullPath()) : false; + } + /// Equality comparison with another FileInfo bool operator== (const FileInfo& rhs) const { diff --git a/test/VFS.cpp b/test/VFS.cpp index 578f453f7a..c66c4bfde4 100644 --- a/test/VFS.cpp +++ b/test/VFS.cpp @@ -2,6 +2,7 @@ #include "ifilesystem.h" #include "os/path.h" +#include "os/file.h" namespace test { @@ -29,10 +30,10 @@ TEST_F(VfsTest, FilePrerequisites) TEST_F(VfsTest, VisitEntireTree) { // Use a visitor to walk the tree - std::set foundFiles; + std::map foundFiles; GlobalFileSystem().forEachFile( "", "*", - [&](const vfs::FileInfo& fi) { foundFiles.insert(fi.name); }, + [&](const vfs::FileInfo& fi) { foundFiles.emplace(fi.name, fi); }, 0 ); EXPECT_EQ(foundFiles.count("dummy"), 0); @@ -40,6 +41,34 @@ TEST_F(VfsTest, VisitEntireTree) EXPECT_EQ(foundFiles.count("models/darkmod/test/unit_cube.ase"), 1); } +TEST_F(VfsTest, GetArchiveFileInfo) +{ + // Use a visitor to walk the tree + std::map foundFiles; + GlobalFileSystem().forEachFile( + "", "*", + [&](const vfs::FileInfo& fi) { foundFiles.emplace(fi.name, fi); }, + 0 + ); + + // Inspect a physical file that is in the test resources + std::string physicalFile = "materials/example.mtr"; + std::string fileInPak = "materials/tdm_bloom_afx.mtr"; // this is in tdm_example_mtrs.pk4 + + EXPECT_EQ(foundFiles.count(physicalFile), 1); // physical file + EXPECT_EQ(foundFiles.count(fileInPak), 1); // file in pk4 + + // Get the file size of example.mtr + fs::path physicalFilePath = _context.getTestResourcePath(); + physicalFilePath /= physicalFile; + + EXPECT_EQ(foundFiles.find(physicalFile)->second.getSize(), os::getFileSize(physicalFilePath.string())); + EXPECT_EQ(foundFiles.find(physicalFile)->second.getIsPhysicalFile(), true); + + EXPECT_EQ(foundFiles.find(fileInPak)->second.getSize(), 1096); // that file should have 1096 bytes + EXPECT_EQ(foundFiles.find(fileInPak)->second.getIsPhysicalFile(), false); +} + TEST_F(VfsTest, VisitMaterialsFolderOnly) { // Visit files only under materials/