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.cpp112
1 files changed, 61 insertions, 51 deletions
diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp
index 4e499021f9..1cdf9848ef 100644
--- a/editor/export_template_manager.cpp
+++ b/editor/export_template_manager.cpp
@@ -52,18 +52,16 @@ void ExportTemplateManager::_update_template_list() {
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
Error err = d->change_dir(EditorSettings::get_singleton()->get_templates_dir());
- d->list_dir_begin();
Set<String> templates;
-
+ d->list_dir_begin();
if (err == OK) {
- bool isdir;
- String c = d->get_next(&isdir);
+ String c = d->get_next();
while (c != String()) {
- if (isdir && !c.begins_with(".")) {
+ if (d->current_is_dir() && !c.begins_with(".")) {
templates.insert(c);
}
- c = d->get_next(&isdir);
+ c = d->get_next();
}
}
d->list_dir_end();
@@ -71,6 +69,9 @@ void ExportTemplateManager::_update_template_list() {
memdelete(d);
String current_version = VERSION_FULL_CONFIG;
+ // Downloadable export templates are only available for stable, alpha, beta and RC versions.
+ // Therefore, don't display download-related features when using a development version
+ const bool downloads_available = String(VERSION_STATUS) != String("dev");
Label *current = memnew(Label);
current->set_h_size_flags(SIZE_EXPAND_FILL);
@@ -78,10 +79,14 @@ void ExportTemplateManager::_update_template_list() {
if (templates.has(current_version)) {
current->add_color_override("font_color", get_color("success_color", "Editor"));
- Button *redownload = memnew(Button);
- redownload->set_text(TTR("Re-Download"));
- current_hb->add_child(redownload);
- redownload->connect("pressed", this, "_download_template", varray(current_version));
+
+ // Only display a redownload button if it can be downloaded in the first place
+ if (downloads_available) {
+ Button *redownload = memnew(Button);
+ redownload->set_text(TTR("Redownload"));
+ current_hb->add_child(redownload);
+ redownload->connect("pressed", this, "_download_template", varray(current_version));
+ }
Button *uninstall = memnew(Button);
uninstall->set_text(TTR("Uninstall"));
@@ -93,6 +98,12 @@ void ExportTemplateManager::_update_template_list() {
current->add_color_override("font_color", get_color("error_color", "Editor"));
Button *redownload = memnew(Button);
redownload->set_text(TTR("Download"));
+
+ if (!downloads_available) {
+ redownload->set_disabled(true);
+ redownload->set_tooltip(TTR("Official export templates aren't available for development builds."));
+ }
+
redownload->connect("pressed", this, "_download_template", varray(current_version));
current_hb->add_child(redownload);
current->set_text(current_version + " " + TTR("(Missing)"));
@@ -154,18 +165,14 @@ void ExportTemplateManager::_uninstall_template_confirm() {
ERR_FAIL_COND(err != OK);
Vector<String> files;
-
d->list_dir_begin();
-
- bool isdir;
- String c = d->get_next(&isdir);
+ String c = d->get_next();
while (c != String()) {
- if (!isdir) {
+ if (!d->current_is_dir()) {
files.push_back(c);
}
- c = d->get_next(&isdir);
+ c = d->get_next();
}
-
d->list_dir_end();
for (int i = 0; i < files.size(); i++) {
@@ -314,7 +321,7 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_
if (!f) {
ret = unzGoToNextFile(pkg);
fc++;
- ERR_CONTINUE(!f);
+ ERR_CONTINUE_MSG(true, "Can't open file from path '" + String(to_write) + "'.");
}
f->store_buffer(data.ptr(), data.size());
@@ -406,9 +413,7 @@ void ExportTemplateManager::_http_download_templates_completed(int p_status, int
} break;
case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED:
case HTTPRequest::RESULT_CONNECTION_ERROR:
- case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: {
- template_list_state->set_text(TTR("Can't connect."));
- } break;
+ case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH:
case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR:
case HTTPRequest::RESULT_CANT_CONNECT: {
template_list_state->set_text(TTR("Can't connect."));
@@ -429,14 +434,16 @@ void ExportTemplateManager::_http_download_templates_completed(int p_status, int
String path = download_templates->get_download_file();
template_list_state->set_text(TTR("Download Complete."));
template_downloader->hide();
- int ret = _install_from_file(path, false);
+ bool ret = _install_from_file(path, false);
if (ret) {
- Error err = OS::get_singleton()->move_to_trash(path);
+ // Clean up downloaded file.
+ DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ Error err = da->remove(path);
if (err != OK) {
- EditorNode::get_singleton()->add_io_error(TTR("Cannot remove:") + "\n" + path + "\n");
+ EditorNode::get_singleton()->add_io_error(TTR("Cannot remove temporary file:") + "\n" + path + "\n");
}
} else {
- WARN_PRINTS(vformat(TTR("Templates installation failed. The problematic templates archives can be found at '%s'."), path));
+ EditorNode::get_singleton()->add_io_error(vformat(TTR("Templates installation failed.\nThe problematic templates archives can be found at '%s'."), path));
}
}
} break;
@@ -465,7 +472,7 @@ void ExportTemplateManager::_begin_template_download(const String &p_url) {
Error err = download_templates->request(p_url);
if (err != OK) {
- EditorNode::get_singleton()->show_warning(TTR("Error requesting url: ") + p_url);
+ EditorNode::get_singleton()->show_warning(TTR("Error requesting URL:") + " " + p_url);
return;
}
@@ -535,7 +542,6 @@ void ExportTemplateManager::_notification(int p_what) {
template_list_state->set_text(status);
if (errored) {
set_process(false);
- ;
}
}
@@ -548,25 +554,31 @@ void ExportTemplateManager::_notification(int p_what) {
bool ExportTemplateManager::can_install_android_template() {
- return FileAccess::exists(EditorSettings::get_singleton()->get_templates_dir().plus_file(VERSION_FULL_CONFIG).plus_file("android_source.zip"));
+ const String templates_dir = EditorSettings::get_singleton()->get_templates_dir().plus_file(VERSION_FULL_CONFIG);
+ return FileAccess::exists(templates_dir.plus_file("android_source.zip")) &&
+ FileAccess::exists(templates_dir.plus_file("android_release.apk")) &&
+ FileAccess::exists(templates_dir.plus_file("android_debug.apk"));
}
Error ExportTemplateManager::install_android_template() {
+ // 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);
- //make android dir (if it does not exist)
+ // Make res://android dir (if it does not exist).
da->make_dir("android");
{
- //add an empty .gdignore file to avoid scan
+ // Add an empty .gdignore file to avoid scan.
FileAccessRef f = FileAccess::open("res://android/.gdignore", FileAccess::WRITE);
ERR_FAIL_COND_V(!f, ERR_CANT_CREATE);
f->store_line("");
f->close();
}
{
- //add version, to ensure building won't work if template and Godot version don't match
+ // 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);
f->store_line(VERSION_FULL_CONFIG);
@@ -576,48 +588,46 @@ Error ExportTemplateManager::install_android_template() {
Error err = da->make_dir_recursive("android/build");
ERR_FAIL_COND_V(err != OK, err);
- String source_zip = EditorSettings::get_singleton()->get_templates_dir().plus_file(VERSION_FULL_CONFIG).plus_file("android_source.zip");
+ // Uncompress source template.
+
+ const String &templates_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(VERSION_FULL_CONFIG);
+ const String &source_zip = templates_path.plus_file("android_source.zip");
ERR_FAIL_COND_V(!FileAccess::exists(source_zip), ERR_CANT_OPEN);
FileAccess *src_f = NULL;
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
unzFile pkg = unzOpen2(source_zip.utf8().get_data(), &io);
- ERR_EXPLAIN("Android sources not in zip format");
- ERR_FAIL_COND_V(!pkg, ERR_CANT_OPEN);
+ ERR_FAIL_COND_V_MSG(!pkg, ERR_CANT_OPEN, "Android sources not in ZIP format.");
int ret = unzGoToFirstFile(pkg);
-
int total_files = 0;
- //count files
+ // Count files to unzip.
while (ret == UNZ_OK) {
total_files++;
ret = unzGoToNextFile(pkg);
}
-
ret = unzGoToFirstFile(pkg);
- //decompress files
- ProgressDialog::get_singleton()->add_task("uncompress", TTR("Uncompressing Android Build Sources"), total_files);
- Set<String> dirs_tested;
+ ProgressDialog::get_singleton()->add_task("uncompress_src", TTR("Uncompressing Android Build Sources"), total_files);
+ Set<String> dirs_tested;
int idx = 0;
while (ret == UNZ_OK) {
- //get filename
+ // Get file path.
unz_file_info info;
- char fname[16384];
- ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
-
- String name = fname;
+ char fpath[16384];
+ ret = unzGetCurrentFileInfo(pkg, &info, fpath, 16384, NULL, 0, NULL, 0);
- String base_dir = name.get_base_dir();
+ String path = fpath;
+ String base_dir = path.get_base_dir();
- if (!name.ends_with("/")) {
+ if (!path.ends_with("/")) {
Vector<uint8_t> data;
data.resize(info.uncompressed_size);
- //read
+ // Read.
unzOpenCurrentFile(pkg);
unzReadCurrentFile(pkg, data.ptrw(), data.size());
unzCloseCurrentFile(pkg);
@@ -627,7 +637,7 @@ Error ExportTemplateManager::install_android_template() {
dirs_tested.insert(base_dir);
}
- String to_write = String("res://android/build").plus_file(name);
+ String to_write = String("res://android/build").plus_file(path);
FileAccess *f = FileAccess::open(to_write, FileAccess::WRITE);
if (f) {
f->store_buffer(data.ptr(), data.size());
@@ -640,13 +650,13 @@ Error ExportTemplateManager::install_android_template() {
}
}
- ProgressDialog::get_singleton()->task_step("uncompress", name, idx);
+ ProgressDialog::get_singleton()->task_step("uncompress_src", path, idx);
idx++;
ret = unzGoToNextFile(pkg);
}
- ProgressDialog::get_singleton()->end_task("uncompress");
+ ProgressDialog::get_singleton()->end_task("uncompress_src");
unzClose(pkg);
return OK;