Add method to manually split archive and delete last split if empty

This commit is contained in:
2021-05-18 20:14:15 +02:00
parent 4eeafafe34
commit 5b4e12b8f5
2 changed files with 14 additions and 1 deletions

View File

@@ -25,7 +25,12 @@ namespace openVulkanoCpp
StartNewFile();
}
MultiPartArchiveWriter::~MultiPartArchiveWriter() = default;
MultiPartArchiveWriter::~MultiPartArchiveWriter()
{
bool deleteLast = m_writer->GetTotalWrittenBytes() == 0;
m_writer = nullptr;
if (deleteLast) std::filesystem::remove(m_archives.back());
}
void MultiPartArchiveWriter::StartNewFile()
{
@@ -96,4 +101,10 @@ namespace openVulkanoCpp
m_dir = newDir;
StartNewFile();
}
void MultiPartArchiveWriter::Split()
{
if (!m_writer->GetTotalWrittenBytes()) return; // Nothing has been written yet, no need to split file
StartNewFile();
}
}

View File

@@ -45,5 +45,7 @@ namespace openVulkanoCpp
void Move(const std::filesystem::path& newDir);
[[nodiscard]] const std::filesystem::path& GetDir() const { return m_dir; }
void Split();
};
}