mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-22 23:30:13 +01:00
JobBoss LoadJobsList change:
Fix Directory.Exists jobsFolderPath to create new Directory Fix Loading Job fails leading to crash.
This commit is contained in:
parent
6aa8413c40
commit
f532e2ff76
@ -1,4 +1,5 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Tranga.MangaConnectors;
|
||||
@ -144,27 +145,25 @@ public class JobBoss : GlobalBase
|
||||
}
|
||||
|
||||
private void LoadJobsList(HashSet<MangaConnector> connectors)
|
||||
{
|
||||
if (!Directory.Exists(TrangaSettings.jobsFolderPath)) //No jobs to load
|
||||
{
|
||||
Directory.CreateDirectory(TrangaSettings.jobsFolderPath);
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(TrangaSettings.jobsFolderPath, UserRead | UserWrite | UserExecute | GroupRead | OtherRead);
|
||||
if (!Directory.Exists(TrangaSettings.jobsFolderPath)) //No jobs to load
|
||||
return;
|
||||
}
|
||||
|
||||
//Load json-job-files
|
||||
foreach (FileInfo file in Directory.GetFiles(TrangaSettings.jobsFolderPath, "*.json").Select(f => new FileInfo(f)))
|
||||
{
|
||||
Log($"Adding {file.Name}");
|
||||
try
|
||||
{
|
||||
Job? job = JsonConvert.DeserializeObject<Job>(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
|
||||
{
|
||||
if (job is null) throw new NullReferenceException();
|
||||
|
||||
Log($"Adding Job {job}");
|
||||
if (!AddJob(job, file.FullName)) //If we detect a duplicate, delete the file.
|
||||
{
|
||||
@ -173,6 +172,16 @@ public class JobBoss : GlobalBase
|
||||
Log($"Duplicate detected or otherwise not able to add job to list.\nMoved job {job} to {path}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e is not UnreachableException or NullReferenceException)
|
||||
throw;
|
||||
Log(e.Message);
|
||||
string newName = file.FullName + ".failed";
|
||||
Log($"Failed loading file {file.Name}.\nMoving to {newName}");
|
||||
File.Move(file.FullName, newName);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//Connect jobs to parent-jobs and add Publications to cache
|
||||
|
Loading…
x
Reference in New Issue
Block a user