Remove cached .tpz archive after templates download and install

Closes #20640.
This commit is contained in:
Rémi Verschelde 2018-08-13 12:46:02 +02:00
parent ec1e8843cf
commit 812d0aba42
2 changed files with 17 additions and 7 deletions

View File

@ -178,7 +178,7 @@ void ExportTemplateManager::_uninstall_template_confirm() {
_update_template_list(); _update_template_list();
} }
void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_progress) { bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_progress) {
FileAccess *fa = NULL; FileAccess *fa = NULL;
zlib_filefunc_def io = zipio_create_io_from_file(&fa); zlib_filefunc_def io = zipio_create_io_from_file(&fa);
@ -187,7 +187,7 @@ void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
if (!pkg) { if (!pkg) {
EditorNode::get_singleton()->show_warning(TTR("Can't open export templates zip.")); EditorNode::get_singleton()->show_warning(TTR("Can't open export templates zip."));
return; return false;
} }
int ret = unzGoToFirstFile(pkg); int ret = unzGoToFirstFile(pkg);
@ -221,7 +221,7 @@ void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
if (data_str.get_slice_count(".") < 3) { if (data_str.get_slice_count(".") < 3) {
EditorNode::get_singleton()->show_warning(vformat(TTR("Invalid version.txt format inside templates: %s."), data_str)); EditorNode::get_singleton()->show_warning(vformat(TTR("Invalid version.txt format inside templates: %s."), data_str));
unzClose(pkg); unzClose(pkg);
return; return false;
} }
version = data_str; version = data_str;
@ -237,7 +237,7 @@ void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
if (version == String()) { if (version == String()) {
EditorNode::get_singleton()->show_warning(TTR("No version.txt found inside templates.")); EditorNode::get_singleton()->show_warning(TTR("No version.txt found inside templates."));
unzClose(pkg); unzClose(pkg);
return; return false;
} }
String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(version); String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(version);
@ -247,7 +247,7 @@ void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
if (err != OK) { if (err != OK) {
EditorNode::get_singleton()->show_warning(TTR("Error creating path for templates:") + "\n" + template_path); EditorNode::get_singleton()->show_warning(TTR("Error creating path for templates:") + "\n" + template_path);
unzClose(pkg); unzClose(pkg);
return; return false;
} }
memdelete(d); memdelete(d);
@ -310,6 +310,8 @@ void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
unzClose(pkg); unzClose(pkg);
_update_template_list(); _update_template_list();
return true;
} }
void ExportTemplateManager::popup_manager() { void ExportTemplateManager::popup_manager() {
@ -401,7 +403,15 @@ void ExportTemplateManager::_http_download_templates_completed(int p_status, int
String path = download_templates->get_download_file(); String path = download_templates->get_download_file();
template_list_state->set_text(TTR("Download Complete.")); template_list_state->set_text(TTR("Download Complete."));
template_downloader->hide(); template_downloader->hide();
_install_from_file(path, false); int ret = _install_from_file(path, false);
if (ret) {
Error err = OS::get_singleton()->move_to_trash(path);
if (err != OK) {
EditorNode::get_singleton()->add_io_error(TTR("Cannot remove:") + "\n" + path + "\n");
}
} else {
WARN_PRINTS(vformat(TTR("Templates installation failed. The problematic templates archives can be found at '%s'."), path));
}
} }
} break; } break;
} }

View File

@ -70,7 +70,7 @@ class ExportTemplateManager : public ConfirmationDialog {
void _uninstall_template_confirm(); void _uninstall_template_confirm();
virtual void ok_pressed(); virtual void ok_pressed();
void _install_from_file(const String &p_file, bool p_use_progress = true); bool _install_from_file(const String &p_file, bool p_use_progress = true);
void _http_download_mirror_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data); void _http_download_mirror_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data);
void _http_download_templates_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data); void _http_download_templates_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data);