diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 9e741860dee..943f6d8f35a 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -30,6 +30,7 @@ #include "editor/editor_node.h" #include "editor_export.h" #include "io/zip_io.h" +#include "main/splash.gen.h" #include "platform/javascript/logo.gen.h" #include "platform/javascript/run_icon.gen.h" @@ -115,6 +116,7 @@ void EditorExportPlatformJavaScript::get_export_options(List *r_op r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), false)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), true)); r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false)); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/custom_html_shell", PROPERTY_HINT_GLOBAL_FILE, "html"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/head_include", PROPERTY_HINT_MULTILINE_TEXT), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "zip"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "zip"), "")); @@ -156,6 +158,7 @@ Error EditorExportPlatformJavaScript::export_project(const Refget("custom_template/debug"); String custom_release = p_preset->get("custom_template/release"); + String custom_html = p_preset->get("html/custom_html_shell"); String template_path = p_debug ? custom_debug : custom_release; @@ -181,14 +184,6 @@ Error EditorExportPlatformJavaScript::export_project(const Refshow_warning(TTR("Could not read file:\n") + pck_path); - return ERR_FILE_CANT_READ; - } - size_t pack_size = f->get_len(); - memdelete(f); - FileAccess *src_f = NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); unzFile pkg = unzOpen2(template_path.utf8().get_data(), &io); @@ -199,13 +194,17 @@ Error EditorExportPlatformJavaScript::export_project(const Refshow_warning(TTR("Invalid export template:\n") + template_path); + unzClose(pkg); + return ERR_FILE_CORRUPT; + } + do { //get filename unz_file_info info; char fname[16384]; - ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); + unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); String file = fname; @@ -221,8 +220,12 @@ Error EditorExportPlatformJavaScript::export_project(const Refstore_buffer(data.ptr(), data.size()); memdelete(f); - ret = unzGoToNextFile(pkg); + } while (unzGoToNextFile(pkg) == UNZ_OK); + unzClose(pkg); + + if (!custom_html.empty()) { + + FileAccess *f = FileAccess::open(custom_html, FileAccess::READ); + if (!f) { + EditorNode::get_singleton()->show_warning(TTR("Could not read custom HTML shell:\n") + custom_html); + return ERR_FILE_CANT_READ; + } + Vector buf; + buf.resize(f->get_len()); + f->get_buffer(buf.ptr(), buf.size()); + memdelete(f); + _fix_html(buf, p_preset, p_path.get_file().get_basename(), p_debug); + + f = FileAccess::open(p_path, FileAccess::WRITE); + if (!f) { + EditorNode::get_singleton()->show_warning(TTR("Could not write file:\n") + p_path); + return ERR_FILE_CANT_WRITE; + } + f->store_buffer(buf.ptr(), buf.size()); + memdelete(f); } + Ref splash; + String splash_path = GLOBAL_GET("application/boot_splash/image"); + splash_path = splash_path.strip_edges(); + if (!splash_path.empty()) { + splash.instance(); + Error err = splash->load(splash_path); + if (err) { + EditorNode::get_singleton()->show_warning(TTR("Could not read boot splash image file:\n") + splash_path + "\nUsing default boot splash image"); + splash.unref(); + } + } + if (splash.is_null()) { + splash = Ref(memnew(Image(boot_splash_png))); + } + String png_path = p_path.get_base_dir().plus_file(p_path.get_file().get_basename() + ".png"); + if (splash->save_png(png_path) != OK) { + EditorNode::get_singleton()->show_warning(TTR("Could not write file:\n") + png_path); + return ERR_FILE_CANT_WRITE; + } return OK; }