From d2b80fdbfc9bc3e85cd32594a25b44a893cb4b27 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Mon, 18 Dec 2017 10:55:07 +0100 Subject: [PATCH] Moved "undelete all" logic to BeatmapManager and added a progress notification --- osu.Game/Beatmaps/BeatmapManager.cs | 30 +++++++++++++++++++ .../Sections/Maintenance/GeneralSettings.cs | 6 +--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 1acca352a7..8170ec959c 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -339,6 +339,36 @@ namespace osu.Game.Beatmaps } } + public void UndeleteAll() + { + var mapSets = QueryBeatmapSets(bs => bs.DeletePending); + + if (mapSets.Count() == 0) return; + + var notification = new ProgressNotification + { + Progress = 0, + State = ProgressNotificationState.Active, + }; + + PostNotification?.Invoke(notification); + + int i = 0; + + foreach (var bs in mapSets) + { + if (notification.State == ProgressNotificationState.Cancelled) + // user requested abort + return; + + notification.Text = $"Restoring ({i} of {mapSets.Count()})"; + notification.Progress = (float)++i / mapSets.Count(); + Undelete(bs); + } + + notification.State = ProgressNotificationState.Completed; + } + public void Undelete(BeatmapSetInfo beatmapSet) { if (beatmapSet.Protected) diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs index dcad5ab52c..0b0cc1a17f 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs @@ -62,11 +62,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance 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)); + Task.Run(() => beatmaps.UndeleteAll()).ContinueWith(t => Schedule(() => undeleteButton.Enabled.Value = true)); } }, };