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