Skip to content

Commit

Permalink
Merge #4297 Fix cloning instances with shared stock files on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 6, 2025
2 parents 644cf5f + d3ac667 commit 7dbd3e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ All notable changes to this project will be documented in this file.
- [Core] Small performance tweaks for DLL scanning (#4275 by: HebaruSan)
- [GUI] Fix broken version label in About dialog (#4277 by: HebaruSan)
- [Core] Handle missing indexes in Steam vdf file lists (#4279 by: HebaruSan)
- [Core] Fix cloning instances with shared stock files on Windows (#4297 by: HebaruSan)

### Internal

Expand Down
19 changes: 15 additions & 4 deletions Core/DirectoryLink.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<string> toRemove)
=> toRemove.FirstOrDefault(orig.StartsWith) switch
{
string s => orig[s.Length..],
null => orig,
};

private static readonly string[] WindowsPathPrefixes = new string[]
{
@"\\?\",
@"\??\",
@"\\.\",
};
}
}

0 comments on commit 7dbd3e9

Please sign in to comment.