Merge pull request #89214 from bruvzg/pack_rel_off
[Export] Use relative file base offset for embedded PCK.
This commit is contained in:
commit
7e65fd8725
3 changed files with 18 additions and 2 deletions
|
@ -196,6 +196,8 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
|
|||
return false;
|
||||
}
|
||||
|
||||
int64_t pck_start_pos = f->get_position() - 4;
|
||||
|
||||
uint32_t version = f->get_32();
|
||||
uint32_t ver_major = 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();
|
||||
|
||||
bool enc_directory = (pack_flags & PACK_DIR_ENCRYPTED);
|
||||
bool rel_filebase = (pack_flags & PACK_REL_FILEBASE);
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
//reserved
|
||||
|
@ -216,6 +219,10 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
|
|||
|
||||
int file_count = f->get_32();
|
||||
|
||||
if (rel_filebase) {
|
||||
file_base += pck_start_pos;
|
||||
}
|
||||
|
||||
if (enc_directory) {
|
||||
Ref<FileAccessEncrypted> fae;
|
||||
fae.instantiate();
|
||||
|
|
|
@ -44,7 +44,8 @@
|
|||
#define PACK_FORMAT_VERSION 2
|
||||
|
||||
enum PackFlags {
|
||||
PACK_DIR_ENCRYPTED = 1 << 0
|
||||
PACK_DIR_ENCRYPTED = 1 << 0,
|
||||
PACK_REL_FILEBASE = 1 << 1,
|
||||
};
|
||||
|
||||
enum PackFileFlags {
|
||||
|
|
|
@ -1613,6 +1613,9 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
|
|||
if (enc_pck && enc_directory) {
|
||||
pack_flags |= PACK_DIR_ENCRYPTED;
|
||||
}
|
||||
if (p_embed) {
|
||||
pack_flags |= PACK_REL_FILEBASE;
|
||||
}
|
||||
f->store_32(pack_flags); // flags
|
||||
|
||||
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_store = file_base;
|
||||
if (pack_flags & PACK_REL_FILEBASE) {
|
||||
file_base_store -= pck_start_pos;
|
||||
}
|
||||
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);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
f->close();
|
||||
|
||||
DirAccess::remove_file_or_error(tmppath);
|
||||
|
||||
|
|
Loading…
Reference in a new issue