Merge pull request #89214 from bruvzg/pack_rel_off

[Export] Use relative file base offset for embedded PCK.
This commit is contained in:
Rémi Verschelde 2024-03-07 00:24:00 +01:00
commit 7e65fd8725
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 18 additions and 2 deletions

View file

@ -196,6 +196,8 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
return false; return false;
} }
int64_t pck_start_pos = f->get_position() - 4;
uint32_t version = f->get_32(); uint32_t version = f->get_32();
uint32_t ver_major = f->get_32(); uint32_t ver_major = f->get_32();
uint32_t ver_minor = f->get_32(); uint32_t ver_minor = f->get_32();
@ -208,6 +210,7 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
uint64_t file_base = f->get_64(); uint64_t file_base = f->get_64();
bool enc_directory = (pack_flags & PACK_DIR_ENCRYPTED); bool enc_directory = (pack_flags & PACK_DIR_ENCRYPTED);
bool rel_filebase = (pack_flags & PACK_REL_FILEBASE);
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
//reserved //reserved
@ -216,6 +219,10 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
int file_count = f->get_32(); int file_count = f->get_32();
if (rel_filebase) {
file_base += pck_start_pos;
}
if (enc_directory) { if (enc_directory) {
Ref<FileAccessEncrypted> fae; Ref<FileAccessEncrypted> fae;
fae.instantiate(); fae.instantiate();

View file

@ -44,7 +44,8 @@
#define PACK_FORMAT_VERSION 2 #define PACK_FORMAT_VERSION 2
enum PackFlags { enum PackFlags {
PACK_DIR_ENCRYPTED = 1 << 0 PACK_DIR_ENCRYPTED = 1 << 0,
PACK_REL_FILEBASE = 1 << 1,
}; };
enum PackFileFlags { enum PackFileFlags {

View file

@ -1613,6 +1613,9 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
if (enc_pck && enc_directory) { if (enc_pck && enc_directory) {
pack_flags |= PACK_DIR_ENCRYPTED; pack_flags |= PACK_DIR_ENCRYPTED;
} }
if (p_embed) {
pack_flags |= PACK_REL_FILEBASE;
}
f->store_32(pack_flags); // flags f->store_32(pack_flags); // flags
uint64_t file_base_ofs = f->get_position(); uint64_t file_base_ofs = f->get_position();
@ -1703,8 +1706,12 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
} }
uint64_t file_base = f->get_position(); uint64_t file_base = f->get_position();
uint64_t file_base_store = file_base;
if (pack_flags & PACK_REL_FILEBASE) {
file_base_store -= pck_start_pos;
}
f->seek(file_base_ofs); f->seek(file_base_ofs);
f->store_64(file_base); // update files base f->store_64(file_base_store); // update files base
f->seek(file_base); f->seek(file_base);
// Save the rest of the data. // Save the rest of the data.
@ -1745,6 +1752,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
*r_embedded_size = f->get_position() - embed_pos; *r_embedded_size = f->get_position() - embed_pos;
} }
} }
f->close();
DirAccess::remove_file_or_error(tmppath); DirAccess::remove_file_or_error(tmppath);