mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 06:36:31 +09:00
Correct and simplify BeatmapStore and BeatmapManager
This commit is contained in:
@ -5,7 +5,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Ionic.Zip;
|
||||
using osu.Framework.Audio.Track;
|
||||
@ -179,7 +178,8 @@ namespace osu.Game.Beatmaps
|
||||
// If we have an ID then we already exist in the database.
|
||||
if (beatmapSetInfo.ID != 0) return;
|
||||
|
||||
beatmaps.Add(beatmapSetInfo);
|
||||
lock (beatmaps)
|
||||
beatmaps.Add(beatmapSetInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -257,7 +257,8 @@ namespace osu.Game.Beatmaps
|
||||
/// <param name="beatmapSet">The beatmap set to delete.</param>
|
||||
public void Delete(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
if (!beatmaps.Delete(beatmapSet)) return;
|
||||
lock (beatmaps)
|
||||
if (!beatmaps.Delete(beatmapSet)) return;
|
||||
|
||||
if (!beatmapSet.Protected)
|
||||
files.Dereference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
|
||||
@ -267,13 +268,21 @@ namespace osu.Game.Beatmaps
|
||||
/// Delete a beatmap difficulty.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap difficulty to hide.</param>
|
||||
public void Hide(BeatmapInfo beatmap) => beatmaps.Hide(beatmap);
|
||||
public void Hide(BeatmapInfo beatmap)
|
||||
{
|
||||
lock (beatmaps)
|
||||
beatmaps.Hide(beatmap);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restore a beatmap difficulty.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap difficulty to restore.</param>
|
||||
public void Restore(BeatmapInfo beatmap) => beatmaps.Restore(beatmap);
|
||||
public void Restore(BeatmapInfo beatmap)
|
||||
{
|
||||
lock (beatmaps)
|
||||
beatmaps.Restore(beatmap);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="BeatmapSetInfo"/> to a usable state if it has previously been deleted but not yet purged.
|
||||
@ -282,7 +291,8 @@ namespace osu.Game.Beatmaps
|
||||
/// <param name="beatmapSet">The beatmap to restore.</param>
|
||||
public void Undelete(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
if (!beatmaps.Undelete(beatmapSet)) return;
|
||||
lock (beatmaps)
|
||||
if (!beatmaps.Undelete(beatmapSet)) return;
|
||||
|
||||
if (!beatmapSet.Protected)
|
||||
files.Reference(beatmapSet.Files.Select(f => f.FileInfo).ToArray());
|
||||
@ -329,11 +339,7 @@ namespace osu.Game.Beatmaps
|
||||
public BeatmapSetInfo QueryBeatmapSet(Func<BeatmapSetInfo, bool> query)
|
||||
{
|
||||
lock (beatmaps)
|
||||
{
|
||||
BeatmapSetInfo set = beatmaps.QueryBeatmapSet(query);
|
||||
|
||||
return set;
|
||||
}
|
||||
return beatmaps.BeatmapSets.FirstOrDefault(query);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -348,9 +354,10 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
/// <param name="query">The query.</param>
|
||||
/// <returns>Results from the provided query.</returns>
|
||||
public List<BeatmapSetInfo> QueryBeatmapSets(Expression<Func<BeatmapSetInfo, bool>> query)
|
||||
public List<BeatmapSetInfo> QueryBeatmapSets(Func<BeatmapSetInfo, bool> query)
|
||||
{
|
||||
return beatmaps.QueryBeatmapSets(query);
|
||||
lock (beatmaps)
|
||||
return beatmaps.BeatmapSets.Where(query).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -360,9 +367,8 @@ namespace osu.Game.Beatmaps
|
||||
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
||||
public BeatmapInfo QueryBeatmap(Func<BeatmapInfo, bool> query)
|
||||
{
|
||||
BeatmapInfo set = beatmaps.QueryBeatmap(query);
|
||||
|
||||
return set;
|
||||
lock (beatmaps)
|
||||
return beatmaps.Beatmaps.FirstOrDefault(query);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -370,9 +376,10 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
/// <param name="query">The query.</param>
|
||||
/// <returns>Results from the provided query.</returns>
|
||||
public List<BeatmapInfo> QueryBeatmaps(Expression<Func<BeatmapInfo, bool>> query)
|
||||
public List<BeatmapInfo> QueryBeatmaps(Func<BeatmapInfo, bool> query)
|
||||
{
|
||||
lock (beatmaps) return beatmaps.QueryBeatmaps(query);
|
||||
lock (beatmaps)
|
||||
return beatmaps.Beatmaps.Where(query).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -411,7 +418,7 @@ namespace osu.Game.Beatmaps
|
||||
// check if this beatmap has already been imported and exit early if so.
|
||||
BeatmapSetInfo beatmapSet;
|
||||
lock (beatmaps)
|
||||
beatmapSet = beatmaps.QueryBeatmapSet(b => b.Hash == hash);
|
||||
beatmapSet = beatmaps.BeatmapSets.FirstOrDefault(b => b.Hash == hash);
|
||||
|
||||
if (beatmapSet != null)
|
||||
{
|
||||
@ -494,9 +501,7 @@ namespace osu.Game.Beatmaps
|
||||
public List<BeatmapSetInfo> GetAllUsableBeatmapSets()
|
||||
{
|
||||
lock (beatmaps)
|
||||
{
|
||||
return beatmaps.QueryBeatmapSets(b => !b.DeletePending);
|
||||
}
|
||||
return beatmaps.BeatmapSets.ToList();
|
||||
}
|
||||
|
||||
protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap
|
||||
@ -531,7 +536,10 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
return beatmap;
|
||||
}
|
||||
catch { return null; }
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private string getPathForFile(string filename) => BeatmapSetInfo.Files.First(f => string.Equals(f.Filename, filename, StringComparison.InvariantCultureIgnoreCase)).FileInfo.StoragePath;
|
||||
@ -545,7 +553,10 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
return new TextureStore(new RawTextureLoaderStore(store), false).Get(getPathForFile(Metadata.BackgroundFile));
|
||||
}
|
||||
catch { return null; }
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override Track GetTrack()
|
||||
@ -555,7 +566,10 @@ namespace osu.Game.Beatmaps
|
||||
var trackData = store.GetStream(getPathForFile(Metadata.AudioFile));
|
||||
return trackData == null ? null : new TrackBass(trackData);
|
||||
}
|
||||
catch { return new TrackVirtual(); }
|
||||
catch
|
||||
{
|
||||
return new TrackVirtual();
|
||||
}
|
||||
}
|
||||
|
||||
protected override Waveform GetWaveform() => new Waveform(store.GetStream(getPathForFile(Metadata.AudioFile)));
|
||||
|
Reference in New Issue
Block a user