diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2019-02-25 20:46:58 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-25 20:46:58 +0100 | 
| commit | 51c1d55cf9089cefbde034893b4784a5d554ddcc (patch) | |
| tree | 734883720bbb6a9ef4d4cc1e68182281c8d0858a | |
| parent | 8930347c48f4bc961746ec7ebe168ed013e07a28 (diff) | |
| parent | 50a137e3939d087a6ff8fba274b256e933043138 (diff) | |
Merge pull request #26283 from neikeq/issue-25330
Make export templates extraction handle subdirectories
| -rw-r--r-- | editor/export_template_manager.cpp | 23 | 
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);  		}  |