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
# Conflicts:
#	Tranga/Jobs/JobBoss.cs
  • Loading branch information
C9Glax committed Oct 30, 2024
2 parents 07c6081 + bd8cb86 commit 3e581e2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
13 changes: 8 additions & 5 deletions Tranga/Chapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ internal bool CheckChapterIsDownloaded()
return false;
FileInfo? mangaArchive = null;
string markerPath = Path.Join(mangaDirectory, $".{id}");
if (this.id is not null
&& File.Exists(markerPath)
&& File.Exists(File.ReadAllText(markerPath)))
if (this.id is not null && File.Exists(markerPath))
{
mangaArchive = new FileInfo(File.ReadAllText(markerPath));
if(File.Exists(File.ReadAllText(markerPath)))
mangaArchive = new FileInfo(File.ReadAllText(markerPath));
else
File.Delete(markerPath);
}
else

if(mangaArchive is null)
{
FileInfo[] archives = new DirectoryInfo(mangaDirectory).GetFiles("*.cbz");
Regex volChRex = new(@"(?:Vol(?:ume)?\.([0-9]+)\D*)?Ch(?:apter)?\.([0-9]+(?:\.[0-9]+)*)");
Expand All @@ -110,6 +112,7 @@ internal bool CheckChapterIsDownloaded()
return m.Groups[2].Value == t.chapterNumber;
});
}

string correctPath = GetArchiveFilePath();
if(mangaArchive is not null && mangaArchive.FullName != correctPath)
mangaArchive.MoveTo(correctPath, true);
Expand Down
30 changes: 18 additions & 12 deletions Tranga/Jobs/JobBoss.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Tranga.MangaConnectors;
using static System.IO.UnixFileMode;

namespace Tranga.Jobs;

Expand All @@ -17,7 +19,7 @@ public JobBoss(GlobalBase clone, HashSet<MangaConnector> connectors) : base(clon
Log($"Next job in {jobs.MinBy(job => job.nextExecution)?.nextExecution.Subtract(DateTime.Now)} {jobs.MinBy(job => job.nextExecution)?.id}");
}

public bool AddJob(Job job)
public bool AddJob(Job job, string? jobFile = null)
{
if (ContainsJobLike(job))
{
Expand All @@ -27,10 +29,11 @@ public bool AddJob(Job job)
else
{
Log($"Added {job}");
this.jobs.Add(job);
UpdateJobFile(job);
return true;
if (!this.jobs.Add(job))
return false;
UpdateJobFile(job, jobFile);
}
return true;
}

public void AddJobs(IEnumerable<Job> jobsToAdd)
Expand Down Expand Up @@ -140,18 +143,18 @@ private void AddJobsToQueue(IEnumerable<Job> newJobs)

private void LoadJobsList(HashSet<MangaConnector> connectors)
{
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
{
Directory.CreateDirectory(TrangaSettings.jobsFolderPath);
return;
}
Regex idRex = new (@"(.*)\.json");

//Load Manga-Files
ImportManga();

//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 @@ -165,8 +168,8 @@ private void LoadJobsList(HashSet<MangaConnector> connectors)
else
{
Log($"Adding Job {job}");
this.jobs.Add(job);
UpdateJobFile(job, file.Name);
if(!AddJob(job, file.Name)) //If we detect a duplicate, delete the file.
file.Delete();
}
}

Expand Down Expand Up @@ -218,7 +221,8 @@ internal void UpdateJobFile(Job job, string? oldFile = null)
}
catch (Exception e)
{
Log(e.ToString());
Log($"Error deleting {oldFilePath} job {job.id}\n{e}");
return; //Don't export a new file when we haven't actually deleted the old one
}
}

Expand All @@ -230,6 +234,8 @@ internal void UpdateJobFile(Job job, string? oldFile = null)
while(IsFileInUse(newJobFilePath))
Thread.Sleep(10);
File.WriteAllText(newJobFilePath, jobStr);
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
File.SetUnixFileMode(newJobFilePath, UserRead | UserWrite | GroupRead | OtherRead);
}
}

Expand Down
7 changes: 4 additions & 3 deletions Tranga/MangaConnectors/ManhuaPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publi
Log("No genres found");
}

string yearNodeStr = document.DocumentNode
.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-clock ')]/../span").InnerText.Replace("\n", "");
int year = int.Parse(yearNodeStr.Split(' ')[0].Split('/')[^1]);
Regex yearRex = new(@"(?:[0-9]{1,2}\/){2}([0-9]{2,4}) [0-9]{1,2}:[0-9]{1,2}");
HtmlNode yearNode = document.DocumentNode.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-clock ')]/../span");
Match match = yearRex.Match(yearNode.InnerText);
int year = match.Success && match.Groups[1].Success ? int.Parse(match.Groups[1].Value) : 1960;

status = document.DocumentNode.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-rss ')]/../span").InnerText.Replace("\n", "");
switch (status.ToLower())
Expand Down

0 comments on commit 3e581e2

Please sign in to comment.