From 13075a87041f399a017fc8bbbcb7aadd54e5058a Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 4 Oct 2023 09:31:03 +0200 Subject: [PATCH] Improved logic in LoadJobsList --- Tranga/Jobs/JobBoss.cs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index fce958a..4f2414c 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -142,24 +142,30 @@ public class JobBoss : GlobalBase AddJobToQueue(job); } - public void LoadJobsList(HashSet connectors) + private void LoadJobsList(HashSet connectors) { - Directory.CreateDirectory(settings.jobsFolderPath); + if (!Directory.Exists(settings.jobsFolderPath)) //No jobs to load + { + Directory.CreateDirectory(settings.jobsFolderPath); + return; + } Regex idRex = new (@"(.*)\.json"); - foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles()) - if (idRex.IsMatch(file.Name)) - { - Job job = JsonConvert.DeserializeObject(File.ReadAllText(file.FullName), - new JobJsonConverter(this, new MangaConnectorJsonConverter(this, connectors)))!; - this.jobs.Add(job); - } - - foreach (Job job in this.jobs) - this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job); + //Load json-job-files + foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name))) + { + Job job = JsonConvert.DeserializeObject(File.ReadAllText(file.FullName), + new JobJsonConverter(this, new MangaConnectorJsonConverter(this, connectors)))!; + this.jobs.Add(job); + } - foreach (DownloadNewChapters ncJob in this.jobs.Where(job => job is DownloadNewChapters)) - cachedPublications.Add(ncJob.manga); + //Connect jobs to parent-jobs and add Publications to cache + foreach (Job job in this.jobs) + { + this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job); + if(job is DownloadNewChapters dncJob) + cachedPublications.Add(dncJob.manga); + } } private void UpdateJobFile(Job job)