diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-03-07 18:04:48 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-03-07 18:04:48 -0500 |
commit | 0ed46c09104b823a5784690fa50e7022efc12c8f (patch) | |
tree | 6e2259d828b761449b27b4c9df85e7bdaea401f9 /src/SMAPI.Toolkit | |
parent | 36cb8e8fcb8afd2965ffe26e7755eb11838264d7 (diff) | |
download | SMAPI-0ed46c09104b823a5784690fa50e7022efc12c8f.tar.gz SMAPI-0ed46c09104b823a5784690fa50e7022efc12c8f.tar.bz2 SMAPI-0ed46c09104b823a5784690fa50e7022efc12c8f.zip |
add descriptive error for PathTooLongException which crashes SMAPI or the installer
Diffstat (limited to 'src/SMAPI.Toolkit')
-rw-r--r-- | src/SMAPI.Toolkit/Properties/AssemblyInfo.cs | 1 | ||||
-rw-r--r-- | src/SMAPI.Toolkit/Utilities/PathUtilities.cs | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/SMAPI.Toolkit/Properties/AssemblyInfo.cs b/src/SMAPI.Toolkit/Properties/AssemblyInfo.cs index 233e680b..eede4562 100644 --- a/src/SMAPI.Toolkit/Properties/AssemblyInfo.cs +++ b/src/SMAPI.Toolkit/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("StardewModdingAPI")] +[assembly: InternalsVisibleTo("SMAPI.Installer")] [assembly: InternalsVisibleTo("SMAPI.Web")] diff --git a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs index c9fb6213..a394edba 100644 --- a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs +++ b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics.Contracts; using System.IO; using System.Linq; @@ -133,5 +134,29 @@ 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) + { + 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; + } + } } } |