From 65e6dd2ac3e01f205b9d4b838696bd49acf2a7d1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 24 Sep 2020 18:34:17 +0900 Subject: [PATCH] Remove the previous audio file before adding a new one --- osu.Game/Screens/Edit/Setup/SetupScreen.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Setup/SetupScreen.cs b/osu.Game/Screens/Edit/Setup/SetupScreen.cs index 02b8afffe9..ce201e544a 100644 --- a/osu.Game/Screens/Edit/Setup/SetupScreen.cs +++ b/osu.Game/Screens/Edit/Setup/SetupScreen.cs @@ -144,14 +144,29 @@ private void audioTrackChanged(ValueChangedEvent filePath) 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