mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-22 16:20:19 +01:00
Use bundled sh.exe, expand %TEMP% per-user
This commit is contained in:
parent
61a59c8eb7
commit
4099030fcd
3 changed files with 38 additions and 28 deletions
31
game.gd
31
game.gd
|
@ -9,9 +9,10 @@ func _ready():
|
||||||
global_shell = Shell.new()
|
global_shell = Shell.new()
|
||||||
|
|
||||||
# Copy fake-editor to tmp directory (because the original might be in a .pck file).
|
# Copy fake-editor to tmp directory (because the original might be in a .pck file).
|
||||||
fake_editor = tmp_prefix + "fake-editor"
|
var fake_editor_outside = tmp_prefix + "fake-editor"
|
||||||
|
fake_editor = "/tmp/fake-editor"
|
||||||
var content = game.read_file("res://scripts/fake-editor")
|
var content = game.read_file("res://scripts/fake-editor")
|
||||||
write_file('C:\\Users\\1\\AppData\\Local\\Temp\\fake-editor', content)
|
write_file(fake_editor_outside, content)
|
||||||
global_shell.run("chmod u+x " + fake_editor)
|
global_shell.run("chmod u+x " + fake_editor)
|
||||||
|
|
||||||
func read_file(path):
|
func read_file(path):
|
||||||
|
@ -34,5 +35,31 @@ func write_file(path, content):
|
||||||
|
|
||||||
func _tmp_prefix():
|
func _tmp_prefix():
|
||||||
var os = OS.get_name()
|
var os = OS.get_name()
|
||||||
|
if os == "X11":
|
||||||
return "/tmp/"
|
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.
|
||||||
|
return exec("echo", ["%TEMP%"]).replacen("\\", "/").replace(" \n", "")
|
||||||
|
else:
|
||||||
|
push_error("Unsupported OS")
|
||||||
|
get_tree().quit()
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
9
main.gd
9
main.gd
|
@ -48,8 +48,8 @@ func load_level(id):
|
||||||
var level = levels[id]
|
var level = levels[id]
|
||||||
var level_prefix = "res://levels/"
|
var level_prefix = "res://levels/"
|
||||||
|
|
||||||
var goal_repository_path = game.tmp_prefix+"goal/"
|
var goal_repository_path = "/tmp/goal/"
|
||||||
var active_repository_path = game.tmp_prefix+"active/"
|
var active_repository_path = "/tmp/active/"
|
||||||
var goal_script = level_prefix+level+"/goal"
|
var goal_script = level_prefix+level+"/goal"
|
||||||
var active_script = level_prefix+level+"/start"
|
var active_script = level_prefix+level+"/start"
|
||||||
|
|
||||||
|
@ -80,8 +80,9 @@ func construct_repo(script, path):
|
||||||
# Becase in an exported game, all assets are in a .pck file, we need to put
|
# Becase in an exported game, all assets are in a .pck file, we need to put
|
||||||
# the script somewhere in the filesystem.
|
# the script somewhere in the filesystem.
|
||||||
var content = game.read_file(script)
|
var content = game.read_file(script)
|
||||||
var script_path = game.tmp_prefix+"/git-hydra-script"
|
var script_path_outside = game.tmp_prefix+"/git-hydra-script"
|
||||||
game.write_file('C:\\Users\\1\\AppData\\Local\\Temp\\git-hydra-script', content)
|
var script_path = "/tmp/git-hydra-script"
|
||||||
|
game.write_file(script_path_outside, content)
|
||||||
|
|
||||||
game.global_shell.run("mkdir " + path)
|
game.global_shell.run("mkdir " + path)
|
||||||
game.global_shell.cd(path)
|
game.global_shell.cd(path)
|
||||||
|
|
24
shell.gd
24
shell.gd
|
@ -6,7 +6,7 @@ var _cwd
|
||||||
signal output(text)
|
signal output(text)
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
_cwd = game.tmp_prefix
|
_cwd = "/tmp"
|
||||||
|
|
||||||
func cd(dir):
|
func cd(dir):
|
||||||
_cwd = dir
|
_cwd = dir
|
||||||
|
@ -28,7 +28,7 @@ func run(command):
|
||||||
hacky_command += "cd '%s';" % _cwd
|
hacky_command += "cd '%s';" % _cwd
|
||||||
hacky_command += command
|
hacky_command += command
|
||||||
|
|
||||||
var output = _exec(_shell_binary(), ["-c", hacky_command])
|
var output = game.exec(_shell_binary(), ["-c", hacky_command])
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print(output)
|
print(output)
|
||||||
|
@ -41,7 +41,7 @@ func _shell_binary():
|
||||||
if os == "X11":
|
if os == "X11":
|
||||||
return "sh"
|
return "sh"
|
||||||
elif os == "Windows":
|
elif os == "Windows":
|
||||||
return "sh.exe"
|
return "dependencies\\windows\\git\\bin\\sh.exe"
|
||||||
else:
|
else:
|
||||||
push_error("Unsupported OS")
|
push_error("Unsupported OS")
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
@ -69,21 +69,3 @@ func run_async_thread(command):
|
||||||
c.disconnect_from_host()
|
c.disconnect_from_host()
|
||||||
s.stop()
|
s.stop()
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
Loading…
Reference in a new issue