First Windows Fixes

This commit is contained in:
bleeptrack 2020-10-20 18:44:33 +02:00
parent 40ec539e49
commit b044ed5d27
3 changed files with 16 additions and 22 deletions

18
game.gd
View file

@ -13,14 +13,15 @@ var state = {}
func _ready(): func _ready():
var dir = Directory.new() var dir = Directory.new()
var repo_dir = tmp_prefix_outside+"repos/"
if not dir.dir_exists(tmp_prefix_outside): if not dir.dir_exists(tmp_prefix_outside):
var err = dir.make_dir(tmp_prefix_outside) var err = dir.make_dir(tmp_prefix_outside)
if err != OK: if err != OK:
helpers.crash("Could not create temporary directory %s." % tmp_prefix_outside) helpers.crash("Could not create temporary directory %s." % tmp_prefix_outside)
if not dir.dir_exists(tmp_prefix_outside+"/repos/"): if not dir.dir_exists(repo_dir):
var err = dir.make_dir(tmp_prefix_outside+"/repos/") var err = dir.make_dir(repo_dir)
if err != OK: 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() global_shell = Shell.new()
fake_editor = copy_file_to_game_env("fake-editor") fake_editor = copy_file_to_game_env("fake-editor")
@ -60,16 +61,7 @@ func copy_file_to_game_env(filename):
return file_inside return file_inside
func _tmp_prefix_inside(): func _tmp_prefix_inside():
var os = OS.get_name() return OS.get_user_data_dir() + "/tmp/"
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/"
func _tmp_prefix_outside(): func _tmp_prefix_outside():
return "user://tmp/" return "user://tmp/"

View file

@ -21,12 +21,11 @@ func exec(command, args=[], crash_on_fail=true):
var output = [] var output = []
var exit_code = OS.execute(command, args, true, output, true) var exit_code = OS.execute(command, args, true, output, true)
output = output[0] output = output[0]
if exit_code != 0 and crash_on_fail: if exit_code != 0 and crash_on_fail:
helpers.crash("OS.execute failed: %s [%s] Output: %s" % [command, PoolStringArray(args).join(", "), output]) helpers.crash("OS.execute failed: %s [%s] Output: %s \nExit Code %d" % [command, PoolStringArray(args).join(", "), output, exit_code])
elif debug:
if debug: print("Output: %s" %output)
print(output)
return output return output
@ -78,7 +77,7 @@ func careful_delete(path_inside):
elif os == "OSX": elif os == "OSX":
expected_prefix = "/Users/%s/Library/Application Support/git-hydra/tmp/" % OS.get_environment("USER") expected_prefix = "/Users/%s/Library/Application Support/git-hydra/tmp/" % OS.get_environment("USER")
elif os == "Windows": 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: else:
helpers.crash("Unsupported OS: %s" % os) helpers.crash("Unsupported OS: %s" % os)

View file

@ -2,6 +2,7 @@ extends Node
class_name Shell class_name Shell
var _cwd var _cwd
var os = OS.get_name()
#signal output(text) #signal output(text)
@ -47,8 +48,10 @@ func run(command, crash_on_fail=true):
# becomes # becomes
# #
# "'test '"'"'fu'"'"' "bla" blubb" # "'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) 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 return output
func _shell_binary(): func _shell_binary():
var os = OS.get_name()
if os == "X11" or os == "OSX": if os == "X11" or os == "OSX":
return "bash" return "bash"