diff --git a/include/vpkpp/format/PCK.h b/include/vpkpp/format/PCK.h index 844c80ad7..68712d624 100644 --- a/include/vpkpp/format/PCK.h +++ b/include/vpkpp/format/PCK.h @@ -12,10 +12,16 @@ constexpr std::string_view PCK_EXTENSION = ".pck"; class PCK : public PackFile { protected: - enum FlagsV2 : uint32_t { - FLAG_NONE = 0, - FLAG_ENCRYPTED = 1 << 0, - FLAG_RELATIVE_FILE_DATA = 1 << 1, + enum FlagsDirV2 : uint32_t { + FLAG_DIR_NONE = 0, + FLAG_DIR_ENCRYPTED = 1 << 0, + FLAG_DIR_RELATIVE_FILE_DATA = 1 << 1, + }; + + enum FlagsFileV2 : uint32_t { + FLAG_FILE_NONE = 0, + FLAG_FILE_ENCRYPTED = 1 << 0, + FLAG_FILE_REMOVED = 1 << 1, }; struct Header { @@ -23,7 +29,7 @@ class PCK : public PackFile { uint32_t godotVersionMajor; uint32_t godotVersionMinor; uint32_t godotVersionPatch; - FlagsV2 flags; // packVersion >= 2 + FlagsDirV2 flags; // packVersion >= 2 }; public: diff --git a/src/vpkpp/format/PCK.cpp b/src/vpkpp/format/PCK.cpp index 5a30efa33..0c74a5b83 100644 --- a/src/vpkpp/format/PCK.cpp +++ b/src/vpkpp/format/PCK.cpp @@ -34,7 +34,7 @@ std::unique_ptr PCK::create(const std::string& path, uint32_t version, if (version > 1) { stream - .write(FlagsV2::FLAG_NONE) + .write(FLAG_DIR_NONE) .write(0); } @@ -80,20 +80,20 @@ std::unique_ptr PCK::open(const std::string& path, const EntryCallback reader.read(pck->header.godotVersionMinor); reader.read(pck->header.godotVersionPatch); - pck->header.flags = FLAG_NONE; + pck->header.flags = FLAG_DIR_NONE; std::size_t extraEntryContentsOffset = 0; if (pck->header.packVersion > 1) { - pck->header.flags = reader.read(); + pck->header.flags = reader.read(); extraEntryContentsOffset = reader.read(); } - if (pck->header.flags & FLAG_ENCRYPTED) { + if (pck->header.flags & FLAG_DIR_ENCRYPTED) { // File directory is encrypted return nullptr; } - if (pck->header.flags & FLAG_RELATIVE_FILE_DATA) { + if (pck->header.flags & FLAG_DIR_RELATIVE_FILE_DATA) { extraEntryContentsOffset += pck->startOffset; - pck->header.flags = static_cast(pck->header.flags & ~FLAG_RELATIVE_FILE_DATA); + pck->header.flags = static_cast(pck->header.flags & ~FLAG_DIR_RELATIVE_FILE_DATA); } // Reserved @@ -115,6 +115,9 @@ std::unique_ptr PCK::open(const std::string& path, const EntryCallback if (pck->header.packVersion > 1) { entry.flags = reader.read(); + if (entry.flags & FLAG_FILE_REMOVED) { + continue; + } } pck->entries.emplace(entryPath, entry); @@ -141,7 +144,7 @@ std::optional> PCK::readEntry(const std::string& path_) c } // It's baked into the file on disk - if (entry->flags & FLAG_ENCRYPTED) { + if (entry->flags & FLAG_FILE_ENCRYPTED) { // File is encrypted return std::nullopt; } @@ -297,7 +300,7 @@ PCK::operator std::string() const { if (this->startOffset > 0) { out += " | Embedded"; } - if (this->header.flags & FLAG_ENCRYPTED) { + if (this->header.flags & FLAG_DIR_ENCRYPTED) { out += " | Encrypted"; } return out;