summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2019-02-25 19:37:51 +0100
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2019-02-25 19:56:58 +0100
commit50a137e3939d087a6ff8fba274b256e933043138 (patch)
tree7e6f1cd6bd9109d1a6c262e2b4a4577ed08afdbe
parentef61c14dda30a6923b587d516344bbdca6983660 (diff)
Make export templates extraction handle subdirectories
Fixes #25330
-rw-r--r--editor/export_template_manager.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp
index ce1d545510..ad3ce90afd 100644
--- a/editor/export_template_manager.cpp
+++ b/editor/export_template_manager.cpp
@@ -193,6 +193,7 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
int fc = 0; //count them and find version
String version;
+ String contents_dir;
while (ret == UNZ_OK) {
@@ -225,6 +226,7 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
}
version = data_str;
+ contents_dir = file.get_base_dir().trim_suffix("/").trim_suffix("\\");
}
if (file.get_file().size() != 0) {
@@ -268,7 +270,9 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
char fname[16384];
unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
- String file = String(fname).get_file();
+ String file_path(fname);
+
+ String file = file_path.get_file();
if (file.size() == 0) {
ret = unzGoToNextFile(pkg);
@@ -283,6 +287,23 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
unzReadCurrentFile(pkg, data.ptrw(), data.size());
unzCloseCurrentFile(pkg);
+ String base_dir = file_path.get_base_dir().trim_suffix("/").trim_suffix("\\");
+
+ if (base_dir != contents_dir && base_dir.begins_with(contents_dir)) {
+ base_dir = base_dir.substr(contents_dir.length(), file_path.length()).trim_prefix("/").trim_prefix("\\");
+ file = base_dir.plus_file(file);
+
+ DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ ERR_CONTINUE(!da);
+
+ String output_dir = template_path.plus_file(base_dir);
+
+ if (!DirAccess::exists(output_dir)) {
+ Error mkdir_err = da->make_dir_recursive(output_dir);
+ ERR_CONTINUE(mkdir_err != OK);
+ }
+ }
+
if (p) {
p->step(TTR("Importing:") + " " + file, fc);
}