From 3a32197cc377796220565d984287b774ac4457c2 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Wed, 5 Feb 2025 23:23:23 +0100 Subject: [PATCH 01/18] Add optional password for archive writer --- openVulkanoCpp/IO/Archive/ArchiveWriter.cpp | 4 +++- openVulkanoCpp/IO/Archive/ArchiveWriter.hpp | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp b/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp index f32e281..153f1ce 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp @@ -11,10 +11,11 @@ #include #include #include +#include namespace OpenVulkano { - ArchiveWriter::ArchiveWriter(const char* fileName, ArchiveConfiguration archiveConfiguration, const std::shared_ptr& logger) + ArchiveWriter::ArchiveWriter(const char* fileName, ArchiveConfiguration archiveConfiguration, const std::shared_ptr& logger, const char* password) : ArchiveBase(archive_write_new(), archive_entry_new(), logger) , m_archiveConfig(archiveConfiguration) , m_shouldCompress(&SimpleFileTypeShouldCompressChecker) @@ -30,6 +31,7 @@ namespace OpenVulkano std::string level = "compression-level=" + std::to_string(archiveConfiguration.compressionLevel); ChkErr(archive_write_set_options(m_archive, level.c_str())); } + if (password) ChkErr(archive_write_set_passphrase(m_archive, password)); ChkErr(archive_write_open_filename(m_archive, fileName)); } diff --git a/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp b/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp index f1540bc..d13afeb 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp +++ b/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp @@ -26,11 +26,11 @@ namespace OpenVulkano std::function m_shouldCompress; public: - ArchiveWriter(const char* fileName, const std::shared_ptr& logger = nullptr) - : ArchiveWriter(fileName, ArchiveConfiguration::FromFileName(fileName), logger) + ArchiveWriter(const char* fileName, const std::shared_ptr& logger = nullptr, const char* password = nullptr) + : ArchiveWriter(fileName, ArchiveConfiguration::FromFileName(fileName), logger, password) {} - ArchiveWriter(const char* fileName, ArchiveConfiguration archiveConfiguration, const std::shared_ptr& logger = nullptr); + ArchiveWriter(const char* fileName, ArchiveConfiguration archiveConfiguration, const std::shared_ptr& logger = nullptr, const char* password = nullptr); ~ArchiveWriter() override; From 07b5883620a0d3fc5dd3c6b1e2d487f58e264ae7 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Thu, 6 Feb 2025 17:14:48 +0100 Subject: [PATCH 02/18] Update compiler warnings --- cmake/functions/SetCompilerSettings.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/functions/SetCompilerSettings.cmake b/cmake/functions/SetCompilerSettings.cmake index 0ec6284..ef7187b 100644 --- a/cmake/functions/SetCompilerSettings.cmake +++ b/cmake/functions/SetCompilerSettings.cmake @@ -20,13 +20,14 @@ endfunction() function(SetWarningSettings TARGET) if (LINUX) - target_compile_options(${TARGET} PRIVATE -Wall -Wno-unknown-pragmas) + target_compile_options(${TARGET} PRIVATE -Wall -Wno-unknown-pragmas -Werror=return-type) elseif (WIN32) if (MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) target_compile_options(${TARGET} PRIVATE "/wd4068;") set_target_properties(${TARGET} PROPERTIES COMPILE_FLAGS "/we4715") set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "/ignore:4099") + target_compile_options(${TARGET} PRIVATE "/WX4715;") endif() endif() endfunction() \ No newline at end of file From 7a965a77677fa1fabc05e46aada2586b1280c468 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Thu, 6 Feb 2025 17:15:43 +0100 Subject: [PATCH 03/18] Add password support for archive reader --- openVulkanoCpp/IO/Archive/ArchiveReader.cpp | 11 +++++++++++ openVulkanoCpp/IO/Archive/ArchiveReader.hpp | 9 +++++++-- openVulkanoCpp/IO/Archive/IArchiveWriter.hpp | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp index b392842..3240ad0 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp @@ -18,6 +18,12 @@ namespace OpenVulkano namespace { constexpr int BUFFER_SIZE = 16384; + + const char* ArchivePasswordCallbackHandler(struct archive *, void *_client_data) + { + ArchiveReader* reader = static_cast(_client_data); + return reader->GetPasswordCallback()(); + } } ArchiveReader::ArchiveReader(const std::shared_ptr& logger, std::optional archiveType) @@ -42,6 +48,11 @@ namespace OpenVulkano ArchiveReader::~ArchiveReader() = default; + void ArchiveReader::SetPasswordCallback(const decltype(m_passwordCallback)& callback) + { + archive_read_set_passphrase_callback(m_archive, this, &ArchivePasswordCallbackHandler); + } + void ArchiveReader::PrepOpen() { if (m_open) diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.hpp b/openVulkanoCpp/IO/Archive/ArchiveReader.hpp index b2f0642..09e1eaf 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.hpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.hpp @@ -19,10 +19,11 @@ namespace OpenVulkano { class ArchiveReader final : public ArchiveBase { - bool m_open = false; - bool m_eof = false; std::optional m_archiveType; std::queue m_archivesToRead; + std::function m_passwordCallback; + bool m_open = false; + bool m_eof = false; public: explicit ArchiveReader(const std::shared_ptr& logger = nullptr, std::optional archiveType = std::nullopt); @@ -35,6 +36,8 @@ namespace OpenVulkano ~ArchiveReader() override; + void SetPasswordCallback(const decltype(m_passwordCallback)& callback); + bool Open(const char* archiveFile); bool Open(const std::string& archiveFile); @@ -72,6 +75,8 @@ namespace OpenVulkano bool GetNextFileAsStream(const std::function& streamReader); + const decltype(m_passwordCallback)& GetPasswordCallback() const { return m_passwordCallback; } + private: void ReadNextHeader(); std::function GetCurrentFormatReadFunc() const; diff --git a/openVulkanoCpp/IO/Archive/IArchiveWriter.hpp b/openVulkanoCpp/IO/Archive/IArchiveWriter.hpp index 7c6a775..efa82da 100644 --- a/openVulkanoCpp/IO/Archive/IArchiveWriter.hpp +++ b/openVulkanoCpp/IO/Archive/IArchiveWriter.hpp @@ -64,7 +64,7 @@ namespace OpenVulkano if (buffer.first == nullptr) continue; size += buffer.second; } - FileDescription description = FileDescription::MakeDescriptionForFile(fileName, size); + const FileDescription description = FileDescription::MakeDescriptionForFile(fileName, size); return AddFile(description, buffers); } From acd73f6cfbd03828d4a695b546414a7ee72d74ef Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Thu, 6 Feb 2025 18:53:10 +0100 Subject: [PATCH 04/18] Add helper functions --- openVulkanoCpp/IO/FileDescription.hpp | 34 ++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/openVulkanoCpp/IO/FileDescription.hpp b/openVulkanoCpp/IO/FileDescription.hpp index a793af2..b16ccec 100644 --- a/openVulkanoCpp/IO/FileDescription.hpp +++ b/openVulkanoCpp/IO/FileDescription.hpp @@ -12,8 +12,8 @@ namespace OpenVulkano { struct FileDescription { - constexpr static inline std::filesystem::perms ALL_READ = std::filesystem::perms::owner_read | std::filesystem::perms::group_read | std::filesystem::perms::others_read; - constexpr static inline size_t UNKNOWN_SIZE = SIZE_MAX; + constexpr static std::filesystem::perms ALL_READ = std::filesystem::perms::owner_read | std::filesystem::perms::group_read | std::filesystem::perms::others_read; + constexpr static size_t UNKNOWN_SIZE = SIZE_MAX; std::filesystem::file_type type; std::string path; @@ -21,7 +21,10 @@ namespace OpenVulkano std::filesystem::perms permissions; time_t createTime = {}, modTime = {}; - static FileDescription MakeDescriptionForFile(const char* path, size_t size) + [[deprecated("Use MkFile instead")]] + static FileDescription MakeDescriptionForFile(const char* path, const size_t size) { return MkFile(path, size); } + + static FileDescription MkFile(const char* path, const size_t size) { return { std::filesystem::file_type::regular, @@ -31,5 +34,30 @@ namespace OpenVulkano std::time(nullptr), std::time(nullptr) }; } + + static FileDescription MkFile(const std::string& path, const size_t size) + { + return { + std::filesystem::file_type::regular, + path, + size, + std::filesystem::perms::owner_write | ALL_READ, + std::time(nullptr), std::time(nullptr) + }; + } + + static FileDescription MkDir(const char* path) + { + FileDescription desc = MkFile(path, 0); + desc.type = std::filesystem::file_type::directory; + return desc; + } + + static FileDescription MkDir(const std::string& path) + { + FileDescription desc = MkFile(path, 0); + desc.type = std::filesystem::file_type::directory; + return desc; + } }; } From 123c6ecc9b84b67776f1b64a9bd53b85036aa5f4 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Thu, 6 Feb 2025 23:53:11 +0100 Subject: [PATCH 05/18] Fix flags on Windows --- cmake/functions/SetCompilerSettings.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/functions/SetCompilerSettings.cmake b/cmake/functions/SetCompilerSettings.cmake index ef7187b..e4abd9f 100644 --- a/cmake/functions/SetCompilerSettings.cmake +++ b/cmake/functions/SetCompilerSettings.cmake @@ -27,7 +27,6 @@ function(SetWarningSettings TARGET) target_compile_options(${TARGET} PRIVATE "/wd4068;") set_target_properties(${TARGET} PROPERTIES COMPILE_FLAGS "/we4715") set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "/ignore:4099") - target_compile_options(${TARGET} PRIVATE "/WX4715;") endif() endif() endfunction() \ No newline at end of file From afd2c8043e03b4b62d71889d4d5a056becce9bbc Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sat, 8 Feb 2025 16:16:03 +0100 Subject: [PATCH 06/18] Silence some warnings --- openVulkanoCpp/IO/Archive/IArchiveWriter.hpp | 6 +++--- openVulkanoCpp/Image/YuvUtils.hpp | 4 ++-- openVulkanoCpp/Scene/DataFormat.cpp | 6 +++--- openVulkanoCpp/Scene/Export/MeshWriter.cpp | 12 ++++++------ openVulkanoCpp/Scene/Geometry.cpp | 2 +- openVulkanoCpp/Scene/Geometry.hpp | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/openVulkanoCpp/IO/Archive/IArchiveWriter.hpp b/openVulkanoCpp/IO/Archive/IArchiveWriter.hpp index efa82da..e54d36e 100644 --- a/openVulkanoCpp/IO/Archive/IArchiveWriter.hpp +++ b/openVulkanoCpp/IO/Archive/IArchiveWriter.hpp @@ -52,7 +52,7 @@ namespace OpenVulkano bool AddFile(const char* inArchiveName, const void* buffer, size_t length) { - FileDescription description = FileDescription::MakeDescriptionForFile(inArchiveName, length); + FileDescription description = FileDescription::MkFile(inArchiveName, length); return AddFile(description, buffer); } @@ -64,7 +64,7 @@ namespace OpenVulkano if (buffer.first == nullptr) continue; size += buffer.second; } - const FileDescription description = FileDescription::MakeDescriptionForFile(fileName, size); + const FileDescription description = FileDescription::MkFile(fileName, size); return AddFile(description, buffers); } @@ -95,4 +95,4 @@ namespace OpenVulkano return true; } }; -} \ No newline at end of file +} diff --git a/openVulkanoCpp/Image/YuvUtils.hpp b/openVulkanoCpp/Image/YuvUtils.hpp index 733253d..d57e9f1 100644 --- a/openVulkanoCpp/Image/YuvUtils.hpp +++ b/openVulkanoCpp/Image/YuvUtils.hpp @@ -13,9 +13,9 @@ namespace OpenVulkano { namespace YuvUtils { - inline void NV12FromChromaPlanes(unsigned char* __restrict src, unsigned char* __restrict dest, int chromaChannelPixelCount) + inline void NV12FromChromaPlanes(unsigned char* __restrict src, unsigned char* __restrict dest, size_t chromaChannelPixelCount) { - for(int i = 0; i < chromaChannelPixelCount; i++) + for(size_t i = 0; i < chromaChannelPixelCount; i++) { dest[i * 2] = src[i]; dest[i * 2 + 1] = src[i + chromaChannelPixelCount]; diff --git a/openVulkanoCpp/Scene/DataFormat.cpp b/openVulkanoCpp/Scene/DataFormat.cpp index 723a69c..fb1185b 100644 --- a/openVulkanoCpp/Scene/DataFormat.cpp +++ b/openVulkanoCpp/Scene/DataFormat.cpp @@ -242,8 +242,8 @@ namespace OpenVulkano { if (format == m_format) { - return format >= BC1_RGB_UNORM_BLOCK && format <= ASTC_12x12_SRGB_BLOCK - || format >= ASTC_4x4_SFLOAT_BLOCK && format <= PVRTC2_4BPP_SRGB_BLOCK_IMG; + return (format >= BC1_RGB_UNORM_BLOCK && format <= ASTC_12x12_SRGB_BLOCK) || + (format >= ASTC_4x4_SFLOAT_BLOCK && format <= PVRTC2_4BPP_SRGB_BLOCK_IMG); } } return false; @@ -268,4 +268,4 @@ namespace OpenVulkano #ifndef __APPLE__ DataFormat DataFormat::GetFromMetalPixelFormat(int formatId) { return UNDEFINED; } #endif -} \ No newline at end of file +} diff --git a/openVulkanoCpp/Scene/Export/MeshWriter.cpp b/openVulkanoCpp/Scene/Export/MeshWriter.cpp index c748015..19f0fc1 100644 --- a/openVulkanoCpp/Scene/Export/MeshWriter.cpp +++ b/openVulkanoCpp/Scene/Export/MeshWriter.cpp @@ -54,18 +54,18 @@ namespace OpenVulkano::Scene std::stringstream objContents; WriteObjContents(geometry, DEFAULT_OBJ_MATERIAL_NAME, objContents); std::string objContentsStr = objContents.str(); - FileDescription objDesc = FileDescription::MakeDescriptionForFile("model.obj", objContentsStr.size()); + FileDescription objDesc = FileDescription::MkFile("model.obj", objContentsStr.size()); zipWriter.AddFile(objDesc, objContentsStr.data()); } { - FileDescription mtlDesc = FileDescription::MakeDescriptionForFile("material.mtl", DEFAULT_OBJ_MATERIAL_CONTENTS.size()); + FileDescription mtlDesc = FileDescription::MkFile("material.mtl", DEFAULT_OBJ_MATERIAL_CONTENTS.size()); zipWriter.AddFile(mtlDesc, DEFAULT_OBJ_MATERIAL_CONTENTS.data()); } if (!texturePath.empty() && std::filesystem::exists(texturePath)) { MemMappedFile textureFile(texturePath); - FileDescription texDesc = FileDescription::MakeDescriptionForFile("texture.png", textureFile.Size()); + FileDescription texDesc = FileDescription::MkFile("texture.png", textureFile.Size()); zipWriter.AddFile(texDesc, textureFile.Data()); } } @@ -78,14 +78,14 @@ namespace OpenVulkano::Scene std::stringstream usdFile; WriteUsdContents(usdFile, geometry); std::string usdFileStr = usdFile.str(); - FileDescription usdDesc = FileDescription::MakeDescriptionForFile("geometry.usda", usdFileStr.size()); + FileDescription usdDesc = FileDescription::MkFile("geometry.usda", usdFileStr.size()); zipWriter.AddFile(usdDesc, usdFileStr.data()); } if (!texturePath.empty() && std::filesystem::exists(texturePath)) { MemMappedFile textureFile(texturePath); - FileDescription texDesc = FileDescription::MakeDescriptionForFile("texture.png", textureFile.Size()); + FileDescription texDesc = FileDescription::MkFile("texture.png", textureFile.Size()); zipWriter.AddFile(texDesc, textureFile.Data()); } } @@ -185,4 +185,4 @@ namespace OpenVulkano::Scene throw std::runtime_error("Unable to convert the scene to FBX: Assimp is not available!"); #endif } -} \ No newline at end of file +} diff --git a/openVulkanoCpp/Scene/Geometry.cpp b/openVulkanoCpp/Scene/Geometry.cpp index 4fa4c9f..cfd5414 100644 --- a/openVulkanoCpp/Scene/Geometry.cpp +++ b/openVulkanoCpp/Scene/Geometry.cpp @@ -154,7 +154,7 @@ namespace OpenVulkano::Scene indices = nullptr; } - uint32_t Geometry::GetIndex(uint32_t index) const + uint32_t Geometry::GetIndex(size_t index) const { uint32_t result = 0; diff --git a/openVulkanoCpp/Scene/Geometry.hpp b/openVulkanoCpp/Scene/Geometry.hpp index cd62b18..cef7b1d 100644 --- a/openVulkanoCpp/Scene/Geometry.hpp +++ b/openVulkanoCpp/Scene/Geometry.hpp @@ -56,7 +56,7 @@ namespace OpenVulkano Vertex* GetVertices() const { return vertices; } void* GetIndices() const { return indices; } - uint32_t GetIndex(uint32_t index) const; + uint32_t GetIndex(size_t index) const; uint16_t* GetIndices16() const { return static_cast(indices); } uint32_t* GetIndices32() const { return static_cast(indices); } uint32_t GetIndexCount() const { return indexCount; } From ba475e6696883a8d7594af42e05aca9a94db08b9 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 9 Feb 2025 02:13:09 +0100 Subject: [PATCH 07/18] Expand archive reader --- openVulkanoCpp/IO/Archive/ArchiveReader.cpp | 53 +++++++++++++-------- openVulkanoCpp/IO/Archive/ArchiveReader.hpp | 16 +++++-- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp index 3240ad0..2eeec6a 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp @@ -66,6 +66,15 @@ namespace OpenVulkano m_open = true; } + bool ArchiveReader::Open(const std::filesystem::path& archiveFile) + { + PrepOpen(); + ChkErr(archive_read_open_filename(m_archive, archiveFile.c_str(), BUFFER_SIZE)); + ReadNextHeader(); + return HasNext(); + } + + bool ArchiveReader::Open(const char* archiveFile) { if (archiveFile[0] == '\0') @@ -176,20 +185,14 @@ namespace OpenVulkano ArchiveType::Type type = *m_archiveType; switch (type) { - case ArchiveType::ZIP: - return archive_read_support_format_zip; - case ArchiveType::SEVEN_ZIP: - return archive_read_support_format_7zip; - case ArchiveType::CPIO: - return archive_read_support_format_cpio; - case ArchiveType::ISO: - return archive_read_support_format_iso9660; - case ArchiveType::TAR: - return archive_read_support_format_tar; - case ArchiveType::WARC: - return archive_read_support_format_warc; - case ArchiveType::XAR: - return archive_read_support_format_xar; + case ArchiveType::SEVEN_ZIP: return archive_read_support_format_7zip; + case ArchiveType::ZIP: return archive_read_support_format_zip; + case ArchiveType::CPIO: return archive_read_support_format_cpio; + case ArchiveType::ISO: return archive_read_support_format_iso9660; + case ArchiveType::TAR: return archive_read_support_format_tar; + case ArchiveType::WARC: return archive_read_support_format_warc; + case ArchiveType::XAR: return archive_read_support_format_xar; + case ArchiveType::SHAR: break; // nothing to do } return archive_read_support_format_all; } @@ -203,6 +206,16 @@ namespace OpenVulkano } return count; } + + size_t ArchiveReader::ExtractRemaining(const std::filesystem::path &targetDir) + { + size_t count = 0; + while (ExtractNext(targetDir)) + { + count++; + } + return count; + } bool ArchiveReader::HasNext() const { @@ -246,19 +259,21 @@ namespace OpenVulkano return std::nullopt; } - std::optional ArchiveReader::ExtractNext(std::string_view targetDir) + std::optional ArchiveReader::ExtractNext(const std::filesystem::path& targetDir) { if (SkipTill(std::filesystem::file_type::regular)) { FileDescription fileDescription = GetNextDescription(); - std::string outputFileName; - outputFileName.reserve(targetDir.size() + 1 + fileDescription.path.size()); - outputFileName.append(targetDir).append("/").append(fileDescription.path); + std::filesystem::path outputFilePath; + if (m_filePathRewrite) + outputFilePath = targetDir / m_filePathRewrite(fileDescription.path); + else + outputFilePath = targetDir / fileDescription.path; std::unique_ptr a(archive_write_disk_new(), archive_write_free); std::unique_ptr entry(archive_entry_clone(m_archiveEntry), archive_entry_free); - archive_entry_set_pathname(entry.get(), outputFileName.c_str()); + archive_entry_set_pathname(entry.get(), outputFilePath.c_str()); ChkErr(archive_write_disk_set_options(a.get(), ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL | ARCHIVE_EXTRACT_FFLAGS)); diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.hpp b/openVulkanoCpp/IO/Archive/ArchiveReader.hpp index 09e1eaf..c66abb2 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.hpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.hpp @@ -12,7 +12,6 @@ #include #include #include -#include #include namespace OpenVulkano @@ -22,6 +21,7 @@ namespace OpenVulkano std::optional m_archiveType; std::queue m_archivesToRead; std::function m_passwordCallback; + std::function m_filePathRewrite; bool m_open = false; bool m_eof = false; @@ -38,6 +38,8 @@ namespace OpenVulkano 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); @@ -50,7 +52,9 @@ namespace OpenVulkano [[nodiscard]] bool IsOpen() const { return m_open; } - size_t ExtractRemaining(std::string_view targetDir); + [[deprecated]] size_t ExtractRemaining(std::string_view targetDir); + + size_t ExtractRemaining(const std::filesystem::path& targetDir); // Element wise operations [[nodiscard]] bool HasNext() const; @@ -63,7 +67,9 @@ namespace OpenVulkano std::optional GetNextDirectory(); - std::optional ExtractNext(std::string_view targetDir); + [[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(); @@ -76,6 +82,10 @@ namespace OpenVulkano 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(); From e53b402a4cb0952691343c76c9124b0169ec29ba Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 9 Feb 2025 02:13:35 +0100 Subject: [PATCH 08/18] Add String support --- .../Extensions/YamlCppConverters.hpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/openVulkanoCpp/Extensions/YamlCppConverters.hpp b/openVulkanoCpp/Extensions/YamlCppConverters.hpp index 3586dac..6f44676 100644 --- a/openVulkanoCpp/Extensions/YamlCppConverters.hpp +++ b/openVulkanoCpp/Extensions/YamlCppConverters.hpp @@ -16,12 +16,32 @@ #include "Math/RGB565.hpp" #include "Math/RGBA5551.hpp" #include "Math/Timestamp.hpp" +#include "Data/Containers/String.hpp" #include #include #include namespace YAML { + template<> + struct convert + { + static Node encode(const OpenVulkano::String& string) + { + return Node(static_cast(string)); + } + + static bool decode(const Node& node, OpenVulkano::String& string) + { + if (node.IsScalar()) + { + string = node.as(); + return true; + } + return false; + } + }; + template<> struct convert { From b72962e27f88e18c9aede0f4769af4699adc65a5 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 9 Feb 2025 02:16:30 +0100 Subject: [PATCH 09/18] enable lto only for release builds --- cmake/functions/SetCompilerSettings.cmake | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmake/functions/SetCompilerSettings.cmake b/cmake/functions/SetCompilerSettings.cmake index e4abd9f..da2cad7 100644 --- a/cmake/functions/SetCompilerSettings.cmake +++ b/cmake/functions/SetCompilerSettings.cmake @@ -1,10 +1,12 @@ include(CheckIPOSupported) function(SetOptimisationSettings) - if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - check_ipo_supported(RESULT result) - if(result) - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE PARENT_SCOPE) + if(CMAKE_BUILD_TYPE STREQUAL "Release") + if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + check_ipo_supported(RESULT result) + if(result) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE PARENT_SCOPE) + endif() endif() endif() From 5c132ecd772eca38df0e0dfaeef19c6dfc24b9b5 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 9 Feb 2025 17:32:19 +0100 Subject: [PATCH 10/18] Add callback option for extract all --- openVulkanoCpp/IO/Archive/ArchiveReader.cpp | 12 ++++++++++++ openVulkanoCpp/IO/Archive/ArchiveReader.hpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp index 2eeec6a..3acdc63 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp @@ -216,6 +216,18 @@ namespace OpenVulkano } return count; } + + size_t ArchiveReader::ExtractRemaining(const std::filesystem::path& targetDir, const std::function extractionCallback) + { + size_t count = 0; + std::optional fd; + while (fd = ExtractNext(targetDir)) + { + extractionCallback(fd.value()); + count++; + } + return count; + } bool ArchiveReader::HasNext() const { diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.hpp b/openVulkanoCpp/IO/Archive/ArchiveReader.hpp index c66abb2..a7f05e9 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.hpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.hpp @@ -55,6 +55,8 @@ namespace OpenVulkano [[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; From 3c7c6ae207abb8bf0d3f99ba28b9759459324f2b Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 9 Feb 2025 18:02:27 +0100 Subject: [PATCH 11/18] Fix tests --- tests/IO/Archive/ArchiveReaderTest.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/IO/Archive/ArchiveReaderTest.cpp b/tests/IO/Archive/ArchiveReaderTest.cpp index 59b9b8f..4e0a434 100644 --- a/tests/IO/Archive/ArchiveReaderTest.cpp +++ b/tests/IO/Archive/ArchiveReaderTest.cpp @@ -18,14 +18,14 @@ using namespace OpenVulkano; namespace { - std::string dummyArchiveDir() + std::filesystem::path dummyArchiveDir() { - return AppFolders::GetAppTempDir().string(); + return AppFolders::GetAppTempDir(); } - std::string dummyArchivePath() + std::filesystem::path dummyArchivePath() { - return dummyArchiveDir() + "/test_archive.zip"; + return dummyArchiveDir() / "test_archive.zip"; } void makeDummyArchive() @@ -115,7 +115,7 @@ TEST_CASE("ExtractNext and Skip Functions", "[ArchiveReader]") std::string testArchive = dummyArchivePath(); ArchiveReader reader(testArchive); - size_t extractedFiles = reader.ExtractRemaining(dummyArchiveDir().c_str()); + size_t extractedFiles = reader.ExtractRemaining(dummyArchiveDir()); REQUIRE(extractedFiles > 0); reader.SkipNext(); REQUIRE(reader.HasNext() == false); From 8bbb22bd64a28da567a40b7a6cf4a3098f027d55 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 9 Feb 2025 18:30:32 +0100 Subject: [PATCH 12/18] Fix some Windows issues --- openVulkanoCpp/IO/Archive/ArchiveReader.cpp | 17 ++++++++++------- openVulkanoCpp/IO/PlatformFolders.cpp | 3 +-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp index 3acdc63..4e98bee 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp @@ -69,7 +69,10 @@ namespace OpenVulkano bool ArchiveReader::Open(const std::filesystem::path& archiveFile) { PrepOpen(); - ChkErr(archive_read_open_filename(m_archive, archiveFile.c_str(), BUFFER_SIZE)); + if constexpr (std::is_same_v) + ChkErr(archive_read_open_filename(m_archive, archiveFile.c_str(), BUFFER_SIZE)); + else + ChkErr(archive_read_open_filename_w(m_archive, (wchar_t*)archiveFile.c_str(), BUFFER_SIZE)); ReadNextHeader(); return HasNext(); } @@ -221,7 +224,7 @@ namespace OpenVulkano { size_t count = 0; std::optional fd; - while (fd = ExtractNext(targetDir)) + while ((fd = ExtractNext(targetDir))) { extractionCallback(fd.value()); count++; @@ -276,14 +279,14 @@ namespace OpenVulkano if (SkipTill(std::filesystem::file_type::regular)) { FileDescription fileDescription = GetNextDescription(); - std::filesystem::path outputFilePath; + std::string outputFilePath; if (m_filePathRewrite) - outputFilePath = targetDir / m_filePathRewrite(fileDescription.path); + outputFilePath = (targetDir / m_filePathRewrite(fileDescription.path)).string(); else - outputFilePath = targetDir / fileDescription.path; + outputFilePath = (targetDir / fileDescription.path).string(); - std::unique_ptr a(archive_write_disk_new(), archive_write_free); - std::unique_ptr entry(archive_entry_clone(m_archiveEntry), archive_entry_free); + const std::unique_ptr a(archive_write_disk_new(), archive_write_free); + const std::unique_ptr entry(archive_entry_clone(m_archiveEntry), archive_entry_free); archive_entry_set_pathname(entry.get(), outputFilePath.c_str()); diff --git a/openVulkanoCpp/IO/PlatformFolders.cpp b/openVulkanoCpp/IO/PlatformFolders.cpp index b9d6acd..84bf797 100644 --- a/openVulkanoCpp/IO/PlatformFolders.cpp +++ b/openVulkanoCpp/IO/PlatformFolders.cpp @@ -56,8 +56,7 @@ namespace OpenVulkano [[nodiscard]] std::filesystem::path GetXDGFolderDefault(const char* envName, std::string_view defaultRelativePath) { #ifndef TARGET_OS_IOS != 1 - const char* envValue = std::getenv(envName); - if (envValue) + if (const char* envValue = std::getenv(envName)) { if (envValue[0] == '/') return envValue; std::cerr << "Ignoring environment '" << envName << "' (value: '" << envValue << "') because it's relative! XDG specifies it should be absolute path. Falling back to default path."; From 23ba70347189a3029cd4929e63334a8a45e9a149 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 9 Feb 2025 18:58:39 +0100 Subject: [PATCH 13/18] Another windows build fix --- openVulkanoCpp/IO/Archive/ArchiveReader.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp index 4e98bee..c7af92a 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp @@ -70,9 +70,9 @@ namespace OpenVulkano { PrepOpen(); if constexpr (std::is_same_v) - ChkErr(archive_read_open_filename(m_archive, archiveFile.c_str(), BUFFER_SIZE)); + ChkErr(archive_read_open_filename(m_archive, (const char*)archiveFile.c_str(), BUFFER_SIZE)); else - ChkErr(archive_read_open_filename_w(m_archive, (wchar_t*)archiveFile.c_str(), BUFFER_SIZE)); + ChkErr(archive_read_open_filename_w(m_archive, (const wchar_t*)archiveFile.c_str(), BUFFER_SIZE)); ReadNextHeader(); return HasNext(); } @@ -82,10 +82,7 @@ namespace OpenVulkano { if (archiveFile[0] == '\0') { - if (m_logger) - { - m_logger->error("Unable to open archive file with an empty name!"); - } + if (m_logger) m_logger->error("Unable to open archive file with an empty name!"); return false; } PrepOpen(); @@ -110,14 +107,14 @@ namespace OpenVulkano bool ArchiveReader::Open(const std::vector& archiveFiles) { if (archiveFiles.empty()) return false; - ArchiveConfiguration ac = ArchiveConfiguration::FromFileName(archiveFiles.front().c_str()); + const ArchiveConfiguration ac = ArchiveConfiguration::FromFileName(archiveFiles.front().c_str()); if (ac.type == ArchiveType::TAR) // TODO handle all archive types correctly { // Queue based approach for all archive types that do not natively support split archives for(const std::string& file : archiveFiles) { m_archivesToRead.push(file); } - bool state = Open(m_archivesToRead.front()); + const bool state = Open(m_archivesToRead.front()); m_archivesToRead.pop(); return state; } From d2c86ede732e591330a136efc3490c76f3a1519c Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 9 Feb 2025 20:26:36 +0100 Subject: [PATCH 14/18] More rework to switch to std::filesystem::path over cstrings --- .../IO/Archive/ArchiveConfiguration.cpp | 7 +++--- .../IO/Archive/ArchiveConfiguration.hpp | 4 +++- openVulkanoCpp/IO/Archive/ArchiveWriter.cpp | 23 +++++++++++++++++++ openVulkanoCpp/IO/Archive/ArchiveWriter.hpp | 6 +++++ tests/IO/Archive/ArchiveReaderTest.cpp | 8 +++---- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/openVulkanoCpp/IO/Archive/ArchiveConfiguration.cpp b/openVulkanoCpp/IO/Archive/ArchiveConfiguration.cpp index a965570..6692df0 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveConfiguration.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveConfiguration.cpp @@ -7,6 +7,7 @@ #include "ArchiveConfiguration.hpp" #include "Base/Utils.hpp" #include +#include namespace OpenVulkano { @@ -34,9 +35,9 @@ namespace OpenVulkano return std::string(tName); } - ArchiveConfiguration ArchiveConfiguration::FromFileName(const char* fileName) + ArchiveConfiguration ArchiveConfiguration::FromFileName(std::filesystem::path fileName) { - std::string_view fName = fileName; + std::string_view fName = fileName.string(); ArchiveConfiguration ac; if (auto type = ArchiveType::FromExtension(fName)) { @@ -77,4 +78,4 @@ namespace OpenVulkano { return COMP_MAP[static_cast(compression)]; } -} \ No newline at end of file +} diff --git a/openVulkanoCpp/IO/Archive/ArchiveConfiguration.hpp b/openVulkanoCpp/IO/Archive/ArchiveConfiguration.hpp index 9a4d879..2ea5abd 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveConfiguration.hpp +++ b/openVulkanoCpp/IO/Archive/ArchiveConfiguration.hpp @@ -6,6 +6,8 @@ #pragma once +#include + #include "ArchiveType.hpp" #include @@ -25,7 +27,7 @@ namespace OpenVulkano : type(archiveType), compression(compressionType), compressionLevel(level) {} - [[nodiscard]] static ArchiveConfiguration FromFileName(const char* fileName); + [[nodiscard]] static ArchiveConfiguration FromFileName(std::filesystem::path fileName); [[nodiscard]] std::string GetFileExtension() const; diff --git a/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp b/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp index 153f1ce..9d0493d 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp @@ -35,6 +35,29 @@ namespace OpenVulkano ChkErr(archive_write_open_filename(m_archive, fileName)); } + ArchiveWriter::ArchiveWriter(const std::filesystem::path& fileName, ArchiveConfiguration archiveConfiguration, const std::shared_ptr& logger, const char* password) + : ArchiveBase(archive_write_new(), archive_entry_new(), logger) + , m_archiveConfig(archiveConfiguration) + , m_shouldCompress(&SimpleFileTypeShouldCompressChecker) + { //TODO error handling + ChkErr(archive_write_set_format(m_archive, archiveConfiguration.GetLibArchiveArchiveType())); + if (archiveConfiguration.type == ArchiveType::TAR) + { + ChkErr(archive_write_add_filter(m_archive, archiveConfiguration.GetLibArchiveCompressionType())); + } + if (archiveConfiguration.compression != CompressionType::NONE && + archiveConfiguration.compressionLevel > 0) + { + std::string level = "compression-level=" + std::to_string(archiveConfiguration.compressionLevel); + ChkErr(archive_write_set_options(m_archive, level.c_str())); + } + if (password) ChkErr(archive_write_set_passphrase(m_archive, password)); + if constexpr (std::is_same_v) + ChkErr(archive_write_open_filename(m_archive, (const char*)fileName.c_str())); + else + ChkErr(archive_write_open_filename_w(m_archive, (const wchar_t*)fileName.c_str())); + } + ArchiveWriter::~ArchiveWriter() { if (m_asBuffer) { m_asBuffer->Close(); m_asBuffer = nullptr; } diff --git a/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp b/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp index d13afeb..c5aa5c0 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp +++ b/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp @@ -32,6 +32,12 @@ namespace OpenVulkano ArchiveWriter(const char* fileName, ArchiveConfiguration archiveConfiguration, const std::shared_ptr& logger = nullptr, const char* password = nullptr); + ArchiveWriter(const std::filesystem::path& fileName, const std::shared_ptr& logger = nullptr, const char* password = nullptr) + : ArchiveWriter(fileName, ArchiveConfiguration::FromFileName(fileName), logger, password) + {} + + ArchiveWriter(const std::filesystem::path& fileName, ArchiveConfiguration archiveConfiguration, const std::shared_ptr& logger = nullptr, const char* password = nullptr); + ~ArchiveWriter() override; [[nodiscard]] size_t GetTotalWrittenBytes() const { return m_bytesWritten; } diff --git a/tests/IO/Archive/ArchiveReaderTest.cpp b/tests/IO/Archive/ArchiveReaderTest.cpp index 4e0a434..73ec031 100644 --- a/tests/IO/Archive/ArchiveReaderTest.cpp +++ b/tests/IO/Archive/ArchiveReaderTest.cpp @@ -30,7 +30,7 @@ namespace void makeDummyArchive() { - ArchiveWriter writer(dummyArchivePath().c_str()); + ArchiveWriter writer(dummyArchivePath()); FileDescription desc; desc.path = "stream1.txt"; @@ -70,7 +70,7 @@ TEST_CASE("Dummy archive creation, default constructor", "[ArchiveReader]") TEST_CASE("Open Archive from File", "[ArchiveReader]") { { - std::string testArchive = dummyArchivePath(); + auto testArchive = dummyArchivePath(); ArchiveReader reader; bool opened = reader.Open(testArchive); REQUIRE(opened == true); @@ -112,7 +112,7 @@ TEST_CASE("Open Archive from Directory with Pattern", "[ArchiveReader]") TEST_CASE("ExtractNext and Skip Functions", "[ArchiveReader]") { - std::string testArchive = dummyArchivePath(); + auto testArchive = dummyArchivePath(); ArchiveReader reader(testArchive); size_t extractedFiles = reader.ExtractRemaining(dummyArchiveDir()); @@ -127,7 +127,7 @@ TEST_CASE("ExtractNext and Skip Functions", "[ArchiveReader]") TEST_CASE("Get Next File Operations", "[ArchiveReader]") { - std::string testArchive = dummyArchivePath(); + auto testArchive = dummyArchivePath(); ArchiveReader reader(testArchive); From 5c7c961c46391229f9e135df00b0787541e9cf2b Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 9 Feb 2025 22:57:02 +0100 Subject: [PATCH 15/18] More windows fixes --- openVulkanoCpp/IO/Archive/ArchiveReader.cpp | 10 +++++++++- openVulkanoCpp/IO/Archive/ArchiveReader.hpp | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp index c7af92a..956f801 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp @@ -32,7 +32,15 @@ namespace OpenVulkano ArchiveReader::ArchiveReader(const std::string& archiveFile, const std::shared_ptr& logger, std::optional archiveType) : ArchiveReader(archiveFile.c_str(), logger, archiveType) - {} + { + } + + ArchiveReader::ArchiveReader(const std::filesystem::path& archiveFile, const std::shared_ptr& logger, + std::optional archiveType) + : ArchiveReader(logger, archiveType) + { + Open(archiveFile); + } ArchiveReader::ArchiveReader(const char* archiveFile, const std::shared_ptr& logger, std::optional archiveType) : ArchiveReader(logger, archiveType) diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.hpp b/openVulkanoCpp/IO/Archive/ArchiveReader.hpp index a7f05e9..3175006 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.hpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.hpp @@ -32,6 +32,8 @@ namespace OpenVulkano 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; From 5fd18bf70b827d74bf1e036dbcc3f0d8ea4c7fcb Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 9 Feb 2025 23:56:13 +0100 Subject: [PATCH 16/18] Make written bytes observable --- openVulkanoCpp/Base/Observable.hpp | 2 +- openVulkanoCpp/IO/Archive/ArchiveWriter.hpp | 7 +++++-- openVulkanoCpp/Image/YuvUtils.hpp | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/openVulkanoCpp/Base/Observable.hpp b/openVulkanoCpp/Base/Observable.hpp index 7688066..041b854 100644 --- a/openVulkanoCpp/Base/Observable.hpp +++ b/openVulkanoCpp/Base/Observable.hpp @@ -23,7 +23,7 @@ namespace OpenVulkano Observable(const T& initValue) : object(initValue) {} - Observable(T&& initValue) : object(std::forward(initValue)) {} + Observable(T&& initValue) : object(std::forward(initValue)) {} //TODO make this somehow only work for none string types to prevent issues? /*template>> diff --git a/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp b/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp index c5aa5c0..a327ac8 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp +++ b/openVulkanoCpp/IO/Archive/ArchiveWriter.hpp @@ -9,6 +9,7 @@ #include "ArchiveBase.hpp" #include "ArchiveConfiguration.hpp" #include "IArchiveWriter.hpp" +#include "Base/Observable.hpp" namespace OpenVulkano { @@ -20,7 +21,7 @@ namespace OpenVulkano friend ArchiveStreamBufferWriter; ArchiveConfiguration m_archiveConfig; - size_t m_bytesWritten = 0; + Observable m_bytesWritten { 0 }; ArchiveOStream::ASBufferPtr m_asBuffer = nullptr; bool m_lastCompressed = true; std::function m_shouldCompress; @@ -49,6 +50,8 @@ namespace OpenVulkano void SetShouldCompressFunction(const std::function& shouldComp) override { m_shouldCompress = shouldComp; } + decltype(m_bytesWritten)& GetBytesWrittenObservable() { return m_bytesWritten; } + private: void WriteHeader(const FileDescription& fileDescription); @@ -56,4 +59,4 @@ namespace OpenVulkano void SetCompressed(); }; -} \ No newline at end of file +} diff --git a/openVulkanoCpp/Image/YuvUtils.hpp b/openVulkanoCpp/Image/YuvUtils.hpp index d57e9f1..9dd1aca 100644 --- a/openVulkanoCpp/Image/YuvUtils.hpp +++ b/openVulkanoCpp/Image/YuvUtils.hpp @@ -45,7 +45,6 @@ namespace OpenVulkano { if (srcLumRowPadding) { - uint32_t srcOffset = 0, destOffset = 0; for(uint32_t y = 0, srcOffset = 0, destOffset = 0; y < sizeLumY; y++, srcOffset += sizeLumX + srcLumRowPadding, destOffset += sizeLumX) { memcpy(buffer.get() + destOffset, srcLum + srcOffset, sizeLumX); From eb5d97c10f15c3b8c76b71ae749a41df753d873d Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Mon, 10 Feb 2025 23:50:01 +0100 Subject: [PATCH 17/18] Small bugfixes --- openVulkanoCpp/Base/Observable.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/openVulkanoCpp/Base/Observable.hpp b/openVulkanoCpp/Base/Observable.hpp index 041b854..9f579f9 100644 --- a/openVulkanoCpp/Base/Observable.hpp +++ b/openVulkanoCpp/Base/Observable.hpp @@ -46,6 +46,8 @@ namespace OpenVulkano template>> operator T() const { return object; } + const T& Get() const { return object; } + operator const T&() const { return object; } bool operator ==(const T& other) const { return object == other; } @@ -56,13 +58,14 @@ namespace OpenVulkano bool operator >=(const T& other) const { return object >= other; } bool operator !() const { return !object; } - template>> - operator bool() const { return static_cast(object); } + //template>> + operator bool() const requires std::convertible_to + { return static_cast(object); } auto& operator ++() { ++object; Notify(); return *this; } auto& operator --() { --object; Notify(); return *this; } - auto& operator ++(int) { object++; Notify(); return *this; } - auto& operator --(int) { object--; Notify(); return *this; } + T operator ++(int) { T temp = *this; ++object; Notify(); return temp; } + T operator --(int) { T temp = *this; --object; Notify(); return temp; } auto& operator +=(const T& other) { object += other; Notify(); return *this; } auto& operator -=(const T& other) { object -= other; Notify(); return *this; } From c41acb47c2e23429673b84f56b0805f766452acf Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Tue, 11 Feb 2025 00:22:25 +0100 Subject: [PATCH 18/18] Attempt to fix windows build issue --- openVulkanoCpp/IO/Archive/ArchiveWriter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp b/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp index 9d0493d..7f083b8 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp @@ -78,7 +78,7 @@ namespace OpenVulkano ChkErr(result); LibArchiveHelper::CheckError(result, archiveDisk.get(), m_logger); ChkErr(archive_write_finish_entry(m_archive)); - m_bytesWritten += archive_entry_size(m_archiveEntry); + m_bytesWritten += static_cast(archive_entry_size(m_archiveEntry)); return true; }