summaryrefslogtreecommitdiffstats
path: root/platform/javascript/api/javascript_tools_editor_plugin.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-05-19 15:53:04 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-05-21 15:31:23 +0200
commitfdf66a21f1a330595f7345f3b0024e0e7cafa28a (patch)
tree4d7e4cc526f209065baba845a0e3ab15d8e99f7c /platform/javascript/api/javascript_tools_editor_plugin.cpp
parent8c2beeea907cb39baac20df198392ae4fdf64029 (diff)
downloadredot-engine-fdf66a21f1a330595f7345f3b0024e0e7cafa28a.tar.gz
[HTML5] Add easy to use download API.
New `JavaScript.download_buffer` method to create a prompt that let the user download a file.
Diffstat (limited to 'platform/javascript/api/javascript_tools_editor_plugin.cpp')
-rw-r--r--platform/javascript/api/javascript_tools_editor_plugin.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/platform/javascript/api/javascript_tools_editor_plugin.cpp b/platform/javascript/api/javascript_tools_editor_plugin.cpp
index 015440f5be..ac4e6a1256 100644
--- a/platform/javascript/api/javascript_tools_editor_plugin.cpp
+++ b/platform/javascript/api/javascript_tools_editor_plugin.cpp
@@ -41,7 +41,7 @@
// JavaScript functions defined in library_godot_editor_tools.js
extern "C" {
-extern void godot_js_editor_download_file(const char *p_path, const char *p_name, const char *p_mime);
+extern int godot_js_os_download_buffer(const uint8_t *p_buf, int p_buf_size, const char *p_name, const char *p_mime);
}
static void _javascript_editor_init_callback() {
@@ -69,7 +69,12 @@ void JavaScriptToolsEditorPlugin::_download_zip(Variant p_v) {
String base_path = resource_path.substr(0, resource_path.rfind("/")) + "/";
_zip_recursive(resource_path, base_path, zip);
zipClose(zip, nullptr);
- godot_js_editor_download_file("/tmp/project.zip", "project.zip", "application/zip");
+ FileAccess *f = FileAccess::open("/tmp/project.zip", FileAccess::READ);
+ ERR_FAIL_COND_MSG(!f, "Unable to create zip file");
+ Vector<uint8_t> buf;
+ buf.resize(f->get_len());
+ f->get_buffer(buf.ptrw(), buf.size());
+ godot_js_os_download_buffer(buf.ptr(), buf.size(), "project.zip", "application/zip");
}
void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, zipFile p_zip) {