Launcher/Main_menu.gd

91 lines
2.5 KiB
GDScript3
Raw Normal View History

2022-10-10 18:11:59 -05:00
extends Control
var newest_version
var newest_version_data
var newest_local_version
var os_name
var suffix
2022-10-10 20:59:43 -05:00
func _process(delta):
if newest_version != null:
newest_local_version = Versions.get_version()
if newest_local_version:
if newest_version > newest_local_version :
$Panel/Play_button.text = "Update"
else:
$Panel/Play_button.text = "Play"
else:
$Panel/Play_button.text = "Update"
2022-10-10 20:59:43 -05:00
func _ready():
if OS.get_name() == "X11":
os_name = "linux"
elif OS.get_name() == "Windows":
os_name = "windows"
var versions_request = HTTPRequest.new()
add_child(versions_request)
versions_request.connect("request_completed", self, "_versions_request_completed")
var error = versions_request.request("https://code.retroedge.tech/api/v1/repos/UltraFlare/UltraFlare/releases?draft=false&pre-release=true&limit=1")
func _versions_request_completed(result, response_code, headers, body):
var data = JSON.parse(body.get_string_from_ascii()).result
newest_version = data[0].tag_name
newest_version_data = data[0]
print("Got versions!")
func _download_request_completed(result, response_code, headers, body):
if OS.get_name() == "X11":
var os_name = "linux"
elif OS.get_name() == "Windows":
var os_name = "windows"
if os_name == "windows":
var suffix = ".exe"
else:
var suffix = ""
print("Download complete")
var dl_file = File.new()
dl_file.open(OS.get_config_dir()+"/UltraFlare/current/UltraFlare-"+os_name+"-x86_64", 7)
dl_file.store_buffer(body)
dl_file.close()
newest_local_version = newest_version_data.tag_name
Store.write_store("current_version", newest_local_version)
if os_name == "linux":
OS.execute("chmod", ["+x", OS.get_config_dir()+"/UltraFlare/current/UltraFlare-"+os_name+"-x86_64"])
2022-10-10 20:59:43 -05:00
func _on_Play_button_pressed():
var suffix = ""
if os_name == "windows":
suffix = ".exe"
print(os_name)
if not newest_local_version or newest_version > newest_local_version:
var download = HTTPRequest.new()
add_child(download)
download.connect("request_completed", self, "_download_request_completed")
var url
for asset in newest_version_data.assets:
if asset.name == "UltraFlare-"+os_name+"-x86_64"+suffix:
url = asset.browser_download_url
break
var error = download.request(url)
else:
var exit_code = OS.execute(OS.get_config_dir()+"/UltraFlare/current/UltraFlare-"+os_name+"-x86_64"+suffix, [], false)
if exit_code != -1:
get_tree().quit()
else:
print("Running UltraFlare failed with code: "+exit_code)