diff --git a/game.gd b/game.gd index aeaf293..e084e9b 100644 --- a/game.gd +++ b/game.gd @@ -13,14 +13,15 @@ var state = {} func _ready(): var dir = Directory.new() + var repo_dir = tmp_prefix_outside+"repos/" if not dir.dir_exists(tmp_prefix_outside): var err = dir.make_dir(tmp_prefix_outside) if err != OK: helpers.crash("Could not create temporary directory %s." % tmp_prefix_outside) - if not dir.dir_exists(tmp_prefix_outside+"/repos/"): - var err = dir.make_dir(tmp_prefix_outside+"/repos/") + if not dir.dir_exists(repo_dir): + var err = dir.make_dir(repo_dir) if err != OK: - helpers.crash("Could not create temporary directory %s." % (tmp_prefix_outside+"/repos/")) + helpers.crash("Could not create temporary directory %s." % repo_dir) global_shell = Shell.new() fake_editor = copy_file_to_game_env("fake-editor") @@ -60,16 +61,7 @@ func copy_file_to_game_env(filename): return file_inside func _tmp_prefix_inside(): - var os = OS.get_name() - var path - if os == "X11" or os == "OSX": - path = OS.get_user_data_dir() - elif os == "Windows": - helpers.crash("Need to figure out Windows tmp_prefix_inside...") - else: - helpers.crash("Unsupported OS: %s" % os) - - return path + "/tmp/" + return OS.get_user_data_dir() + "/tmp/" func _tmp_prefix_outside(): return "user://tmp/" diff --git a/helpers.gd b/helpers.gd index d5b6344..2bb1200 100644 --- a/helpers.gd +++ b/helpers.gd @@ -21,12 +21,11 @@ func exec(command, args=[], crash_on_fail=true): var output = [] var exit_code = OS.execute(command, args, true, output, true) output = output[0] - + if exit_code != 0 and crash_on_fail: - helpers.crash("OS.execute failed: %s [%s] Output: %s" % [command, PoolStringArray(args).join(", "), output]) - - if debug: - print(output) + helpers.crash("OS.execute failed: %s [%s] Output: %s \nExit Code %d" % [command, PoolStringArray(args).join(", "), output, exit_code]) + elif debug: + print("Output: %s" %output) return output @@ -78,7 +77,7 @@ func careful_delete(path_inside): elif os == "OSX": expected_prefix = "/Users/%s/Library/Application Support/git-hydra/tmp/" % OS.get_environment("USER") elif os == "Windows": - helpers.crash("Need to figure out delete_prefix on Windows") + expected_prefix = "C:/Users/%s/AppData/Roaming/git-hydra/tmp/" % OS.get_environment("USERNAME") else: helpers.crash("Unsupported OS: %s" % os) diff --git a/shell.gd b/shell.gd index c3f268b..db9d7ba 100644 --- a/shell.gd +++ b/shell.gd @@ -2,6 +2,7 @@ extends Node class_name Shell var _cwd +var os = OS.get_name() #signal output(text) @@ -47,8 +48,10 @@ func run(command, crash_on_fail=true): # becomes # # "'test '"'"'fu'"'"' "bla" blubb" - # - hacky_command = '"\''+hacky_command.replace("'", "'\"'\"'")+'\'"' + # + # Quoting Magic is not needed for Windows! + if os == "X11" or os == "OSX": + hacky_command = '"\''+hacky_command.replace("'", "'\"'\"'")+'\'"' var output = helpers.exec(_shell_binary(), ["-c", hacky_command], crash_on_fail) @@ -58,7 +61,7 @@ func run(command, crash_on_fail=true): return output func _shell_binary(): - var os = OS.get_name() + if os == "X11" or os == "OSX": return "bash"