From 8ac9f7d2ddc0a42f970d7221145650dd1a1e4461 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 23 Mar 2014 14:44:18 +0000 Subject: [PATCH] Lua Console - try to use relative paths when saving and loading lua scripts --- BizHawk.Client.Common/lua/LuaFileList.cs | 2 +- .../tools/Lua/LuaConsole.cs | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/BizHawk.Client.Common/lua/LuaFileList.cs b/BizHawk.Client.Common/lua/LuaFileList.cs index 4c5f8b11c5..b608e88a40 100644 --- a/BizHawk.Client.Common/lua/LuaFileList.cs +++ b/BizHawk.Client.Common/lua/LuaFileList.cs @@ -138,7 +138,7 @@ namespace BizHawk.Client.Common sb .Append(file.Enabled ? "1" : "0") .Append(' ') - .Append(file.Path) + .Append(PathManager.TryMakeRelative(file.Path)) .AppendLine(); } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 1c0213a044..1a8338660e 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -109,18 +109,20 @@ namespace BizHawk.Client.EmuHawk public void LoadLuaFile(string path) { - if (LuaAlreadyInSession(path) == false) + var processedPath = PathManager.TryMakeRelative(path); + + if (LuaAlreadyInSession(processedPath) == false) { - var luaFile = new LuaFile(string.Empty, path); + var luaFile = new LuaFile(string.Empty, processedPath); _luaList.Add(luaFile); LuaListView.ItemCount = _luaList.Count; - Global.Config.RecentLua.Add(path); + Global.Config.RecentLua.Add(processedPath); if (!Global.Config.DisableLuaScriptsOnLoad) { try { - luaFile.Thread = LuaImp.SpawnCoroutine(path); + luaFile.Thread = LuaImp.SpawnCoroutine(processedPath); luaFile.Enabled = true; } catch (Exception e) @@ -145,7 +147,7 @@ namespace BizHawk.Client.EmuHawk } else { - foreach (var file in _luaList.Where(file => path == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad)) + foreach (var file in _luaList.Where(file => processedPath == file.Path && file.Enabled == false && !Global.Config.DisableLuaScriptsOnLoad)) { file.Toggle(); break; @@ -234,10 +236,20 @@ namespace BizHawk.Client.EmuHawk } else if (column == 1) { - text = _luaList[index].Path; + text = DressUpRelative(_luaList[index].Path); } } + private string DressUpRelative(string path) + { + if (path.StartsWith(".\\")) + { + return path.Replace(".\\", string.Empty); + } + + return path; + } + private void SaveConfigSettings() { LuaImp.Close();