Browse Source

Add auto-updating feature

master
Luna 7 years ago
parent
commit
982e8f0d34
5 changed files with 150 additions and 13 deletions
  1. +0
    -12
      bootstrap.py
  2. +1
    -1
      project.godot
  3. +101
    -0
      scenes/update.tscn
  4. +47
    -0
      scripts/update.gd
  5. +1
    -0
      vanagloria

+ 0
- 12
bootstrap.py View File

@ -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")

+ 1
- 1
project.godot View File

@ -11,7 +11,7 @@ config_version=3
[application] [application]
config/name="mv-moba" config/name="mv-moba"
run/main_scene="res://scenes/lobby.tscn"
run/main_scene="res://scenes/update.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[autoload] [autoload]


+ 101
- 0
scenes/update.tscn View File

@ -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" ]

+ 47
- 0
scripts/update.gd View File

@ -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")

+ 1
- 0
vanagloria View File

@ -0,0 +1 @@
/opt/godot/godot

Loading…
Cancel
Save