From aaea8a0e3f1229ace868fdf1a1f24f8a014db35c Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 27 Oct 2022 11:31:30 -0500 Subject: [PATCH] Set launcher to only keep one version (+ other changes) --- Main_menu.gd | 80 +++++++++++++++++++++++++++++--------------------- Main_menu.tscn | 8 ++--- Store.gd | 2 +- Versions.gd | 30 +++++++------------ 4 files changed, 62 insertions(+), 58 deletions(-) diff --git a/Main_menu.gd b/Main_menu.gd index 2885de1..8378125 100644 --- a/Main_menu.gd +++ b/Main_menu.gd @@ -2,20 +2,22 @@ extends Control var newest_version var newest_version_data -var newest_local_version = Versions.get_versions().max() +var newest_local_version var os_name var suffix func _process(delta): if newest_version != null: - newest_local_version = Versions.get_versions().max() + newest_local_version = Versions.get_version() if newest_local_version: - if newest_version > 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" -func _ready(): +func _ready(): if OS.get_name() == "X11": os_name = "linux" elif OS.get_name() == "Windows": @@ -31,12 +33,14 @@ 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.get_name() == "X11": + var os_name = "linux" + elif OS.get_name() == "Windows": + var os_name = "windows" if os_name == "windows": var suffix = ".exe" @@ -45,34 +49,42 @@ func _download_request_completed(result, response_code, headers, body): print("Download complete") 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.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(): - print(Versions.get_versions()) - if newest_version: - var suffix = "" - if os_name == "windows": - suffix = ".exe" - if 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": - url = asset.browser_download_url - - var error = download.request(url) - + 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: - var exit_code = OS.execute(OS.get_config_dir()+"/UltraFlare/versions/"+newest_local_version+"/UltraFlare-"+os_name+"-x86_64"+suffix, [], false) - - if exit_code != -1: - get_tree().quit() - else: - print("Running UltraFlare failed with code: "+exit_code) + print("Running UltraFlare failed with code: "+exit_code) diff --git a/Main_menu.tscn b/Main_menu.tscn index 0130757..498842b 100644 --- a/Main_menu.tscn +++ b/Main_menu.tscn @@ -54,7 +54,7 @@ anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 64.0 -margin_top = -120.0 +margin_top = -136.0 margin_right = -64.0 margin_bottom = -24.0 theme = ExtResource( 5 ) @@ -62,9 +62,9 @@ custom_styles/panel = SubResource( 4 ) [node name="Play_button" type="Button" parent="Panel"] margin_left = 288.0 -margin_top = 8.0 -margin_right = 612.0 -margin_bottom = 61.0 +margin_top = 32.0 +margin_right = 621.0 +margin_bottom = 85.0 rect_scale = Vector2( 0.962016, 0.91427 ) custom_fonts/font = SubResource( 5 ) text = "play" diff --git a/Store.gd b/Store.gd index 7b97e8c..cfba318 100644 --- a/Store.gd +++ b/Store.gd @@ -18,7 +18,7 @@ func _ready(): for path in store_paths: # If the path exists, 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 store_path = path # Break out of the loop diff --git a/Versions.gd b/Versions.gd index 397e5d8..8c30a23 100644 --- a/Versions.gd +++ b/Versions.gd @@ -1,27 +1,22 @@ 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 suffix = "" -func get_versions(): - var versions = [] - versions_dir.open(versions_dir_path) - versions_dir.list_dir_begin(true) +var exec_path = OS.get_config_dir()+"/current/UltraFlare-"+os_name+"-x86_64"+suffix +var executable = File.new() + +func get_version(): + var version - var file_name = versions_dir.get_next() - while file_name != "": - 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() - #versions.sort() + if store.has("current_version"): + version = store["current_version"] + else: + version = null - return versions + return version func _ready(): @@ -32,7 +27,4 @@ func _ready(): if os_name == "windows": suffix = ".exe" - - if not versions_dir.dir_exists(versions_dir_path): - versions_dir.make_dir_recursive(versions_dir_path)