46 lines
1.8 KiB
GDScript
46 lines
1.8 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("Подгружаем данные с сервера...")
|
||
|
||
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]")
|