Skip to content

Commit

Permalink
FIX: the name of .osu in different directory can not be same...🤬
Browse files Browse the repository at this point in the history
  • Loading branch information
QingQiz committed Jul 4, 2022
1 parent 533094a commit ec0881f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion BmsToOsu/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions BmsToOsu/Utils/PathExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "_");
}
}

0 comments on commit ec0881f

Please sign in to comment.