Lua Sessions - make scripts relative to the lua session instead of relative to the .exe, note: this wrecks existing luases files

This commit is contained in:
adelikat 2015-01-29 02:08:12 +00:00
parent 24a517d293
commit b1b94da6ef
2 changed files with 19 additions and 2 deletions

View File

@ -359,6 +359,16 @@ namespace BizHawk.Client.Common
return absolutePath;
}
public static string MakeRelativeTo(string absolutePath, string basePath)
{
if (IsSubfolder(basePath, absolutePath))
{
return absolutePath.Replace(basePath, ".");
}
return absolutePath;
}
//http://stackoverflow.com/questions/3525775/how-to-check-if-directory-1-is-a-subdirectory-of-dir2-and-vice-versa
public static bool IsSubfolder(string parentPath, string childPath)
{

View File

@ -96,7 +96,14 @@ namespace BizHawk.Client.Common
}
else
{
Add(new LuaFile(line.Substring(2, line.Length - 2))
var scriptPath = line.Substring(2, line.Length - 2);
if (!Path.IsPathRooted(scriptPath))
{
var directory = Path.GetDirectoryName(path);
scriptPath = Path.Combine(directory, scriptPath);
}
Add(new LuaFile(scriptPath)
{
Enabled = !Global.Config.DisableLuaScriptsOnLoad &&
line.Substring(0, 1) == "1",
@ -138,7 +145,7 @@ namespace BizHawk.Client.Common
sb
.Append(file.Enabled ? "1" : "0")
.Append(' ')
.Append(PathManager.TryMakeRelative(file.Path))
.Append(PathManager.MakeRelativeTo(file.Path, Path.GetDirectoryName(path)))
.AppendLine();
}