1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 15:53:21 +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); var info = new FileInfo(filePath.NewValue);
if (!info.Exists) if (!info.Exists)
{
audioTrackTextBox.Current.Value = filePath.OldValue; 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; IO.FileInfo osuFileInfo;
using (var stream = info.OpenRead()) using (var stream = info.OpenRead())
osuFileInfo = files.Add(stream); osuFileInfo = files.Add(stream);
Beatmap.Value.BeatmapSetInfo.Files.Add(new BeatmapSetFileInfo beatmapFiles.Add(new BeatmapSetFileInfo
{ {
FileInfo = osuFileInfo, FileInfo = osuFileInfo,
Filename = info.Name Filename = info.Name