diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-09-03 07:33:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-03 07:33:19 +0200 |
commit | 4a5138bb99f5a063035c1d34de26af050bef5dc3 (patch) | |
tree | 6ed4d6eecf7ed43ff107873619260788ebcc5e50 /core/io/file_access_pack.cpp | |
parent | 71833520da2bfa39201bc9734432de47a18aaa14 (diff) | |
parent | c524d50444f98039faab75f7d701ca54a82e5848 (diff) |
Merge pull request #40400 from Arivval/load-resourcepack-with-offset
Added PCK file loading with offset feature
Diffstat (limited to 'core/io/file_access_pack.cpp')
-rw-r--r-- | core/io/file_access_pack.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 37240f234a..024ec3b2b5 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -34,9 +34,9 @@ #include <stdio.h> -Error PackedData::add_pack(const String &p_path, bool p_replace_files) { +Error PackedData::add_pack(const String &p_path, bool p_replace_files, size_t p_offset) { for (int i = 0; i < sources.size(); i++) { - if (sources[i]->try_open_pack(p_path, p_replace_files)) { + if (sources[i]->try_open_pack(p_path, p_replace_files, p_offset)) { return OK; } } @@ -123,15 +123,24 @@ PackedData::~PackedData() { ////////////////////////////////////////////////////////////////// -bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) { +bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset) { FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { return false; } + f->seek(p_offset); + uint32_t magic = f->get_32(); if (magic != PACK_HEADER_MAGIC) { + // loading with offset feature not supported for self contained exe files + if (p_offset != 0) { + f->close(); + memdelete(f); + ERR_FAIL_V_MSG(false, "Loading self-contained executable with offset not supported."); + } + //maybe at the end.... self contained exe f->seek_end(); f->seek(f->get_position() - 4); @@ -191,7 +200,7 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) uint64_t size = f->get_64(); uint8_t md5[16]; f->get_buffer(md5, 16); - PackedData::get_singleton()->add_path(p_path, path, ofs, size, md5, this, p_replace_files); + PackedData::get_singleton()->add_path(p_path, path, ofs + p_offset, size, md5, this, p_replace_files); } f->close(); |