From 985f2524301940192e29f6fbb4f9fb98e0d00d94 Mon Sep 17 00:00:00 2001 From: Nordup Date: Sun, 25 Jun 2023 16:46:46 +0400 Subject: [PATCH] download_shared_lib --- project/scripts/loading/file_downloader.gd | 21 +++++++++++++++++++++ project/scripts/loading/gate_loader.gd | 4 ++-- project/scripts/loading/sandbox_manager.gd | 3 ++- project/scripts/resources/gate.gd | 8 +++----- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/project/scripts/loading/file_downloader.gd b/project/scripts/loading/file_downloader.gd index 6329a4b..71abbda 100644 --- a/project/scripts/loading/file_downloader.gd +++ b/project/scripts/loading/file_downloader.gd @@ -26,5 +26,26 @@ func download(url: String) -> String: return save_path if err == OK else "" +# Returns directory where file was downloaded. Keeps filename +func download_shared_lib(url: String, gate_url: String) -> String: + var dir = folder + "/" + gate_url.md5_text() + var save_path = dir + "/" + url.get_file() + if FileAccess.file_exists(save_path): + await get_tree().process_frame # TODO: remove workaround + return dir + DirAccess.make_dir_recursive_absolute(dir) + + var http = HTTPRequest.new() + http.use_threads = true + add_child(http) + + http.download_file = save_path + var err = http.request(url) + await http.request_completed + + remove_child(http) + return dir if err == OK else "" + + func _exit_tree() -> void: FileTools.remove_recursive(folder) diff --git a/project/scripts/loading/gate_loader.gd b/project/scripts/loading/gate_loader.gd index f6a106f..431d675 100644 --- a/project/scripts/loading/gate_loader.gd +++ b/project/scripts/loading/gate_loader.gd @@ -15,13 +15,13 @@ func load_gate(config_url: String) -> void: c_gate = ConfigGate.new(config_path, config_url) var image_path = await FileDownloader.download(c_gate.image_url) - var gate = Gate.create(config_url, c_gate.title, c_gate.description, image_path, "", "", "") + var gate = Gate.create(config_url, c_gate.title, c_gate.description, image_path, "", "") gate_events.gate_info_loaded_emit(gate) gate.resource_pack = await FileDownloader.download(c_gate.resource_pack_url) Debug.logclr("Downloading GDExtension libraries: " + str(c_gate.libraries), Color.DIM_GRAY) for lib in c_gate.libraries: - var lib_path = await FileDownloader.download(lib) + gate.shared_libs_dir = await FileDownloader.download_shared_lib(lib, config_url) gate_events.gate_loaded_emit(gate) diff --git a/project/scripts/loading/sandbox_manager.gd b/project/scripts/loading/sandbox_manager.gd index e032988..d48d024 100644 --- a/project/scripts/loading/sandbox_manager.gd +++ b/project/scripts/loading/sandbox_manager.gd @@ -17,9 +17,10 @@ func create_process(gate: Gate) -> void: Debug.logerr("Sandbox executable not found at " + snbx_executable.path); return var pack_file = ProjectSettings.globalize_path(gate.resource_pack) + var shared_libs = ProjectSettings.globalize_path(gate.shared_libs_dir) var args = [ "--main-pack", pack_file, - "--gdext-libs-dir", "/home/nordup/projects/godot/the-gates-folder/ServerFiles/exports/rust", + "--gdext-libs-dir", shared_libs, "--resolution", "%dx%d" % [render_result.width, render_result.height] ] Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DARK_VIOLET) diff --git a/project/scripts/resources/gate.gd b/project/scripts/resources/gate.gd index 344f08a..f3d405f 100644 --- a/project/scripts/resources/gate.gd +++ b/project/scripts/resources/gate.gd @@ -7,19 +7,17 @@ class_name Gate @export var title: String @export var description: String @export_file("*.png", "*.jpg") var image: String -var godot_config: String -var global_script_class: String var resource_pack: String +var shared_libs_dir: String static func create(_url: String, _title: String, _description: String, - _image: String, _godot_config: String, _global_script_class: String, _resource_pack: String) -> Gate: + _image: String, _resource_pack: String, _shared_libs_dir: String) -> Gate: var gate = Gate.new() gate.url = _url gate.title = _title gate.description = _description gate.image = _image - gate.godot_config = _godot_config - gate.global_script_class = _global_script_class gate.resource_pack = _resource_pack + gate.shared_libs_dir = _shared_libs_dir return gate