From d2074fae356cecd439236f70927fb679a2ea58fb Mon Sep 17 00:00:00 2001 From: Glax Date: Sat, 21 Sep 2024 20:23:21 +0200 Subject: [PATCH 1/2] Readable CheckChapterIsDownloaded check --- Tranga/Chapter.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index 2dbf346..ef82ec7 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -84,24 +84,25 @@ public readonly struct Chapter : IComparable /// true if chapter is present internal bool CheckChapterIsDownloaded() { - if (!Directory.Exists(Path.Join(TrangaSettings.downloadLocation, parentManga.folderName))) + string mangaDirectory = Path.Join(TrangaSettings.downloadLocation, parentManga.folderName); + if (!Directory.Exists(mangaDirectory)) return false; - FileInfo[] archives = new DirectoryInfo(Path.Join(TrangaSettings.downloadLocation, parentManga.folderName)).GetFiles().Where(file => file.Name.Split('.')[^1] == "cbz").ToArray(); + FileInfo[] archives = new DirectoryInfo(mangaDirectory).GetFiles("*.cbz"); Regex volChRex = new(@"(?:Vol(?:ume)?\.([0-9]+)\D*)?Ch(?:apter)?\.([0-9]+(?:\.[0-9]+)*)"); Chapter t = this; - string thisPath = GetArchiveFilePath(); + string correctPath = GetArchiveFilePath(); FileInfo? archive = archives.FirstOrDefault(archive => { Match m = volChRex.Match(archive.Name); - string archiveVolNum = m.Groups[1].Success ? m.Groups[1].Value : "0"; - string archiveChNum = m.Groups[2].Value; - return archiveVolNum == t.volumeNumber && archiveChNum == t.chapterNumber || - archiveVolNum == "0" && archiveChNum == t.chapterNumber; + if (m.Groups[1].Success) + return m.Groups[1].Value == t.volumeNumber && m.Groups[2].Value == t.chapterNumber; + else + return m.Groups[2].Value == t.chapterNumber; }); - if(archive is not null && thisPath != archive.FullName) - archive.MoveTo(thisPath, true); - return archive is not null; + if(archive is not null && archive.FullName != correctPath) + archive.MoveTo(correctPath, true); + return (archive is not null); } /// /// Creates full file path of chapter-archive From ec8eb4094136466ff9c5908dfc3ec0247fc9fe62 Mon Sep 17 00:00:00 2001 From: Glax Date: Sat, 21 Sep 2024 20:30:55 +0200 Subject: [PATCH 2/2] Allow Versions to lose their volume number, if site no longer lists it. --- Tranga/Chapter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index ef82ec7..6ae48a2 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -95,9 +95,10 @@ public readonly struct Chapter : IComparable FileInfo? archive = archives.FirstOrDefault(archive => { Match m = volChRex.Match(archive.Name); + /*Uncommenting this section will only allow *Version without Volume number* -> *Version with Volume number* but not the other way if (m.Groups[1].Success) return m.Groups[1].Value == t.volumeNumber && m.Groups[2].Value == t.chapterNumber; - else + else*/ return m.Groups[2].Value == t.chapterNumber; }); if(archive is not null && archive.FullName != correctPath)