From 6db46463361b8451583b581d6f64f378cd262d30 Mon Sep 17 00:00:00 2001 From: Glax Date: Sat, 29 Jun 2024 19:11:18 +0200 Subject: [PATCH] Move/rename archives if volume number gets updated. --- Tranga/Chapter.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index a699cb5..3c47878 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -91,18 +91,22 @@ public readonly struct Chapter : IComparable { if (!Directory.Exists(Path.Join(downloadLocation, parentManga.folderName))) return false; - FileInfo[] archives = new DirectoryInfo(Path.Join(downloadLocation, parentManga.folderName)).GetFiles(); + FileInfo[] archives = new DirectoryInfo(Path.Join(downloadLocation, parentManga.folderName)).GetFiles().Where(file => file.Name.Split('.')[^1] == "cbz").ToArray(); Regex volChRex = new(@"(?:Vol(?:ume)?\.([0-9]+)\D*)?Ch(?:apter)?\.([0-9]+(?:\.[0-9]+)*)"); Chapter t = this; - return archives.Select(archive => archive.Name).Any(archiveFileName => + string thisPath = GetArchiveFilePath(downloadLocation); + FileInfo? archive = archives.FirstOrDefault(archive => { - Match m = volChRex.Match(archiveFileName); + 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; + return archiveVolNum == t.volumeNumber && archiveChNum == t.chapterNumber || + archiveVolNum == "0" && archiveChNum == t.chapterNumber; }); + if(archive is not null && thisPath != archive.FullName) + archive.MoveTo(thisPath); + return archive is not null; } /// /// Creates full file path of chapter-archive