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
1 changed files with 16 additions and 1 deletions

View File

@ -144,14 +144,29 @@ private void audioTrackChanged(ValueChangedEvent<string> 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