From 7d4c8156d55547c7106ee953d0a33d2a32e518cb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 2 Sep 2022 17:14:32 -0500 Subject: add NormalizePath() --- src/slskd/Common/CommonExtensions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/slskd/Common/CommonExtensions.cs') diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index 65949016..f9c597f8 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -239,6 +239,16 @@ 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 -- cgit v1.2.3 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/slskd/Common/CommonExtensions.cs') 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 From 1b81de8d8c90e3377ab0b8102b099ccadbc64155 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 3 Sep 2022 12:36:59 -0500 Subject: tweak docs --- src/slskd/Common/CommonExtensions.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/slskd/Common/CommonExtensions.cs') diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index cc657919..6f39d17f 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -254,7 +254,7 @@ namespace slskd } /// - /// Converts the given path to the normalized format (normalizes path separators to backslashes) + /// Converts the given path to the normalized format (normalizes path separators to backslashes). /// /// The path to convert. /// The converted path. @@ -263,7 +263,6 @@ namespace slskd return path.Replace('/', '\\'); } - /// /// Converts the given path to the local format (normalizes path separators to Path.DirectorySeparatorChar). /// -- cgit v1.2.3