Chelimbalo/systems/auto_update.gd
2025-12-17 02:21:36 +05:00

48 lines
1.9 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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_path = OS.get_executable_path()
var splitted = exec_path.split("/")
var exec_dir = exec_path.replace(splitted[len(splitted)-1],"")
patch_request.download_file = exec_dir + "chelimbalo.pck"
patch_request.request_completed.connect(patch_downloaded)
update_version_text.emit("Подгружаем данные с сервера...")
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]Ошибка загрузки данных:" + 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("Доступна новая версия!")
popup.popup_centered()
else:
update_version_text.emit("[color=green]У вас самая актуальная версия игры![/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]Ошибка загрузки новой версии:" + str(result) +"[/color]")