diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 75e01a6..637b3ae 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -171,18 +171,18 @@ public class JobBoss : GlobalBase } } - internal void UpdateJobFile(Job job) + internal void UpdateJobFile(Job job, string? oldFile = null) { - string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json"); + string newJobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json"); if (!this.jobs.Any(jjob => jjob.id == job.id)) { try { - Log($"Deleting Job-file {jobFilePath}"); - while(IsFileInUse(jobFilePath)) + Log($"Deleting Job-file {newJobFilePath}"); + while(IsFileInUse(newJobFilePath)) Thread.Sleep(10); - File.Delete(jobFilePath); + File.Delete(newJobFilePath); } catch (Exception e) { @@ -191,12 +191,25 @@ public class JobBoss : GlobalBase } else { - Log($"Exporting Job {jobFilePath}"); + Log($"Exporting Job {newJobFilePath}"); string jobStr = JsonConvert.SerializeObject(job); - while(IsFileInUse(jobFilePath)) + while(IsFileInUse(newJobFilePath)) Thread.Sleep(10); - File.WriteAllText(jobFilePath, jobStr); + File.WriteAllText(newJobFilePath, jobStr); } + + if(oldFile is not null) + try + { + Log($"Deleting old Job-file {oldFile}"); + while(IsFileInUse(oldFile)) + Thread.Sleep(10); + File.Delete(oldFile); + } + catch (Exception e) + { + Log(e.ToString()); + } } private void UpdateAllJobFiles() diff --git a/Tranga/Jobs/UpdateMetadata.cs b/Tranga/Jobs/UpdateMetadata.cs index 9fab4dc..4dc3ae7 100644 --- a/Tranga/Jobs/UpdateMetadata.cs +++ b/Tranga/Jobs/UpdateMetadata.cs @@ -38,13 +38,20 @@ public class UpdateMetadata : Job this.mangaConnector.CopyCoverFromCacheToDownloadLocation(manga); foreach (Job job in jobBoss.GetJobsLike(publication: this.manga)) { + string oldFile; if (job is DownloadNewChapters dc) + { + oldFile = dc.id; dc.manga = this.manga; + } else if (job is UpdateMetadata um) + { + oldFile = um.id; um.manga = this.manga; + } else continue; - jobBoss.UpdateJobFile(job); + jobBoss.UpdateJobFile(job, oldFile); } this.progressToken.Complete(); }