diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-11-01 09:41:40 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-11-01 09:41:40 -0500 |
| commit | 9a8fb3dcf945d6b8bd2005ce99ce4017484d9a8b (patch) | |
| tree | 85b5c642590821a2ddbfac6b28efab0f920f3c4f /src | |
| parent | 1942348884602745ca82ffa577c1953867dea68a (diff) | |
| download | slskd-9a8fb3dcf945d6b8bd2005ce99ce4017484d9a8b.tar.gz | |
add extensions for normalized path handling
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/CommonExtensions.cs | 20 |
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). |
