1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 05:42:56 +08:00

Add GetPathForFile to BeatmapSetInfo

This is used in several places, and so should probably have a function rather than remaining as duplicated code.

Also applies this together with the previous commit to `BeatmapManagerWorkingBeatmap`.
This commit is contained in:
Naxess 2021-04-17 17:49:10 +02:00
parent 400f8b3938
commit b36da2664c
2 changed files with 8 additions and 9 deletions

View File

@ -3,7 +3,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.IO;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures;
@ -37,7 +36,7 @@ namespace osu.Game.Beatmaps
try
{
using (var stream = new LineBufferedReader(resources.Files.GetStream(getPathForFile(BeatmapInfo.Path))))
using (var stream = new LineBufferedReader(GetStream(BeatmapSetInfo.GetPathForFile(BeatmapInfo.Path))))
return Decoder.GetDecoder<Beatmap>(stream).Decode(stream);
}
catch (Exception e)
@ -47,8 +46,6 @@ namespace osu.Game.Beatmaps
}
}
private string getPathForFile(string filename) => BeatmapSetInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
protected override bool BackgroundStillValid(Texture b) => false; // bypass lazy logic. we want to return a new background each time for refcounting purposes.
protected override Texture GetBackground()
@ -58,7 +55,7 @@ namespace osu.Game.Beatmaps
try
{
return resources.LargeTextureStore.Get(getPathForFile(Metadata.BackgroundFile));
return resources.LargeTextureStore.Get(BeatmapSetInfo.GetPathForFile(Metadata.BackgroundFile));
}
catch (Exception e)
{
@ -74,7 +71,7 @@ namespace osu.Game.Beatmaps
try
{
return resources.Tracks.Get(getPathForFile(Metadata.AudioFile));
return resources.Tracks.Get(BeatmapSetInfo.GetPathForFile(Metadata.AudioFile));
}
catch (Exception e)
{
@ -90,7 +87,7 @@ namespace osu.Game.Beatmaps
try
{
var trackData = resources.Files.GetStream(getPathForFile(Metadata.AudioFile));
var trackData = GetStream(BeatmapSetInfo.GetPathForFile(Metadata.AudioFile));
return trackData == null ? null : new Waveform(trackData);
}
catch (Exception e)
@ -106,7 +103,7 @@ namespace osu.Game.Beatmaps
try
{
using (var stream = new LineBufferedReader(resources.Files.GetStream(getPathForFile(BeatmapInfo.Path))))
using (var stream = new LineBufferedReader(GetStream(BeatmapSetInfo.GetPathForFile(BeatmapInfo.Path))))
{
var decoder = Decoder.GetDecoder<Storyboard>(stream);
@ -115,7 +112,7 @@ namespace osu.Game.Beatmaps
storyboard = decoder.Decode(stream);
else
{
using (var secondaryStream = new LineBufferedReader(resources.Files.GetStream(getPathForFile(BeatmapSetInfo.StoryboardFile))))
using (var secondaryStream = new LineBufferedReader(GetStream(BeatmapSetInfo.GetPathForFile(BeatmapSetInfo.StoryboardFile))))
storyboard = decoder.Decode(stream, secondaryStream);
}
}

View File

@ -59,6 +59,8 @@ namespace osu.Game.Beatmaps
public string StoryboardFile => Files?.Find(f => f.Filename.EndsWith(".osb", StringComparison.OrdinalIgnoreCase))?.Filename;
public string GetPathForFile(string filename) => Files?.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
public List<BeatmapSetFileInfo> Files { get; set; }
public override string ToString() => Metadata?.ToString() ?? base.ToString();