diff --git a/BizHawk.Client.Common/PathManager.cs b/BizHawk.Client.Common/PathManager.cs index 465dacb381..b86cccb6a4 100644 --- a/BizHawk.Client.Common/PathManager.cs +++ b/BizHawk.Client.Common/PathManager.cs @@ -428,21 +428,44 @@ namespace BizHawk.Client.Common // http://stackoverflow.com/questions/3525775/how-to-check-if-directory-1-is-a-subdirectory-of-dir2-and-vice-versa private static bool IsSubfolder(string parentPath, string childPath) { - var parentUri = new Uri(parentPath); - - var childUri = new DirectoryInfo(childPath).Parent; - - while (childUri != null) + if (!BizHawk.Common.PlatformLinkedLibSingleton.RunningOnUnix) { - if (new Uri(childUri.FullName) == parentUri) + var parentUri = new Uri(parentPath); + + var childUri = new DirectoryInfo(childPath).Parent; + + while (childUri != null) { - return true; + if (new Uri(childUri.FullName) == parentUri) + { + return true; + } + + childUri = childUri.Parent; } - childUri = childUri.Parent; + return false; } + else + { + var parentUri = new Uri(parentPath.TrimEnd('.')); - return false; + var childUri = new DirectoryInfo(childPath).Parent; + + while (childUri != null) + { + var ch = new Uri(childUri.FullName).AbsolutePath.TrimEnd('/'); + var pr = parentUri.AbsolutePath.TrimEnd('/'); + if (ch == pr) + { + return true; + } + + childUri = childUri.Parent; + } + + return false; + } } /// diff --git a/BizHawk.Client.Common/lua/LuaSandbox.cs b/BizHawk.Client.Common/lua/LuaSandbox.cs index 7a025ebfa6..29f911a12d 100644 --- a/BizHawk.Client.Common/lua/LuaSandbox.cs +++ b/BizHawk.Client.Common/lua/LuaSandbox.cs @@ -44,20 +44,23 @@ namespace BizHawk.Client.Common // WARNING: setting the current directory is SLOW!!! security checks for some reason. // so we're bypassing it with windows hacks - #if WINDOWS + if (!BizHawk.Common.PlatformLinkedLibSingleton.RunningOnUnix) + { fixed (byte* pstr = &System.Text.Encoding.Unicode.GetBytes(target + "\0")[0]) return SetCurrentDirectoryW(pstr); - #else - if (System.IO.Directory.Exists(CurrentDirectory)) // race condition for great justice + } + else + { + if (System.IO.Directory.Exists(_currentDirectory)) // race condition for great justice { - Environment.CurrentDirectory = CurrentDirectory; // thats right, you can't set a directory as current that doesnt exist because .net's got to do SENSELESS SLOW-ASS SECURITY CHECKS on it and it can't do that on a NONEXISTENT DIRECTORY + Environment.CurrentDirectory = _currentDirectory; // thats right, you can't set a directory as current that doesnt exist because .net's got to do SENSELESS SLOW-ASS SECURITY CHECKS on it and it can't do that on a NONEXISTENT DIRECTORY return true; } else { return false; } - #endif + } } private string CoolGetCurrentDirectory() @@ -66,16 +69,19 @@ namespace BizHawk.Client.Common // .NET DOES A SECURITY CHECK ON THE DIRECTORY WE JUST RETRIEVED // AS IF ASKING FOR THE CURRENT DIRECTORY IS EQUIVALENT TO TRYING TO ACCESS IT // SCREW YOU - #if WINDOWS + if (!BizHawk.Common.PlatformLinkedLibSingleton.RunningOnUnix) + { var buf = new byte[32768]; - fixed(byte* pBuf = &buf[0]) + fixed (byte* pBuf = &buf[0]) { uint ret = GetCurrentDirectoryW(32767, pBuf); - return System.Text.Encoding.Unicode.GetString(buf, 0, (int)ret*2); + return System.Text.Encoding.Unicode.GetString(buf, 0, (int)ret * 2); } - #else + } + else + { return Environment.CurrentDirectory; - #endif + } } private void Sandbox(Action callback, Action exceptionCallback) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index c84ad96923..fd055c4f22 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -58,8 +58,8 @@ namespace BizHawk.Client.EmuHawk if (AskSaveChanges()) { SaveColumnInfo(LuaListView, Settings.Columns); - - GlobalWin.DisplayManager.ClearLuaSurfaces(); + if (GlobalWin.DisplayManager != null) + GlobalWin.DisplayManager.ClearLuaSurfaces(); LuaImp.GuiLibrary.DrawFinish(); CloseLua(); } @@ -174,7 +174,7 @@ namespace BizHawk.Client.EmuHawk var currentScripts = LuaImp?.ScriptList; // Temp fix for now LuaImp = PlatformLinkedLibSingleton.RunningOnUnix - ? (PlatformEmuLuaLibrary) new NotReallyLuaLibrary() + ? (PlatformEmuLuaLibrary) new EmuLuaLibrary(Emulator.ServiceProvider)//NotReallyLuaLibrary() : (PlatformEmuLuaLibrary) new EmuLuaLibrary(Emulator.ServiceProvider); if (currentScripts != null) { diff --git a/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/BizHawk.Client.EmuHawk/tools/ToolManager.cs index e26c0930ef..fc257ceb12 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -732,7 +732,7 @@ namespace BizHawk.Client.EmuHawk return false; } - if (t == typeof(LuaConsole) && PlatformLinkedLibSingleton.RunningOnUnix) return false; + //if (t == typeof(LuaConsole) && PlatformLinkedLibSingleton.RunningOnUnix) return false; var tool = Assembly .GetExecutingAssembly()