mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 20:13:22 +08:00
Add progress notification to migration
This commit is contained in:
parent
41b607c165
commit
a8db3a9484
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all usable <see cref="BeatmapSetInfo"/>s.
|
||||
/// </summary>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user