Browse Source

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.
pull/2726/head
Siegfried Pammer 3 years ago
parent
commit
8dd721aee3
  1. 36
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs
  2. 1
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

36
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs

@ -47,6 +47,8 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -47,6 +47,8 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
/// </summary>
public class WholeProjectDecompiler : IProjectInfoProvider
{
const int maxSegmentLength = 255;
#region Settings
/// <summary>
/// Gets the setting this instance uses for decompiling.
@ -536,37 +538,6 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -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);
}
}
/// <summary>
/// Cleans up a node name for use as a file name.
/// </summary>
@ -601,7 +572,6 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -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 @@ -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('-');

1
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -65,7 +65,6 @@ @@ -65,7 +65,6 @@
<Import Project="..\packages.props" />
<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">

Loading…
Cancel
Save