2023-05-18 20:06:29 +02:00
|
|
|
|
using System.Globalization;
|
2023-05-25 16:55:58 +02:00
|
|
|
|
using System.Text.RegularExpressions;
|
2023-05-18 20:06:29 +02:00
|
|
|
|
|
|
|
|
|
namespace Tranga;
|
2023-05-17 23:23:01 +02:00
|
|
|
|
|
2023-05-19 19:52:24 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Has to be Part of a publication
|
|
|
|
|
/// Includes the Chapter-Name, -VolumeNumber, -ChapterNumber, the location of the chapter on the internet and the saveName of the local file.
|
|
|
|
|
/// </summary>
|
2023-05-17 23:23:01 +02:00
|
|
|
|
public struct Chapter
|
|
|
|
|
{
|
2023-05-18 16:03:00 +02:00
|
|
|
|
public string? name { get; }
|
|
|
|
|
public string? volumeNumber { get; }
|
|
|
|
|
public string? chapterNumber { get; }
|
2023-05-18 16:21:21 +02:00
|
|
|
|
public string url { get; }
|
2023-05-18 19:51:26 +02:00
|
|
|
|
public string fileName { get; }
|
2023-05-20 02:39:23 +02:00
|
|
|
|
public string sortNumber { get; }
|
2023-05-25 16:55:58 +02:00
|
|
|
|
|
2023-05-25 17:34:24 +02:00
|
|
|
|
private static readonly Regex LegalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*");
|
2023-05-19 19:32:47 +02:00
|
|
|
|
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
|
2023-05-17 23:23:01 +02:00
|
|
|
|
{
|
|
|
|
|
this.name = name;
|
2023-05-20 02:42:36 +02:00
|
|
|
|
this.volumeNumber = volumeNumber is { Length: > 0 } ? volumeNumber : "1";
|
2023-05-17 23:23:01 +02:00
|
|
|
|
this.chapterNumber = chapterNumber;
|
2023-05-18 16:21:21 +02:00
|
|
|
|
this.url = url;
|
2023-05-25 16:55:58 +02:00
|
|
|
|
string chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
|
2023-05-20 02:10:10 +02:00
|
|
|
|
NumberFormatInfo nfi = new NumberFormatInfo()
|
|
|
|
|
{
|
|
|
|
|
NumberDecimalSeparator = "."
|
|
|
|
|
};
|
2023-05-20 02:42:36 +02:00
|
|
|
|
sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber) * Convert.ToDecimal(this.chapterNumber, nfi), 1)
|
2023-05-20 02:39:23 +02:00
|
|
|
|
.ToString(nfi);
|
|
|
|
|
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {sortNumber}";
|
2023-05-17 23:23:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|