From 1d44b6d9c6216ab0ffffe02b8a61464cc684d641 Mon Sep 17 00:00:00 2001 From: Glax Date: Sun, 26 May 2024 18:10:29 +0200 Subject: [PATCH 1/2] Log added Jobs during Startup --- Tranga/Jobs/JobBoss.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 51fdece..275864b 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -150,15 +150,23 @@ private void LoadJobsList(HashSet connectors) //Load json-job-files foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name))) { + Log($"Adding {file.Name}"); Job job = JsonConvert.DeserializeObject(File.ReadAllText(file.FullName), new JobJsonConverter(this, new MangaConnectorJsonConverter(this, connectors)))!; + Log($"Adding Job {job}"); this.jobs.Add(job); } //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); + Log($"Loading Job {job}"); + Job? parentJob = this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId); + if (parentJob is not null) + { + parentJob.AddSubJob(job); + Log($"Parent Job {parentJob}"); + } if (job is DownloadNewChapters dncJob) AddMangaToCache(dncJob.manga); } From f4996659efdfe5330dd3eb11f7e4919aba8bbc33 Mon Sep 17 00:00:00 2001 From: Glax Date: Sun, 26 May 2024 18:22:51 +0200 Subject: [PATCH 2/2] Fix loading file results in "null"-job and crashes. --- Tranga/Jobs/JobBoss.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 275864b..c8cd28b 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -151,10 +151,19 @@ private void LoadJobsList(HashSet connectors) foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name))) { Log($"Adding {file.Name}"); - Job job = JsonConvert.DeserializeObject(File.ReadAllText(file.FullName), - new JobJsonConverter(this, new MangaConnectorJsonConverter(this, connectors)))!; - Log($"Adding Job {job}"); - this.jobs.Add(job); + Job? job = JsonConvert.DeserializeObject(File.ReadAllText(file.FullName), + new JobJsonConverter(this, new MangaConnectorJsonConverter(this, connectors))); + if (job is null) + { + string newName = file.FullName + ".failed"; + Log($"Failed loading file {file.Name}.\nMoving to {newName}"); + File.Move(file.FullName, newName); + } + else + { + Log($"Adding Job {job}"); + this.jobs.Add(job); + } } //Connect jobs to parent-jobs and add Publications to cache