46 lines
1.7 KiB
GDScript
46 lines
1.7 KiB
GDScript
extends HTTPRequest
|
|
|
|
var popup_scene: PackedScene = preload("uid://5goo8fyxkv33")
|
|
|
|
var new_version_avaiable: bool
|
|
var popup: ConfirmationDialog
|
|
|
|
signal update_version_text(to: StringName)
|
|
|
|
func _ready() -> void:
|
|
request_completed.connect(on_request_completed)
|
|
popup = popup_scene.instantiate()
|
|
add_child(popup)
|
|
|
|
popup.confirmed.connect(download_button_pressed)
|
|
var patch_request: HTTPRequest = popup.get_node("HTTPRequest")
|
|
var exec_dir = OS.get_executable_path().get_base_dir()
|
|
patch_request.download_file = exec_dir.path_join("chelimbalo.pck")
|
|
patch_request.request_completed.connect(patch_downloaded)
|
|
|
|
update_version_text.emit(tr("au_loading"))
|
|
|
|
request("https://2ndbeam.ru/durenije/chelimbalo/release/deploy_data")
|
|
|
|
func on_request_completed(result: int, _response_code: int, _headers: PackedStringArray, body: PackedByteArray):
|
|
if result != OK:
|
|
update_version_text.emit("[color=red]" + tr("au_err_load") + str(result) +"[/color]")
|
|
return
|
|
|
|
|
|
var ver_hash = body.get_string_from_ascii().split("\n")[1]
|
|
if ver_hash != load("res://version.tres").version:
|
|
update_version_text.emit(tr("au_new_version"))
|
|
popup.popup_centered()
|
|
else:
|
|
update_version_text.emit("[color=green]"+tr("au_current_version")+"[/color]")
|
|
|
|
func download_button_pressed() -> void:
|
|
popup.get_node("HTTPRequest").request("https://2ndbeam.ru/durenije/chelimbalo/release/chelimbalo.pck")
|
|
|
|
func patch_downloaded(result: int, _response_code: int, _headers: PackedStringArray, _body: PackedByteArray) -> void:
|
|
if result == OK:
|
|
OS.create_process(OS.get_executable_path(),OS.get_cmdline_args())
|
|
get_tree().quit()
|
|
else:
|
|
update_version_text.emit("[color=red]" + tr("au_err_install") + str(result) +"[/color]")
|