From 4998375a9e89b675ac14876205b082b94d350a06 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 8 Apr 2024 16:41:28 +0200 Subject: [PATCH 1/3] Use NaturalSort.Extension instead of Interop --- Directory.Packages.props | 1 + ILSpy/ILSpy.csproj | 1 + ILSpy/TreeNodes/NaturalStringComparer.cs | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 13e1ebab60..578c8be2f1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -28,6 +28,7 @@ + diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index 5e8184796c..93feab3a11 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -48,6 +48,7 @@ + diff --git a/ILSpy/TreeNodes/NaturalStringComparer.cs b/ILSpy/TreeNodes/NaturalStringComparer.cs index 016b7758f9..dd13ec0870 100644 --- a/ILSpy/TreeNodes/NaturalStringComparer.cs +++ b/ILSpy/TreeNodes/NaturalStringComparer.cs @@ -16,9 +16,13 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System; +using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; +using NaturalSort.Extension; + namespace ICSharpCode.ILSpy.TreeNodes { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass")] @@ -27,7 +31,8 @@ public sealed class NaturalStringComparer : IComparer [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] static extern int StrCmpLogicalW(string psz1, string psz2); - public static readonly NaturalStringComparer Instance = new NaturalStringComparer(); + // public static readonly NaturalStringComparer Instance = new NaturalStringComparer(); + public static readonly IComparer Instance = StringComparison.OrdinalIgnoreCase.WithNaturalSort(); public int Compare(string x, string y) { From b958eaecf1bb06fcb5f887043b317b3c85ac6247 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 15 Apr 2024 14:57:08 +0200 Subject: [PATCH 2/3] Update to latest NaturalSort.Extensions and update 3rd party notices --- Directory.Packages.props | 2 +- ILSpy/TreeNodes/NaturalStringComparer.cs | 20 ++++++++++++---- doc/third-party-notices.txt | 29 ++++++++++++------------ 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 578c8be2f1..1a9168125f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -28,7 +28,7 @@ - + diff --git a/ILSpy/TreeNodes/NaturalStringComparer.cs b/ILSpy/TreeNodes/NaturalStringComparer.cs index dd13ec0870..ba3007b728 100644 --- a/ILSpy/TreeNodes/NaturalStringComparer.cs +++ b/ILSpy/TreeNodes/NaturalStringComparer.cs @@ -17,7 +17,6 @@ // DEALINGS IN THE SOFTWARE. using System; -using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; @@ -25,18 +24,29 @@ namespace ICSharpCode.ILSpy.TreeNodes { + /// + /// .NET natural string comparison emulating .Instance behavior of original native-interop variant + /// + public sealed class NaturalStringComparer + { + public static readonly IComparer Instance = StringComparison.CurrentCultureIgnoreCase.WithNaturalSort(); + // public static readonly NaturalStringComparer Instance = new NaturalStringComparer(); + } + +#if WINDOWS + /// + /// Native-Interop natural string comparion using StrCmpLogicalW from shlwapi.dll + /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass")] - public sealed class NaturalStringComparer : IComparer + public sealed class NativeNaturalStringComparer : IComparer { [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] static extern int StrCmpLogicalW(string psz1, string psz2); - // public static readonly NaturalStringComparer Instance = new NaturalStringComparer(); - public static readonly IComparer Instance = StringComparison.OrdinalIgnoreCase.WithNaturalSort(); - public int Compare(string x, string y) { return StrCmpLogicalW(x, y); } } +#endif } diff --git a/doc/third-party-notices.txt b/doc/third-party-notices.txt index 84d8a2107e..4a9e010b80 100644 --- a/doc/third-party-notices.txt +++ b/doc/third-party-notices.txt @@ -499,32 +499,31 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -License Notice for OSVersionHelper (part of ILSpy) +License Notice for NaturalSort.Extension (part of ILSpy) --------------------------- -https://github.com/novotnyllc/OSVersionHelper/blob/master/LICENSE.txt +https://github.com/tompazourek/NaturalSort.Extension/blob/master/LICENSE The MIT License (MIT) -Copyright (c) [year] [fullname] +Copyright (c) 2022 Tomáš Pažourek -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. License Notice for Tom's Toolbox (part of ILSpy) From e3ec6d8e5918edbbab22660c12cd0599706da13e Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Fri, 26 Apr 2024 12:07:13 +0200 Subject: [PATCH 3/3] Remove old interop implementation --- ILSpy/TreeNodes/NaturalStringComparer.cs | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/ILSpy/TreeNodes/NaturalStringComparer.cs b/ILSpy/TreeNodes/NaturalStringComparer.cs index ba3007b728..40f32bb119 100644 --- a/ILSpy/TreeNodes/NaturalStringComparer.cs +++ b/ILSpy/TreeNodes/NaturalStringComparer.cs @@ -18,35 +18,16 @@ using System; using System.Collections.Generic; -using System.Runtime.InteropServices; using NaturalSort.Extension; namespace ICSharpCode.ILSpy.TreeNodes { /// - /// .NET natural string comparison emulating .Instance behavior of original native-interop variant + /// .NET natural string comparison /// public sealed class NaturalStringComparer { public static readonly IComparer Instance = StringComparison.CurrentCultureIgnoreCase.WithNaturalSort(); - // public static readonly NaturalStringComparer Instance = new NaturalStringComparer(); } - -#if WINDOWS - /// - /// Native-Interop natural string comparion using StrCmpLogicalW from shlwapi.dll - /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass")] - public sealed class NativeNaturalStringComparer : IComparer - { - [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] - static extern int StrCmpLogicalW(string psz1, string psz2); - - public int Compare(string x, string y) - { - return StrCmpLogicalW(x, y); - } - } -#endif }