try sandboxing currenty directory harder
This commit is contained in:
parent
ab16e9238b
commit
da865e28b8
|
@ -13,13 +13,30 @@ namespace BizHawk.Client.Common
|
|||
public static void SetLogger(Action<string> logger)
|
||||
{
|
||||
Logger = logger;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void SetCurrentDirectory(string dir)
|
||||
{
|
||||
CurrentDirectory = dir;
|
||||
}
|
||||
|
||||
static string CurrentDirectory;
|
||||
|
||||
public static void Sandbox(Action callback, Action exceptionCallback = null)
|
||||
{
|
||||
string savedEnvironmentCurrDir = null;
|
||||
try
|
||||
{
|
||||
//so. lets talk about current directories.
|
||||
//ideally we'd have one current directory per script. but things get hairy.
|
||||
//events and callbacks can get setup and it isn't clear what script they belong to.
|
||||
//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;
|
||||
|
||||
EnvironmentSandbox.Sandbox(callback);
|
||||
CurrentDirectory = Environment.CurrentDirectory;
|
||||
}
|
||||
catch (LuaException ex)
|
||||
{
|
||||
|
@ -29,6 +46,11 @@ namespace BizHawk.Client.Common
|
|||
exceptionCallback();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(savedEnvironmentCurrDir != null)
|
||||
Environment.CurrentDirectory = savedEnvironmentCurrDir;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
LuaListView.VirtualMode = true;
|
||||
|
||||
LuaSandbox.SetLogger(this.ConsoleLog);
|
||||
LuaSandbox.SetCurrentDirectory(PathManager.GetLuaPath());
|
||||
}
|
||||
|
||||
public EmuLuaLibrary LuaImp { get; set; }
|
||||
|
@ -162,7 +163,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
LuaSandbox.Sandbox(() =>
|
||||
{
|
||||
file.Thread = LuaImp.SpawnCoroutine(file.Path);
|
||||
string pathToLoad = PathManager.MakeProgramRelativePath(file.Path); //JUNIPIER SQUATCHBOX COMPLEX
|
||||
file.Thread = LuaImp.SpawnCoroutine(pathToLoad);
|
||||
file.State = LuaFile.RunState.Running;
|
||||
}, () =>
|
||||
{
|
||||
|
@ -197,7 +199,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
LuaSandbox.Sandbox(() =>
|
||||
{
|
||||
luaFile.Thread = LuaImp.SpawnCoroutine(processedPath);
|
||||
string pathToLoad = PathManager.MakeProgramRelativePath(processedPath); //JUNIPIER SQUATCHBOX COMPLEX
|
||||
luaFile.Thread = LuaImp.SpawnCoroutine(pathToLoad);
|
||||
luaFile.State = LuaFile.RunState.Running;
|
||||
}, () =>
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue