From 50a137e3939d087a6ff8fba274b256e933043138 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Mon, 25 Feb 2019 19:37:51 +0100 Subject: [PATCH] Make export templates extraction handle subdirectories Fixes #25330 --- editor/export_template_manager.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index ce1d545510d..ad3ce90afdd 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); }