Skip to content

Commit

Permalink
Проверка обновлений (вау)
Browse files Browse the repository at this point in the history
  • Loading branch information
Summersay415 committed Nov 24, 2024
1 parent 8f5608b commit 1a466a7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions launcher/launcher.gd
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ func remove_version(version_code: String) -> void:
dd.popup_centered()


func show_update(version_code: String, engine_version: String, beta: bool) -> void:
var ud: ConfirmationDialog = $UpdateDialog
ud.dialog_text = "Доступна новая %sверсия %s! Скачать её?" % [
"бета-" if beta else "",
($RemoteManager as RemoteManager).remote_versions.get_value(version_code, "name")
]
ud.confirmed.connect(
($Downloader as Downloader).download_version.bind(version_code, engine_version)
)
ud.popup_centered()


func get_server_url() -> String:
return settings_file.get_value("settings", "server")

Expand Down Expand Up @@ -429,3 +441,9 @@ func _on_download_pressed() -> void:

func _on_delete_dialog_canceled() -> void:
($DeleteDialog as AcceptDialog).confirmed.disconnect(_remove_version)


func _on_update_dialog_canceled() -> void:
($UpdateDialog as AcceptDialog).confirmed.disconnect(
($Downloader as Downloader).download_version
)
7 changes: 7 additions & 0 deletions launcher/launcher.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ visible = false
[node name="Downloader" parent="." instance_placeholder="res://downloader/downloader.tscn"]
visible = false

[node name="UpdateDialog" type="ConfirmationDialog" parent="."]
title = "Доступно обновление!"
unresizable = true
ok_button_text = "Скачать"
cancel_button_text = "Отмена"

[connection signal="pressed" from="Main/Actions/Download" to="." method="_on_download_pressed"]
[connection signal="pressed" from="Main/Actions/Import" to="MouseBlock" method="show"]
[connection signal="pressed" from="Main/Actions/Import" to="ImportFileDialog" method="popup_centered"]
Expand All @@ -171,3 +177,4 @@ visible = false
[connection signal="canceled" from="ImportFileDialog" to="." method="_on_import_file_dialog_canceled"]
[connection signal="file_selected" from="ImportFileDialog" to="." method="_import_version"]
[connection signal="canceled" from="DeleteDialog" to="." method="_on_delete_dialog_canceled"]
[connection signal="canceled" from="UpdateDialog" to="." method="_on_update_dialog_canceled"]
27 changes: 27 additions & 0 deletions remote_manager/remote_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extends Window
var remote_versions := ConfigFile.new()
var remote_engine_versions := ConfigFile.new()
var versions_downloaded := false
var update_showed := false

var _remote_version_scene: PackedScene = preload("uid://b2y07vkguxpwu")

Expand All @@ -22,6 +23,7 @@ func _ready() -> void:
func download_remote_configs() -> void:
_clear_versions()
versions_downloaded = false
update_showed = false
_status.show()
_status.text = "Скачивание списка версий..."
_update_button.disabled = true
Expand Down Expand Up @@ -54,6 +56,7 @@ func list_remote_versions() -> void:
prints("Installed engines:", supported_engines)

var version_nodes: Array[Node]
var highest_version: int = -1
for version_code: String in remote_versions.get_sections():
print("Checking version %s (%s)." % [
remote_versions.get_value(version_code, "name"),
Expand All @@ -72,6 +75,7 @@ func list_remote_versions() -> void:
if remote_versions.get_value(version_code, "beta") \
and not _launcher.settings_file.get_value("settings", "betas"):
continue

var remote_version_node: PanelContainer = _remote_version_scene.instantiate()
remote_version_node.name = StringName(version_code)
var version_name: String = "Версия %s" % remote_versions.get_value(version_code, "name")
Expand All @@ -86,6 +90,12 @@ func list_remote_versions() -> void:
(remote_version_node.get_node(^"%Download") as BaseButton).disabled = true
(remote_version_node.get_node(^"%Download") as Button).text = "Скачано"
version_nodes.append(remote_version_node)

if int(version_code) > highest_version:
if not remote_versions.get_value(version_code, "beta"):
highest_version = int(version_code)
elif _launcher.settings_file.get_value("settings", "beta_updates"):
highest_version = int(version_code)

version_nodes.sort_custom(func(first: Node, second: Node) -> bool:
return int(first.name) < int(second.name))
Expand All @@ -96,6 +106,23 @@ func list_remote_versions() -> void:
%Versions.move_child(node, 0)
var newest_label: Label = %Versions.get_child(0).get_node(^"%VersionName")
newest_label.text = "Новейшая " + newest_label.text

var highest_installed_version: int = -1
for installed_version: String in _launcher.versions_file.get_sections():
if int(installed_version) > highest_installed_version:
highest_installed_version = int(installed_version)

print("Highest remote version: %d, highest installed version: %d." % [
highest_version,
highest_installed_version
])
if not update_showed and highest_version > highest_installed_version \
and _launcher.settings_file.get_value("settings", "updates"):
update_showed = true
var version_code: String = str(highest_version)
var engine_version: String = remote_versions.get_value(version_code, "engine_version")
var beta: bool = remote_versions.get_value(version_code, "beta")
_launcher.show_update(version_code, engine_version, beta)


func _clear_versions() -> void:
Expand Down

0 comments on commit 1a466a7

Please sign in to comment.