Skip to content

Commit

Permalink
Misc: Replace invalid chars in .osz filenames with underscores instea…
Browse files Browse the repository at this point in the history
…d of removing them
  • Loading branch information
Piotrekol committed Jul 30, 2021
1 parent 55a57ac commit d4cc04d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions App/Misc/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ namespace App.Misc
{
public static class Helpers
{
public static string StripInvalidCharacters(string name)
public static string StripInvalidFileNameCharacters(string name, string replacementString = "")
{
foreach (var invalidChar in Path.GetInvalidFileNameChars())
{
name = name.Replace(invalidChar.ToString(), string.Empty);
name = name.Replace(invalidChar.ToString(), replacementString);
}
return name.Replace(".", string.Empty);

return name;
}

public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly)
{
if (assembly == null) throw new ArgumentNullException("assembly");
Expand Down
2 changes: 1 addition & 1 deletion App/OsuDownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private DownloadItem GetDownloadItem(Beatmap beatmap)
private string CreateFileName(Beatmap map)
{
var filename = map.MapSetId + " " + map.ArtistRoman + " - " + map.TitleRoman;
return Helpers.StripInvalidCharacters(filename) + ".osz";
return Helpers.StripInvalidFileNameCharacters(filename) + ".osz";
}
}
}
3 changes: 2 additions & 1 deletion App/SidePanelActionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ private void LoadCollection(string fileLocation)
try
{
var loadedCollections = _osuFileIo.CollectionLoader.LoadCollection(fileLocation);
//var cc = string.Join("\n",loadedCollections.SelectMany(c => c.AllBeatmaps()).Select(bb => bb.Md5));
_collectionEditor.EditCollection(CollectionEditArgs.AddCollections(loadedCollections));
}
catch (CorruptedFileException ex)
Expand Down Expand Up @@ -544,7 +545,7 @@ private async void SaveInvidualCollections(object sender, object data = null)
await BeforeCollectionSave(Initalizer.LoadedCollections);
foreach (var collection in Initalizer.LoadedCollections)
{
var filename = $"{Helpers.StripInvalidCharacters(collection.Name)}.{fileFormat}";
var filename = $"{Helpers.StripInvalidFileNameCharacters(collection.Name, "_")}.{fileFormat}";
_osuFileIo.CollectionLoader.SaveCollection(new Collections() { collection }, Path.Combine(saveDirectory, filename));
}
}
Expand Down

0 comments on commit d4cc04d

Please sign in to comment.