From 42c0b622617546b1a118ead55a00a24b9498ee54 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 31 Jan 2016 03:18:34 -0600 Subject: [PATCH] fix some lua currdir bugs, but its all broken, dont pay any attention to it --- BizHawk.Client.Common/lua/LuaSandbox.cs | 12 ++++++++---- BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/BizHawk.Client.Common/lua/LuaSandbox.cs b/BizHawk.Client.Common/lua/LuaSandbox.cs index d55e497a53..5db63e6687 100644 --- a/BizHawk.Client.Common/lua/LuaSandbox.cs +++ b/BizHawk.Client.Common/lua/LuaSandbox.cs @@ -33,7 +33,8 @@ namespace BizHawk.Client.Common //moreover we don't really have a sense of sandboxing individual scripts, they kind of all get run together in the same VM, i think //so let's just try keeping one 'current directory' for all lua. it's an improvement over lua's 'current directory' for the process, interfering with the core emulator's savedEnvironmentCurrDir = Environment.CurrentDirectory; - Environment.CurrentDirectory = CurrentDirectory; + if(System.IO.Directory.Exists(CurrentDirectory)) //race condition for great justice + Environment.CurrentDirectory = CurrentDirectory; EnvironmentSandbox.Sandbox(callback); CurrentDirectory = Environment.CurrentDirectory; @@ -47,9 +48,12 @@ namespace BizHawk.Client.Common } } finally - { - if(savedEnvironmentCurrDir != null) - Environment.CurrentDirectory = savedEnvironmentCurrDir; + { + if (savedEnvironmentCurrDir != null) + { + if (System.IO.Directory.Exists(savedEnvironmentCurrDir)) //race condition for great justice + Environment.CurrentDirectory = savedEnvironmentCurrDir; + } } } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index ea56bf123c..6c6b32d125 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -159,11 +159,11 @@ namespace BizHawk.Client.EmuHawk foreach (var file in runningScripts) { + string pathToLoad = Path.IsPathRooted(file.Path) ? file.Path : PathManager.MakeProgramRelativePath(file.Path); //JUNIPIER SQUATCHBOX COMPLEX try { LuaSandbox.Sandbox(() => { - string pathToLoad = PathManager.MakeProgramRelativePath(file.Path); //JUNIPIER SQUATCHBOX COMPLEX file.Thread = LuaImp.SpawnCoroutine(pathToLoad); file.State = LuaFile.RunState.Running; }, () => @@ -183,6 +183,7 @@ namespace BizHawk.Client.EmuHawk public void LoadLuaFile(string path) { var processedPath = PathManager.TryMakeRelative(path); + string pathToLoad = Path.IsPathRooted(processedPath) ? processedPath : PathManager.MakeProgramRelativePath(processedPath); //JUNIPIER SQUATCHBOX COMPLEX if (LuaAlreadyInSession(processedPath) == false) { @@ -199,7 +200,6 @@ namespace BizHawk.Client.EmuHawk { LuaSandbox.Sandbox(() => { - string pathToLoad = PathManager.MakeProgramRelativePath(processedPath); //JUNIPIER SQUATCHBOX COMPLEX luaFile.Thread = LuaImp.SpawnCoroutine(pathToLoad); luaFile.State = LuaFile.RunState.Running; }, () =>