From bf386598b6abe4be1758bf2b7045a26cb3208679 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Thu, 30 Nov 2017 10:58:32 +0100 Subject: [PATCH] Added a new "undelete" button that restores every beatmap with "DeletePending" set to true. --- osu.Game/Beatmaps/BeatmapManager.cs | 22 +++++++++++++++++++ .../Sections/Maintenance/GeneralSettings.cs | 14 ++++++++++++ 2 files changed, 36 insertions(+) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 0641cabcd8..376cbe183a 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -338,6 +338,28 @@ namespace osu.Game.Beatmaps } } + public void Undelete(BeatmapSetInfo beatmapSet) + { + lock (importContext) + { + var context = importContext.Value; + + using (var transaction = context.BeginTransaction()) + { + context.ChangeTracker.AutoDetectChangesEnabled = false; + + var iFiles = new FileStore(() => context, storage); + var iBeatmaps = createBeatmapStore(() => context); + + if (iBeatmaps.Undelete(beatmapSet)) + iFiles.Reference(beatmapSet.Files.Select(f => f.FileInfo).ToArray()); + + context.ChangeTracker.AutoDetectChangesEnabled = true; + context.SaveChanges(transaction); + } + } + } + /// /// Delete a beatmap difficulty. /// diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs index 4f4f381ae1..dcad5ab52c 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs @@ -15,6 +15,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance private TriangleButton importButton; private TriangleButton deleteButton; private TriangleButton restoreButton; + private TriangleButton undeleteButton; protected override string Header => "General"; @@ -55,6 +56,19 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance }).ContinueWith(t => Schedule(() => restoreButton.Enabled.Value = true)); } }, + undeleteButton = new SettingsButton + { + Text = "Restore all recently deleted beatmaps", + Action = () => + { + undeleteButton.Enabled.Value = false; + Task.Run(() => + { + foreach (var bs in beatmaps.QueryBeatmapSets(bs => bs.DeletePending).ToList()) + beatmaps.Undelete(bs); + }).ContinueWith(t => Schedule(() => undeleteButton.Enabled.Value = true)); + } + }, }; } }