diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-11-01 23:12:28 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-11-01 23:13:27 -0300 |
commit | 79f81b77e2160fd4fb490b9e8e05636de70174bf (patch) | |
tree | e1596942656e0e6d9249e3f1921530edc40824fd /editor | |
parent | 93a3d1714ee9b1535ac8f902bd7b2b3135712b90 (diff) |
-Modules can now add custom version info (added it for Mono)
-Version string takes this version info
-Ability to download templates from the interweb (listing does not work yet)
Diffstat (limited to 'editor')
-rw-r--r-- | editor/export_template_manager.cpp | 226 | ||||
-rw-r--r-- | editor/export_template_manager.h | 20 |
2 files changed, 244 insertions, 2 deletions
diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index d867404f3d..164d02c580 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -31,10 +31,10 @@ #include "editor_node.h" #include "editor_scale.h" +#include "io/json.h" #include "io/zip_io.h" #include "os/dir_access.h" #include "version.h" - void ExportTemplateManager::_update_template_list() { while (current_hb->get_child_count()) { @@ -66,7 +66,7 @@ void ExportTemplateManager::_update_template_list() { memdelete(d); - String current_version = itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "-" + _MKSTR(VERSION_STATUS); + String current_version = itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "-" + _MKSTR(VERSION_STATUS) + VERSION_MODULE_CONFIG; Label *current = memnew(Label); current->set_h_size_flags(SIZE_EXPAND_FILL); @@ -120,6 +120,16 @@ void ExportTemplateManager::_update_template_list() { void ExportTemplateManager::_download_template(const String &p_version) { print_line("download " + p_version); + while (template_list->get_child_count()) { + memdelete(template_list->get_child(0)); + } + template_downloader->popup_centered_minsize(); + template_list_state->set_text(TTR("Retrieving mirrors, please wait..")); + template_download_progress->set_max(100); + template_download_progress->set_value(0); + request_mirror->request("https://www.godotengine.org/download_mirrors.php?version=" + p_version); + template_list_state->show(); + template_download_progress->show(); } void ExportTemplateManager::_uninstall_template(const String &p_version) { @@ -307,12 +317,195 @@ void ExportTemplateManager::ok_pressed() { template_open->popup_centered_ratio(); } +void ExportTemplateManager::_http_download_mirror_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data) { + + print_line("mirror complete"); + String mirror_str = "{ \"mirrors\":[{\"name\":\"Official\",\"url\":\"http://op.godotengine.org:81/downloads/2.1.4/Godot_v2.1.4-stable_linux_server.64.zip\"}] }"; + + template_list_state->hide(); + template_download_progress->hide(); + + Variant r; + String errs; + int errline; + Error err = JSON::parse(mirror_str, r, errs, errline); + if (err != OK) { + EditorNode::get_singleton()->show_warning("Error parsing JSON with mirror list. Please report this issue!"); + return; + } + + bool mirrors_found = false; + + Dictionary d = r; + print_line(r); + if (d.has("mirrors")) { + Array mirrors = d["mirrors"]; + for (int i = 0; i < mirrors.size(); i++) { + Dictionary m = mirrors[i]; + ERR_CONTINUE(!m.has("url") || !m.has("name")); + LinkButton *lb = memnew(LinkButton); + lb->set_text(m["name"]); + lb->connect("pressed", this, "_begin_template_download", varray(m["url"])); + template_list->add_child(lb); + mirrors_found = true; + } + } + + if (!mirrors_found) { + EditorNode::get_singleton()->show_warning(TTR("No download links found for this version. Direct download is only available for official releases.")); + return; + } +} +void ExportTemplateManager::_http_download_templates_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data) { + + switch (p_status) { + + case HTTPRequest::RESULT_CANT_RESOLVE: { + template_list_state->set_text(TTR("Can't resolve.")); + } 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_SSL_HANDSHAKE_ERROR: + case HTTPRequest::RESULT_CANT_CONNECT: { + template_list_state->set_text(TTR("Can't connect.")); + } break; + case HTTPRequest::RESULT_NO_RESPONSE: { + template_list_state->set_text(TTR("No response.")); + } break; + case HTTPRequest::RESULT_REQUEST_FAILED: { + template_list_state->set_text(TTR("Req. Failed.")); + } break; + case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: { + template_list_state->set_text(TTR("Redirect Loop.")); + } break; + default: { + if (p_code != 200) { + template_list_state->set_text(TTR("Failed:") + " " + itos(p_code)); + } else { + String path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("tmp_templates.tpz"); + FileAccess *f = FileAccess::open(path, FileAccess::WRITE); + if (!f) { + template_list_state->set_text(TTR("Can't write file.")); + } else { + int size = p_data.size(); + PoolVector<uint8_t>::Read r = p_data.read(); + f->store_buffer(r.ptr(), size); + memdelete(f); + template_list_state->set_text(TTR("Download Complete.")); + template_downloader->hide(); + _install_from_file(path); + } + } + } break; + } + + set_process(false); +} + +void ExportTemplateManager::_begin_template_download(const String &p_url) { + + for (int i = 0; i < template_list->get_child_count(); i++) { + BaseButton *b = Object::cast_to<BaseButton>(template_list->get_child(0)); + if (b) { + b->set_disabled(true); + } + } + + download_data.clear(); + + Error err = download_templates->request(p_url); + if (err != OK) { + EditorNode::get_singleton()->show_warning(TTR("Error requesting url: ") + p_url); + return; + } + + set_process(true); + + template_list_state->show(); + template_download_progress->set_max(100); + template_download_progress->set_value(0); + template_download_progress->show(); + template_list_state->set_text(TTR("Connecting to Mirror..")); +} + +void ExportTemplateManager::_notification(int p_what) { + + if (p_what == NOTIFICATION_PROCESS) { + + update_countdown -= get_process_delta_time(); + + if (update_countdown > 0) { + return; + } + update_countdown = 0.5; + String status; + bool errored = false; + + switch (download_templates->get_http_client_status()) { + case HTTPClient::STATUS_DISCONNECTED: + status = TTR("Disconnected"); + errored = true; + break; + case HTTPClient::STATUS_RESOLVING: status = TTR("Resolving"); break; + case HTTPClient::STATUS_CANT_RESOLVE: + status = TTR("Can't Resolve"); + errored = true; + break; + case HTTPClient::STATUS_CONNECTING: status = TTR("Connecting.."); break; + case HTTPClient::STATUS_CANT_CONNECT: + status = TTR("Can't Conect"); + errored = true; + break; + case HTTPClient::STATUS_CONNECTED: status = TTR("Connected"); break; + case HTTPClient::STATUS_REQUESTING: status = TTR("Requesting.."); break; + case HTTPClient::STATUS_BODY: + status = TTR("Downloading"); + if (download_templates->get_body_size() > 0) { + status += " " + String::humanize_size(download_templates->get_downloaded_bytes()) + "/" + String::humanize_size(download_templates->get_body_size()); + template_download_progress->set_max(download_templates->get_body_size()); + template_download_progress->set_value(download_templates->get_downloaded_bytes()); + } else { + status += " " + String::humanize_size(download_templates->get_downloaded_bytes()); + } + break; + case HTTPClient::STATUS_CONNECTION_ERROR: + status = TTR("Connection Error"); + errored = true; + break; + case HTTPClient::STATUS_SSL_HANDSHAKE_ERROR: + status = TTR("SSL Handshake Error"); + errored = true; + break; + } + + template_list_state->set_text(status); + if (errored) { + set_process(false); + ; + } + } + + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + if (!is_visible_in_tree()) { + print_line("closed"); + download_templates->cancel_request(); + set_process(false); + } + } +} + void ExportTemplateManager::_bind_methods() { ClassDB::bind_method("_download_template", &ExportTemplateManager::_download_template); ClassDB::bind_method("_uninstall_template", &ExportTemplateManager::_uninstall_template); ClassDB::bind_method("_uninstall_template_confirm", &ExportTemplateManager::_uninstall_template_confirm); ClassDB::bind_method("_install_from_file", &ExportTemplateManager::_install_from_file); + ClassDB::bind_method("_http_download_mirror_completed", &ExportTemplateManager::_http_download_mirror_completed); + ClassDB::bind_method("_http_download_templates_completed", &ExportTemplateManager::_http_download_templates_completed); + ClassDB::bind_method("_begin_template_download", &ExportTemplateManager::_begin_template_download); } ExportTemplateManager::ExportTemplateManager() { @@ -350,4 +543,33 @@ ExportTemplateManager::ExportTemplateManager() { set_title(TTR("Export Template Manager")); set_hide_on_ok(false); + + request_mirror = memnew(HTTPRequest); + add_child(request_mirror); + request_mirror->connect("request_completed", this, "_http_download_mirror_completed"); + + download_templates = memnew(HTTPRequest); + add_child(download_templates); + download_templates->connect("request_completed", this, "_http_download_templates_completed"); + + template_downloader = memnew(AcceptDialog); + template_downloader->set_title(TTR("Download Templates")); + template_downloader->get_ok()->set_text(TTR("Close")); + add_child(template_downloader); + + VBoxContainer *vbc = memnew(VBoxContainer); + template_downloader->add_child(vbc); + ScrollContainer *sc = memnew(ScrollContainer); + sc->set_custom_minimum_size(Size2(400, 200) * EDSCALE); + vbc->add_margin_child(TTR("Select mirror from list: "), sc); + template_list = memnew(VBoxContainer); + sc->add_child(template_list); + sc->set_enable_v_scroll(true); + sc->set_enable_h_scroll(false); + template_list_state = memnew(Label); + vbc->add_child(template_list_state); + template_download_progress = memnew(ProgressBar); + vbc->add_child(template_download_progress); + + update_countdown = 0; } diff --git a/editor/export_template_manager.h b/editor/export_template_manager.h index c77f85688f..644c6b466b 100644 --- a/editor/export_template_manager.h +++ b/editor/export_template_manager.h @@ -33,13 +33,20 @@ #include "editor/editor_settings.h" #include "scene/gui/dialogs.h" #include "scene/gui/file_dialog.h" +#include "scene/gui/progress_bar.h" #include "scene/gui/scroll_container.h" +#include "scene/main/http_request.h" class ExportTemplateVersion; class ExportTemplateManager : public ConfirmationDialog { GDCLASS(ExportTemplateManager, ConfirmationDialog) + AcceptDialog *template_downloader; + VBoxContainer *template_list; + Label *template_list_state; + ProgressBar *template_download_progress; + ScrollContainer *installed_scroll; VBoxContainer *installed_vb; HBoxContainer *current_hb; @@ -48,6 +55,13 @@ class ExportTemplateManager : public ConfirmationDialog { ConfirmationDialog *remove_confirm; String to_remove; + HTTPRequest *request_mirror; + HTTPRequest *download_templates; + + Vector<uint8_t> download_data; + + float update_countdown; + void _update_template_list(); void _download_template(const String &p_version); @@ -57,7 +71,13 @@ class ExportTemplateManager : public ConfirmationDialog { virtual void ok_pressed(); void _install_from_file(const String &p_file); + 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 _begin_template_download(const String &p_url); + protected: + void _notification(int p_what); static void _bind_methods(); public: |