summaryrefslogtreecommitdiff
path: root/editor/export_template_manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/export_template_manager.cpp')
-rw-r--r--editor/export_template_manager.cpp84
1 files changed, 47 insertions, 37 deletions
diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp
index 3cad600002..4ca2e1fdbf 100644
--- a/editor/export_template_manager.cpp
+++ b/editor/export_template_manager.cpp
@@ -35,6 +35,7 @@
#include "core/io/json.h"
#include "core/io/zip_io.h"
#include "core/os/keyboard.h"
+#include "core/templates/rb_set.h"
#include "core/version.h"
#include "editor/editor_node.h"
#include "editor/editor_paths.h"
@@ -44,13 +45,13 @@
void ExportTemplateManager::_update_template_status() {
// Fetch installed templates from the file system.
- DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
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 + "'.");
- Set<String> templates;
+ RBSet<String> templates;
da->list_dir_begin();
if (err == OK) {
String c = da->get_next();
@@ -62,7 +63,6 @@ void ExportTemplateManager::_update_template_status() {
}
}
da->list_dir_end();
- memdelete(da);
// Update the state of the current version.
String current_version = VERSION_FULL_CONFIG;
@@ -98,7 +98,7 @@ void ExportTemplateManager::_update_template_status() {
installed_table->clear();
TreeItem *installed_root = installed_table->create_item();
- for (Set<String>::Element *E = templates.back(); E; E = E->prev()) {
+ for (RBSet<String>::Element *E = templates.back(); E; E = E->prev()) {
String version_string = E->get();
if (version_string == current_version) {
continue;
@@ -129,7 +129,7 @@ void ExportTemplateManager::_download_current() {
}
_download_template(mirror_url, true);
- } else if (!mirrors_available && !is_refreshing_mirrors) {
+ } else if (!is_refreshing_mirrors) {
_set_current_progress_status(TTR("Retrieving the mirror list..."));
_refresh_mirrors();
}
@@ -148,8 +148,8 @@ void ExportTemplateManager::_download_template(const String &p_url, bool p_skip_
download_templates->set_download_file(EditorPaths::get_singleton()->get_cache_dir().plus_file("tmp_templates.tpz"));
download_templates->set_use_threads(true);
- const String proxy_host = EDITOR_DEF("network/http_proxy/host", "");
- const int proxy_port = EDITOR_DEF("network/http_proxy/port", -1);
+ const String proxy_host = EDITOR_GET("network/http_proxy/host");
+ const int proxy_port = EDITOR_GET("network/http_proxy/port");
download_templates->set_http_proxy(proxy_host, proxy_port);
download_templates->set_https_proxy(proxy_host, proxy_port);
@@ -195,7 +195,7 @@ void ExportTemplateManager::_download_template_completed(int p_status, int p_cod
bool ret = _install_file_selected(path, true);
if (ret) {
// Clean up downloaded file.
- DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
Error err = da->remove(path);
if (err != OK) {
EditorNode::get_singleton()->add_io_error(TTR("Cannot remove temporary file:") + "\n" + path + "\n");
@@ -375,10 +375,8 @@ void ExportTemplateManager::_install_file() {
}
bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_skip_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 = nullptr;
- zlib_filefunc_def io = zipio_create_io_from_file(&fa);
+ Ref<FileAccess> io_fa;
+ zlib_filefunc_def io = zipio_create_io(&io_fa);
unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
if (!pkg) {
@@ -396,6 +394,9 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_
unz_file_info info;
char fname[16384];
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
+ if (ret != UNZ_OK) {
+ break;
+ }
String file = String::utf8(fname);
if (file.ends_with("version.txt")) {
@@ -405,6 +406,7 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_
// Read.
unzOpenCurrentFile(pkg);
ret = unzReadCurrentFile(pkg, data.ptrw(), data.size());
+ ERR_BREAK_MSG(ret < 0, vformat("An error occurred while attempting to read from file: %s. This file will not be used.", file));
unzCloseCurrentFile(pkg);
String data_str;
@@ -436,7 +438,7 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_
return false;
}
- DirAccessRef d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(version);
Error err = d->make_dir_recursive(template_path);
if (err != OK) {
@@ -456,7 +458,10 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_
// Get filename.
unz_file_info info;
char fname[16384];
- unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
+ ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
+ if (ret != UNZ_OK) {
+ break;
+ }
String file_path(String::utf8(fname).simplify_path());
@@ -472,7 +477,8 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_
// Read
unzOpenCurrentFile(pkg);
- unzReadCurrentFile(pkg, data.ptrw(), data.size());
+ ret = unzReadCurrentFile(pkg, data.ptrw(), data.size());
+ ERR_BREAK_MSG(ret < 0, vformat("An error occurred while attempting to read from file: %s. This file will not be used.", file));
unzCloseCurrentFile(pkg);
String base_dir = file_path.get_base_dir().trim_suffix("/");
@@ -481,8 +487,8 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_
base_dir = base_dir.substr(contents_dir.length(), file_path.length()).trim_prefix("/");
file = base_dir.plus_file(file);
- DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- ERR_CONTINUE(!da);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ ERR_CONTINUE(da.is_null());
String output_dir = template_path.plus_file(base_dir);
@@ -497,16 +503,16 @@ bool ExportTemplateManager::_install_file_selected(const String &p_file, bool p_
}
String to_write = template_path.plus_file(file);
- FileAccessRef f = FileAccess::open(to_write, FileAccess::WRITE);
+ Ref<FileAccess> f = FileAccess::open(to_write, FileAccess::WRITE);
- if (!f) {
+ if (f.is_null()) {
ret = unzGoToNextFile(pkg);
fc++;
ERR_CONTINUE_MSG(true, "Can't open file from path '" + String(to_write) + "'.");
}
f->store_buffer(data.ptr(), data.size());
-
+ f.unref(); // close file.
#ifndef WINDOWS_ENABLED
FileAccess::set_unix_permissions(to_write, (info.external_fa >> 16) & 0x01FF);
#endif
@@ -531,7 +537,7 @@ void ExportTemplateManager::_uninstall_template(const String &p_version) {
}
void ExportTemplateManager::_uninstall_template_confirmed() {
- DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
const String &templates_dir = EditorSettings::get_singleton()->get_templates_dir();
Error err = da->change_dir(templates_dir);
@@ -587,7 +593,10 @@ void ExportTemplateManager::_mirror_options_button_cbk(int p_id) {
}
}
-void ExportTemplateManager::_installed_table_button_cbk(Object *p_item, int p_column, int p_id) {
+void ExportTemplateManager::_installed_table_button_cbk(Object *p_item, int p_column, int p_id, MouseButton p_button) {
+ if (p_button != MouseButton::LEFT) {
+ return;
+ }
TreeItem *ti = Object::cast_to<TreeItem>(p_item);
if (!ti) {
return;
@@ -645,17 +654,16 @@ Error ExportTemplateManager::install_android_template_from_file(const String &p_
// To support custom Android builds, we install the Java source code and buildsystem
// from android_source.zip to the project's res://android folder.
- DirAccessRef da = DirAccess::open("res://");
- ERR_FAIL_COND_V(!da, ERR_CANT_CREATE);
+ Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ ERR_FAIL_COND_V(da.is_null(), ERR_CANT_CREATE);
// Make res://android dir (if it does not exist).
da->make_dir("android");
{
// Add version, to ensure building won't work if template and Godot version don't match.
- FileAccessRef f = FileAccess::open("res://android/.build_version", FileAccess::WRITE);
- ERR_FAIL_COND_V(!f, ERR_CANT_CREATE);
+ Ref<FileAccess> f = FileAccess::open("res://android/.build_version", FileAccess::WRITE);
+ ERR_FAIL_COND_V(f.is_null(), ERR_CANT_CREATE);
f->store_line(VERSION_FULL_CONFIG);
- f->close();
}
// Create the android plugins directory.
@@ -666,16 +674,15 @@ Error ExportTemplateManager::install_android_template_from_file(const String &p_
ERR_FAIL_COND_V(err != OK, err);
{
// Add an empty .gdignore file to avoid scan.
- FileAccessRef f = FileAccess::open("res://android/build/.gdignore", FileAccess::WRITE);
- ERR_FAIL_COND_V(!f, ERR_CANT_CREATE);
+ Ref<FileAccess> f = FileAccess::open("res://android/build/.gdignore", FileAccess::WRITE);
+ ERR_FAIL_COND_V(f.is_null(), ERR_CANT_CREATE);
f->store_line("");
- f->close();
}
// Uncompress source template.
- FileAccess *src_f = nullptr;
- zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
+ Ref<FileAccess> io_fa;
+ zlib_filefunc_def io = zipio_create_io(&io_fa);
unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
ERR_FAIL_COND_V_MSG(!pkg, ERR_CANT_OPEN, "Android sources not in ZIP format.");
@@ -691,13 +698,16 @@ Error ExportTemplateManager::install_android_template_from_file(const String &p_
ProgressDialog::get_singleton()->add_task("uncompress_src", TTR("Uncompressing Android Build Sources"), total_files);
- Set<String> dirs_tested;
+ HashSet<String> dirs_tested;
int idx = 0;
while (ret == UNZ_OK) {
// Get file path.
unz_file_info info;
char fpath[16384];
ret = unzGetCurrentFileInfo(pkg, &info, fpath, 16384, nullptr, 0, nullptr, 0);
+ if (ret != UNZ_OK) {
+ break;
+ }
String path = String::utf8(fpath);
String base_dir = path.get_base_dir();
@@ -717,10 +727,10 @@ Error ExportTemplateManager::install_android_template_from_file(const String &p_
}
String to_write = String("res://android/build").plus_file(path);
- FileAccess *f = FileAccess::open(to_write, FileAccess::WRITE);
- if (f) {
+ Ref<FileAccess> f = FileAccess::open(to_write, FileAccess::WRITE);
+ if (f.is_valid()) {
f->store_buffer(data.ptr(), data.size());
- memdelete(f);
+ f.unref(); // close file.
#ifndef WINDOWS_ENABLED
FileAccess::set_unix_permissions(to_write, (info.external_fa >> 16) & 0x01FF);
#endif
@@ -968,7 +978,7 @@ ExportTemplateManager::ExportTemplateManager() {
installed_table->set_custom_minimum_size(Size2(0, 100) * EDSCALE);
installed_table->set_v_size_flags(Control::SIZE_EXPAND_FILL);
main_vb->add_child(installed_table);
- installed_table->connect("button_pressed", callable_mp(this, &ExportTemplateManager::_installed_table_button_cbk));
+ installed_table->connect("button_clicked", callable_mp(this, &ExportTemplateManager::_installed_table_button_cbk));
// Dialogs.
uninstall_confirm = memnew(ConfirmationDialog);