Set launcher to only keep one version (+ other changes)

This commit is contained in:
Noah 2022-10-27 11:31:30 -05:00
parent a3a2b73a75
commit aaea8a0e3f
4 changed files with 62 additions and 58 deletions

View File

@ -2,18 +2,20 @@ extends Control
var newest_version var newest_version
var newest_version_data var newest_version_data
var newest_local_version = Versions.get_versions().max() var newest_local_version
var os_name var os_name
var suffix var suffix
func _process(delta): func _process(delta):
if newest_version != null: if newest_version != null:
newest_local_version = Versions.get_versions().max() newest_local_version = Versions.get_version()
if newest_local_version: if newest_local_version:
if newest_version > newest_local_version : if newest_version > newest_local_version :
$Panel/Play_button.text = "Update" $Panel/Play_button.text = "Update"
else: else:
$Panel/Play_button.text = "Play" $Panel/Play_button.text = "Play"
else:
$Panel/Play_button.text = "Update"
func _ready(): func _ready():
if OS.get_name() == "X11": if OS.get_name() == "X11":
@ -32,11 +34,13 @@ func _versions_request_completed(result, response_code, headers, body):
newest_version = data[0].tag_name newest_version = data[0].tag_name
newest_version_data = data[0] newest_version_data = data[0]
print("Got versions!")
func _download_request_completed(result, response_code, headers, body): func _download_request_completed(result, response_code, headers, body):
#if OS.get_name() == "X11": if OS.get_name() == "X11":
var os_name = "linux" var os_name = "linux"
#elif OS.get_name() == "Windows": elif OS.get_name() == "Windows":
# var os_name = "windows" var os_name = "windows"
if os_name == "windows": if os_name == "windows":
var suffix = ".exe" var suffix = ".exe"
@ -45,17 +49,24 @@ func _download_request_completed(result, response_code, headers, body):
print("Download complete") print("Download complete")
var dl_file = File.new() var dl_file = File.new()
dl_file.open(OS.get_config_dir()+"/UltraFlare/versions/"+newest_version+"/UltraFlare-"+os_name+"-x86_64", 7) dl_file.open(OS.get_config_dir()+"/UltraFlare/current/UltraFlare-"+os_name+"-x86_64", 7)
dl_file.store_buffer(body) dl_file.store_buffer(body)
dl_file.close() 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"])
func _on_Play_button_pressed(): func _on_Play_button_pressed():
print(Versions.get_versions())
if newest_version:
var suffix = "" var suffix = ""
if os_name == "windows": if os_name == "windows":
suffix = ".exe" suffix = ".exe"
if newest_version > newest_local_version:
print(os_name)
if not newest_local_version or newest_version > newest_local_version:
var download = HTTPRequest.new() var download = HTTPRequest.new()
add_child(download) add_child(download)
@ -64,13 +75,14 @@ func _on_Play_button_pressed():
var url var url
for asset in newest_version_data.assets: for asset in newest_version_data.assets:
if asset.name == "UltraFlare-"+os_name+"-x86_64": if asset.name == "UltraFlare-"+os_name+"-x86_64"+suffix:
url = asset.browser_download_url url = asset.browser_download_url
break
var error = download.request(url) var error = download.request(url)
else: else:
var exit_code = OS.execute(OS.get_config_dir()+"/UltraFlare/versions/"+newest_local_version+"/UltraFlare-"+os_name+"-x86_64"+suffix, [], false) var exit_code = OS.execute(OS.get_config_dir()+"/UltraFlare/current/UltraFlare-"+os_name+"-x86_64"+suffix, [], false)
if exit_code != -1: if exit_code != -1:
get_tree().quit() get_tree().quit()

View File

@ -54,7 +54,7 @@ anchor_top = 1.0
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_left = 64.0 margin_left = 64.0
margin_top = -120.0 margin_top = -136.0
margin_right = -64.0 margin_right = -64.0
margin_bottom = -24.0 margin_bottom = -24.0
theme = ExtResource( 5 ) theme = ExtResource( 5 )
@ -62,9 +62,9 @@ custom_styles/panel = SubResource( 4 )
[node name="Play_button" type="Button" parent="Panel"] [node name="Play_button" type="Button" parent="Panel"]
margin_left = 288.0 margin_left = 288.0
margin_top = 8.0 margin_top = 32.0
margin_right = 612.0 margin_right = 621.0
margin_bottom = 61.0 margin_bottom = 85.0
rect_scale = Vector2( 0.962016, 0.91427 ) rect_scale = Vector2( 0.962016, 0.91427 )
custom_fonts/font = SubResource( 5 ) custom_fonts/font = SubResource( 5 )
text = "play" text = "play"

View File

@ -18,7 +18,7 @@ func _ready():
for path in store_paths: for path in store_paths:
# If the path exists, # If the path exists,
if store_dir.dir_exists(path): if store_dir.dir_exists(path):
if store_file.file_exists(path): if store_file.file_exists(path+"/store.json"):
# Set the data_path to that path # Set the data_path to that path
store_path = path store_path = path
# Break out of the loop # Break out of the loop

View File

@ -1,27 +1,22 @@
extends Node extends Node
var versions_dir_path = OS.get_config_dir()+"/UltraFlare/versions"
var versions_dir = Directory.new()
var executable = File.new()
var os_name = "" var os_name = ""
var suffix = "" var suffix = ""
func get_versions(): var exec_path = OS.get_config_dir()+"/current/UltraFlare-"+os_name+"-x86_64"+suffix
var versions = [] var executable = File.new()
versions_dir.open(versions_dir_path)
versions_dir.list_dir_begin(true)
var file_name = versions_dir.get_next() func get_version():
while file_name != "": var version
if executable.file_exists(versions_dir_path+"/"+file_name+"/UltraFlare-"+os_name+"-x86_64"+suffix):
versions.append(file_name)
file_name = versions_dir.get_next() var store = Store.get_store()
versions_dir.list_dir_end() if store.has("current_version"):
#versions.sort() version = store["current_version"]
else:
version = null
return versions return version
func _ready(): func _ready():
@ -33,6 +28,3 @@ func _ready():
if os_name == "windows": if os_name == "windows":
suffix = ".exe" suffix = ".exe"
if not versions_dir.dir_exists(versions_dir_path):
versions_dir.make_dir_recursive(versions_dir_path)