From 6735bf4f1b984055170130753788de67d648c7d7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 2 Sep 2022 22:31:14 -0500 Subject: localize/normalize --- src/slskd/Common/CommonExtensions.cs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src') 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(str); - public static string NormalizePath(this string filename) - { - if (Path.DirectorySeparatorChar == '\\') - { - return filename; - } - - return filename.Replace(Path.DirectorySeparatorChar, '\\'); - } - /// /// Converts a fully qualified remote filename to a local filename based in the provided /// , swapping directory characters for those specific to the local OS, removing any @@ -264,11 +254,22 @@ namespace slskd } /// - /// Converts the given path to the local format (normalizes path separators). + /// Converts the given path to the normalized format (normalizes path separators to backslashes) + /// + /// The path to convert. + /// The converted path. + public static string NormalizePath(this string path) + { + return path.Replace('/', '\\'); + } + + + /// + /// Converts the given path to the local format (normalizes path separators to Path.DirectorySeparatorChar). /// /// The path to convert. /// The converted path. - 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); -- cgit v1.2.3