/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #include "ArchiveBase.hpp" #include "Data/Containers/Array.hpp" #include "ArchiveType.hpp" #include #include #include #include namespace OpenVulkano { class ArchiveReader final : public ArchiveBase { std::optional m_archiveType; std::queue m_archivesToRead; std::function m_passwordCallback; std::function m_filePathRewrite; bool m_open = false; bool m_eof = false; public: explicit ArchiveReader(const std::shared_ptr& logger = nullptr, std::optional archiveType = std::nullopt); explicit ArchiveReader(const char* archiveFile, const std::shared_ptr& logger = nullptr, std::optional archiveType = std::nullopt); explicit ArchiveReader(const std::string& archiveFile, const std::shared_ptr& logger = nullptr, std::optional archiveType = std::nullopt); explicit ArchiveReader(const std::filesystem::path& archiveFile, const std::shared_ptr& logger = nullptr, std::optional archiveType = std::nullopt); ArchiveReader(const void* archiveBuffer, size_t size, const std::shared_ptr& logger = nullptr, std::optional archiveType = std::nullopt); ~ArchiveReader() override; void SetPasswordCallback(const decltype(m_passwordCallback)& callback); bool Open(const std::filesystem::path& archiveFile); bool Open(const char* archiveFile); bool Open(const std::string& archiveFile); bool OpenMemory(const void* archiveBuffer, size_t size); bool Open(const std::vector& archiveFiles); bool Open(const std::filesystem::path& dir, const std::string& fileNamePattern, size_t* outSize = nullptr); [[nodiscard]] bool IsOpen() const { return m_open; } [[deprecated]] size_t ExtractRemaining(std::string_view targetDir); size_t ExtractRemaining(const std::filesystem::path& targetDir); size_t ExtractRemaining(const std::filesystem::path& targetDir, const std::function extractionCallback); // Element wise operations [[nodiscard]] bool HasNext() const; void SkipNext(); bool SkipTill(std::filesystem::file_type type = std::filesystem::file_type::regular); [[nodiscard]] FileDescription GetNextDescription() const; std::optional GetNextDirectory(); [[deprecated]] std::optional ExtractNext(std::string_view targetDir) { return ExtractNext(std::filesystem::path(targetDir)); } std::optional ExtractNext(const std::filesystem::path& targetDir); std::optional>> GetNextFile(); std::optional>> GetNextFileAsVector(); std::optional>> GetFile(const std::string& path); std::optional StreamNextFile(std::ostream& stream); bool GetNextFileAsStream(const std::function& streamReader); const decltype(m_passwordCallback)& GetPasswordCallback() const { return m_passwordCallback; } void SetPathRewriteFunction(const decltype(m_filePathRewrite)& rewriteFunc) { m_filePathRewrite = rewriteFunc; } const decltype(m_filePathRewrite)& GetPathRewriteFunction() const { return m_filePathRewrite; } private: void ReadNextHeader(); std::function GetCurrentFormatReadFunc() const; void PrepOpen(); }; }