1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 16:42:53 +08:00
osu-lazer/osu.Game/Overlays/Settings/Sections/Maintenance/MigrationSelectScreen.cs

129 lines
4.4 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.
2020-05-14 16:40:43 +08:00
using System;
using System.IO;
2020-05-13 21:58:05 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-05-14 16:40:43 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Logging;
using osu.Framework.Platform;
2020-05-13 21:58:05 +08:00
using osu.Framework.Screens;
2020-05-14 16:40:43 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2020-05-13 21:58:05 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
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 MigrationSelectScreen : OsuScreen
{
private DirectorySelector directorySelector;
2020-05-14 16:40:43 +08:00
public override bool AllowExternalScreenChange => false;
public override bool DisallowExternalBeatmapRulesetChanges => true;
public override bool HideOverlaysOnEnter => true;
2020-05-14 18:05:35 +08:00
[BackgroundDependencyLoader(true)]
2020-05-14 16:40:43 +08:00
private void load(OsuGame game, Storage storage, OsuColour colours)
2020-05-13 21:58:05 +08:00
{
2020-05-14 18:05:35 +08:00
game?.Toolbar.Hide();
2020-05-14 16:40:43 +08:00
// begin selection in the parent directory of the current storage location
var initialPath = new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent?.FullName;
InternalChild = new Container
2020-05-13 21:58:05 +08:00
{
2020-05-14 16:40:43 +08:00
Masking = true,
CornerRadius = 10,
2020-05-13 21:58:05 +08:00
RelativeSizeAxes = Axes.Both,
2020-05-14 16:40:43 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(0.5f, 0.8f),
Children = new Drawable[]
2020-05-13 21:58:05 +08:00
{
2020-05-14 16:40:43 +08:00
new Box
2020-05-13 21:58:05 +08:00
{
2020-05-14 16:40:43 +08:00
Colour = colours.GreySeafoamDark,
RelativeSizeAxes = Axes.Both,
},
new GridContainer
{
RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
2020-05-13 21:58:05 +08:00
{
2020-05-14 16:40:43 +08:00
new Dimension(),
new Dimension(GridSizeMode.Relative, 0.8f),
new Dimension(),
2020-05-13 21:58:05 +08:00
},
2020-05-14 16:40:43 +08:00
Content = new[]
{
new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "Please select a new location",
Font = OsuFont.Default.With(size: 40)
},
},
new Drawable[]
{
directorySelector = new DirectorySelector(initialPath)
{
RelativeSizeAxes = Axes.Both,
}
},
new Drawable[]
{
new TriangleButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 300,
Text = "Begin folder migration",
Action = start
},
}
}
2020-05-13 21:58:05 +08:00
}
}
};
}
2020-05-14 16:40:43 +08:00
public override void OnSuspending(IScreen next)
{
base.OnSuspending(next);
this.FadeOut(250);
}
2020-05-13 21:58:05 +08:00
private void start()
{
var target = directorySelector.CurrentPath.Value;
2020-05-14 16:40:43 +08:00
try
{
if (target.GetDirectories().Length > 0 || target.GetFiles().Length > 0)
target = target.CreateSubdirectory("osu-lazer");
}
catch (Exception e)
{
2020-05-14 18:05:35 +08:00
Logger.Log($"Error during migration: {e.Message}", level: LogLevel.Error);
2020-05-14 16:40:43 +08:00
return;
}
2020-05-13 21:58:05 +08:00
ValidForResume = false;
2020-05-14 18:05:35 +08:00
BeginMigration(target);
2020-05-13 21:58:05 +08:00
}
2020-05-14 18:05:35 +08:00
protected virtual void BeginMigration(DirectoryInfo target) => this.Push(new MigrationRunScreen(target));
2020-05-13 21:58:05 +08:00
}
}