2
0

Improved logic in LoadJobsList

This commit is contained in:
glax 2023-10-04 09:31:03 +02:00
parent e7d9f53a93
commit 13075a8704

View File

@ -142,24 +142,30 @@ public class JobBoss : GlobalBase
AddJobToQueue(job); AddJobToQueue(job);
} }
public void LoadJobsList(HashSet<MangaConnector> connectors) private void LoadJobsList(HashSet<MangaConnector> connectors)
{ {
Directory.CreateDirectory(settings.jobsFolderPath); if (!Directory.Exists(settings.jobsFolderPath)) //No jobs to load
{
Directory.CreateDirectory(settings.jobsFolderPath);
return;
}
Regex idRex = new (@"(.*)\.json"); Regex idRex = new (@"(.*)\.json");
foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles()) //Load json-job-files
if (idRex.IsMatch(file.Name)) foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name)))
{ {
Job job = JsonConvert.DeserializeObject<Job>(File.ReadAllText(file.FullName), Job job = JsonConvert.DeserializeObject<Job>(File.ReadAllText(file.FullName),
new JobJsonConverter(this, new MangaConnectorJsonConverter(this, connectors)))!; new JobJsonConverter(this, new MangaConnectorJsonConverter(this, connectors)))!;
this.jobs.Add(job); this.jobs.Add(job);
} }
//Connect jobs to parent-jobs and add Publications to cache
foreach (Job job in this.jobs) foreach (Job job in this.jobs)
{
this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job); this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job);
if(job is DownloadNewChapters dncJob)
foreach (DownloadNewChapters ncJob in this.jobs.Where(job => job is DownloadNewChapters)) cachedPublications.Add(dncJob.manga);
cachedPublications.Add(ncJob.manga); }
} }
private void UpdateJobFile(Job job) private void UpdateJobFile(Job job)