From 56aa985f7f80829daee5cbea91072ed8d9c63d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henri=20Hyyryl=C3=A4inen?= Date: Sat, 5 Aug 2023 11:23:48 +0300 Subject: [PATCH] Automatically adjust the written format version based on the selected Godot version --- src/pck/PckFile.cpp | 15 +++++++++++++++ src/pck/PckFile.h | 16 +++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/pck/PckFile.cpp b/src/pck/PckFile.cpp index 0e4c551..b39d6a0 100644 --- a/src/pck/PckFile.cpp +++ b/src/pck/PckFile.cpp @@ -420,6 +420,21 @@ std::string PckFile::ReadContainedFileContents(uint64_t offset, uint64_t size) return result; } // ------------------------------------ // +void PckFile::SetGodotVersion(uint32_t major, uint32_t minor, uint32_t patch) +{ + MajorGodotVersion = major; + MinorGodotVersion = minor; + PatchGodotVersion = patch; + + if(MajorGodotVersion <= 3) { + + FormatVersion = GODOT_3_PCK_VERSION; + } else if(MajorGodotVersion >= 4) { + + FormatVersion = GODOT_4_PCK_VERSION; + } +} +// ------------------------------------ // uint32_t PckFile::Read32() { uint32_t value; diff --git a/src/pck/PckFile.h b/src/pck/PckFile.h index bb4cd12..d34ce45 100644 --- a/src/pck/PckFile.h +++ b/src/pck/PckFile.h @@ -20,6 +20,9 @@ constexpr uint32_t PACK_DIR_ENCRYPTED = 1; constexpr int MAX_SUPPORTED_PCK_VERSION_LOAD = 2; constexpr int MAX_SUPPORTED_PCK_VERSION_SAVE = 1; +constexpr int GODOT_3_PCK_VERSION = 1; +constexpr int GODOT_4_PCK_VERSION = 2; + //! \brief A single pck file object. Handles reading and writing //! //! Probably only works on little endian systems @@ -69,12 +72,11 @@ class PckFile { std::string ReadContainedFileContents(uint64_t offset, uint64_t size); - void SetGodotVersion(uint32_t major, uint32_t minor, uint32_t patch) - { - MajorGodotVersion = major; - MinorGodotVersion = minor; - PatchGodotVersion = patch; - } + //! \brief Set the specified Godot engine version this pck says it is + //! + //! This will update the .pck file format version to also match the engine version if + //! necessary (for example Godot 4 uses pck version 2) + void SetGodotVersion(uint32_t major, uint32_t minor, uint32_t patch); //! \brief Sets a filter for entries to be added to this object //! @@ -90,7 +92,7 @@ class PckFile { } private: - // These need swaps on non little endian machine + // These need swaps on non-little endian machine uint32_t Read32(); uint64_t Read64(); void Write32(uint32_t value);