From 31dc5c97f2e0399795767332bddab53a5959c24f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 17 Oct 2017 11:10:55 +0900 Subject: [PATCH] Fix intro and duplicate inserts --- osu.Game/Beatmaps/BeatmapManager.cs | 2 +- osu.Game/Beatmaps/BeatmapStore.cs | 5 ++-- osu.Game/IO/FileStore.cs | 4 +--- osu.Game/Screens/Menu/Intro.cs | 1 - osu.Game/Screens/Select/SongSelect.cs | 34 +++++++++++++-------------- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index af88f22e40..f546172bfe 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -501,7 +501,7 @@ namespace osu.Game.Beatmaps public List GetAllUsableBeatmapSets() { lock (beatmaps) - return beatmaps.BeatmapSets.ToList(); + return beatmaps.BeatmapSets.Where(s => !s.DeletePending).ToList(); } protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap diff --git a/osu.Game/Beatmaps/BeatmapStore.cs b/osu.Game/Beatmaps/BeatmapStore.cs index 6464db86d4..ea5c5f7155 100644 --- a/osu.Game/Beatmaps/BeatmapStore.cs +++ b/osu.Game/Beatmaps/BeatmapStore.cs @@ -50,7 +50,7 @@ namespace osu.Game.Beatmaps /// The beatmap to add. public void Add(BeatmapSetInfo beatmapSet) { - Connection.BeatmapSetInfo.Add(beatmapSet); + Connection.BeatmapSetInfo.Attach(beatmapSet); Connection.SaveChanges(); BeatmapSetAdded?.Invoke(beatmapSet); @@ -135,8 +135,7 @@ namespace osu.Game.Beatmaps .Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset) .Include(s => s.Beatmaps).ThenInclude(b => b.Difficulty) .Include(s => s.Beatmaps).ThenInclude(b => b.Metadata) - .Include(s => s.Files).ThenInclude(f => f.FileInfo) - .Where(s => !s.DeletePending); + .Include(s => s.Files).ThenInclude(f => f.FileInfo); public IEnumerable Beatmaps => Connection.BeatmapInfo .Include(b => b.BeatmapSet).ThenInclude(s => s.Metadata) diff --git a/osu.Game/IO/FileStore.cs b/osu.Game/IO/FileStore.cs index ae0cfb30c8..19237c6063 100644 --- a/osu.Game/IO/FileStore.cs +++ b/osu.Game/IO/FileStore.cs @@ -66,10 +66,8 @@ namespace osu.Game.IO } if (existing == null) - { + // SaveChanges is performed in Reference. Connection.FileInfo.Add(info); - Connection.SaveChanges(); - } if (reference || existing == null) Reference(info); diff --git a/osu.Game/Screens/Menu/Intro.cs b/osu.Game/Screens/Menu/Intro.cs index b597fc11e4..ee84cf2d30 100644 --- a/osu.Game/Screens/Menu/Intro.cs +++ b/osu.Game/Screens/Menu/Intro.cs @@ -89,7 +89,6 @@ namespace osu.Game.Screens.Menu { // we need to import the default menu background beatmap setInfo = beatmaps.Import(new OszArchiveReader(game.Resources.GetStream(@"Tracks/circles.osz"))); - setInfo.Protected = true; } } diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index b11613634a..e11eed7040 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -26,7 +26,7 @@ namespace osu.Game.Screens.Select { public abstract class SongSelect : OsuScreen { - private BeatmapManager manager; + private BeatmapManager beatmaps; protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(); private readonly BeatmapCarousel carousel; @@ -108,9 +108,9 @@ namespace osu.Game.Screens.Select SelectionChanged = carouselSelectionChanged, BeatmapsChanged = carouselBeatmapsLoaded, DeleteRequested = promptDelete, - RestoreRequested = s => { foreach (var b in s.Beatmaps) manager.Restore(b); }, + RestoreRequested = s => { foreach (var b in s.Beatmaps) beatmaps.Restore(b); }, EditRequested = editRequested, - HideDifficultyRequested = b => manager.Hide(b), + HideDifficultyRequested = b => beatmaps.Hide(b), StartRequested = () => carouselRaisedStart(), }); Add(FilterControl = new FilterControl @@ -171,16 +171,16 @@ namespace osu.Game.Screens.Select BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, () => promptDelete(Beatmap.Value.BeatmapSetInfo), Key.Number4, float.MaxValue); } - if (manager == null) - manager = beatmaps; + if (this.beatmaps == null) + this.beatmaps = beatmaps; if (osu != null) Ruleset.BindTo(osu.Ruleset); - manager.BeatmapSetAdded += onBeatmapSetAdded; - manager.BeatmapSetRemoved += onBeatmapSetRemoved; - manager.BeatmapHidden += onBeatmapHidden; - manager.BeatmapRestored += onBeatmapRestored; + this.beatmaps.BeatmapSetAdded += onBeatmapSetAdded; + this.beatmaps.BeatmapSetRemoved += onBeatmapSetRemoved; + this.beatmaps.BeatmapHidden += onBeatmapHidden; + this.beatmaps.BeatmapRestored += onBeatmapRestored; dialogOverlay = dialog; @@ -189,7 +189,7 @@ namespace osu.Game.Screens.Select initialAddSetsTask = new CancellationTokenSource(); - carousel.Beatmaps = manager.GetAllUsableBeatmapSets(); + carousel.Beatmaps = this.beatmaps.GetAllUsableBeatmapSets(); Beatmap.ValueChanged += beatmap_ValueChanged; @@ -199,7 +199,7 @@ namespace osu.Game.Screens.Select private void editRequested(BeatmapInfo beatmap) { - Beatmap.Value = manager.GetWorkingBeatmap(beatmap, Beatmap); + Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap, Beatmap); Push(new Editor()); } @@ -248,7 +248,7 @@ namespace osu.Game.Screens.Select { bool preview = beatmap?.BeatmapSetInfoID != Beatmap.Value.BeatmapInfo.BeatmapSetInfoID; - Beatmap.Value = manager.GetWorkingBeatmap(beatmap, Beatmap); + Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap, Beatmap); ensurePlayingSelected(preview); } @@ -357,12 +357,12 @@ namespace osu.Game.Screens.Select { base.Dispose(isDisposing); - if (manager != null) + if (beatmaps != null) { - manager.BeatmapSetAdded -= onBeatmapSetAdded; - manager.BeatmapSetRemoved -= onBeatmapSetRemoved; - manager.BeatmapHidden -= onBeatmapHidden; - manager.BeatmapRestored -= onBeatmapRestored; + beatmaps.BeatmapSetAdded -= onBeatmapSetAdded; + beatmaps.BeatmapSetRemoved -= onBeatmapSetRemoved; + beatmaps.BeatmapHidden -= onBeatmapHidden; + beatmaps.BeatmapRestored -= onBeatmapRestored; } initialAddSetsTask?.Cancel();