Skip to content

Commit

Permalink
Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into Server-V2
Browse files Browse the repository at this point in the history
  • Loading branch information
C9Glax committed Sep 16, 2024
2 parents 18edcef + 52d0489 commit c36204c
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions Tranga/Jobs/JobBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private void LoadJobsList(HashSet<MangaConnector> connectors)
Regex idRex = new (@"(.*)\.json");

//Load json-job-files
foreach (FileInfo file in new DirectoryInfo(TrangaSettings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name)))
foreach (FileInfo file in new DirectoryInfo(TrangaSettings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name)))
{
Log($"Adding {file.Name}");
Job? job = JsonConvert.DeserializeObject<Job>(File.ReadAllText(file.FullName),
Expand All @@ -163,6 +163,7 @@ private void LoadJobsList(HashSet<MangaConnector> connectors)
{
Log($"Adding Job {job}");
this.jobs.Add(job);
UpdateJobFile(job, file.Name);
}
}

Expand Down Expand Up @@ -203,42 +204,28 @@ private void LoadJobsList(HashSet<MangaConnector> connectors)
internal void UpdateJobFile(Job job, string? oldFile = null)
{
string newJobFilePath = Path.Join(TrangaSettings.jobsFolderPath, $"{job.id}.json");

if (!this.jobs.Any(jjob => jjob.id == job.id))
string oldFilePath = Path.Join(TrangaSettings.jobsFolderPath, oldFile);

if (File.Exists(oldFilePath))
{
Log($"Deleting Job-file {oldFilePath}");
try
{
Log($"Deleting Job-file {newJobFilePath}");
while(IsFileInUse(newJobFilePath))
while(IsFileInUse(oldFilePath))
Thread.Sleep(10);
File.Delete(newJobFilePath);
File.Delete(oldFilePath);
}
catch (Exception e)
{
Log(e.ToString());
}
}
else
{
Log($"Exporting Job {newJobFilePath}");
string jobStr = JsonConvert.SerializeObject(job, Formatting.Indented);
while(IsFileInUse(newJobFilePath))
Thread.Sleep(10);
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());
}
Log($"Exporting Job {newJobFilePath}");
string jobStr = JsonConvert.SerializeObject(job, Formatting.Indented);
while(IsFileInUse(newJobFilePath))
Thread.Sleep(10);
File.WriteAllText(newJobFilePath, jobStr);
}

private void UpdateAllJobFiles()
Expand Down

0 comments on commit c36204c

Please sign in to comment.