You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-15 13:51:40 +00:00
Fix uninstallation of mono templates directory
The previous code didn't take into account that templates directories can have subdirectories like the mono templates have. Also fix an unclosed dir handle.
This commit is contained in:
@@ -155,38 +155,27 @@ void ExportTemplateManager::_uninstall_template(const String &p_version) {
|
|||||||
|
|
||||||
void ExportTemplateManager::_uninstall_template_confirm() {
|
void ExportTemplateManager::_uninstall_template_confirm() {
|
||||||
|
|
||||||
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||||
Error err = d->change_dir(EditorSettings::get_singleton()->get_templates_dir());
|
const String &templates_dir = EditorSettings::get_singleton()->get_templates_dir();
|
||||||
|
Error err = da->change_dir(templates_dir);
|
||||||
|
ERR_FAIL_COND_MSG(err != OK, "Could not access templates directory at '" + templates_dir + "'.");
|
||||||
|
err = da->change_dir(to_remove);
|
||||||
|
ERR_FAIL_COND_MSG(err != OK, "Could not access templates directory at '" + templates_dir.plus_file(to_remove) + "'.");
|
||||||
|
|
||||||
ERR_FAIL_COND(err != OK);
|
err = da->erase_contents_recursive();
|
||||||
|
ERR_FAIL_COND_MSG(err != OK, "Could not remove all templates in '" + templates_dir.plus_file(to_remove) + "'.");
|
||||||
|
|
||||||
err = d->change_dir(to_remove);
|
da->change_dir("..");
|
||||||
|
da->remove(to_remove);
|
||||||
ERR_FAIL_COND(err != OK);
|
ERR_FAIL_COND_MSG(err != OK, "Could not remove templates directory at '" + templates_dir.plus_file(to_remove) + "'.");
|
||||||
|
|
||||||
Vector<String> files;
|
|
||||||
d->list_dir_begin();
|
|
||||||
String c = d->get_next();
|
|
||||||
while (c != String()) {
|
|
||||||
if (!d->current_is_dir()) {
|
|
||||||
files.push_back(c);
|
|
||||||
}
|
|
||||||
c = d->get_next();
|
|
||||||
}
|
|
||||||
d->list_dir_end();
|
|
||||||
|
|
||||||
for (int i = 0; i < files.size(); i++) {
|
|
||||||
d->remove(files[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
d->change_dir("..");
|
|
||||||
d->remove(to_remove);
|
|
||||||
|
|
||||||
_update_template_list();
|
_update_template_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool 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) {
|
||||||
|
|
||||||
|
// unzClose() will take care of closing the file stored in the unzFile,
|
||||||
|
// so we don't need to `memdelete(fa)` in this method.
|
||||||
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);
|
||||||
|
|
||||||
@@ -251,7 +240,7 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
|
|||||||
|
|
||||||
String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(version);
|
String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(version);
|
||||||
|
|
||||||
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
DirAccessRef d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||||
Error err = d->make_dir_recursive(template_path);
|
Error err = d->make_dir_recursive(template_path);
|
||||||
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);
|
||||||
@@ -259,8 +248,6 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memdelete(d);
|
|
||||||
|
|
||||||
ret = unzGoToFirstFile(pkg);
|
ret = unzGoToFirstFile(pkg);
|
||||||
|
|
||||||
EditorProgress *p = NULL;
|
EditorProgress *p = NULL;
|
||||||
@@ -316,7 +303,7 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
|
|||||||
}
|
}
|
||||||
|
|
||||||
String to_write = template_path.plus_file(file);
|
String to_write = template_path.plus_file(file);
|
||||||
FileAccess *f = FileAccess::open(to_write, FileAccess::WRITE);
|
FileAccessRef f = FileAccess::open(to_write, FileAccess::WRITE);
|
||||||
|
|
||||||
if (!f) {
|
if (!f) {
|
||||||
ret = unzGoToNextFile(pkg);
|
ret = unzGoToNextFile(pkg);
|
||||||
@@ -326,8 +313,6 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
|
|||||||
|
|
||||||
f->store_buffer(data.ptr(), data.size());
|
f->store_buffer(data.ptr(), data.size());
|
||||||
|
|
||||||
memdelete(f);
|
|
||||||
|
|
||||||
#ifndef WINDOWS_ENABLED
|
#ifndef WINDOWS_ENABLED
|
||||||
FileAccess::set_unix_permissions(to_write, (info.external_fa >> 16) & 0x01FF);
|
FileAccess::set_unix_permissions(to_write, (info.external_fa >> 16) & 0x01FF);
|
||||||
#endif
|
#endif
|
||||||
@@ -343,7 +328,6 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
|
|||||||
unzClose(pkg);
|
unzClose(pkg);
|
||||||
|
|
||||||
_update_template_list();
|
_update_template_list();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user