From dccaa2b87807d261adc2611ccec14782dbcc7e5b Mon Sep 17 00:00:00 2001 From: Asnivor Date: Tue, 22 Jan 2019 13:56:57 +0000 Subject: [PATCH] Client.Common.PathManager (unix): fixes to trymakerelative - Paths dialog now functions as it should #8 --- BizHawk.Client.Common/PathManager.cs | 44 +++++++++++++++++++++------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/BizHawk.Client.Common/PathManager.cs b/BizHawk.Client.Common/PathManager.cs index b86cccb6a4..f435daf410 100644 --- a/BizHawk.Client.Common/PathManager.cs +++ b/BizHawk.Client.Common/PathManager.cs @@ -407,9 +407,24 @@ namespace BizHawk.Client.Common GetGlobalBasePathAbsolute() : MakeAbsolutePath(GetPlatformBase(system), system); - if (IsSubfolder(parentPath, absolutePath)) + if (!BizHawk.Common.PlatformLinkedLibSingleton.RunningOnUnix) { - return absolutePath.Replace(parentPath, "."); + if (IsSubfolder(parentPath, absolutePath)) + { + return absolutePath.Replace(parentPath, "."); + } + } + else + { + // weird kludges for linux systems + if (IsSubfolder(parentPath, absolutePath)) + { + return absolutePath.Replace(parentPath.TrimEnd('.'), "./"); + } + else if (parentPath.TrimEnd('.') == absolutePath + "/") + { + return "."; + } } return absolutePath; @@ -448,23 +463,30 @@ namespace BizHawk.Client.Common } else { + // more weird linux stuff var parentUri = new Uri(parentPath.TrimEnd('.')); - var childUri = new DirectoryInfo(childPath).Parent; - while (childUri != null) + try { - var ch = new Uri(childUri.FullName).AbsolutePath.TrimEnd('/'); - var pr = parentUri.AbsolutePath.TrimEnd('/'); - if (ch == pr) + while (childUri != null) { - return true; + var ch = new Uri(childUri.FullName).AbsolutePath.TrimEnd('/'); + var pr = parentUri.AbsolutePath.TrimEnd('/'); + if (ch == pr) + { + return true; + } + + childUri = childUri.Parent; } - childUri = childUri.Parent; + return false; + } + catch + { + return false; } - - return false; } }