Core: Filter invalid directory name for Windows

This commit is contained in:
genteure 2022-08-01 21:34:09 +08:00
parent e0b01bbd4f
commit bf40fe27ec

View File

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using BililiveRecorder.Core.Config.V3;
using Fluid;
@ -224,11 +225,16 @@ namespace BililiveRecorder.Core.Templating
}
}
private static readonly Regex invalidDirectoryNameRegex = new Regex(@"([ .])([\\\/])", RegexOptions.Compiled);
internal static string RemoveInvalidFileName(string input, bool ignore_slash = true)
{
foreach (var c in Path.GetInvalidFileNameChars())
if (!ignore_slash || c != '\\' && c != '/')
input = input.Replace(c, '_');
input = invalidDirectoryNameRegex.Replace(input, "$1_$2");
return input;
}