summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit/Utilities
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-03-07 20:15:10 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-03-07 20:15:10 -0500
commit5399239c2be01396958ed454d6ae56f006d20ca5 (patch)
tree87683eda0873a0c24d9bcee5d47f1cec896f21bb /src/SMAPI.Toolkit/Utilities
parentdb011ee751bdfb8bbd9abbeb706966db4c4e2461 (diff)
parenta571f459f59a6ecfdd53e3158ba8d29157598920 (diff)
downloadSMAPI-5399239c2be01396958ed454d6ae56f006d20ca5.tar.gz
SMAPI-5399239c2be01396958ed454d6ae56f006d20ca5.tar.bz2
SMAPI-5399239c2be01396958ed454d6ae56f006d20ca5.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Toolkit/Utilities')
-rw-r--r--src/SMAPI.Toolkit/Utilities/PathUtilities.cs25
1 files changed, 25 insertions, 0 deletions
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;
+ }
+ }
}
}