Add support for multipart archives
This commit is contained in:
@@ -6,9 +6,11 @@
|
||||
|
||||
#include "ArchiveReader.hpp"
|
||||
#include "LibArchiveHelper.hpp"
|
||||
#include "Base/Utils.hpp"
|
||||
#include <archive.h>
|
||||
#include <archive_entry.h>
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
|
||||
namespace openVulkanoCpp
|
||||
{
|
||||
@@ -39,13 +41,18 @@ namespace openVulkanoCpp
|
||||
|
||||
ArchiveReader::~ArchiveReader() = default;
|
||||
|
||||
bool ArchiveReader::Open(const char* archiveFile)
|
||||
void ArchiveReader::PrepOpen()
|
||||
{
|
||||
if (m_open) ChkErr(archive_read_close(m_archive));
|
||||
ChkErr(archive_read_support_filter_all(m_archive));
|
||||
ChkErr(archive_read_support_format_all(m_archive));
|
||||
ChkErr(archive_read_open_filename(m_archive, archiveFile, BUFFER_SIZE));
|
||||
m_open = true;
|
||||
}
|
||||
|
||||
bool ArchiveReader::Open(const char* archiveFile)
|
||||
{
|
||||
PrepOpen();
|
||||
ChkErr(archive_read_open_filename(m_archive, archiveFile, BUFFER_SIZE));
|
||||
ReadNextHeader();
|
||||
return HasNext();
|
||||
}
|
||||
@@ -57,15 +64,39 @@ namespace openVulkanoCpp
|
||||
|
||||
bool ArchiveReader::Open(const void* archiveBuffer, size_t size)
|
||||
{
|
||||
if (m_open) ChkErr(archive_read_close(m_archive));
|
||||
ChkErr(archive_read_support_filter_all(m_archive));
|
||||
ChkErr(archive_read_support_format_all(m_archive));
|
||||
PrepOpen();
|
||||
ChkErr(archive_read_open_memory(m_archive, archiveBuffer, size));
|
||||
m_open = true;
|
||||
ReadNextHeader();
|
||||
return HasNext();
|
||||
}
|
||||
|
||||
bool ArchiveReader::Open(const std::vector<std::string>& archiveFiles)
|
||||
{
|
||||
auto files = Utils::toCString(archiveFiles);
|
||||
files.push_back(nullptr);
|
||||
PrepOpen();
|
||||
ChkErr(archive_read_open_filenames(m_archive, files.data(), BUFFER_SIZE));
|
||||
ReadNextHeader();
|
||||
return HasNext();
|
||||
}
|
||||
|
||||
bool ArchiveReader::Open(const std::filesystem::path& dir, const std::string& fileNamePattern)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
|
||||
std::regex fileRegex(fileNamePattern);
|
||||
for(auto const& dirEntry : std::filesystem::directory_iterator(dir))
|
||||
{
|
||||
if (std::regex_match(dirEntry.path().native(), fileRegex))
|
||||
{
|
||||
files.push_back(dirEntry.path().native());
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(files.begin(), files.end());
|
||||
return Open(files);
|
||||
}
|
||||
|
||||
void ArchiveReader::ReadNextHeader()
|
||||
{
|
||||
if (m_eof || !m_open)
|
||||
|
||||
@@ -20,8 +20,6 @@ namespace openVulkanoCpp
|
||||
bool m_open = false;
|
||||
bool m_eof = false;
|
||||
|
||||
void ReadNextHeader();
|
||||
|
||||
public:
|
||||
explicit ArchiveReader(const std::shared_ptr<spdlog::logger>& logger = nullptr);
|
||||
|
||||
@@ -39,6 +37,10 @@ namespace openVulkanoCpp
|
||||
|
||||
bool Open(const void* archiveBuffer, size_t size);
|
||||
|
||||
bool Open(const std::vector<std::string>& archiveFiles);
|
||||
|
||||
bool Open(const std::filesystem::path& dir, const std::string& fileNamePattern);
|
||||
|
||||
[[nodiscard]] bool IsOpen() const { return m_open; }
|
||||
|
||||
size_t ExtractRemaining(std::string_view targetDir);
|
||||
@@ -61,5 +63,10 @@ namespace openVulkanoCpp
|
||||
std::optional<FileDescription> StreamNextFile(std::ostream& stream);
|
||||
|
||||
bool GetNextFileAsStream(const std::function<void(const FileDescription&, std::istream&)>& streamReader);
|
||||
|
||||
private:
|
||||
void ReadNextHeader();
|
||||
|
||||
void PrepOpen();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user