Add option to get file size of all opened archives

This commit is contained in:
Georg Hagen
2024-08-14 15:43:01 +02:00
parent a3a8409c73
commit c5dfbc41e0
3 changed files with 8 additions and 4 deletions

View File

@@ -101,7 +101,7 @@ namespace OpenVulkano
}
}
bool ArchiveReader::Open(const std::filesystem::path& dir, const std::string& fileNamePattern)
bool ArchiveReader::Open(const std::filesystem::path& dir, const std::string& fileNamePattern, size_t* outSize)
{
std::vector<std::string> files;
@@ -109,9 +109,13 @@ namespace OpenVulkano
for(const std::filesystem::directory_entry& dirEntry : std::filesystem::directory_iterator(dir))
{
std::string entryPath = dirEntry.path().string();
if (std::regex_match(entryPath, fileRegex))
if (!dirEntry.is_directory() && std::regex_match(entryPath, fileRegex))
{
files.push_back(std::move(entryPath));
if (outSize)
{
*outSize += dirEntry.file_size();
}
}
}

View File

@@ -42,7 +42,7 @@ namespace OpenVulkano
bool Open(const std::vector<std::string>& archiveFiles);
bool Open(const std::filesystem::path& dir, const std::string& fileNamePattern);
bool Open(const std::filesystem::path& dir, const std::string& fileNamePattern, size_t* outSize = nullptr);
[[nodiscard]] bool IsOpen() const { return m_open; }

View File

@@ -36,7 +36,7 @@ namespace OpenVulkano
ArchiveWriter::~ArchiveWriter()
{
if (m_asBuffer) { m_asBuffer->Close(); m_asBuffer = nullptr; }
archive_write_close(m_archive);
ChkErr(archive_write_close(m_archive));
archive_entry_free(m_archiveEntry);
}