diff --git a/server/RdtClient.Data/Data/DownloadData.cs b/server/RdtClient.Data/Data/DownloadData.cs index 9817130..a59357a 100644 --- a/server/RdtClient.Data/Data/DownloadData.cs +++ b/server/RdtClient.Data/Data/DownloadData.cs @@ -269,7 +269,7 @@ public class DownloadData(DataContext dataContext) { var dbDownload = await dataContext.Downloads .FirstOrDefaultAsync(m => m.DownloadId == downloadId) - ?? throw new Exception($"Cannot find download with ID {downloadId}"); + ?? throw new($"Cannot find download with ID {downloadId}"); dbDownload.RetryCount = 0; dbDownload.Link = null; diff --git a/server/RdtClient.Data/Data/SettingData.cs b/server/RdtClient.Data/Data/SettingData.cs index 10f5fe4..d37a109 100644 --- a/server/RdtClient.Data/Data/SettingData.cs +++ b/server/RdtClient.Data/Data/SettingData.cs @@ -9,7 +9,7 @@ namespace RdtClient.Data.Data; public class SettingData(DataContext dataContext, ILogger logger) { - public static DbSettings Get { get; } = new DbSettings(); + public static DbSettings Get { get; } = new(); public static IList GetAll() { @@ -57,7 +57,7 @@ public class SettingData(DataContext dataContext, ILogger logger) if (settings.Count == 0) { - throw new Exception("No settings found, please restart"); + throw new("No settings found, please restart"); } SetSettings(settings, Get, null); @@ -124,7 +124,7 @@ public class SettingData(DataContext dataContext, ILogger logger) if (property.PropertyType.IsEnum) { settingProperty.Type = "Enum"; - settingProperty.EnumValues = new Dictionary(); + settingProperty.EnumValues = new(); foreach (var e in Enum.GetValues(property.PropertyType).Cast()) { diff --git a/server/RdtClient.Service/Services/DownloadClient.cs b/server/RdtClient.Service/Services/DownloadClient.cs index 16ab063..edb6815 100644 --- a/server/RdtClient.Service/Services/DownloadClient.cs +++ b/server/RdtClient.Service/Services/DownloadClient.cs @@ -28,7 +28,7 @@ public class DownloadClient(Download download, Torrent torrent, String destinati { if (download.Link == null) { - throw new Exception($"Invalid download link"); + throw new($"Invalid download link"); } var filePath = DownloadHelper.GetDownloadPath(destinationPath, torrent, download); @@ -36,7 +36,7 @@ public class DownloadClient(Download download, Torrent torrent, String destinati if (filePath == null || downloadPath == null) { - throw new Exception("Invalid download path"); + throw new("Invalid download path"); } await FileHelper.Delete(filePath); @@ -49,7 +49,7 @@ public class DownloadClient(Download download, Torrent torrent, String destinati Data.Enums.DownloadClient.Bezzad => new BezzadDownloader(download.Link, filePath), Data.Enums.DownloadClient.Aria2c => new Aria2cDownloader(download.RemoteId, download.Link, filePath, downloadPath), Data.Enums.DownloadClient.Symlink => new SymlinkDownloader(download.Link, filePath), - _ => throw new Exception($"Unknown download client {Settings.Get.DownloadClient}") + _ => throw new($"Unknown download client {Settings.Get.DownloadClient}") }; Downloader.DownloadComplete += (_, args) => diff --git a/server/RdtClient.Service/Services/Downloaders/Aria2cDownloader.cs b/server/RdtClient.Service/Services/Downloaders/Aria2cDownloader.cs index d199064..c6e078a 100644 --- a/server/RdtClient.Service/Services/Downloaders/Aria2cDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/Aria2cDownloader.cs @@ -42,12 +42,12 @@ public class Aria2cDownloader : IDownloader Timeout = TimeSpan.FromSeconds(10) }; - _aria2NetClient = new Aria2NetClient(Settings.Get.DownloadClient.Aria2cUrl, Settings.Get.DownloadClient.Aria2cSecret, httpClient, 10); + _aria2NetClient = new(Settings.Get.DownloadClient.Aria2cUrl, Settings.Get.DownloadClient.Aria2cSecret, httpClient, 10); } public async Task Download() { - var path = Path.GetDirectoryName(_remotePath) ?? throw new Exception($"Invalid file path {_filePath}"); + var path = Path.GetDirectoryName(_remotePath) ?? throw new($"Invalid file path {_filePath}"); var fileName = Path.GetFileName(_filePath); _logger.Debug($"Starting download of {_uri}, writing to path: {_filePath} (on aria2: {_remotePath}), fileName: {fileName}"); @@ -58,7 +58,7 @@ public class Aria2cDownloader : IDownloader if (isAlreadyAdded) { - throw new Exception($"The download link {_uri} has already been added to Aria2"); + throw new($"The download link {_uri} has already been added to Aria2"); } } @@ -172,7 +172,7 @@ public class Aria2cDownloader : IDownloader if (download == null) { - DownloadComplete?.Invoke(this, new DownloadCompleteEventArgs + DownloadComplete?.Invoke(this, new() { Error = $"Download was not found in Aria2" }); @@ -182,7 +182,7 @@ public class Aria2cDownloader : IDownloader if (!String.IsNullOrWhiteSpace(download.ErrorMessage) || download.Status == "error") { await Remove(); - DownloadComplete?.Invoke(this, new DownloadCompleteEventArgs + DownloadComplete?.Invoke(this, new() { Error = $"{download.ErrorCode}: {download.ErrorMessage}" }); @@ -200,7 +200,7 @@ public class Aria2cDownloader : IDownloader { if (retryCount >= 10) { - DownloadComplete?.Invoke(this, new DownloadCompleteEventArgs + DownloadComplete?.Invoke(this, new() { Error = $"File not found at {_filePath} (on aria2 {_remotePath})" }); @@ -209,7 +209,7 @@ public class Aria2cDownloader : IDownloader if (File.Exists(_filePath)) { - DownloadComplete?.Invoke(this, new DownloadCompleteEventArgs()); + DownloadComplete?.Invoke(this, new()); break; } @@ -219,7 +219,7 @@ public class Aria2cDownloader : IDownloader return; } - DownloadProgress?.Invoke(this, new DownloadProgressEventArgs + DownloadProgress?.Invoke(this, new() { BytesDone = download.CompletedLength, BytesTotal = download.TotalLength, diff --git a/server/RdtClient.Service/Services/Downloaders/BezzadDownloader.cs b/server/RdtClient.Service/Services/Downloaders/BezzadDownloader.cs index 603e04d..b62b925 100644 --- a/server/RdtClient.Service/Services/Downloaders/BezzadDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/BezzadDownloader.cs @@ -30,7 +30,7 @@ public class BezzadDownloader : IDownloader var settingProxyServer = Settings.Get.DownloadClient.ProxyServer; // For all options, see https://github.com/bezzad/Downloader - _downloadConfiguration = new DownloadConfiguration + _downloadConfiguration = new() { MaxTryAgainOnFailover = 5, RangeDownload = false, @@ -56,7 +56,7 @@ public class BezzadDownloader : IDownloader _downloadConfiguration.RequestConfiguration.Proxy = new WebProxy(new Uri(settingProxyServer), false); } - _downloadService = new DownloadService(_downloadConfiguration); + _downloadService = new(_downloadConfiguration); _downloadService.DownloadProgressChanged += (_, args) => { @@ -66,7 +66,7 @@ public class BezzadDownloader : IDownloader } DownloadProgress.Invoke(this, - new DownloadProgressEventArgs + new() { Speed = (Int64)args.BytesPerSecondSpeed, BytesDone = args.ReceivedBytesSize, @@ -88,7 +88,7 @@ public class BezzadDownloader : IDownloader } DownloadComplete?.Invoke(this, - new DownloadCompleteEventArgs + new() { Error = error }); diff --git a/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs b/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs index e51029b..b30655f 100644 --- a/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/InternalDownloader.cs @@ -27,11 +27,11 @@ public class InternalDownloader : IDownloader _uri = uri; _filePath = filePath; - _downloadConfiguration = new DownloaderNET.Settings(); + _downloadConfiguration = new(); SetSettings(); - _downloadService = new DownloaderNET.Downloader(_uri, _filePath, _downloadConfiguration); + _downloadService = new(_uri, _filePath, _downloadConfiguration); //_downloadService.OnLog += message => Debug.WriteLine(message.Message); @@ -43,7 +43,7 @@ public class InternalDownloader : IDownloader } DownloadProgress.Invoke(this, - new DownloadProgressEventArgs + new() { Speed = (Int64)chunks.Where(m => m.IsActive).Sum(m => m.Speed), BytesDone = chunks.Sum(m => m.DownloadBytes), @@ -54,7 +54,7 @@ public class InternalDownloader : IDownloader _downloadService.OnComplete += (_, error) => { DownloadComplete?.Invoke(this, - new DownloadCompleteEventArgs + new() { Error = error?.Message }); diff --git a/server/RdtClient.Service/Services/QBittorrent.cs b/server/RdtClient.Service/Services/QBittorrent.cs index 9b5e9e5..dd70891 100644 --- a/server/RdtClient.Service/Services/QBittorrent.cs +++ b/server/RdtClient.Service/Services/QBittorrent.cs @@ -127,7 +127,7 @@ public class QBittorrent(ILogger logger, Settings settings, Authent SavePath = "", SavePathChangedTmmEnabled = false, SaveResumeDataInterval = 60, - ScanDirs = new ScanDirs(), + ScanDirs = new(), ScheduleFromHour = 8, ScheduleFromMin = 0, ScheduleToHour = 20, @@ -190,13 +190,13 @@ public class QBittorrent(ILogger logger, Settings settings, Authent var results = new List(); - var torrents1 = await torrents.Get(); + var allTorrents = await torrents.Get(); var prio = 0; Decimal? downloadProgress = 0; - foreach (var torrent in torrents1) + foreach (var torrent in allTorrents) { var downloadPath = savePath; @@ -485,9 +485,9 @@ public class QBittorrent(ILogger logger, Settings settings, Authent public async Task> TorrentsCategories() { - var torrents1 = await torrents.Get(); + var allTorrents = await torrents.Get(); - var torrentsToGroup = torrents1.Where(m => !String.IsNullOrWhiteSpace(m.Category)) + var torrentsToGroup = allTorrents.Where(m => !String.IsNullOrWhiteSpace(m.Category)) .Select(m => m.Category!.ToLower()) .ToList(); @@ -580,9 +580,9 @@ public class QBittorrent(ILogger logger, Settings settings, Authent return; } - var downloads1 = await downloads.GetForTorrent(torrent.TorrentId); + var downloadsForTorrent = await downloads.GetForTorrent(torrent.TorrentId); - foreach (var download in downloads1) + foreach (var download in downloadsForTorrent) { if (TorrentRunner.ActiveDownloadClients.TryGetValue(download.DownloadId, out var downloadClient)) { @@ -600,9 +600,9 @@ public class QBittorrent(ILogger logger, Settings settings, Authent return; } - var downloads1 = await downloads.GetForTorrent(torrent.TorrentId); + var downloadsForTorrent = await downloads.GetForTorrent(torrent.TorrentId); - foreach (var download in downloads1) + foreach (var download in downloadsForTorrent) { if (TorrentRunner.ActiveDownloadClients.TryGetValue(download.DownloadId, out var downloadClient)) { @@ -619,7 +619,7 @@ public class QBittorrent(ILogger logger, Settings settings, Authent var activeDownloads = TorrentRunner.ActiveDownloadClients.Sum(m => m.Value.Speed); - return new SyncMetaData + return new() { Categories = categories, FullUpdate = true, @@ -627,7 +627,7 @@ public class QBittorrent(ILogger logger, Settings settings, Authent Tags = null, Trackers = new Dictionary>(), Torrents = torrents.ToDictionary(m => m.Hash, m => m), - ServerState = new SyncMetaDataServerState + ServerState = new() { DlInfoSpeed = activeDownloads, UpInfoSpeed = 0 diff --git a/server/RdtClient.Service/Services/RemoteService.cs b/server/RdtClient.Service/Services/RemoteService.cs index 942ece4..032e3f8 100644 --- a/server/RdtClient.Service/Services/RemoteService.cs +++ b/server/RdtClient.Service/Services/RemoteService.cs @@ -6,18 +6,17 @@ public class RemoteService(IHubContext hub, Torrents torrents) { public async Task Update() { - var torrents1 = await torrents.Get(); + var allTorrents = await torrents.Get(); // Prevent infinite recursion when serializing - foreach (var file in torrents1.SelectMany(torrent => torrent.Downloads)) + foreach (var file in allTorrents.SelectMany(torrent => torrent.Downloads)) { file.Torrent = null; } await hub.Clients.All.SendCoreAsync("update", - new Object[] - { - torrents1 - }); + [ + allTorrents + ]); } } \ No newline at end of file diff --git a/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs index b8c6c4e..f5955ba 100644 --- a/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/RealDebridTorrentClient.cs @@ -20,7 +20,7 @@ public class RealDebridTorrentClient(ILogger logger, IH if (String.IsNullOrWhiteSpace(apiKey)) { - throw new Exception("Real-Debrid API Key not set in the settings"); + throw new("Real-Debrid API Key not set in the settings"); } var httpClient = httpClientFactory.CreateClient(); @@ -63,7 +63,7 @@ public class RealDebridTorrentClient(ILogger logger, IH private TorrentClientTorrent Map(Torrent torrent) { - return new TorrentClientTorrent + return new() { Id = torrent.Id, Filename = torrent.Filename, @@ -116,7 +116,7 @@ public class RealDebridTorrentClient(ILogger logger, IH { var user = await GetClient().User.GetAsync(); - return new TorrentClientUser + return new() { Username = user.Username, Expiration = user.Premium > 0 ? user.Expiration : null @@ -272,7 +272,7 @@ public class RealDebridTorrentClient(ILogger logger, IH if (result.Download == null) { - throw new Exception($"Unrestrict returned an invalid download"); + throw new($"Unrestrict returned an invalid download"); } return result.Download; @@ -287,7 +287,7 @@ public class RealDebridTorrentClient(ILogger logger, IH return torrent; } - var rdTorrent = await GetInfo(torrent.RdId) ?? throw new Exception($"Resource not found"); + var rdTorrent = await GetInfo(torrent.RdId) ?? throw new($"Resource not found"); if (!String.IsNullOrWhiteSpace(rdTorrent.Filename)) { diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index 3c86c22..cc39252 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -26,6 +26,11 @@ public class Torrents( { private static readonly SemaphoreSlim RealDebridUpdateLock = new(1, 1); + private static readonly JsonSerializerOptions JsonSerializerOptions = new() + { + ReferenceHandler = ReferenceHandler.IgnoreCycles + }; + private ITorrentClient TorrentClient { get @@ -35,7 +40,7 @@ public class Torrents( Provider.Premiumize => premiumizeTorrentClient, Provider.RealDebrid => realDebridTorrentClient, Provider.AllDebrid => allDebridTorrentClient, - _ => throw new Exception("Invalid Provider") + _ => throw new("Invalid Provider") }; } } @@ -105,7 +110,7 @@ public class Torrents( catch (Exception ex) { logger.LogError(ex, "{ex.Message}, trying to parse {magnetLink}", ex.Message, magnetLink); - throw new Exception($"{ex.Message}, trying to parse {magnetLink}"); + throw new($"{ex.Message}, trying to parse {magnetLink}"); } var id = await TorrentClient.AddMagnet(magnetLink); @@ -156,7 +161,7 @@ public class Torrents( } catch (Exception ex) { - throw new Exception($"{ex.Message}, trying to parse {fileAsBase64}"); + throw new($"{ex.Message}, trying to parse {fileAsBase64}"); } var id = await TorrentClient.AddFile(bytes); @@ -352,12 +357,7 @@ public class Torrents( public async Task UnrestrictLink(Guid downloadId) { - var download = await downloads.GetById(downloadId); - - if (download == null) - { - throw new Exception($"Download with ID {downloadId} not found"); - } + var download = await downloads.GetById(downloadId) ?? throw new($"Download with ID {downloadId} not found"); Log($"Unrestricting link", download, download.Torrent); @@ -494,7 +494,7 @@ public class Torrents( if (String.IsNullOrWhiteSpace(torrent.FileOrMagnet)) { - throw new Exception($"Cannot re-add this torrent, original magnet or file not found"); + throw new($"Cannot re-add this torrent, original magnet or file not found"); } Torrent newTorrent; @@ -681,14 +681,9 @@ public class Torrents( return; } - var torrent = await torrentData.GetById(torrentId); + var torrent = await torrentData.GetById(torrentId) ?? throw new($"Cannot find Torrent with ID {torrentId}"); - if (torrent == null) - { - throw new Exception($"Cannot find Torrent with ID {torrentId}"); - } - - var downloads1 = await downloads.GetForTorrent(torrentId); + var downloadsForTorrent = await downloads.GetForTorrent(torrentId); var fileName = Settings.Get.General.RunOnTorrentCompleteFileName; var arguments = Settings.Get.General.RunOnTorrentCompleteArguments ?? ""; @@ -712,7 +707,7 @@ public class Torrents( arguments = arguments.Replace("%F", $"\"{filePath}\""); arguments = arguments.Replace("%R", $"\"{downloadPath}\""); arguments = arguments.Replace("%D", $"\"{torrentPath}\""); - arguments = arguments.Replace("%C", downloads1.Count.ToString(CultureInfo.InvariantCulture).Replace(",", "").Replace(".", "")); + arguments = arguments.Replace("%C", downloadsForTorrent.Count.ToString(CultureInfo.InvariantCulture).Replace(",", "").Replace(".", "")); arguments = arguments.Replace("%Z", torrent.RdSize?.ToString(CultureInfo.InvariantCulture).Replace(",", "").Replace(".", "")); arguments = arguments.Replace("%I", torrent.Hash); @@ -778,19 +773,11 @@ public class Torrents( { try { - var originalTorrent = JsonSerializer.Serialize(torrent, - new JsonSerializerOptions - { - ReferenceHandler = ReferenceHandler.IgnoreCycles - }); + var originalTorrent = JsonSerializer.Serialize(torrent, JsonSerializerOptions); await TorrentClient.UpdateData(torrent, torrentClientTorrent); - var newTorrent = JsonSerializer.Serialize(torrent, - new JsonSerializerOptions - { - ReferenceHandler = ReferenceHandler.IgnoreCycles - }); + var newTorrent = JsonSerializer.Serialize(torrent, JsonSerializerOptions); if (originalTorrent != newTorrent) { diff --git a/server/RdtClient.Service/Services/UnpackClient.cs b/server/RdtClient.Service/Services/UnpackClient.cs index 9c0eb16..b840966 100644 --- a/server/RdtClient.Service/Services/UnpackClient.cs +++ b/server/RdtClient.Service/Services/UnpackClient.cs @@ -15,9 +15,9 @@ public class UnpackClient(Download download, String destinationPath) public Int32 Progess { get; private set; } - private readonly Torrent _torrent = download.Torrent ?? throw new Exception($"Torrent is null"); + private readonly Torrent _torrent = download.Torrent ?? throw new($"Torrent is null"); - private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource(); + private readonly CancellationTokenSource _cancellationTokenSource = new(); public void Start() { @@ -25,12 +25,7 @@ public class UnpackClient(Download download, String destinationPath) try { - var filePath = DownloadHelper.GetDownloadPath(destinationPath, _torrent, download); - - if (filePath == null) - { - throw new Exception("Invalid download path"); - } + var filePath = DownloadHelper.GetDownloadPath(destinationPath, _torrent, download) ?? throw new("Invalid download path"); Task.Run(async delegate { diff --git a/server/RdtClient.Web/Controllers/SettingsController.cs b/server/RdtClient.Web/Controllers/SettingsController.cs index 58e10f4..83d5c13 100644 --- a/server/RdtClient.Web/Controllers/SettingsController.cs +++ b/server/RdtClient.Web/Controllers/SettingsController.cs @@ -63,7 +63,7 @@ public class SettingsController(Settings settings, Torrents torrents) : Controll if (!Directory.Exists(path)) { - throw new Exception($"Path {path} does not exist"); + throw new($"Path {path} does not exist"); } var testFile = $"{path}/test.txt"; @@ -88,7 +88,7 @@ public class SettingsController(Settings settings, Torrents torrents) : Controll var download = new Download { Link = "https://34.download.real-debrid.com/speedtest/testDefault.rar", - Torrent = new Torrent + Torrent = new() { RdName = "" } diff --git a/server/RdtClient.sln.DotSettings b/server/RdtClient.sln.DotSettings index 777664e..5267e9a 100644 --- a/server/RdtClient.sln.DotSettings +++ b/server/RdtClient.sln.DotSettings @@ -1,5 +1,9 @@  False + True + True + True + ExplicitlyExcluded *.appxmanifest *.d.ts *.debug.js @@ -28,6 +32,8 @@ SUGGESTION DO_NOT_SHOW ERROR + ERROR + ERROR DO_NOT_SHOW ERROR ERROR @@ -123,9 +129,11 @@ ALWAYS_ADD ALWAYS_ADD ALWAYS_ADD + False True True NO_INDENT + INDENT 1 1 False