Compare commits

..

No commits in common. "39307f4313633d319a65b1aadca8de403c442432" and "569622099d3772c87e1ad3eb06f7352d7500fd63" have entirely different histories.

4 changed files with 19 additions and 61 deletions

View File

@ -19,7 +19,7 @@ public class DownloadChapter : Job
protected override string GetId()
{
return $"{GetType()}-{chapter.parentManga.internalId}-{chapter.chapterNumber}";
return Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(this.GetType().ToString(), chapter.parentManga.internalId, chapter.chapterNumber)));
}
public override string ToString()

View File

@ -21,7 +21,7 @@ public class DownloadNewChapters : Job
protected override string GetId()
{
return $"{GetType()}-{manga.internalId}";
return Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Concat(this.GetType().ToString(), manga.internalId)));
}
public override string ToString()

View File

@ -1,5 +1,4 @@
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json;
using Tranga.MangaConnectors;
namespace Tranga.Jobs;
@ -11,8 +10,16 @@ public class JobBoss : GlobalBase
public JobBoss(GlobalBase clone, HashSet<MangaConnector> connectors) : base(clone)
{
if (File.Exists(settings.jobsFilePath))
{
this.jobs = JsonConvert.DeserializeObject<HashSet<Job>>(File.ReadAllText(settings.jobsFilePath), new JobJsonConverter(this, new MangaConnectorJsonConverter(this, connectors)))!;
foreach (Job job in this.jobs)
this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job);
}
else
this.jobs = new();
LoadJobsList(connectors);
foreach (DownloadNewChapters ncJob in this.jobs.Where(job => job is DownloadNewChapters))
cachedPublications.Add(ncJob.manga);
this.mangaConnectorJobQueue = new();
}
@ -141,62 +148,13 @@ public class JobBoss : GlobalBase
AddJobToQueue(job);
}
public void LoadJobsList(HashSet<MangaConnector> connectors)
{
Directory.CreateDirectory(settings.jobsFolderPath);
Regex idRex = new (@"(.*)\.json");
foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles())
if (idRex.IsMatch(file.Name))
{
Job job = JsonConvert.DeserializeObject<Job>(File.ReadAllText(file.FullName),
new JobJsonConverter(this, new MangaConnectorJsonConverter(this, connectors)))!;
this.jobs.Add(job);
}
foreach (Job job in this.jobs)
this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job);
foreach (DownloadNewChapters ncJob in this.jobs.Where(job => job is DownloadNewChapters))
cachedPublications.Add(ncJob.manga);
}
public void ExportJobsList()
{
Log("Exporting Jobs");
foreach (Job job in this.jobs)
{
string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json");
if (!File.Exists(jobFilePath))
{
string jobStr = JsonConvert.SerializeObject(job);
while(IsFileInUse(jobFilePath))
Log($"Exporting {settings.jobsFilePath}");
string content = JsonConvert.SerializeObject(this.jobs);
while(IsFileInUse(settings.jobsFilePath))
Thread.Sleep(10);
Log($"Exporting Job {jobFilePath}");
File.WriteAllText(jobFilePath, jobStr);
}
}
//Remove files with jobs not in this.jobs-list
Regex idRex = new (@"(.*)\.json");
foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles())
{
if (idRex.IsMatch(file.Name))
{
string id = idRex.Match(file.Name).Groups[1].Value;
if (!this.jobs.Any(job => job.id == id))
{
try
{
file.Delete();
}
catch (Exception e)
{
Log(e.ToString());
}
}
}
}
File.WriteAllText(settings.jobsFilePath, content);
}
public void CheckJobs()

View File

@ -14,7 +14,7 @@ public class TrangaSettings
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
[JsonIgnore] public string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
[JsonIgnore] public string jobsFolderPath => Path.Join(workingDirectory, "jobs");
[JsonIgnore] public string jobsFilePath => Path.Join(workingDirectory, "jobs.json");
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
public ushort? version { get; set; }