mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 11:42:22 +08:00
Core: Filter invalid directory name for Windows
This commit is contained in:
parent
e0b01bbd4f
commit
bf40fe27ec
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user