download_shared_lib

This commit is contained in:
Nordup 2023-06-25 16:46:46 +04:00
parent 8fa99f746e
commit 985f252430
4 changed files with 28 additions and 8 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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