From b209fcaf7e97c267de6325fc3012511bf5404eda Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 13 Oct 2022 09:51:32 -0500 Subject: [PATCH] Committed current work (Too many changes to count) --- Main_menu.gd | 77 ++++++++++++++++++++++++++++++++++++++++++--- Main_menu.tscn | 11 +------ Versions.gd | 18 +++++++++-- bin/placeholder.txt | 0 4 files changed, 89 insertions(+), 17 deletions(-) create mode 100644 bin/placeholder.txt diff --git a/Main_menu.gd b/Main_menu.gd index 6a22059..2885de1 100644 --- a/Main_menu.gd +++ b/Main_menu.gd @@ -1,11 +1,78 @@ extends Control -onready var Version_menu = $Panel/Version_menu +var newest_version +var newest_version_data +var newest_local_version = Versions.get_versions().max() +var os_name +var suffix -func _ready(): - for version in Versions.get_versions(): - $Panel/Version_menu.add_item(version) +func _process(delta): + if newest_version != null: + newest_local_version = Versions.get_versions().max() + if newest_local_version: + if newest_version > newest_local_version: + $Panel/Play_button.text = "Update" + else: + $Panel/Play_button.text = "Play" +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] + +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/versions/"+newest_version+"/UltraFlare-"+os_name+"-x86_64", 7) + dl_file.store_buffer(body) + dl_file.close() func _on_Play_button_pressed(): - var version = Version_menu.get_item_text(Version_menu.selected) + 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) + + 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) diff --git a/Main_menu.tscn b/Main_menu.tscn index 735b87c..0130757 100644 --- a/Main_menu.tscn +++ b/Main_menu.tscn @@ -1,11 +1,10 @@ -[gd_scene load_steps=11 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://textures/Title-Background.png" type="Texture" id=1] [ext_resource path="res://fonts/SPACEBAR.ttf" type="DynamicFontData" id=2] [ext_resource path="res://Main_menu.gd" type="Script" id=3] [ext_resource path="res://fonts/Title-font.tres" type="DynamicFont" id=4] [ext_resource path="res://themes/Base_theme.tres" type="Theme" id=5] -[ext_resource path="res://fonts/retro_gaming.tres" type="DynamicFont" id=7] [sub_resource type="Theme" id=1] default_font = ExtResource( 4 ) @@ -61,14 +60,6 @@ margin_bottom = -24.0 theme = ExtResource( 5 ) custom_styles/panel = SubResource( 4 ) -[node name="Version_menu" type="OptionButton" parent="Panel"] -margin_left = 304.0 -margin_top = 64.0 -margin_right = 432.0 -margin_bottom = 91.0 -theme = ExtResource( 5 ) -custom_fonts/font = ExtResource( 7 ) - [node name="Play_button" type="Button" parent="Panel"] margin_left = 288.0 margin_top = 8.0 diff --git a/Versions.gd b/Versions.gd index 7265076..397e5d8 100644 --- a/Versions.gd +++ b/Versions.gd @@ -1,7 +1,10 @@ extends Node -var versions_dir_path = OS.get_config_dir()+"/UltraFlare/versions/" +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 = [] @@ -10,15 +13,26 @@ func get_versions(): var file_name = versions_dir.get_next() while file_name != "": - versions.append(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() versions_dir.list_dir_end() + #versions.sort() return versions func _ready(): + if OS.get_name() == "X11": + os_name = "linux" + elif OS.get_name() == "Windows": + os_name = "windows" + + if os_name == "windows": + suffix = ".exe" + if not versions_dir.dir_exists(versions_dir_path): versions_dir.make_dir_recursive(versions_dir_path) diff --git a/bin/placeholder.txt b/bin/placeholder.txt new file mode 100644 index 0000000..e69de29