From ec0881f08d352f0b30995d7f6dc3fa4c03995b04 Mon Sep 17 00:00:00 2001 From: QingQiz Date: Tue, 5 Jul 2022 04:06:01 +0800 Subject: [PATCH] =?UTF-8?q?FIX:=20the=20name=20of=20.osu=20in=20different?= =?UTF-8?q?=20directory=20can=20not=20be=20same...=F0=9F=A4=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BmsToOsu/Program.cs | 5 ++++- BmsToOsu/Utils/PathExt.cs | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/BmsToOsu/Program.cs b/BmsToOsu/Program.cs index d92b746..1873c11 100644 --- a/BmsToOsu/Program.cs +++ b/BmsToOsu/Program.cs @@ -82,8 +82,11 @@ var dest = dir.Replace(o.InputPath, o.OutPath); + var osuName = + $"{data.Metadata.Title} - {data.Metadata.Artist} - BMS Converted - {Path.GetFileNameWithoutExtension(fp)}.osu"; + Directory.CreateDirectory(dest); - File.WriteAllText(Path.Join(dest, Path.GetFileNameWithoutExtension(fp) + ".osu"), osu); + File.WriteAllText(Path.Join(dest, osuName.MakeValidFileName()), osu); }); if (!o.NoCopy) diff --git a/BmsToOsu/Utils/PathExt.cs b/BmsToOsu/Utils/PathExt.cs index b220d63..2a91342 100644 --- a/BmsToOsu/Utils/PathExt.cs +++ b/BmsToOsu/Utils/PathExt.cs @@ -36,4 +36,13 @@ public static string Escape(this string path) { return path.Replace(",", "-comma-"); } + + public static string MakeValidFileName(this string name) + { + var invalidChars = + System.Text.RegularExpressions.Regex.Escape(new string(System.IO.Path.GetInvalidFileNameChars())); + var invalidRegStr = string.Format(@"([{0}]*\.+$)|([{0}]+)", invalidChars); + + return System.Text.RegularExpressions.Regex.Replace(name, invalidRegStr, "_"); + } } \ No newline at end of file