2020-01-29 20:25:13 +01:00
|
|
|
extends Node
|
|
|
|
|
2020-09-09 11:48:42 +02:00
|
|
|
var tmp_prefix = _tmp_prefix()
|
2020-09-08 16:36:52 +02:00
|
|
|
var global_shell
|
2020-09-08 20:13:49 +02:00
|
|
|
var debug = false
|
2020-09-09 11:48:42 +02:00
|
|
|
var fake_editor
|
2020-01-29 20:25:13 +01:00
|
|
|
|
|
|
|
func _ready():
|
2020-09-08 16:36:52 +02:00
|
|
|
global_shell = Shell.new()
|
2020-09-09 11:48:42 +02:00
|
|
|
|
|
|
|
# Copy fake-editor to tmp directory (because the original might be in a .pck file).
|
2020-09-09 17:59:56 +02:00
|
|
|
var fake_editor_outside = tmp_prefix + "fake-editor"
|
|
|
|
fake_editor = "/tmp/fake-editor"
|
2020-09-09 11:48:42 +02:00
|
|
|
var content = game.read_file("res://scripts/fake-editor")
|
2020-09-09 17:59:56 +02:00
|
|
|
write_file(fake_editor_outside, content)
|
2020-09-09 11:48:42 +02:00
|
|
|
global_shell.run("chmod u+x " + fake_editor)
|
2020-09-01 19:20:51 +02:00
|
|
|
|
|
|
|
func read_file(path):
|
2020-09-08 20:13:49 +02:00
|
|
|
if debug:
|
|
|
|
print("reading " + path)
|
2020-09-04 14:57:37 +02:00
|
|
|
var file = File.new()
|
|
|
|
file.open(path, File.READ)
|
|
|
|
var content = file.get_as_text()
|
|
|
|
file.close()
|
|
|
|
return content
|
2020-09-01 19:20:51 +02:00
|
|
|
|
|
|
|
func write_file(path, content):
|
2020-09-08 20:13:49 +02:00
|
|
|
if debug:
|
|
|
|
print("writing " + path)
|
2020-09-04 14:57:37 +02:00
|
|
|
var file = File.new()
|
|
|
|
file.open(path, File.WRITE)
|
|
|
|
file.store_string(content)
|
|
|
|
file.close()
|
|
|
|
return true
|
2020-09-09 11:48:42 +02:00
|
|
|
|
|
|
|
func _tmp_prefix():
|
|
|
|
var os = OS.get_name()
|
2020-09-09 17:59:56 +02:00
|
|
|
if os == "X11":
|
|
|
|
return "/tmp/"
|
|
|
|
elif os == "Windows":
|
|
|
|
# For some reason, this command outputs a space in the end? We remove it.
|
|
|
|
# Also, Godot's default is to use forward slashes for everything.
|
2020-09-09 18:32:57 +02:00
|
|
|
return exec("echo", ["%TEMP%"]).replacen("\\", "/").replace(" \n", "/")
|
2020-09-09 17:59:56 +02:00
|
|
|
else:
|
|
|
|
push_error("Unsupported OS")
|
|
|
|
get_tree().quit()
|
2020-09-09 13:25:00 +02:00
|
|
|
|
2020-09-09 17:59:56 +02:00
|
|
|
# Run a simple command with arguments, blocking, using OS.execute.
|
|
|
|
func exec(command, args=[]):
|
|
|
|
var debug = true
|
|
|
|
|
|
|
|
if debug:
|
|
|
|
print("exec: %s [%s]" % [command, PoolStringArray(args).join(", ")])
|
|
|
|
|
|
|
|
var output = []
|
|
|
|
var exit_code = OS.execute(command, args, true, output, true)
|
|
|
|
output = output[0]
|
|
|
|
|
|
|
|
if exit_code != 0:
|
|
|
|
push_error("OS.execute failed: %s [%s] Output: %s" % [command, PoolStringArray(args).join(", "), output])
|
|
|
|
|
|
|
|
if debug:
|
|
|
|
print(output)
|
|
|
|
|
|
|
|
return output
|