From 9d104b25f8479509c11e38ba6cddf73a39620605 Mon Sep 17 00:00:00 2001 From: glax Date: Sat, 20 May 2023 01:06:00 +0200 Subject: [PATCH] Renamed some variables, changed some access-types to protected/readonly Made Resharper a bit happier --- Tranga-CLI/Tranga_Cli.cs | 8 ++++---- Tranga/Connector.cs | 4 ++-- Tranga/Connectors/MangaDex.cs | 4 ++-- Tranga/Publication.cs | 2 +- Tranga/TaskManager.cs | 14 ++++++-------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Tranga-CLI/Tranga_Cli.cs b/Tranga-CLI/Tranga_Cli.cs index 2cf8a52..a57cd82 100644 --- a/Tranga-CLI/Tranga_Cli.cs +++ b/Tranga-CLI/Tranga_Cli.cs @@ -78,15 +78,15 @@ public static class Tranga_Cli string? query = Console.ReadLine(); while (query is null || query.Length < 1) query = Console.ReadLine(); - PrintTasks(taskManager.GetAllTasks().Where(task => - ((Publication)task.publication!).sortName.ToLower() + PrintTasks(taskManager.GetAllTasks().Where(qTask => + ((Publication)qTask.publication!).sortName.ToLower() .Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray()); Console.WriteLine("Press any key."); Console.ReadKey(); menu = 0; break; case 6: - PrintTasks(taskManager.GetAllTasks().Where(task => task.isBeingExecuted).ToArray()); + PrintTasks(taskManager.GetAllTasks().Where(eTask => eTask.isBeingExecuted).ToArray()); Console.WriteLine("Press any key."); Console.ReadKey(); menu = 0; @@ -315,7 +315,7 @@ public static class Tranga_Cli selected = Console.ReadLine(); int start = 0; - int end = 0; + int end; if (selected == "a") end = chapters.Length - 1; else if (selected.Contains('-')) diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index b911225..647698c 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -68,7 +68,7 @@ public abstract class Connector File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson()); } - public static string CreateComicInfo(Publication publication, Chapter chapter) + protected static string CreateComicInfo(Publication publication, Chapter chapter) { XElement comicInfo = new XElement("ComicInfo", new XElement("Tags", string.Join(',',publication.tags)), @@ -118,7 +118,7 @@ public abstract class Connector foreach (string imageUrl in imageUrls) { string[] split = imageUrl.Split('.'); - string extension = split[split.Length - 1]; + string extension = split[^1]; DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient); } diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index 14c3a1a..050e3b8 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -224,13 +224,13 @@ public class MangaDex : Connector if (result is null) return; - string fileName = result!["data"]!["attributes"]!["fileName"]!.GetValue(); + string fileName = result["data"]!["attributes"]!["fileName"]!.GetValue(); string coverUrl = $"https://uploads.mangadex.org/covers/{publication.downloadUrl}/{fileName}"; //Get file-extension (jpg, png) string[] split = coverUrl.Split('.'); - string extension = split[split.Length - 1]; + string extension = split[^1]; string outFolderPath = Path.Join(downloadLocation, publication.folderName); Directory.CreateDirectory(outFolderPath); diff --git a/Tranga/Publication.cs b/Tranga/Publication.cs index b23b9b0..029fb75 100644 --- a/Tranga/Publication.cs +++ b/Tranga/Publication.cs @@ -5,7 +5,7 @@ namespace Tranga; /// /// Contains information on a Publication (Manga) /// -public struct Publication +public readonly struct Publication { public string sortName { get; } [JsonIgnore]public string[,] altTitles { get; } diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs index 46f20af..0b877aa 100644 --- a/Tranga/TaskManager.cs +++ b/Tranga/TaskManager.cs @@ -12,8 +12,7 @@ public class TaskManager private readonly Dictionary> _chapterCollection; private readonly HashSet _allTasks; private bool _continueRunning = true; - private readonly Connector[] connectors; - private readonly string folderPath; + private readonly Connector[] _connectors; /// /// @@ -21,8 +20,7 @@ public class TaskManager /// Local path to save data (Manga) to public TaskManager(string folderPath) { - this.folderPath = folderPath; - this.connectors = new Connector[]{ new MangaDex(folderPath) }; + this._connectors = new Connector[]{ new MangaDex(folderPath) }; _chapterCollection = new(); _allTasks = ImportTasks(Directory.GetCurrentDirectory()); Thread taskChecker = new(TaskCheckerThread); @@ -36,7 +34,7 @@ public class TaskManager foreach (TrangaTask task in _allTasks) { if(task.ShouldExecute()) - TaskExecutor.Execute(this.connectors, task, this._chapterCollection); + TaskExecutor.Execute(this._connectors, task, this._chapterCollection); } Thread.Sleep(1000); } @@ -53,7 +51,7 @@ public class TaskManager Task t = new Task(() => { - TaskExecutor.Execute(this.connectors, task, this._chapterCollection); + TaskExecutor.Execute(this._connectors, task, this._chapterCollection); }); t.Start(); } @@ -71,7 +69,7 @@ public class TaskManager string language = "") { //Get appropriate Connector from available Connectors for TrangaTask - Connector? connector = connectors.FirstOrDefault(c => c.name == connectorName); + Connector? connector = _connectors.FirstOrDefault(c => c.name == connectorName); if (connector is null) throw new ArgumentException($"Connector {connectorName} is not a known connector."); @@ -108,7 +106,7 @@ public class TaskManager /// All available Connectors public Dictionary GetAvailableConnectors() { - return this.connectors.ToDictionary(connector => connector.name, connector => connector); + return this._connectors.ToDictionary(connector => connector.name, connector => connector); } ///