1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 09:27:34 +08:00

Remove the previous audio file before adding a new one

This commit is contained in:
Dean Herbert 2020-09-24 18:34:17 +09:00
parent 4d714866cd
commit 65e6dd2ac3

View File

@ -144,14 +144,29 @@ namespace osu.Game.Screens.Edit.Setup
var info = new FileInfo(filePath.NewValue);
if (!info.Exists)
{
audioTrackTextBox.Current.Value = filePath.OldValue;
return;
}
var beatmapFiles = Beatmap.Value.BeatmapSetInfo.Files;
// remove the old file
var oldFile = beatmapFiles.FirstOrDefault(f => f.Filename == filePath.OldValue);
if (oldFile != null)
{
beatmapFiles.Remove(oldFile);
files.Dereference(oldFile.FileInfo);
}
// add the new file
IO.FileInfo osuFileInfo;
using (var stream = info.OpenRead())
osuFileInfo = files.Add(stream);
Beatmap.Value.BeatmapSetInfo.Files.Add(new BeatmapSetFileInfo
beatmapFiles.Add(new BeatmapSetFileInfo
{
FileInfo = osuFileInfo,
Filename = info.Name