diff --git a/Core/DirectoryLink.cs b/Core/DirectoryLink.cs index a87d21207..369d779cd 100644 --- a/Core/DirectoryLink.cs +++ b/Core/DirectoryLink.cs @@ -1,5 +1,7 @@ using System; using System.IO; +using System.Linq; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; using Microsoft.Win32.SafeHandles; @@ -71,7 +73,7 @@ public static bool TryGetTarget(string link, out string? target) { if (junctionInfo.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { - target = junctionInfo.PathBuffer.TrimStart("\\\\?\\"); + target = junctionInfo.PathBuffer.TrimStart(WindowsPathPrefixes); } } h.Close(); @@ -203,9 +205,18 @@ private static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPTStr) [MarshalAs(UnmanagedType.U4)] uint flagsAndAttributes, IntPtr templateFile); - private static string TrimStart(this string orig, string toRemove) - => orig.StartsWith(toRemove) ? orig.Remove(0, toRemove.Length) - : orig; + private static string TrimStart(this string orig, IEnumerable toRemove) + => toRemove.FirstOrDefault(orig.StartsWith) switch + { + string s => orig[s.Length..], + null => orig, + }; + private static readonly string[] WindowsPathPrefixes = new string[] + { + @"\\?\", + @"\??\", + @"\\.\", + }; } }