Lua: enabled LuaConsole and fixed various linux-related path method issues (#8)

(the Lua VirtualListView is still not functional on mono yet though)
This commit is contained in:
Asnivor 2019-01-22 12:09:35 +00:00 committed by GitHub
parent cc5331b767
commit 519e114721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 23 deletions

View File

@ -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;
}
}
/// <summary>

View File

@ -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)

View File

@ -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)
{

View File

@ -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()