aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-11-01 09:41:40 -0500
committerJP Dillingham <jp@dillingham.me>2022-11-01 09:41:40 -0500
commit9a8fb3dcf945d6b8bd2005ce99ce4017484d9a8b (patch)
tree85b5c642590821a2ddbfac6b28efab0f920f3c4f /src/slskd/Common
parent1942348884602745ca82ffa577c1953867dea68a (diff)
downloadslskd-9a8fb3dcf945d6b8bd2005ce99ce4017484d9a8b.tar.gz
add extensions for normalized path handling
Diffstat (limited to 'src/slskd/Common')
-rw-r--r--src/slskd/Common/CommonExtensions.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs
index 29383fcb..ed07f9ea 100644
--- a/src/slskd/Common/CommonExtensions.cs
+++ b/src/slskd/Common/CommonExtensions.cs
@@ -302,6 +302,26 @@ namespace slskd
}
/// <summary>
+ /// <see cref="Path.GetDirectoryName"/>, but for paths normalized to use backslashes.
+ /// </summary>
+ /// <param name="path"></param>
+ /// <returns></returns>
+ public static string GetNormalizedDirectoryName(this string path)
+ {
+ return string.Join('\\', path.Split('\\').SkipLast(1));
+ }
+
+ /// <summary>
+ /// <see cref="Path.GetFileName"/>, but for paths normalized to use backslashes.
+ /// </summary>
+ /// <param name="path"></param>
+ /// <returns></returns>
+ public static string GetNormalizedFileName(this string path)
+ {
+ return string.Join('\\', path.Split('\\').TakeLast(1));
+ }
+
+ /// <summary>
/// Converts a fully qualified remote filename to a local filename, swapping directory characters for those specific
/// to the local OS, removing any characters that are invalid for the local OS, and making the path relative to the
/// remote store (including the filename and the parent folder).