From cb1b89dac5b9a73612ccf8f61dfcc9d55c9ad598 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 1 Mar 2021 17:53:56 +0100 Subject: [HTML5] Export process writes sizes in template. This allow the loading bar to be much more reliable, even in cases where realible stream loading status is not detectable (server-side compression, chunked encoding). --- platform/javascript/export/export.cpp | 46 +++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'platform/javascript/export/export.cpp') diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 353cc49ef8..46d0458ca1 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -242,7 +242,7 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform { return name; } - void _fix_html(Vector &p_html, const Ref &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector p_shared_objects); + void _fix_html(Vector &p_html, const Ref &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector p_shared_objects, const Dictionary &p_file_sizes); static void _server_thread_poll(void *data); @@ -281,7 +281,7 @@ public: ~EditorExportPlatformJavaScript(); }; -void EditorExportPlatformJavaScript::_fix_html(Vector &p_html, const Ref &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector p_shared_objects) { +void EditorExportPlatformJavaScript::_fix_html(Vector &p_html, const Ref &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector p_shared_objects, const Dictionary &p_file_sizes) { String str_template = String::utf8(reinterpret_cast(p_html.ptr()), p_html.size()); String str_export; Vector lines = str_template.split("\n"); @@ -300,6 +300,7 @@ void EditorExportPlatformJavaScript::_fix_html(Vector &p_html, const Re config["gdnativeLibs"] = libs; config["executable"] = p_name; config["args"] = args; + config["fileSizes"] = p_file_sizes; const String str_config = JSON::print(config); for (int i = 0; i < lines.size(); i++) { @@ -472,6 +473,8 @@ Error EditorExportPlatformJavaScript::export_project(const Ref html; + Dictionary file_sizes; do { //get filename unz_file_info info; @@ -480,6 +483,16 @@ Error EditorExportPlatformJavaScript::export_project(const Ref data; data.resize(info.uncompressed_size); @@ -490,14 +503,7 @@ Error EditorExportPlatformJavaScript::export_project(const Refshow_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.ptrw(), buf.size()); + html.resize(f->get_len()); + f->get_buffer(html.ptrw(), html.size()); memdelete(f); - _fix_html(buf, p_preset, p_path.get_file().get_basename(), p_debug, p_flags, shared_objects); - + } + { + FileAccess *f = FileAccess::open(pck_path, FileAccess::READ); + if (f) { + file_sizes[pck_path.get_file()] = (uint64_t)f->get_len(); + memdelete(f); + f = NULL; + } + _fix_html(html, p_preset, p_path.get_file().get_basename(), p_debug, p_flags, shared_objects, file_sizes); 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()); + f->store_buffer(html.ptr(), html.size()); memdelete(f); + html.resize(0); } Ref splash; -- cgit v1.2.3