mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 15:22:56 +08:00
Preserve existing beatmap background/audio files if used elsewhere
This commit is contained in:
parent
259ad8ae0f
commit
871c365fd8
@ -77,27 +77,35 @@ namespace osu.Game.Screens.Edit.Setup
|
|||||||
if (!source.Exists)
|
if (!source.Exists)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
var beatmap = working.Value.BeatmapInfo;
|
||||||
var set = working.Value.BeatmapSetInfo;
|
var set = working.Value.BeatmapSetInfo;
|
||||||
|
|
||||||
var destination = new FileInfo($@"bg{source.Extension}");
|
string[] filenames = set.Files.Select(f => f.Filename).Where(f =>
|
||||||
|
f.StartsWith(@"bg", StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
f.EndsWith(source.Extension, StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||||
|
|
||||||
// remove the previous background for now.
|
string currentFilename = working.Value.Metadata.BackgroundFile;
|
||||||
// in the future we probably want to check if this is being used elsewhere (other difficulties?)
|
string? newFilename = null;
|
||||||
var oldFile = set.GetFile(working.Value.Metadata.BackgroundFile);
|
|
||||||
|
var oldFile = set.GetFile(currentFilename);
|
||||||
|
|
||||||
|
if (oldFile != null && set.Beatmaps.Where(b => !b.Equals(beatmap)).All(b => b.Metadata.BackgroundFile != currentFilename))
|
||||||
|
{
|
||||||
|
beatmaps.DeleteFile(set, oldFile);
|
||||||
|
newFilename = currentFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
newFilename ??= NamingUtils.GetNextBestFilename(filenames, $@"bg{source.Extension}");
|
||||||
|
|
||||||
using (var stream = source.OpenRead())
|
using (var stream = source.OpenRead())
|
||||||
{
|
beatmaps.AddFile(set, stream, newFilename);
|
||||||
if (oldFile != null)
|
|
||||||
beatmaps.DeleteFile(set, oldFile);
|
|
||||||
|
|
||||||
beatmaps.AddFile(set, stream, destination.Name);
|
working.Value.Metadata.BackgroundFile = newFilename;
|
||||||
}
|
updateAllDifficultiesButton.Enabled.Value = true;
|
||||||
|
|
||||||
editorBeatmap.SaveState();
|
editorBeatmap.SaveState();
|
||||||
|
|
||||||
working.Value.Metadata.BackgroundFile = destination.Name;
|
|
||||||
headerBackground.UpdateBackground();
|
headerBackground.UpdateBackground();
|
||||||
|
|
||||||
editor?.ApplyToBackground(bg => bg.RefreshBackground());
|
editor?.ApplyToBackground(bg => bg.RefreshBackground());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -108,23 +116,31 @@ namespace osu.Game.Screens.Edit.Setup
|
|||||||
if (!source.Exists)
|
if (!source.Exists)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
var beatmap = working.Value.BeatmapInfo;
|
||||||
var set = working.Value.BeatmapSetInfo;
|
var set = working.Value.BeatmapSetInfo;
|
||||||
|
|
||||||
var destination = new FileInfo($@"audio{source.Extension}");
|
string[] filenames = set.Files.Select(f => f.Filename).Where(f =>
|
||||||
|
f.StartsWith(@"audio", StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
f.EndsWith(source.Extension, StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||||
|
|
||||||
// remove the previous audio track for now.
|
string currentFilename = working.Value.Metadata.AudioFile;
|
||||||
// in the future we probably want to check if this is being used elsewhere (other difficulties?)
|
string? newFilename = null;
|
||||||
var oldFile = set.GetFile(working.Value.Metadata.AudioFile);
|
|
||||||
|
|
||||||
using (var stream = source.OpenRead())
|
var oldFile = set.GetFile(currentFilename);
|
||||||
|
|
||||||
|
if (oldFile != null && set.Beatmaps.Where(b => !b.Equals(beatmap)).All(b => b.Metadata.AudioFile != currentFilename))
|
||||||
{
|
{
|
||||||
if (oldFile != null)
|
|
||||||
beatmaps.DeleteFile(set, oldFile);
|
beatmaps.DeleteFile(set, oldFile);
|
||||||
|
newFilename = currentFilename;
|
||||||
beatmaps.AddFile(set, stream, destination.Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
working.Value.Metadata.AudioFile = destination.Name;
|
newFilename ??= NamingUtils.GetNextBestFilename(filenames, $@"audio{source.Extension}");
|
||||||
|
|
||||||
|
using (var stream = source.OpenRead())
|
||||||
|
beatmaps.AddFile(set, stream, newFilename);
|
||||||
|
|
||||||
|
working.Value.Metadata.AudioFile = newFilename;
|
||||||
|
updateAllDifficultiesButton.Enabled.Value = true;
|
||||||
|
|
||||||
editorBeatmap.SaveState();
|
editorBeatmap.SaveState();
|
||||||
music.ReloadCurrentTrack();
|
music.ReloadCurrentTrack();
|
||||||
|
Loading…
Reference in New Issue
Block a user