From 724a5fff03a16a428fd73737bfb00b9674b03048 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Wed, 9 Sep 2020 11:48:42 +0200 Subject: [PATCH] Add some switches that set proper paths for Windows --- game.gd | 21 +++++++++++++++++++-- main.gd | 10 +++++----- shell.gd | 10 +++------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/game.gd b/game.gd index 786d8f8..4a7a1ec 100644 --- a/game.gd +++ b/game.gd @@ -1,12 +1,18 @@ extends Node -var tmp_prefix = "/tmp/" +var tmp_prefix = _tmp_prefix() var global_shell var debug = false +var fake_editor func _ready(): global_shell = Shell.new() - global_shell.cd(tmp_prefix) + + # Copy fake-editor to tmp directory (because the original might be in a .pck file). + var fake_editor = tmp_prefix + "fake-editor" + var content = game.read_file("res://scripts/fake-editor") + write_file(fake_editor, content) + global_shell.run("chmod u+x " + fake_editor) func read_file(path): if debug: @@ -25,3 +31,14 @@ func write_file(path, content): file.store_string(content) file.close() return true + +func _tmp_prefix(): + var os = OS.get_name() + + if os == "X11": + return "/tmp/" + elif os == "Windows": + return "%temp%/" + else: + push_error("Unsupported OS") + get_tree().quit() diff --git a/main.gd b/main.gd index c1695fb..7a119b7 100644 --- a/main.gd +++ b/main.gd @@ -83,11 +83,11 @@ func construct_repo(script, path): var script_path = game.tmp_prefix+"/git-hydra-script" game.write_file(script_path, content) - var shell = Shell.new() - shell.run("mkdir " + path) - shell.cd(path) - shell.run("git init") - var o = shell.run("source "+script_path) + game.global_shell.run("mkdir " + path) + game.global_shell.cd(path) + game.global_shell.run("git init") + var o = game.global_shell.run("source "+script_path) + if game.debug: print(o) diff --git a/shell.gd b/shell.gd index 853df9b..fe61223 100644 --- a/shell.gd +++ b/shell.gd @@ -7,11 +7,7 @@ var _fake_editor signal output(text) func _init(): - # Copy fake-editor to tmp directory (because the original might be in a .pck file). - _fake_editor = game.tmp_prefix + "fake-editor" - var content = game.read_file("res://scripts/fake-editor") - game.write_file(_fake_editor, content) - _exec("chmod", ["u+x", _fake_editor]) + _cwd = game.tmp_prefix func cd(dir): _cwd = dir @@ -44,9 +40,9 @@ func _shell_binary(): var os = OS.get_name() if os == "X11": - return "/bin/sh" + return "sh" elif os == "Windows": - return "external/git_bash.exe" + return "sh.exe" else: push_error("Unsupported OS") get_tree().quit()