mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 20:30:41 +00:00
fix: Added processing logic for special characters to prevent file write failures.
This commit is contained in:
parent
1f312c749d
commit
62d08df735
@ -1,9 +1,11 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace ZonyLrcTools.Common
|
namespace ZonyLrcTools.Common
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 歌曲信息的承载类,携带歌曲的相关数据。
|
/// 歌曲信息的承载类,携带歌曲的相关数据。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MusicInfo
|
public partial class MusicInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 歌曲对应的物理文件路径。
|
/// 歌曲对应的物理文件路径。
|
||||||
@ -38,9 +40,17 @@ namespace ZonyLrcTools.Common
|
|||||||
/// <param name="artist">歌曲的作者。</param>
|
/// <param name="artist">歌曲的作者。</param>
|
||||||
public MusicInfo(string filePath, string name, string artist)
|
public MusicInfo(string filePath, string name, string artist)
|
||||||
{
|
{
|
||||||
FilePath = filePath;
|
FilePath = Path.Combine(Path.GetDirectoryName(filePath)!, HandleInvalidFilePath(Path.GetFileName(filePath)));
|
||||||
Name = name;
|
Name = name;
|
||||||
Artist = artist;
|
Artist = artist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string HandleInvalidFilePath(string srcText)
|
||||||
|
{
|
||||||
|
return InvalidFilePathRegex().Replace(srcText, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"[<>:""/\\|?*]")]
|
||||||
|
private static partial Regex InvalidFilePathRegex();
|
||||||
}
|
}
|
||||||
}
|
}
|
15
tests/ZonyLrcTools.Tests/MusicInfoTests.cs
Normal file
15
tests/ZonyLrcTools.Tests/MusicInfoTests.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using Shouldly;
|
||||||
|
using Xunit;
|
||||||
|
using ZonyLrcTools.Common;
|
||||||
|
|
||||||
|
namespace ZonyLrcTools.Tests;
|
||||||
|
|
||||||
|
public class MusicInfoTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void InvalidFilePathTest()
|
||||||
|
{
|
||||||
|
var musicInfo = new MusicInfo("C:\\Users\\Zony\\Music\\[ZonyLrcTools]:? - 01. 你好.mp3", "你好", "Zony");
|
||||||
|
musicInfo.FilePath.ShouldBe(@"C:\Users\Zony\Music\[ZonyLrcTools] - 01. 你好.mp3");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user