2
0

Delete old jobfiles.

This commit is contained in:
Glax 2024-04-25 21:24:11 +02:00
parent ec9290f41f
commit d52213002e
2 changed files with 29 additions and 9 deletions

View File

@ -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()

View File

@ -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();
}