diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-11-01 09:58:00 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-01 09:58:00 -0500 |
| commit | fa536c755972040bf0000e95b8cb2d39ea7f1300 (patch) | |
| tree | c6410dcdffefb36274de127eb07498a2bb8a4750 /src/slskd/Common/CommonExtensions.cs | |
| parent | 1942348884602745ca82ffa577c1953867dea68a (diff) | |
| parent | cdd4e53a5dd202828ae568e64830905a6f66beeb (diff) | |
| download | slskd-fa536c755972040bf0000e95b8cb2d39ea7f1300.tar.gz | |
Merge pull request #724 from slskd/paths
Don't use the built-in System.IO.Path methods for handling normalized paths
Diffstat (limited to 'src/slskd/Common/CommonExtensions.cs')
| -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). |
