MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / try_open_pack

Method try_open_pack

utility/file_access_apk.cpp:170–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170bool APKArchive::try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset, const Vector<uint8_t> &p_decryption_key) {
171 // load with offset feature only supported for PCK files
172 ERR_FAIL_COND_V_MSG(p_offset != 0, false, "Invalid PCK data. Note that loading files with a non-zero offset isn't supported with ZIP archives.");
173 String pack_path = p_path.replace("_GDRE_a_really_dumb_hack", "");
174 String ext = pack_path.get_extension().to_lower();
175 // This handles zip files, too
176 if (ext != "apk" && ext != "zip") {
177 return false;
178 }
179 bool is_apk = ext == "apk";
180 zlib_filefunc64_def io;
181 memset(&io, 0, sizeof(io));
182
183 io.opaque = nullptr;
184 io.zopen64_file = godot_open;
185 io.zread_file = godot_read;
186 io.zwrite_file = godot_write;
187
188 io.ztell64_file = godot_tell;
189 io.zseek64_file = godot_seek;
190 io.zclose_file = godot_close;
191 io.zerror_file = godot_testerror;
192
193 io.alloc_mem = godot_alloc;
194 io.free_mem = godot_free;
195
196 unzFile zfile = unzOpen2_64(pack_path.utf8().get_data(), &io);
197 ERR_FAIL_COND_V(!zfile, false);
198
199 unz_global_info64 gi;
200 int err = unzGetGlobalInfo64(zfile, &gi);
201 ERR_FAIL_COND_V(err != UNZ_OK, false);
202
203 Package pkg;
204 pkg.filename = pack_path;
205 pkg.zfile = zfile;
206 packages.push_back(pkg);
207 int pkg_num = packages.size() - 1;
208 uint32_t asset_count = 0;
209 uint32_t fmt_ver = 1;
210 Ref<GodotVer> godot_ver;
211 godot_ver.instantiate();
212 String ver_string = "unknown";
213 for (uint64_t i = 0; i < gi.number_entry; i++) {
214 char filename_inzip[256];
215
216 unz_file_info64 file_info;
217 err = unzGetCurrentFileInfo64(zfile, &file_info, filename_inzip, sizeof(filename_inzip), nullptr, 0, nullptr, 0);
218 ERR_CONTINUE(err != UNZ_OK);
219
220 File f;
221 f.package = pkg_num;
222
223 unzGetFilePos(zfile, &f.file_pos);
224 String original_fname = String::utf8(filename_inzip);
225 String fname;
226 if (is_apk) {
227 if (original_fname == "AndroidManifest.xml") {

Callers

nothing calls this directly

Calls 7

parseFunction · 0.85
push_backMethod · 0.80
add_pack_infoMethod · 0.80
get_dataMethod · 0.45
sizeMethod · 0.45
add_pathMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected