From 8dd721aee36f566e1b2c9278751ece94e7b81229 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 15 Jun 2022 23:04:56 +0200 Subject: [PATCH] Fix #2706: Filenames and directories truncated to 30 characters. With the built-in support for long paths in .NET 6.0, we no longer need to check for the registry key. The only limitation that remains is maxSegmentLength, which seems to be 255 on all commonly used file systems/all platforms. Also there is no need to differentiate between Windows and other platforms. - Windows Explorer in Windows 10 seems to be fine with files generated by ILSpy that have names longer than 260 characters. - Notepad++ and other applications seem to use 8.3 path syntax to access the file. - Visual Studio 2022 does not like the long path names, affected users should raise an issue with MS. ILSpy generates proper paths. --- .../WholeProjectDecompiler.cs | 36 ++----------------- .../ICSharpCode.Decompiler.csproj | 1 - 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs index 6b0bf55fe..ad3ffdb8f 100644 --- a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs @@ -47,6 +47,8 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler /// public class WholeProjectDecompiler : IProjectInfoProvider { + const int maxSegmentLength = 255; + #region Settings /// /// Gets the setting this instance uses for decompiling. @@ -536,37 +538,6 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler } #endregion - static readonly Lazy<(bool longPathsEnabled, int maxPathLength, int maxSegmentLength)> longPathSupport = - new Lazy<(bool longPathsEnabled, int maxPathLength, int maxSegmentLength)>(GetLongPathSupport, isThreadSafe: true); - - static (bool longPathsEnabled, int maxPathLength, int maxSegmentLength) GetLongPathSupport() - { - try - { - switch (Environment.OSVersion.Platform) - { - case PlatformID.MacOSX: - case PlatformID.Unix: - return (true, int.MaxValue, 255); - case PlatformID.Win32NT: - const string key = @"SYSTEM\CurrentControlSet\Control\FileSystem"; - var fileSystem = Registry.LocalMachine.OpenSubKey(key); - var value = (int?)fileSystem.GetValue("LongPathsEnabled"); - if (value == 1) - { - return (true, int.MaxValue, 255); - } - return (false, 200, 30); - default: - return (false, 200, 30); - } - } - catch - { - return (false, 200, 30); - } - } - /// /// Cleans up a node name for use as a file name. /// @@ -601,7 +572,6 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler text = text.Trim(); string extension = null; int currentSegmentLength = 0; - var (supportsLongPaths, maxPathLength, maxSegmentLength) = longPathSupport.Value; if (treatAsFileName) { // Check if input is a file name, i.e., has a valid extension @@ -663,8 +633,6 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler if (currentSegmentLength <= maxSegmentLength) b.Append('-'); } - if (b.Length >= maxPathLength && !supportsLongPaths) - break; // limit to 200 chars, if long paths are not supported. } if (b.Length == 0) b.Append('-'); diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index e168def6e..b17df4ce6 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -65,7 +65,6 @@ -