summaryrefslogtreecommitdiffstats
path: root/core/io/file_access_zip.cpp
diff options
context:
space:
mode:
authorMichael Alexsander <michaelalexsander@protonmail.com>2020-01-17 22:26:44 -0300
committerMichael Alexsander <michaelalexsander@protonmail.com>2020-04-16 22:52:26 -0300
commit3c261e0dfa19d9c661ad6ca908a3b8ccee050016 (patch)
tree7850bd7338298f0aeb5831c179cfa5ec650afe43 /core/io/file_access_zip.cpp
parent30ab5c9baae1cad3e157d906395a4eb8cef77e42 (diff)
downloadredot-engine-3c261e0dfa19d9c661ad6ca908a3b8ccee050016.tar.gz
Made possible to specify where to dump the contents when loading a ".pck" file
Diffstat (limited to 'core/io/file_access_zip.cpp')
-rw-r--r--core/io/file_access_zip.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp
index 57de66afaf..5696e47193 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -160,7 +160,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
return pkg;
}
-bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) {
+bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, const String &p_destination) {
//printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0)
@@ -206,7 +206,26 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) {
f.package = pkg_num;
unzGetFilePos(zfile, &f.file_pos);
- String fname = String("res://") + filename_inzip;
+ String fname;
+ if (p_destination != "") {
+ String destination = "res://" + p_destination;
+ if (!destination.ends_with("/")) {
+ destination += "/";
+ }
+
+ DirAccess *dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ if (!dir->dir_exists(destination)) {
+ memdelete(dir);
+
+ return false;
+ }
+ memdelete(dir);
+
+ fname = destination + filename_inzip;
+ } else {
+ fname = String("res://") + filename_inzip;
+ }
+
files[fname] = f;
uint8_t md5[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };