diff --git a/ComicNodes/Comics/ComicConverter.cs b/ComicNodes/Comics/ComicConverter.cs index 68d51908..fd41f93d 100644 --- a/ComicNodes/Comics/ComicConverter.cs +++ b/ComicNodes/Comics/ComicConverter.cs @@ -177,16 +177,32 @@ public class ComicConverter: Node if (DeleteNonPageImages) { + List nonPages = new(); + float imageCount = 0; foreach (var file in Directory.GetFiles(destinationPath, "*.*", SearchOption.AllDirectories)) { if(rgxImages.IsMatch(file) == false) continue; + imageCount++; string nameNoExtension = FileHelper.GetShortFileName(file); nameNoExtension = nameNoExtension[..nameNoExtension.LastIndexOf(".", StringComparison.Ordinal)]; if (Regex.IsMatch(nameNoExtension, @"[\d]{2,}$") == false) { - args.Logger?.ILog("Deleting non page image: " + file); - File.Delete(file); + nonPages.Add(file); + } + } + + if (nonPages.Any()) + { + float percent = ((float)nonPages.Count) / imageCount * 100; + if (percent < 10) + { + // only delete if the number of non images is low, we dont want to mistakenly identify all pages as non images + foreach (var file in nonPages) + { + args.Logger?.ILog("Deleting non page image: " + file); + File.Delete(file); + } } } } diff --git a/ComicNodes/Comics/CreateComicInfo.cs b/ComicNodes/Comics/CreateComicInfo.cs index 3547c9fc..cb94ab08 100644 --- a/ComicNodes/Comics/CreateComicInfo.cs +++ b/ComicNodes/Comics/CreateComicInfo.cs @@ -194,7 +194,9 @@ public class CreateComicInfo : Node else { // Pad the number with leading zeros based on the specified number of digits - string paddedNumber = info.Number.Value.ToString().PadLeft(issueDigits, '0'); + string paddedNumber = info.Number < 0 ? + ("-" + info.Number.Value.ToString()[1..].PadLeft(issueDigits -1, '0')) : + info.Number.Value.ToString().PadLeft(issueDigits, '0'); // Add the padded number to the name name += $" - #{paddedNumber}"; @@ -268,8 +270,9 @@ public class CreateComicInfo : Node if (parts.Length < 2) { // remove any junk + shortname = Regex.Replace(shortname, @"\(([\-]?\d+)\)", "$1").Trim(); shortname = Regex.Replace(shortname, @"\s*\([^)]*\)\s*", " ").Trim(); - var lastChanceMatch = Regex.Match(shortname, @"(\d)+$"); + var lastChanceMatch = Regex.Match(shortname, @"([\-]?\d)+$"); if(lastChanceMatch.Success) { info.Number = int.Parse(lastChanceMatch.Value); diff --git a/ComicNodes/Tests/ComicInfoTests.cs b/ComicNodes/Tests/ComicInfoTests.cs index fb811efb..3e9e1ef9 100644 --- a/ComicNodes/Tests/ComicInfoTests.cs +++ b/ComicNodes/Tests/ComicInfoTests.cs @@ -119,6 +119,31 @@ public class ComicInfoTests : TestBase Assert.AreEqual("X-Man - #045.cbz", name.Value); } + [TestMethod] + public void MinusOne() + { + var result = CreateComicInfo.GetInfo(Logger, + "/home/john/Comics/Marvel/X-Men/Cable (1993)/Cable (-1) (1997) (Digital) (Dark-Star).cbz", + "/home/john/Comics", + true); + + TestContext.WriteLine(Logger.ToString()); + + Assert.IsFalse(result.IsFailed); + var info = result.Value; + Assert.IsNotNull(info); + Assert.AreEqual("Marvel", info.Publisher); + Assert.AreEqual("Cable (1993)", info.Series); + Assert.AreEqual(-1, info.Number); + + var xml = CreateComicInfo.SerializeToXml(info); + Assert.IsFalse(string.IsNullOrWhiteSpace(xml)); + TestContext.WriteLine(new string('-', 70)); + TestContext.WriteLine(xml); + + var name = CreateComicInfo.GetNewName(info, "cbz", 3); + Assert.AreEqual("Cable (1993) - #-01.cbz", name.Value); + } [TestMethod] public void NameAndNumber2()