fix global base path handling to make some sense to me
This commit is contained in:
parent
e2d0e7dfc3
commit
9ad4c32b73
|
@ -45,44 +45,23 @@ namespace BizHawk.Client.Common
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets absolute base as derived from EXE
|
/// Gets absolute base as derived from EXE
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetBasePathAbsolute()
|
public static string GetGlobalBasePathAbsolute()
|
||||||
{
|
{
|
||||||
if (Global.Config.PathEntries.GlobalBaseFragment.Length < 1) // If empty, then EXE path
|
var gbase = Global.Config.PathEntries.GlobalBaseFragment;
|
||||||
{
|
|
||||||
return GetExeDirectoryAbsolute();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Global.Config.PathEntries.GlobalBaseFragment.Length >= 5
|
// if %exe% prefixed then substitute exe path and repeat
|
||||||
&& Global.Config.PathEntries.GlobalBaseFragment.Substring(0, 5) == "%exe%")
|
if(gbase.StartsWith("%exe%",StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
gbase = GetExeDirectoryAbsolute() + gbase.Substring(5);
|
||||||
return GetExeDirectoryAbsolute();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Global.Config.PathEntries.GlobalBaseFragment[0] == '.')
|
//rooted paths get returned without change
|
||||||
{
|
//(this is done after keyword substitution to avoid problems though)
|
||||||
if (Global.Config.PathEntries.GlobalBaseFragment.Length == 1)
|
if (Path.IsPathRooted(gbase))
|
||||||
{
|
return gbase;
|
||||||
return GetExeDirectoryAbsolute();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Global.Config.PathEntries.GlobalBaseFragment.Length == 2 &&
|
//not-rooted things are relative to exe path
|
||||||
Global.Config.PathEntries.GlobalBaseFragment == ".\\")
|
gbase = Path.Combine(GetExeDirectoryAbsolute(), gbase);
|
||||||
{
|
|
||||||
return GetExeDirectoryAbsolute();
|
|
||||||
}
|
|
||||||
|
|
||||||
var tmp = Global.Config.PathEntries.GlobalBaseFragment.Remove(0, 1);
|
return gbase;
|
||||||
tmp = tmp.Insert(0, GetExeDirectoryAbsolute());
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Global.Config.PathEntries.GlobalBaseFragment.Substring(0, 2) == "..")
|
|
||||||
{
|
|
||||||
return RemoveParents(Global.Config.PathEntries.GlobalBaseFragment, GetExeDirectoryAbsolute());
|
|
||||||
}
|
|
||||||
|
|
||||||
// In case of error, return EXE path
|
|
||||||
return GetExeDirectoryAbsolute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetPlatformBase(string system)
|
public static string GetPlatformBase(string system)
|
||||||
|
@ -106,7 +85,7 @@ namespace BizHawk.Client.Common
|
||||||
// This function translates relative path and special identifiers in absolute paths
|
// This function translates relative path and special identifiers in absolute paths
|
||||||
if (path.Length < 1)
|
if (path.Length < 1)
|
||||||
{
|
{
|
||||||
return GetBasePathAbsolute();
|
return GetGlobalBasePathAbsolute();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path == "%recent%")
|
if (path == "%recent%")
|
||||||
|
@ -136,13 +115,13 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
if (path.Length == 1)
|
if (path.Length == 1)
|
||||||
{
|
{
|
||||||
return GetBasePathAbsolute();
|
return GetGlobalBasePathAbsolute();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path[0] == '.')
|
if (path[0] == '.')
|
||||||
{
|
{
|
||||||
path = path.Remove(0, 1);
|
path = path.Remove(0, 1);
|
||||||
path = path.Insert(0, GetBasePathAbsolute());
|
path = path.Insert(0, GetGlobalBasePathAbsolute());
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
|
@ -414,7 +393,7 @@ namespace BizHawk.Client.Common
|
||||||
public static string TryMakeRelative(string absolutePath, string system = null)
|
public static string TryMakeRelative(string absolutePath, string system = null)
|
||||||
{
|
{
|
||||||
var parentPath = string.IsNullOrWhiteSpace(system) ?
|
var parentPath = string.IsNullOrWhiteSpace(system) ?
|
||||||
GetBasePathAbsolute() :
|
GetGlobalBasePathAbsolute() :
|
||||||
MakeAbsolutePath(GetPlatformBase(system), system);
|
MakeAbsolutePath(GetPlatformBase(system), system);
|
||||||
|
|
||||||
if (IsSubfolder(parentPath, absolutePath))
|
if (IsSubfolder(parentPath, absolutePath))
|
||||||
|
|
|
@ -188,7 +188,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
if (attachedConsole)
|
if (attachedConsole)
|
||||||
{
|
{
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
Console.WriteLine("use cmd /c {0} to get more sensible console behaviour", Path.GetFileName(PathManager.GetBasePathAbsolute()));
|
Console.WriteLine("use cmd /c {0} to get more sensible console behaviour", Path.GetFileName(PathManager.GetGlobalBasePathAbsolute()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue