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:
parent
24a517d293
commit
b1b94da6ef
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue