From 982e8f0d34a1d425b205d3c372327b3159fbaa51 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 12 Mar 2018 20:00:45 -0400 Subject: [PATCH] Add auto-updating feature --- bootstrap.py | 12 ------- project.godot | 2 +- scenes/update.tscn | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/update.gd | 47 +++++++++++++++++++++++++ vanagloria | 1 + 5 files changed, 150 insertions(+), 13 deletions(-) delete mode 100644 bootstrap.py create mode 100644 scenes/update.tscn create mode 100644 scripts/update.gd create mode 120000 vanagloria diff --git a/bootstrap.py b/bootstrap.py deleted file mode 100644 index 5f10cea..0000000 --- a/bootstrap.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python - -import os - -if os.path.exists("project.godot"): - # Update - os.system("git pull") - os.system("godot") -else: - # Initial download - os.system("git clone --depth 1 https://github.com/CosineGaming/nv-moba .") - os.system("godot") diff --git a/project.godot b/project.godot index 8aff89d..e943465 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=3 [application] config/name="mv-moba" -run/main_scene="res://scenes/lobby.tscn" +run/main_scene="res://scenes/update.tscn" config/icon="res://icon.png" [autoload] diff --git a/scenes/update.tscn b/scenes/update.tscn new file mode 100644 index 0000000..ae86eb1 --- /dev/null +++ b/scenes/update.tscn @@ -0,0 +1,101 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://scripts/update.gd" type="Script" id=1] +[ext_resource path="res://assets/DejaVuSansMono.ttf" type="DynamicFontData" id=2] + +[sub_resource type="DynamicFont" id=1] + +size = 0 +use_mipmaps = false +use_filter = false +font_data = ExtResource( 2 ) +_sections_unfolded = [ "Extra Spacing", "Font", "Resource", "Settings" ] + +[node name="Control" type="Control" index="0"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +rect_pivot_offset = Vector2( 0, 0 ) +mouse_filter = 0 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 + +[node name="HTTPRequest" type="HTTPRequest" parent="." index="0"] + +download_file = "" +use_threads = false +body_size_limit = -1 +max_redirects = 8 +script = ExtResource( 1 ) + +[node name="ProgressBar" type="ProgressBar" parent="." index="1"] + +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -431.0 +margin_top = -30.5 +margin_right = 431.0 +margin_bottom = 30.5 +rect_pivot_offset = Vector2( 0, 0 ) +mouse_filter = 0 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 0 +min_value = 0.0 +max_value = 100.0 +step = 1.0 +page = 0.0 +value = 0.0 +exp_edit = false +rounded = false +percent_visible = true + +[node name="Updating" type="Label" parent="." index="2"] + +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -35.0 +margin_top = -63.0 +margin_right = 34.0 +margin_bottom = -49.0 +rect_pivot_offset = Vector2( 0, 0 ) +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 4 +text = "Updating..." +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 + +[node name="Title" type="Label" parent="." index="3"] + +anchor_left = 0.5 +anchor_top = 0.0 +anchor_right = 0.5 +anchor_bottom = 0.0 +margin_left = -20.0 +margin_top = 56.0 +margin_right = 20.0 +margin_bottom = 70.0 +rect_pivot_offset = Vector2( 0, 0 ) +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 4 +custom_fonts/font = SubResource( 1 ) +text = "VANAGLORIA" +align = 1 +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 +_sections_unfolded = [ "custom_fonts" ] + + diff --git a/scripts/update.gd b/scripts/update.gd new file mode 100644 index 0000000..0a1fdb3 --- /dev/null +++ b/scripts/update.gd @@ -0,0 +1,47 @@ +extends HTTPRequest + +var is_update_payload = false +var save_to +var time = 0 + +func _ready(): + connect("request_completed", self, "_request_completed") + # Check if we need an update + request("http://localhost:8080/vanagloria/version") + set_process(true) + +func _request_completed(result, response_code, headers, body): + if result != RESULT_SUCCESS: + print("ERROR: COULD NOT UPDATE. RESULT #" + str(result)) + completed() + return + if not is_update_payload: + # Just checking if we need an update + var server = JSON.parse(body.get_string_from_utf8()).result + if server.version == util.version: + completed() + else: + is_update_payload = true + save_to = server.save_location + request(server.download_path) + else: + var file = File.new() + file.open(save_to, File.WRITE) + file.store_buffer(body) + file.close() + restart() + +func _process(delta): + time += delta + var fake_progress = 1 - (0.8 / time) + get_node("../ProgressBar").value = 100*fake_progress + +func restart(): + # Pass on args to new instance, then quit + var output = [] + OS.execute("./vanagloria", [], false, output) # Mirror just runs godot again + get_tree().quit() + +func completed(): + get_tree().change_scene("res://scenes/lobby.tscn") + diff --git a/vanagloria b/vanagloria new file mode 120000 index 0000000..19ef04a --- /dev/null +++ b/vanagloria @@ -0,0 +1 @@ +/opt/godot/godot \ No newline at end of file