diff --git a/server/RdtClient.Service/Helpers/DownloadHelper.cs b/server/RdtClient.Service/Helpers/DownloadHelper.cs index 36c20cd..39f8635 100644 --- a/server/RdtClient.Service/Helpers/DownloadHelper.cs +++ b/server/RdtClient.Service/Helpers/DownloadHelper.cs @@ -38,7 +38,12 @@ public static class DownloadHelper { subPath = subPath.Trim('/').Trim('\\'); - torrentPath = Path.Combine(torrentPath, subPath); + subPath = StripTorrentNamePrefix(subPath, directory); + + if (!String.IsNullOrWhiteSpace(subPath)) + { + torrentPath = Path.Combine(torrentPath, subPath); + } } } @@ -87,7 +92,12 @@ public static class DownloadHelper { subPath = subPath.Trim('/').Trim('\\'); - torrentPath = Path.Combine(torrentPath, subPath); + subPath = StripTorrentNamePrefix(subPath, torrentPath); + + if (!String.IsNullOrWhiteSpace(subPath)) + { + torrentPath = Path.Combine(torrentPath, subPath); + } } } @@ -117,4 +127,22 @@ public static class DownloadHelper { return String.Concat(path.Split(Path.GetInvalidPathChars())); } + + private static String StripTorrentNamePrefix(String subPath, String torrentName) + { + var prefix = torrentName.TrimEnd('/', '\\'); + + if (subPath.Equals(prefix, StringComparison.OrdinalIgnoreCase)) + { + return String.Empty; + } + + if (subPath.StartsWith(prefix + "/", StringComparison.OrdinalIgnoreCase) || + subPath.StartsWith(prefix + "\\", StringComparison.OrdinalIgnoreCase)) + { + return subPath[(prefix.Length + 1)..]; + } + + return subPath; + } }