diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index c96b889213..6b547afe5d 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -20,6 +20,7 @@ using osu.Game.Beatmaps.IO; using osu.Game.Database; using osu.Game.Graphics; using osu.Game.IO; +using osu.Game.IO.Serialization; using osu.Game.IPC; using osu.Game.Online.API; using osu.Game.Online.API.Requests; @@ -570,6 +571,53 @@ namespace osu.Game.Beatmaps } } + public void MigrateAllToNewFormat() + { + var usableSets = GetAllUsableBeatmapSets(); + + if (usableSets.Count == 0) + return; + + var notification = new ProgressNotification + { + Progress = 0, + State = ProgressNotificationState.Active, + }; + + PostNotification?.Invoke(notification); + + int i = 1; + foreach (var set in usableSets) + { + if (notification.State == ProgressNotificationState.Cancelled) + // user requested abort + return; + + notification.Text = $"Migrating ({i} of {usableSets.Count})"; + notification.Progress = (float)i++ / usableSets.Count; + + foreach (var beatmap in set.Beatmaps) + { + if (notification.State == ProgressNotificationState.Cancelled) + // user requested abort + return; + + var working = GetWorkingBeatmap(beatmap); + using (var ms = new MemoryStream()) + using (var sw = new StreamWriter(ms)) + { + sw.Write(working.Beatmap.Serialize()); + sw.Flush(); + + ms.Position = 0; + UpdateContent(beatmap, ms); + } + } + } + + notification.State = ProgressNotificationState.Completed; + } + /// /// Returns a list of all usable s. /// diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs index a41da6109c..9ae331daf0 100644 --- a/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Maintenance/GeneralSettings.cs @@ -65,34 +65,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance Action = () => { migrateButton.Enabled.Value = false; - Task.Run(() => - { - var usableSets = beatmaps.GetAllUsableBeatmapSets(); - foreach (var set in usableSets) - { - foreach (var beatmap in set.Beatmaps) - { - var working = beatmaps.GetWorkingBeatmap(beatmap); - using (var ms = new MemoryStream()) - using (var sw = new StreamWriter(ms)) - { - try - { - sw.Write(working.Beatmap.Serialize()); - } - catch (Exception e) - { - Console.WriteLine(e); - throw; - } - sw.Flush(); - - ms.Position = 0; - beatmaps.UpdateContent(beatmap, ms); - } - } - } - }).ContinueWith(t => Schedule(() => migrateButton.Enabled.Value = true)); + Task.Factory.StartNew(beatmaps.MigrateAllToNewFormat).ContinueWith(t => Schedule(() => migrateButton.Enabled.Value = true), TaskContinuationOptions.LongRunning); } } };