From 6858a365523981bddfe670e61e4470a70e290487 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 31 Jan 2021 10:02:45 +1000 Subject: [PATCH] Fix Unix implementation of GetRelativePath; expand on docs --- .../tools/MultiDiskBundler/MultiDiskBundler.cs | 2 +- src/BizHawk.Common/Extensions/PathExtensions.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs index 79cd66b069..1a00d10eb4 100644 --- a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs +++ b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs @@ -213,7 +213,7 @@ namespace BizHawk.Client.EmuHawk new XElement("LoadAssets", names.Select(n => new XElement( "Asset", - new XAttribute("FileName", OSTailoredCode.IsUnixHost ? PathExtensions.GetRelativePath(n, basePath) : PathExtensions.GetRelativePath(basePath, n)) + new XAttribute("FileName", PathExtensions.GetRelativePath(basePath, n)) )) ) ); diff --git a/src/BizHawk.Common/Extensions/PathExtensions.cs b/src/BizHawk.Common/Extensions/PathExtensions.cs index 4aaa40dcd1..e7c04b4ed5 100644 --- a/src/BizHawk.Common/Extensions/PathExtensions.cs +++ b/src/BizHawk.Common/Extensions/PathExtensions.cs @@ -50,11 +50,15 @@ namespace BizHawk.Common.PathExtensions /// running on Windows host, and unmanaged call failed /// running on Windows host, and either path is not a regular file or directory - /// Algorithm for Windows taken from https://stackoverflow.com/a/485516/7467292 + /// + /// always returns a relative path, even if it means going up first
+ /// algorithm for Windows taken from https://stackoverflow.com/a/485516/7467292
+ /// the parameter names seem backwards, but those are the names used in the Win32 API we're calling + ///
public static string? GetRelativePath(string? fromPath, string? toPath) { if (fromPath == null || toPath == null) return null; - if (OSTailoredCode.IsUnixHost) return fromPath.MakeRelativeTo(toPath); + if (OSTailoredCode.IsUnixHost) return toPath.MakeRelativeTo(fromPath); //TODO merge this with the Windows implementation in MakeRelativeTo static FileAttributes GetPathAttribute(string path1) @@ -87,7 +91,10 @@ namespace BizHawk.Common.PathExtensions public static string MakeProgramRelativePath(this string path) => Path.Combine(PathUtils.ExeDirectoryPath, path); /// the relative path which is equivalent to when the CWD is , or if either path is - /// returned string omits trailing slash; implementation calls for you + /// + /// only returns a relative path if is a child of (uses ), otherwise returns
+ /// returned string omits trailing slash + ///
public static string? MakeRelativeTo(this string? absolutePath, string? basePath) { if (absolutePath == null || basePath == null) return null;