2
0

Spelling, redundant calls

This commit is contained in:
glax 2023-05-31 21:18:41 +02:00
parent 1b9ebd096b
commit d5ecc1c37d
4 changed files with 25 additions and 29 deletions

View File

@ -28,11 +28,7 @@ public static class Tranga_Cli
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, null, logFilePath); Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, null, logFilePath);
logger.WriteLine("Tranga_CLI", "Loading Taskmanager."); logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
TrangaSettings settings; TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, null);
if (File.Exists(settingsFilePath))
settings = TrangaSettings.LoadSettings(settingsFilePath);
else
settings = new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, null);
logger.WriteLine("Tranga_CLI", "User Input"); logger.WriteLine("Tranga_CLI", "User Input");
@ -85,7 +81,7 @@ public static class Tranga_Cli
{ {
TaskManager taskManager = new (settings, logger); TaskManager taskManager = new (settings, logger);
ConsoleKey selection = ConsoleKey.EraseEndOfFile; ConsoleKey selection = ConsoleKey.EraseEndOfFile;
PrintMenu(taskManager, taskManager.settings.downloadLocation, logger); PrintMenu(taskManager, taskManager.settings.downloadLocation);
while (selection != ConsoleKey.Q) while (selection != ConsoleKey.Q)
{ {
int taskCount = taskManager.GetAllTasks().Length; int taskCount = taskManager.GetAllTasks().Length;
@ -106,7 +102,7 @@ public static class Tranga_Cli
Console.ReadKey(); Console.ReadKey();
break; break;
case ConsoleKey.C: case ConsoleKey.C:
CreateTask(taskManager, taskManager.settings, logger); CreateTask(taskManager, logger);
Console.WriteLine("Press any key."); Console.WriteLine("Press any key.");
Console.ReadKey(); Console.ReadKey();
break; break;
@ -159,7 +155,7 @@ public static class Tranga_Cli
Console.ReadKey(); Console.ReadKey();
break; break;
} }
PrintMenu(taskManager, taskManager.settings.downloadLocation, logger); PrintMenu(taskManager, taskManager.settings.downloadLocation);
} }
Thread.Sleep(200); Thread.Sleep(200);
} }
@ -179,7 +175,7 @@ public static class Tranga_Cli
taskManager.Shutdown(false); 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 taskCount = taskManager.GetAllTasks().Length;
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running); int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running);
@ -264,17 +260,17 @@ public static class Tranga_Cli
Console.Clear(); Console.Clear();
logger.WriteLine("Tranga_CLI", "Menu: Add Manga Download to queue"); 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) if (connector is null)
return; return;
Publication? publication = SelectPublication(taskManager, connector!, logger); Publication? publication = SelectPublication(taskManager, connector, logger);
if (publication is null) if (publication is null)
return; return;
TimeSpan reoccurrence = SelectReoccurrence(logger); TimeSpan reoccurrence = SelectReoccurrence(logger);
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager"); 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); 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"); logger.WriteLine("Tranga_CLI", "Menu: Creating Task");
TrangaTask.Task? tmpTask = SelectTaskType(logger); TrangaTask.Task? tmpTask = SelectTaskType(logger);
if (tmpTask is null) if (tmpTask is null)
return; return;
TrangaTask.Task task = (TrangaTask.Task)tmpTask!; TrangaTask.Task task = (TrangaTask.Task)tmpTask;
Connector? connector = null; Connector? connector = null;
if (task != TrangaTask.Task.UpdateKomgaLibrary) 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) if (connector is null)
return; return;
} }
@ -431,7 +427,7 @@ public static class Tranga_Cli
return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US")); 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"); logger.WriteLine("Tranga_CLI", "Menu: Select Connector");
Console.Clear(); Console.Clear();

View File

@ -123,7 +123,7 @@ public abstract class Connector
/// </summary> /// </summary>
/// <param name="imageUrl"></param> /// <param name="imageUrl"></param>
/// <param name="fullPath"></param> /// <param name="fullPath"></param>
/// <param name="requestType">Requesttype for ratelimit</param> /// <param name="requestType">RequestType for Rate-Limit</param>
private void DownloadImage(string imageUrl, string fullPath, byte requestType) private void DownloadImage(string imageUrl, string fullPath, byte requestType)
{ {
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType); DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType);
@ -183,8 +183,8 @@ public abstract class Connector
/// <summary> /// <summary>
/// Creates a httpClient /// Creates a httpClient
/// </summary> /// </summary>
/// <param name="delay">minimum delay between requests (to avoid spam)</param>
/// <param name="rateLimitRequestsPerMinute">Rate limits for requests. byte is RequestType, int maximum requests per minute for RequestType</param> /// <param name="rateLimitRequestsPerMinute">Rate limits for requests. byte is RequestType, int maximum requests per minute for RequestType</param>
/// <param name="logger"></param>
public DownloadClient(Dictionary<byte, int> rateLimitRequestsPerMinute, Logger? logger) public DownloadClient(Dictionary<byte, int> rateLimitRequestsPerMinute, Logger? logger)
{ {
this.logger = logger; this.logger = logger;

View File

@ -11,7 +11,7 @@ namespace Tranga;
/// </summary> /// </summary>
public class TaskManager public class TaskManager
{ {
public Dictionary<Publication, List<Chapter>> _chapterCollection = new(); public Dictionary<Publication, List<Chapter>> chapterCollection = new();
private HashSet<TrangaTask> _allTasks; private HashSet<TrangaTask> _allTasks;
private bool _continueRunning = true; private bool _continueRunning = true;
private readonly Connector[] _connectors; private readonly Connector[] _connectors;
@ -138,7 +138,7 @@ public class TaskManager
{ {
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {task} {connectorName} {publication?.sortName}"); logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {task} {connectorName} {publication?.sortName}");
TrangaTask newTask = null; TrangaTask? newTask = null;
if (task == TrangaTask.Task.UpdateKomgaLibrary) if (task == TrangaTask.Task.UpdateKomgaLibrary)
{ {
newTask = new UpdateKomgaLibraryTask(task, reoccurrence); newTask = new UpdateKomgaLibraryTask(task, reoccurrence);
@ -164,10 +164,10 @@ public class TaskManager
trangaTask.connectorName == connector.name)) trangaTask.connectorName == connector.name))
{ {
_allTasks.Add(newTask); _allTasks.Add(newTask);
logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask.ToString()}"); logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask}");
} }
else else
logger?.WriteLine(this.GetType().ToString(), $"Task already exists {newTask.ToString()}"); logger?.WriteLine(this.GetType().ToString(), $"Task already exists {newTask}");
} }
ExportDataAndSettings(); ExportDataAndSettings();
@ -252,8 +252,8 @@ public class TaskManager
Publication[] ret = connector.GetPublications(title ?? ""); Publication[] ret = connector.GetPublications(title ?? "");
foreach (Publication publication in ret) foreach (Publication publication in ret)
{ {
if(!_chapterCollection.Any(pub => pub.Key.sortName == publication.sortName)) if(!chapterCollection.Any(pub => pub.Key.sortName == publication.sortName))
this._chapterCollection.TryAdd(publication, new List<Chapter>()); this.chapterCollection.TryAdd(publication, new List<Chapter>());
} }
return ret; return ret;
} }
@ -261,7 +261,7 @@ public class TaskManager
/// <returns>All added Publications</returns> /// <returns>All added Publications</returns>
public Publication[] GetAllPublications() public Publication[] GetAllPublications()
{ {
return this._chapterCollection.Keys.ToArray(); return this.chapterCollection.Keys.ToArray();
} }
/// <summary> /// <summary>
@ -276,7 +276,7 @@ public class TaskManager
Connector? ret = this._connectors.FirstOrDefault(connector => connector.name == connectorName); Connector? ret = this._connectors.FirstOrDefault(connector => connector.name == connectorName);
if (ret is null) if (ret is null)
throw new Exception($"Connector {connectorName} is not an available Connector."); throw new Exception($"Connector {connectorName} is not an available Connector.");
return (Connector)ret!; return ret;
} }
/// <summary> /// <summary>
@ -316,7 +316,7 @@ public class TaskManager
buffer = File.ReadAllText(settings.knownPublicationsPath); buffer = File.ReadAllText(settings.knownPublicationsPath);
Publication[] publications = JsonConvert.DeserializeObject<Publication[]>(buffer)!; Publication[] publications = JsonConvert.DeserializeObject<Publication[]>(buffer)!;
foreach (Publication publication in publications) foreach (Publication publication in publications)
this._chapterCollection.TryAdd(publication, new List<Chapter>()); this.chapterCollection.TryAdd(publication, new List<Chapter>());
} }
} }
@ -332,7 +332,7 @@ public class TaskManager
File.WriteAllText(settings.tasksFilePath, JsonConvert.SerializeObject(this._allTasks)); File.WriteAllText(settings.tasksFilePath, JsonConvert.SerializeObject(this._allTasks));
logger?.WriteLine(this.GetType().ToString(), $"Exporting known publications to {settings.knownPublicationsPath}"); 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()));
} }

View File

@ -15,7 +15,7 @@ public class DownloadNewChaptersTask : TrangaTask
string publicationFolder = Path.Join(connector.downloadLocation, pub.folderName); string publicationFolder = Path.Join(connector.downloadLocation, pub.folderName);
if(!Directory.Exists(publicationFolder)) if(!Directory.Exists(publicationFolder))
Directory.CreateDirectory(publicationFolder); Directory.CreateDirectory(publicationFolder);
List<Chapter> newChapters = UpdateChapters(connector, pub, language!, ref taskManager._chapterCollection); List<Chapter> newChapters = UpdateChapters(connector, pub, language!, ref taskManager.chapterCollection);
connector.CopyCoverFromCacheToDownloadLocation(pub, taskManager.settings); connector.CopyCoverFromCacheToDownloadLocation(pub, taskManager.settings);