From 8cee11aa22bcfd72f8570e4589fcfa57ad5b3abb Mon Sep 17 00:00:00 2001 From: Glax Date: Tue, 29 Oct 2024 19:15:19 +0100 Subject: [PATCH 1/7] Fix #272 Manhuaplus missing year string --- Tranga/MangaConnectors/ManhuaPlus.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tranga/MangaConnectors/ManhuaPlus.cs b/Tranga/MangaConnectors/ManhuaPlus.cs index 98bc368..d66fede 100644 --- a/Tranga/MangaConnectors/ManhuaPlus.cs +++ b/Tranga/MangaConnectors/ManhuaPlus.cs @@ -108,9 +108,10 @@ public class ManhuaPlus : MangaConnector 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()) From 420013f07b71e21863c598535e553baa4b3daaa7 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 30 Oct 2024 18:23:14 +0100 Subject: [PATCH 2/7] Delete chapterMarkers if the file doesn't exist anymore. --- Tranga/Chapter.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index 6e40c6b..928591a 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -89,13 +89,15 @@ public readonly struct Chapter : IComparable 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]+)*)"); @@ -110,6 +112,7 @@ public readonly struct Chapter : IComparable return m.Groups[2].Value == t.chapterNumber; }); } + string correctPath = GetArchiveFilePath(); if(mangaArchive is not null && mangaArchive.FullName != correctPath) mangaArchive.MoveTo(correctPath, true); From 4b88cdbd9031949b6819af0d38c0f9185ef62837 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 30 Oct 2024 20:31:16 +0100 Subject: [PATCH 3/7] When updating Jobfiles, dont write a new file if we werent able to successfully delete the old one --- Tranga/Jobs/JobBoss.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index bd33c62..7377c38 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -203,7 +203,8 @@ public class JobBoss : GlobalBase } 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 } } From 067497ddd0d4406bb8341853608528ea7adbb133 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 30 Oct 2024 20:38:53 +0100 Subject: [PATCH 4/7] Delete duplicate files on startup. --- Tranga/Jobs/JobBoss.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 7377c38..bbdf95d 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -17,18 +17,21 @@ public class JobBoss : GlobalBase Log($"Next job in {jobs.MinBy(job => job.nextExecution)?.nextExecution.Subtract(DateTime.Now)} {jobs.MinBy(job => job.nextExecution)?.id}"); } - public void AddJob(Job job) + public bool AddJob(Job job, string? jobFile = null) { if (ContainsJobLike(job)) { Log($"Already Contains Job {job}"); + return false; } else { Log($"Added {job}"); - this.jobs.Add(job); - UpdateJobFile(job); + if (!this.jobs.Add(job)) + return false; + UpdateJobFile(job, jobFile); } + return true; } public void AddJobs(IEnumerable jobsToAdd) @@ -162,8 +165,8 @@ public class JobBoss : GlobalBase 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(); } } From 02cf8578c99c781720d15b4836afa289cfc5a393 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 30 Oct 2024 22:27:50 +0100 Subject: [PATCH 5/7] Explicitly set File/Directory permissions for jobs --- Tranga/Jobs/JobBoss.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index bbdf95d..95456dc 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -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; @@ -146,6 +148,8 @@ public class JobBoss : GlobalBase 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); return; } Regex idRex = new (@"(.*)\.json"); From 469039443785726f1b5982fcc9999e37280d4411 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 30 Oct 2024 22:27:55 +0100 Subject: [PATCH 6/7] Formatting --- Tranga/Jobs/JobBoss.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 95456dc..c00458b 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -155,7 +155,7 @@ public class JobBoss : GlobalBase 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(File.ReadAllText(file.FullName), @@ -190,7 +190,7 @@ public class JobBoss : GlobalBase string[] coverFiles = Directory.GetFiles(TrangaSettings.coverImageCache); foreach(string fileName in coverFiles.Where(fileName => !GetAllCachedManga().Any(manga => manga.coverFileNameInCache == fileName))) - File.Delete(fileName); + File.Delete(fileName); } internal void UpdateJobFile(Job job, string? oldFile = null) @@ -223,6 +223,8 @@ public class JobBoss : GlobalBase while(IsFileInUse(newJobFilePath)) Thread.Sleep(10); File.WriteAllText(newJobFilePath, jobStr); + if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + File.SetUnixFileMode(newJobFilePath, UserRead | UserWrite | GroupRead | OtherRead); } } From bd8cb86c529afbe16ceeb29330a1d0d677b7dec0 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 30 Oct 2024 22:29:16 +0100 Subject: [PATCH 7/7] Always set directory-permissions --- Tranga/Jobs/JobBoss.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index c00458b..e3b8b9c 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -145,13 +145,11 @@ public class JobBoss : GlobalBase private void LoadJobsList(HashSet 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); - if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - File.SetUnixFileMode(TrangaSettings.jobsFolderPath, UserRead | UserWrite | UserExecute | GroupRead | OtherRead); return; - } Regex idRex = new (@"(.*)\.json"); //Load json-job-files