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;
|
2022-02-10 17:48:37 +08:00
|
|
|
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;
|
2022-02-10 17:48:37 +08:00
|
|
|
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;
|
2022-09-16 17:31:02 +08:00
|
|
|
using osu.Game.Localisation;
|
2022-02-10 17:48:37 +08:00
|
|
|
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; }
|
|
|
|
|
2022-02-10 17:48:37 +08:00
|
|
|
[Resolved]
|
2022-04-18 18:59:57 +08:00
|
|
|
private INotificationOverlay notifications { get; set; }
|
2022-02-10 17:48:37 +08:00
|
|
|
|
|
|
|
[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,
|
2022-09-16 17:31:02 +08:00
|
|
|
Text = MaintenanceSettingsStrings.MigrationInProgress,
|
2020-05-14 16:40:43 +08:00
|
|
|
Font = OsuFont.Default.With(size: 40)
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2022-09-16 17:31:02 +08:00
|
|
|
Text = MaintenanceSettingsStrings.MigrationDescription,
|
2020-05-14 16:40:43 +08:00
|
|
|
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,
|
2022-09-16 17:31:02 +08:00
|
|
|
Text = MaintenanceSettingsStrings.ProhibitedInteractDuringMigration,
|
2020-05-14 16:40:43 +08:00
|
|
|
Font = OsuFont.Default.With(size: 30)
|
|
|
|
},
|
2020-05-13 21:58:05 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Beatmap.Value = Beatmap.Default;
|
|
|
|
|
2022-02-10 17:48:37 +08:00
|
|
|
var originalStorage = new NativeStorage(storage.GetFullPath(string.Empty), host);
|
|
|
|
|
2020-05-14 18:05:35 +08:00
|
|
|
migrationTask = Task.Run(PerformMigration)
|
2022-02-10 17:48:37 +08:00
|
|
|
.ContinueWith(task =>
|
2020-05-13 21:58:05 +08:00
|
|
|
{
|
2022-02-10 17:48:37 +08:00
|
|
|
if (task.IsFaulted)
|
|
|
|
{
|
|
|
|
Logger.Error(task.Exception, $"Error during migration: {task.Exception?.Message}");
|
|
|
|
}
|
|
|
|
else if (!task.GetResultSafely())
|
|
|
|
{
|
|
|
|
notifications.Post(new SimpleNotification
|
|
|
|
{
|
2022-09-16 17:31:02 +08:00
|
|
|
Text = MaintenanceSettingsStrings.FailedCleanupNotification,
|
2022-02-10 17:48:37 +08:00
|
|
|
Activated = () =>
|
|
|
|
{
|
|
|
|
originalStorage.PresentExternally();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-05-13 21:58:05 +08:00
|
|
|
|
|
|
|
Schedule(this.Exit);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-10 17:48:37 +08:00
|
|
|
protected virtual bool PerformMigration() => game?.Migrate(destination.FullName) != false;
|
2020-05-14 18:05:35 +08:00
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
public override void OnEntering(ScreenTransitionEvent e)
|
2020-05-14 16:40:43 +08:00
|
|
|
{
|
2022-04-21 23:52:44 +08:00
|
|
|
base.OnEntering(e);
|
2020-05-14 16:40:43 +08:00
|
|
|
|
|
|
|
this.FadeOut().Delay(250).Then().FadeIn(250);
|
|
|
|
}
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
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;
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
return base.OnExiting(e);
|
2020-05-13 21:58:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|