using System.Runtime.InteropServices; namespace FluidExplorer.Services.Shell; /// /// 资源管理器"名称"列用的排序:调用系统 shlwapi 的 StrCmpLogicalW(自然排序,数字按数值比较)。 /// 这样 "文件2" 会排在 "文件10" 前面,和原版体验一致。 /// public sealed class NaturalStringComparer : IComparer { public static NaturalStringComparer Instance { get; } = new(); public int Compare(string? x, string? y) { if (ReferenceEquals(x, y)) return 0; if (x is null) return -1; if (y is null) return 1; try { return StrCmpLogicalW(x, y); } catch { return string.Compare(x, y, StringComparison.CurrentCultureIgnoreCase); } } [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] private static extern int StrCmpLogicalW(string psz1, string psz2); }