1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 08:34:04 +08:00
osu-lazer/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationRunScreen.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

146 lines
5.1 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-05-13 21:58:05 +08:00
using System.IO;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
2020-05-13 21:58:05 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Framework.Platform;
2020-05-13 21:58:05 +08:00
using osu.Framework.Screens;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Notifications;
2020-05-13 21:58:05 +08:00
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; }
[Resolved]
private INotificationOverlay notifications { get; set; }
[Resolved]
private Storage storage { get; set; }
[Resolved]
private GameHost host { get; set; }
2020-05-13 21:58:05 +08:00
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;
var originalStorage = new NativeStorage(storage.GetFullPath(string.Empty), host);
2020-05-14 18:05:35 +08:00
migrationTask = Task.Run(PerformMigration)
.ContinueWith(task =>
2020-05-13 21:58:05 +08:00
{
if (task.IsFaulted)
{
Logger.Error(task.Exception, $"Error during migration: {task.Exception?.Message}");
}
else if (!task.GetResultSafely())
{
notifications.Post(new SimpleNotification
{
Text = "Some files couldn't be cleaned up during migration. Clicking this notification will open the folder so you can manually clean things up.",
Activated = () =>
{
originalStorage.PresentExternally();
return true;
}
});
}
2020-05-13 21:58:05 +08:00
Schedule(this.Exit);
});
}
protected virtual bool PerformMigration() => game?.Migrate(destination.FullName) != false;
2020-05-14 18:05:35 +08:00
public override void OnEntering(ScreenTransitionEvent e)
2020-05-14 16:40:43 +08:00
{
base.OnEntering(e);
2020-05-14 16:40:43 +08:00
this.FadeOut().Delay(250).Then().FadeIn(250);
}
public override bool OnExiting(ScreenExitEvent e)
2020-05-13 21:58:05 +08:00
{
// block until migration is finished
if (migrationTask?.IsCompleted == false)
return true;
return base.OnExiting(e);
2020-05-13 21:58:05 +08:00
}
}
}