Compare commits

..

No commits in common. "2f0fbbd3cbaab1186419305b62597e5d3d407f2e" and "d8df6eccb14e33af6d85b7afd944f38a3c7b0a71" have entirely different histories.

View File

@ -27,20 +27,13 @@ public readonly struct Chapter : IComparable
this.volumeNumber = volumeNumber ?? "0"; this.volumeNumber = volumeNumber ?? "0";
this.chapterNumber = chapterNumber; this.chapterNumber = chapterNumber;
this.url = url; this.url = url;
string chapterVolNumStr;
if (volumeNumber is not null && volumeNumber.Length > 0)
chapterVolNumStr = $"Vol.{volumeNumber} Ch.{chapterNumber}";
else
chapterVolNumStr = $"Ch.{chapterNumber}";
if (name is not null && name.Length > 0) string chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
{ string volStr = volumeNumber is not null ? $"Vol.{volumeNumber} " : "";
string chapterName = IllegalStrings.Replace(string.Concat(LegalCharacters.Matches(name)), ""); string chNumberStr = $"Ch.{chapterNumber} ";
this.fileName = $"{chapterVolNumStr} - {chapterName}"; string chNameStr = chapterName.Length > 0 ? $"- {chapterName}" : "";
} chNameStr = IllegalStrings.Replace(chNameStr, "");
else this.fileName = $"{volStr}{chNumberStr}{chNameStr}";
this.fileName = chapterVolNumStr;
} }
public override string ToString() public override string ToString()
@ -88,20 +81,23 @@ public readonly struct Chapter : IComparable
/// <returns>true if chapter is present</returns> /// <returns>true if chapter is present</returns>
internal bool CheckChapterIsDownloaded(string downloadLocation) internal bool CheckChapterIsDownloaded(string downloadLocation)
{ {
string newFilePath = GetArchiveFilePath(downloadLocation);
if (!Directory.Exists(Path.Join(downloadLocation, parentManga.folderName))) if (!Directory.Exists(Path.Join(downloadLocation, parentManga.folderName)))
return false; return false;
FileInfo[] archives = new DirectoryInfo(Path.Join(downloadLocation, parentManga.folderName)).GetFiles(); FileInfo[] archives = new DirectoryInfo(Path.Join(downloadLocation, parentManga.folderName)).GetFiles();
Regex volChRex = new(@".*Vol(?:ume)?\.?([0-9]+).*Ch(?:apter)?\.?([0-9]+[\.0-9]*).*"); Regex chapterInfoRex = new(@"Ch\.[0-9.]+");
Regex chapterRex = new(@"[0-9]+(\.[0-9]+)?");
if (File.Exists(newFilePath))
return true;
Chapter t = this; string cn = this.chapterNumber;
return archives.Select(archive => archive.Name).Any(archiveFileName => if (archives.FirstOrDefault(archive => chapterRex.Match(chapterInfoRex.Match(archive.Name).Value).Value == cn) is { } path)
{ {
Match m = volChRex.Match(archiveFileName); File.Move(path.FullName, newFilePath);
string archiveVolNum = m.Groups[1].Value; return true;
string archiveChNum = m.Groups[2].Value; }
return archiveVolNum == t.volumeNumber && return false;
archiveChNum == t.chapterNumber;
});
} }
/// <summary> /// <summary>
/// Creates full file path of chapter-archive /// Creates full file path of chapter-archive