Skip to content

Commit 519e114

Browse files
authored
Lua: enabled LuaConsole and fixed various linux-related path method issues (#8)
(the Lua VirtualListView is still not functional on mono yet though)
1 parent cc5331b commit 519e114

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

BizHawk.Client.Common/PathManager.cs

+31-8
Original file line numberDiff line numberDiff line change
@@ -428,21 +428,44 @@ public static string MakeRelativeTo(string absolutePath, string basePath)
428428
// http://stackoverflow.com/questions/3525775/how-to-check-if-directory-1-is-a-subdirectory-of-dir2-and-vice-versa
429429
private static bool IsSubfolder(string parentPath, string childPath)
430430
{
431-
var parentUri = new Uri(parentPath);
431+
if (!BizHawk.Common.PlatformLinkedLibSingleton.RunningOnUnix)
432+
{
433+
var parentUri = new Uri(parentPath);
432434

433-
var childUri = new DirectoryInfo(childPath).Parent;
435+
var childUri = new DirectoryInfo(childPath).Parent;
434436

435-
while (childUri != null)
436-
{
437-
if (new Uri(childUri.FullName) == parentUri)
437+
while (childUri != null)
438438
{
439-
return true;
439+
if (new Uri(childUri.FullName) == parentUri)
440+
{
441+
return true;
442+
}
443+
444+
childUri = childUri.Parent;
440445
}
441446

442-
childUri = childUri.Parent;
447+
return false;
443448
}
449+
else
450+
{
451+
var parentUri = new Uri(parentPath.TrimEnd('.'));
444452

445-
return false;
453+
var childUri = new DirectoryInfo(childPath).Parent;
454+
455+
while (childUri != null)
456+
{
457+
var ch = new Uri(childUri.FullName).AbsolutePath.TrimEnd('/');
458+
var pr = parentUri.AbsolutePath.TrimEnd('/');
459+
if (ch == pr)
460+
{
461+
return true;
462+
}
463+
464+
childUri = childUri.Parent;
465+
}
466+
467+
return false;
468+
}
446469
}
447470

448471
/// <summary>

BizHawk.Client.Common/lua/LuaSandbox.cs

+16-10
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,23 @@ private bool CoolSetCurrentDirectory(string path, string currDirSpeedHack = null
4444

4545
// WARNING: setting the current directory is SLOW!!! security checks for some reason.
4646
// so we're bypassing it with windows hacks
47-
#if WINDOWS
47+
if (!BizHawk.Common.PlatformLinkedLibSingleton.RunningOnUnix)
48+
{
4849
fixed (byte* pstr = &System.Text.Encoding.Unicode.GetBytes(target + "\0")[0])
4950
return SetCurrentDirectoryW(pstr);
50-
#else
51-
if (System.IO.Directory.Exists(CurrentDirectory)) // race condition for great justice
51+
}
52+
else
53+
{
54+
if (System.IO.Directory.Exists(_currentDirectory)) // race condition for great justice
5255
{
53-
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
56+
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
5457
return true;
5558
}
5659
else
5760
{
5861
return false;
5962
}
60-
#endif
63+
}
6164
}
6265

6366
private string CoolGetCurrentDirectory()
@@ -66,16 +69,19 @@ private string CoolGetCurrentDirectory()
6669
// .NET DOES A SECURITY CHECK ON THE DIRECTORY WE JUST RETRIEVED
6770
// AS IF ASKING FOR THE CURRENT DIRECTORY IS EQUIVALENT TO TRYING TO ACCESS IT
6871
// SCREW YOU
69-
#if WINDOWS
72+
if (!BizHawk.Common.PlatformLinkedLibSingleton.RunningOnUnix)
73+
{
7074
var buf = new byte[32768];
71-
fixed(byte* pBuf = &buf[0])
75+
fixed (byte* pBuf = &buf[0])
7276
{
7377
uint ret = GetCurrentDirectoryW(32767, pBuf);
74-
return System.Text.Encoding.Unicode.GetString(buf, 0, (int)ret*2);
78+
return System.Text.Encoding.Unicode.GetString(buf, 0, (int)ret * 2);
7579
}
76-
#else
80+
}
81+
else
82+
{
7783
return Environment.CurrentDirectory;
78-
#endif
84+
}
7985
}
8086

8187
private void Sandbox(Action callback, Action exceptionCallback)

BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public LuaConsole()
5858
if (AskSaveChanges())
5959
{
6060
SaveColumnInfo(LuaListView, Settings.Columns);
61-
62-
GlobalWin.DisplayManager.ClearLuaSurfaces();
61+
if (GlobalWin.DisplayManager != null)
62+
GlobalWin.DisplayManager.ClearLuaSurfaces();
6363
LuaImp.GuiLibrary.DrawFinish();
6464
CloseLua();
6565
}
@@ -174,7 +174,7 @@ public void Restart()
174174

175175
var currentScripts = LuaImp?.ScriptList; // Temp fix for now
176176
LuaImp = PlatformLinkedLibSingleton.RunningOnUnix
177-
? (PlatformEmuLuaLibrary) new NotReallyLuaLibrary()
177+
? (PlatformEmuLuaLibrary) new EmuLuaLibrary(Emulator.ServiceProvider)//NotReallyLuaLibrary()
178178
: (PlatformEmuLuaLibrary) new EmuLuaLibrary(Emulator.ServiceProvider);
179179
if (currentScripts != null)
180180
{

BizHawk.Client.EmuHawk/tools/ToolManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ public bool IsAvailable(Type t)
732732
return false;
733733
}
734734

735-
if (t == typeof(LuaConsole) && PlatformLinkedLibSingleton.RunningOnUnix) return false;
735+
//if (t == typeof(LuaConsole) && PlatformLinkedLibSingleton.RunningOnUnix) return false;
736736

737737
var tool = Assembly
738738
.GetExecutingAssembly()

0 commit comments

Comments
 (0)