diff --git a/Tranga-CLI/Tranga_Cli.cs b/Tranga-CLI/Tranga_Cli.cs index 7a0133d..b21fc62 100644 --- a/Tranga-CLI/Tranga_Cli.cs +++ b/Tranga-CLI/Tranga_Cli.cs @@ -28,11 +28,7 @@ public static class Tranga_Cli Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, null, logFilePath); logger.WriteLine("Tranga_CLI", "Loading Taskmanager."); - TrangaSettings settings; - if (File.Exists(settingsFilePath)) - settings = TrangaSettings.LoadSettings(settingsFilePath); - else - settings = new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, null); + TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, null); logger.WriteLine("Tranga_CLI", "User Input"); @@ -85,7 +81,7 @@ public static class Tranga_Cli { TaskManager taskManager = new (settings, logger); ConsoleKey selection = ConsoleKey.EraseEndOfFile; - PrintMenu(taskManager, taskManager.settings.downloadLocation, logger); + PrintMenu(taskManager, taskManager.settings.downloadLocation); while (selection != ConsoleKey.Q) { int taskCount = taskManager.GetAllTasks().Length; @@ -106,7 +102,7 @@ public static class Tranga_Cli Console.ReadKey(); break; case ConsoleKey.C: - CreateTask(taskManager, taskManager.settings, logger); + CreateTask(taskManager, logger); Console.WriteLine("Press any key."); Console.ReadKey(); break; @@ -159,7 +155,7 @@ public static class Tranga_Cli Console.ReadKey(); break; } - PrintMenu(taskManager, taskManager.settings.downloadLocation, logger); + PrintMenu(taskManager, taskManager.settings.downloadLocation); } Thread.Sleep(200); } @@ -179,7 +175,7 @@ public static class Tranga_Cli taskManager.Shutdown(false); } - private static void PrintMenu(TaskManager taskManager, string folderPath, Logger logger) + private static void PrintMenu(TaskManager taskManager, string folderPath) { int taskCount = taskManager.GetAllTasks().Length; int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running); @@ -264,17 +260,17 @@ public static class Tranga_Cli Console.Clear(); logger.WriteLine("Tranga_CLI", "Menu: Add Manga Download to queue"); - Connector? connector = SelectConnector(taskManager.settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray(), logger); + Connector? connector = SelectConnector(taskManager.GetAvailableConnectors().Values.ToArray(), logger); if (connector is null) return; - Publication? publication = SelectPublication(taskManager, connector!, logger); + Publication? publication = SelectPublication(taskManager, connector, logger); if (publication is null) return; TimeSpan reoccurrence = SelectReoccurrence(logger); logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager"); - TrangaTask newTask = taskManager.AddTask(TrangaTask.Task.DownloadNewChapters, connector?.name, publication, reoccurrence, "en"); + TrangaTask newTask = taskManager.AddTask(TrangaTask.Task.DownloadNewChapters, connector.name, publication, reoccurrence, "en"); Console.WriteLine(newTask); } @@ -327,18 +323,18 @@ public static class Tranga_Cli } } - private static void CreateTask(TaskManager taskManager, TrangaSettings settings, Logger logger) + private static void CreateTask(TaskManager taskManager, Logger logger) { logger.WriteLine("Tranga_CLI", "Menu: Creating Task"); TrangaTask.Task? tmpTask = SelectTaskType(logger); if (tmpTask is null) return; - TrangaTask.Task task = (TrangaTask.Task)tmpTask!; + TrangaTask.Task task = (TrangaTask.Task)tmpTask; Connector? connector = null; if (task != TrangaTask.Task.UpdateKomgaLibrary) { - connector = SelectConnector(settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray(), logger); + connector = SelectConnector(taskManager.GetAvailableConnectors().Values.ToArray(), logger); if (connector is null) return; } @@ -431,7 +427,7 @@ public static class Tranga_Cli return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US")); } - private static Connector? SelectConnector(string folderPath, Connector[] connectors, Logger logger) + private static Connector? SelectConnector(Connector[] connectors, Logger logger) { logger.WriteLine("Tranga_CLI", "Menu: Select Connector"); Console.Clear(); diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index b132e64..705e5db 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -123,7 +123,7 @@ public abstract class Connector /// /// /// - /// Requesttype for ratelimit + /// RequestType for Rate-Limit private void DownloadImage(string imageUrl, string fullPath, byte requestType) { DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType); @@ -183,8 +183,8 @@ public abstract class Connector /// /// Creates a httpClient /// - /// minimum delay between requests (to avoid spam) /// Rate limits for requests. byte is RequestType, int maximum requests per minute for RequestType + /// public DownloadClient(Dictionary rateLimitRequestsPerMinute, Logger? logger) { this.logger = logger; diff --git a/Tranga/TaskManager.cs b/Tranga/TaskManager.cs index d2269e3..9eab790 100644 --- a/Tranga/TaskManager.cs +++ b/Tranga/TaskManager.cs @@ -11,7 +11,7 @@ namespace Tranga; /// public class TaskManager { - public Dictionary> _chapterCollection = new(); + public Dictionary> chapterCollection = new(); private HashSet _allTasks; private bool _continueRunning = true; private readonly Connector[] _connectors; @@ -138,7 +138,7 @@ public class TaskManager { logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {task} {connectorName} {publication?.sortName}"); - TrangaTask newTask = null; + TrangaTask? newTask = null; if (task == TrangaTask.Task.UpdateKomgaLibrary) { newTask = new UpdateKomgaLibraryTask(task, reoccurrence); @@ -164,10 +164,10 @@ public class TaskManager trangaTask.connectorName == connector.name)) { _allTasks.Add(newTask); - logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask.ToString()}"); + logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask}"); } else - logger?.WriteLine(this.GetType().ToString(), $"Task already exists {newTask.ToString()}"); + logger?.WriteLine(this.GetType().ToString(), $"Task already exists {newTask}"); } ExportDataAndSettings(); @@ -252,8 +252,8 @@ public class TaskManager Publication[] ret = connector.GetPublications(title ?? ""); foreach (Publication publication in ret) { - if(!_chapterCollection.Any(pub => pub.Key.sortName == publication.sortName)) - this._chapterCollection.TryAdd(publication, new List()); + if(!chapterCollection.Any(pub => pub.Key.sortName == publication.sortName)) + this.chapterCollection.TryAdd(publication, new List()); } return ret; } @@ -261,7 +261,7 @@ public class TaskManager /// All added Publications public Publication[] GetAllPublications() { - return this._chapterCollection.Keys.ToArray(); + return this.chapterCollection.Keys.ToArray(); } /// @@ -276,7 +276,7 @@ public class TaskManager Connector? ret = this._connectors.FirstOrDefault(connector => connector.name == connectorName); if (ret is null) throw new Exception($"Connector {connectorName} is not an available Connector."); - return (Connector)ret!; + return ret; } /// @@ -316,7 +316,7 @@ public class TaskManager buffer = File.ReadAllText(settings.knownPublicationsPath); Publication[] publications = JsonConvert.DeserializeObject(buffer)!; foreach (Publication publication in publications) - this._chapterCollection.TryAdd(publication, new List()); + this.chapterCollection.TryAdd(publication, new List()); } } @@ -332,7 +332,7 @@ public class TaskManager File.WriteAllText(settings.tasksFilePath, JsonConvert.SerializeObject(this._allTasks)); logger?.WriteLine(this.GetType().ToString(), $"Exporting known publications to {settings.knownPublicationsPath}"); - File.WriteAllText(settings.knownPublicationsPath, JsonConvert.SerializeObject(this._chapterCollection.Keys.ToArray())); + File.WriteAllText(settings.knownPublicationsPath, JsonConvert.SerializeObject(this.chapterCollection.Keys.ToArray())); } diff --git a/Tranga/TrangaTasks/DownloadNewChaptersTask.cs b/Tranga/TrangaTasks/DownloadNewChaptersTask.cs index 1aabace..dbc81b4 100644 --- a/Tranga/TrangaTasks/DownloadNewChaptersTask.cs +++ b/Tranga/TrangaTasks/DownloadNewChaptersTask.cs @@ -15,7 +15,7 @@ public class DownloadNewChaptersTask : TrangaTask string publicationFolder = Path.Join(connector.downloadLocation, pub.folderName); if(!Directory.Exists(publicationFolder)) Directory.CreateDirectory(publicationFolder); - List newChapters = UpdateChapters(connector, pub, language!, ref taskManager._chapterCollection); + List newChapters = UpdateChapters(connector, pub, language!, ref taskManager.chapterCollection); connector.CopyCoverFromCacheToDownloadLocation(pub, taskManager.settings);