6 Commits

Author SHA1 Message Date
5bfd6bc196 Delete Tempfolder even with files in it. 2023-05-19 20:55:19 +02:00
bc99735f76 Download Cover and Create Series Info before Chapters.
Create Publication Directory when calling SaveSeriesInfo and DownloadCover
2023-05-19 20:55:04 +02:00
c9602d5f67 Bug where Value was not returned 2023-05-19 20:35:51 +02:00
b040419e12 Fix bug where if no tasks were available, the program could not continue. 2023-05-19 20:34:34 +02:00
204ec203d5 Changed some strings 2023-05-19 20:34:09 +02:00
8fcee6ca22 Store last selected Folder-Path 2023-05-19 20:33:53 +02:00
4 changed files with 36 additions and 16 deletions

View File

@ -12,7 +12,7 @@ app.MapGet("/GetPublications", (string connectorName, string? title) =>
{ {
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(c => c.Key == connectorName).Value; Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(c => c.Key == connectorName).Value;
if (connector is null) if (connector is null)
JsonSerializer.Serialize($"Connector {connectorName} is not a known connector."); return JsonSerializer.Serialize($"Connector {connectorName} is not a known connector.");
Publication[] publications; Publication[] publications;
if (title is not null) if (title is not null)

View File

@ -8,12 +8,18 @@ public static class Tranga_Cli
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
Console.WriteLine("Output folder path [standard D:]:"); string folderPath = Directory.GetCurrentDirectory();
string? folderPath = Console.ReadLine(); string settingsPath = Path.Join(Directory.GetCurrentDirectory(), "lastPath.setting");
while(folderPath is null ) if (File.Exists(settingsPath))
folderPath = Console.ReadLine(); folderPath = File.ReadAllText(settingsPath);
if (folderPath.Length < 1)
folderPath = "D:"; Console.WriteLine($"Output folder path [{folderPath}]:");
string? tmpPath = Console.ReadLine();
while(tmpPath is null)
tmpPath = Console.ReadLine();
if(tmpPath.Length > 0)
folderPath = tmpPath;
File.WriteAllText(settingsPath, folderPath);
Console.Write("Mode (D: Interactive only, T: TaskManager):"); Console.Write("Mode (D: Interactive only, T: TaskManager):");
ConsoleKeyInfo mode = Console.ReadKey(); ConsoleKeyInfo mode = Console.ReadKey();
@ -106,12 +112,11 @@ public static class Tranga_Cli
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.isBeingExecuted); int taskRunningCount = taskManager.GetAllTasks().Count(task => task.isBeingExecuted);
Console.Clear(); Console.Clear();
Console.WriteLine($"Download Folder: {folderPath} Tasks (Running/Total): {taskRunningCount}/{taskCount}"); Console.WriteLine($"Download Folder: {folderPath} Tasks (Running/Total): {taskRunningCount}/{taskCount}");
Console.WriteLine("Select Option:");
Console.WriteLine("L: List tasks"); Console.WriteLine("L: List tasks");
Console.WriteLine("C: Create Task"); Console.WriteLine("C: Create Task");
Console.WriteLine("D: Delete Task"); Console.WriteLine("D: Delete Task");
Console.WriteLine("E: Execute Task now"); Console.WriteLine("E: Execute Task now");
Console.WriteLine("Q: Exit with saving"); Console.WriteLine("Q: Exit");
ConsoleKey selection = Console.ReadKey().Key; ConsoleKey selection = Console.ReadKey().Key;
Console.WriteLine(); Console.WriteLine();
return selection; return selection;
@ -131,9 +136,15 @@ public static class Tranga_Cli
private static void ExecuteTask(TaskManager taskManager) private static void ExecuteTask(TaskManager taskManager)
{ {
TrangaTask[] tasks = taskManager.GetAllTasks(); TrangaTask[] tasks = taskManager.GetAllTasks();
if (tasks.Length < 1)
{
Console.Clear();
Console.WriteLine("There are no available Tasks.");
return;
}
PrintTasks(tasks); PrintTasks(tasks);
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):"); Console.WriteLine($"Select Task (0-{tasks.Length}):");
string? selectedTask = Console.ReadLine(); string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1) while(selectedTask is null || selectedTask.Length < 1)
@ -146,9 +157,15 @@ public static class Tranga_Cli
private static void RemoveTask(TaskManager taskManager) private static void RemoveTask(TaskManager taskManager)
{ {
TrangaTask[] tasks = taskManager.GetAllTasks(); TrangaTask[] tasks = taskManager.GetAllTasks();
if (tasks.Length < 1)
{
Console.Clear();
Console.WriteLine("There are no available Tasks.");
return;
}
PrintTasks(tasks); PrintTasks(tasks);
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):"); Console.WriteLine($"Select Task (0-{tasks.Length}):");
string? selectedTask = Console.ReadLine(); string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1) while(selectedTask is null || selectedTask.Length < 1)
@ -167,7 +184,7 @@ public static class Tranga_Cli
Console.WriteLine("Available Tasks:"); Console.WriteLine("Available Tasks:");
foreach (string taskName in taskNames) foreach (string taskName in taskNames)
Console.WriteLine($"{tIndex++}: {taskName}"); Console.WriteLine($"{tIndex++}: {taskName}");
Console.WriteLine($"Select Task (0-{taskNames.Length - 1}):"); Console.WriteLine($"Select Task (0-{taskNames.Length}):");
string? selectedTask = Console.ReadLine(); string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1) while(selectedTask is null || selectedTask.Length < 1)

View File

@ -57,7 +57,10 @@ public abstract class Connector
/// <param name="publication">Publication to save series.json for</param> /// <param name="publication">Publication to save series.json for</param>
public void SaveSeriesInfo(Publication publication) public void SaveSeriesInfo(Publication publication)
{ {
string seriesInfoPath = Path.Join(downloadLocation, publication.folderName, "series.json"); //Check if Publication already has a Folder and a series.json
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
Directory.CreateDirectory(publicationFolder);
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
if(!File.Exists(seriesInfoPath)) if(!File.Exists(seriesInfoPath))
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfo()); File.WriteAllText(seriesInfoPath,publication.GetSeriesInfo());
} }
@ -110,7 +113,7 @@ public abstract class Connector
//ZIP-it and ship-it //ZIP-it and ship-it
ZipFile.CreateFromDirectory(tempFolder, fullPath); ZipFile.CreateFromDirectory(tempFolder, fullPath);
Directory.Delete(tempFolder); //Cleanup Directory.Delete(tempFolder, true); //Cleanup
} }
protected class DownloadClient protected class DownloadClient

View File

@ -67,10 +67,10 @@ public static class TaskExecutor
private static void DownloadNewChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection) private static void DownloadNewChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection)
{ {
List<Chapter> newChapters = UpdateChapters(connector, publication, language, chapterCollection); List<Chapter> newChapters = UpdateChapters(connector, publication, language, chapterCollection);
foreach(Chapter newChapter in newChapters)
connector.DownloadChapter(publication, newChapter);
connector.DownloadCover(publication); connector.DownloadCover(publication);
connector.SaveSeriesInfo(publication); connector.SaveSeriesInfo(publication);
foreach(Chapter newChapter in newChapters)
connector.DownloadChapter(publication, newChapter);
} }
/// <summary> /// <summary>