1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 06:17:24 +08:00
osu-lazer/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationRunScreen.cs

116 lines
3.8 KiB
C#
Raw Normal View History

2020-05-13 21:58:05 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.IO;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens;
2020-05-14 16:40:43 +08:00
using osuTK;
2020-05-13 21:58:05 +08:00
namespace osu.Game.Overlays.Settings.Sections.Maintenance
{
public class MigrationRunScreen : OsuScreen
{
private readonly DirectoryInfo destination;
2020-05-14 18:05:35 +08:00
[Resolved(canBeNull: true)]
2020-05-13 21:58:05 +08:00
private OsuGame game { get; set; }
public override bool AllowBackButton => false;
public override bool AllowExternalScreenChange => false;
public override bool DisallowExternalBeatmapRulesetChanges => true;
2020-05-14 16:40:43 +08:00
public override bool HideOverlaysOnEnter => true;
2020-05-13 21:58:05 +08:00
private Task migrationTask;
public MigrationRunScreen(DirectoryInfo destination)
{
this.destination = destination;
}
protected override void LoadComplete()
{
base.LoadComplete();
InternalChildren = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2020-05-14 16:40:43 +08:00
Spacing = new Vector2(10),
2020-05-13 21:58:05 +08:00
Children = new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Migration in progress",
2020-05-14 16:40:43 +08:00
Font = OsuFont.Default.With(size: 40)
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "This could take a few minutes depending on the speed of your disk(s).",
Font = OsuFont.Default.With(size: 30)
2020-05-13 21:58:05 +08:00
},
new LoadingSpinner(true)
{
State = { Value = Visibility.Visible }
2020-05-14 16:40:43 +08:00
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Please avoid interacting with the game!",
Font = OsuFont.Default.With(size: 30)
},
2020-05-13 21:58:05 +08:00
}
},
};
Beatmap.Value = Beatmap.Default;
2020-05-14 18:05:35 +08:00
migrationTask = Task.Run(PerformMigration)
2020-05-13 21:58:05 +08:00
.ContinueWith(t =>
{
if (t.IsFaulted)
Logger.Log($"Error during migration: {t.Exception?.Message}", level: LogLevel.Error);
Schedule(this.Exit);
});
}
2020-05-14 18:05:35 +08:00
protected virtual void PerformMigration() => game?.Migrate(destination.FullName);
2020-05-14 16:40:43 +08:00
public override void OnEntering(IScreen last)
{
base.OnEntering(last);
this.FadeOut().Delay(250).Then().FadeIn(250);
}
2020-05-13 21:58:05 +08:00
public override bool OnExiting(IScreen next)
{
// block until migration is finished
if (migrationTask?.IsCompleted == false)
return true;
return base.OnExiting(next);
}
}
}