remove path-too-long exception handling

The path length limit no longer applies in .NET 5.
This commit is contained in:
Jesse Plamondon-Willard 2021-08-18 23:55:43 -04:00
parent b349e956c6
commit 89c98223eb
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
3 changed files with 1 additions and 57 deletions

View File

@ -259,17 +259,6 @@ namespace StardewModdingApi.Installer
Console.ReadLine();
return;
}
// game folder doesn't contain paths beyond the max limit
{
string[] tooLongPaths = PathUtilities.GetTooLongPaths(Path.Combine(paths.GamePath, "Mods")).ToArray();
if (tooLongPaths.Any())
{
this.PrintError($"SMAPI can't install to the detected game folder, because some of its files exceed the maximum {context.Platform} path length.\nIf you need help fixing this error, see https://smapi.io/help\n\nAffected paths:\n {string.Join("\n ", tooLongPaths)}");
Console.ReadLine();
return;
}
}
Console.Clear();

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
@ -150,32 +149,5 @@ namespace StardewModdingAPI.Toolkit.Utilities
{
return !Regex.IsMatch(str, "[^a-z0-9_.-]", RegexOptions.IgnoreCase);
}
/// <summary>Get the paths which exceed the OS length limit.</summary>
/// <param name="rootPath">The root path to search.</param>
internal static IEnumerable<string> GetTooLongPaths(string rootPath)
{
if (!Directory.Exists(rootPath))
return new string[0];
return Directory
.EnumerateFileSystemEntries(rootPath, "*.*", SearchOption.AllDirectories)
.Where(PathUtilities.IsPathTooLong);
}
/// <summary>Get whether a file or directory path exceeds the OS path length limit.</summary>
/// <param name="path">The path to test.</param>
internal static bool IsPathTooLong(string path)
{
try
{
_ = Path.GetFullPath(path);
return false;
}
catch (PathTooLongException)
{
return true;
}
}
}
}

View File

@ -250,24 +250,7 @@ namespace StardewModdingAPI.Framework.Logging
/// <param name="exception">The exception details.</param>
public void LogFatalLaunchError(Exception exception)
{
switch (exception)
{
// path too long exception
case PathTooLongException _:
{
string[] affectedPaths = PathUtilities.GetTooLongPaths(Constants.ModsPath).ToArray();
string message = affectedPaths.Any()
? $"SMAPI can't launch because some of your mod files exceed the maximum path length on {Constants.Platform}.\nIf you need help fixing this error, see https://smapi.io/help\n\nAffected paths:\n {string.Join("\n ", affectedPaths)}"
: $"The game failed to launch: {exception.GetLogSummary()}";
this.MonitorForGame.Log(message, LogLevel.Error);
}
break;
// generic exception
default:
this.MonitorForGame.Log($"The game failed to launch: {exception.GetLogSummary()}", LogLevel.Error);
break;
}
this.MonitorForGame.Log($"The game failed to launch: {exception.GetLogSummary()}", LogLevel.Error);
}
/****