diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-09-02 22:31:14 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-09-02 22:31:14 -0500 |
| commit | 6735bf4f1b984055170130753788de67d648c7d7 (patch) | |
| tree | 3ddd7fd9f3eb01bc831ddfe53ff92b5fbe1be49b /src | |
| parent | b7eacb3a513038ec5c7d205668042c920ca56dc2 (diff) | |
| download | slskd-6735bf4f1b984055170130753788de67d648c7d7.tar.gz | |
localize/normalize
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/CommonExtensions.cs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index f9c597f8..cc657919 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -239,16 +239,6 @@ namespace slskd .Build() .Deserialize<T>(str); - public static string NormalizePath(this string filename) - { - if (Path.DirectorySeparatorChar == '\\') - { - return filename; - } - - return filename.Replace(Path.DirectorySeparatorChar, '\\'); - } - /// <summary> /// Converts a fully qualified remote filename to a local filename based in the provided /// <paramref name="baseDirectory"/>, swapping directory characters for those specific to the local OS, removing any @@ -264,11 +254,22 @@ namespace slskd } /// <summary> - /// Converts the given path to the local format (normalizes path separators). + /// Converts the given path to the normalized format (normalizes path separators to backslashes) + /// </summary> + /// <param name="path">The path to convert.</param> + /// <returns>The converted path.</returns> + public static string NormalizePath(this string path) + { + return path.Replace('/', '\\'); + } + + + /// <summary> + /// Converts the given path to the local format (normalizes path separators to Path.DirectorySeparatorChar). /// </summary> /// <param name="path">The path to convert.</param> /// <returns>The converted path.</returns> - public static string ToLocalOSPath(this string path) + public static string LocalizePath(this string path) { return path.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar); } @@ -288,7 +289,7 @@ namespace slskd } // normalize path separators - var localizedRemoteFilename = remoteFilename.ToLocalOSPath(); + var localizedRemoteFilename = remoteFilename.LocalizePath(); var parts = localizedRemoteFilename.Split(Path.DirectorySeparatorChar); |
