Skip to content

Commit

Permalink
Automatically adjust the written format version based on the selected…
Browse files Browse the repository at this point in the history
… Godot version
  • Loading branch information
hhyyrylainen committed Aug 5, 2023
1 parent 0cdfea3 commit 56aa985
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/pck/PckFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 9 additions & 7 deletions src/pck/PckFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
//!
Expand All @@ -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);
Expand Down

0 comments on commit 56aa985

Please sign in to comment.