Skip to content

Commit 206e571

Browse files
feat(vpkpp): support latest PCK flag addition, removing files without removing their contents
1 parent 9b44cc1 commit 206e571

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

include/vpkpp/format/PCK.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@ constexpr std::string_view PCK_EXTENSION = ".pck";
1212

1313
class PCK : public PackFile {
1414
protected:
15-
enum FlagsV2 : uint32_t {
16-
FLAG_NONE = 0,
17-
FLAG_ENCRYPTED = 1 << 0,
18-
FLAG_RELATIVE_FILE_DATA = 1 << 1,
15+
enum FlagsDirV2 : uint32_t {
16+
FLAG_DIR_NONE = 0,
17+
FLAG_DIR_ENCRYPTED = 1 << 0,
18+
FLAG_DIR_RELATIVE_FILE_DATA = 1 << 1,
19+
};
20+
21+
enum FlagsFileV2 : uint32_t {
22+
FLAG_FILE_NONE = 0,
23+
FLAG_FILE_ENCRYPTED = 1 << 0,
24+
FLAG_FILE_REMOVED = 1 << 1,
1925
};
2026

2127
struct Header {
2228
uint32_t packVersion;
2329
uint32_t godotVersionMajor;
2430
uint32_t godotVersionMinor;
2531
uint32_t godotVersionPatch;
26-
FlagsV2 flags; // packVersion >= 2
32+
FlagsDirV2 flags; // packVersion >= 2
2733
};
2834

2935
public:

src/vpkpp/format/PCK.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ std::unique_ptr<PackFile> PCK::create(const std::string& path, uint32_t version,
3434

3535
if (version > 1) {
3636
stream
37-
.write(FlagsV2::FLAG_NONE)
37+
.write(FLAG_DIR_NONE)
3838
.write<uint64_t>(0);
3939
}
4040

@@ -80,20 +80,20 @@ std::unique_ptr<PackFile> PCK::open(const std::string& path, const EntryCallback
8080
reader.read(pck->header.godotVersionMinor);
8181
reader.read(pck->header.godotVersionPatch);
8282

83-
pck->header.flags = FLAG_NONE;
83+
pck->header.flags = FLAG_DIR_NONE;
8484
std::size_t extraEntryContentsOffset = 0;
8585
if (pck->header.packVersion > 1) {
86-
pck->header.flags = reader.read<FlagsV2>();
86+
pck->header.flags = reader.read<FlagsDirV2>();
8787
extraEntryContentsOffset = reader.read<uint64_t>();
8888
}
8989

90-
if (pck->header.flags & FLAG_ENCRYPTED) {
90+
if (pck->header.flags & FLAG_DIR_ENCRYPTED) {
9191
// File directory is encrypted
9292
return nullptr;
9393
}
94-
if (pck->header.flags & FLAG_RELATIVE_FILE_DATA) {
94+
if (pck->header.flags & FLAG_DIR_RELATIVE_FILE_DATA) {
9595
extraEntryContentsOffset += pck->startOffset;
96-
pck->header.flags = static_cast<FlagsV2>(pck->header.flags & ~FLAG_RELATIVE_FILE_DATA);
96+
pck->header.flags = static_cast<FlagsDirV2>(pck->header.flags & ~FLAG_DIR_RELATIVE_FILE_DATA);
9797
}
9898

9999
// Reserved
@@ -115,6 +115,9 @@ std::unique_ptr<PackFile> PCK::open(const std::string& path, const EntryCallback
115115

116116
if (pck->header.packVersion > 1) {
117117
entry.flags = reader.read<uint32_t>();
118+
if (entry.flags & FLAG_FILE_REMOVED) {
119+
continue;
120+
}
118121
}
119122

120123
pck->entries.emplace(entryPath, entry);
@@ -141,7 +144,7 @@ std::optional<std::vector<std::byte>> PCK::readEntry(const std::string& path_) c
141144
}
142145

143146
// It's baked into the file on disk
144-
if (entry->flags & FLAG_ENCRYPTED) {
147+
if (entry->flags & FLAG_FILE_ENCRYPTED) {
145148
// File is encrypted
146149
return std::nullopt;
147150
}
@@ -297,7 +300,7 @@ PCK::operator std::string() const {
297300
if (this->startOffset > 0) {
298301
out += " | Embedded";
299302
}
300-
if (this->header.flags & FLAG_ENCRYPTED) {
303+
if (this->header.flags & FLAG_DIR_ENCRYPTED) {
301304
out += " | Encrypted";
302305
}
303306
return out;

0 commit comments

Comments
 (0)