From 147a20385b106af38d624ccd60ed00cfa9c77d16 Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 25 May 2023 16:55:58 +0200 Subject: [PATCH] illegal filenames --- Tranga/Chapter.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index 7d3e91a..ad9251b 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -1,4 +1,5 @@ using System.Globalization; +using System.Text.RegularExpressions; namespace Tranga; @@ -14,14 +15,15 @@ public struct Chapter public string url { get; } public string fileName { get; } public string sortNumber { get; } - + + private static readonly Regex LegalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*~*!*)*"); public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url) { this.name = name; this.volumeNumber = volumeNumber is { Length: > 0 } ? volumeNumber : "1"; this.chapterNumber = chapterNumber; this.url = url; - string chapterName = string.Concat((name ?? "").Split(Path.GetInvalidFileNameChars())); + string chapterName = string.Concat(LegalCharacters.Matches(name ?? "")); NumberFormatInfo nfi = new NumberFormatInfo() { NumberDecimalSeparator = "."