mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Merge pull request #9020 from peppy/migration-ui
Add ability to change data folder path
This commit is contained in:
commit
e33c177018
36
osu.Game.Tests/Visual/Settings/TestSceneMigrationScreens.cs
Normal file
36
osu.Game.Tests/Visual/Settings/TestSceneMigrationScreens.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// 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;
|
||||||
|
using osu.Framework.Screens;
|
||||||
|
using osu.Game.Overlays.Settings.Sections.Maintenance;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Settings
|
||||||
|
{
|
||||||
|
public class TestSceneMigrationScreens : ScreenTestScene
|
||||||
|
{
|
||||||
|
public TestSceneMigrationScreens()
|
||||||
|
{
|
||||||
|
AddStep("Push screen", () => Stack.Push(new TestMigrationSelectScreen()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestMigrationSelectScreen : MigrationSelectScreen
|
||||||
|
{
|
||||||
|
protected override void BeginMigration(DirectoryInfo target) => this.Push(new TestMigrationRunScreen());
|
||||||
|
|
||||||
|
private class TestMigrationRunScreen : MigrationRunScreen
|
||||||
|
{
|
||||||
|
protected override void PerformMigration()
|
||||||
|
{
|
||||||
|
Thread.Sleep(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestMigrationRunScreen()
|
||||||
|
: base(null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,11 +28,11 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
private GameHost host { get; set; }
|
private GameHost host { get; set; }
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private readonly Bindable<DirectoryInfo> currentDirectory = new Bindable<DirectoryInfo>();
|
public readonly Bindable<DirectoryInfo> CurrentDirectory = new Bindable<DirectoryInfo>();
|
||||||
|
|
||||||
public DirectorySelector(string initialPath = null)
|
public DirectorySelector(string initialPath = null)
|
||||||
{
|
{
|
||||||
currentDirectory.Value = new DirectoryInfo(initialPath ?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
|
CurrentDirectory.Value = new DirectoryInfo(initialPath ?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -40,19 +40,25 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
{
|
{
|
||||||
Padding = new MarginPadding(10);
|
Padding = new MarginPadding(10);
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChild = new GridContainer
|
||||||
{
|
{
|
||||||
new FillFlowContainer
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
RowDimensions = new[]
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
new Dimension(GridSizeMode.Absolute, 50),
|
||||||
Direction = FillDirection.Vertical,
|
new Dimension(),
|
||||||
Children = new Drawable[]
|
},
|
||||||
|
Content = new[]
|
||||||
|
{
|
||||||
|
new Drawable[]
|
||||||
{
|
{
|
||||||
new CurrentDirectoryDisplay
|
new CurrentDirectoryDisplay
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Height = 50,
|
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
new Drawable[]
|
||||||
|
{
|
||||||
new OsuScrollContainer
|
new OsuScrollContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -65,10 +71,10 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
currentDirectory.BindValueChanged(updateDisplay, true);
|
CurrentDirectory.BindValueChanged(updateDisplay, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDisplay(ValueChangedEvent<DirectoryInfo> directory)
|
private void updateDisplay(ValueChangedEvent<DirectoryInfo> directory)
|
||||||
@ -86,9 +92,9 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
directoryFlow.Add(new ParentDirectoryPiece(currentDirectory.Value.Parent));
|
directoryFlow.Add(new ParentDirectoryPiece(CurrentDirectory.Value.Parent));
|
||||||
|
|
||||||
foreach (var dir in currentDirectory.Value.GetDirectories().OrderBy(d => d.Name))
|
foreach (var dir in CurrentDirectory.Value.GetDirectories().OrderBy(d => d.Name))
|
||||||
{
|
{
|
||||||
if ((dir.Attributes & FileAttributes.Hidden) == 0)
|
if ((dir.Attributes & FileAttributes.Hidden) == 0)
|
||||||
directoryFlow.Add(new DirectoryPiece(dir));
|
directoryFlow.Add(new DirectoryPiece(dir));
|
||||||
@ -97,8 +103,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
currentDirectory.Value = directory.OldValue;
|
CurrentDirectory.Value = directory.OldValue;
|
||||||
|
|
||||||
this.FlashColour(Color4.Red, 300);
|
this.FlashColour(Color4.Red, 300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ namespace osu.Game.IO
|
|||||||
if (topLevelExcludes && IGNORE_FILES.Contains(fi.Name))
|
if (topLevelExcludes && IGNORE_FILES.Contains(fi.Name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
fi.Delete();
|
attemptOperation(() => fi.Delete());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (DirectoryInfo dir in target.GetDirectories())
|
foreach (DirectoryInfo dir in target.GetDirectories())
|
||||||
@ -92,8 +92,11 @@ namespace osu.Game.IO
|
|||||||
if (topLevelExcludes && IGNORE_DIRECTORIES.Contains(dir.Name))
|
if (topLevelExcludes && IGNORE_DIRECTORIES.Contains(dir.Name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
dir.Delete(true);
|
attemptOperation(() => dir.Delete(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (target.GetFiles().Length == 0 && target.GetDirectories().Length == 0)
|
||||||
|
attemptOperation(target.Delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copyRecursive(DirectoryInfo source, DirectoryInfo destination, bool topLevelExcludes = true)
|
private static void copyRecursive(DirectoryInfo source, DirectoryInfo destination, bool topLevelExcludes = true)
|
||||||
@ -106,7 +109,7 @@ namespace osu.Game.IO
|
|||||||
if (topLevelExcludes && IGNORE_FILES.Contains(fi.Name))
|
if (topLevelExcludes && IGNORE_FILES.Contains(fi.Name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
attemptCopy(fi, Path.Combine(destination.FullName, fi.Name));
|
attemptOperation(() => fi.CopyTo(Path.Combine(destination.FullName, fi.Name), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (DirectoryInfo dir in source.GetDirectories())
|
foreach (DirectoryInfo dir in source.GetDirectories())
|
||||||
@ -118,24 +121,27 @@ namespace osu.Game.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void attemptCopy(System.IO.FileInfo fileInfo, string destination)
|
/// <summary>
|
||||||
|
/// Attempt an IO operation multiple times and only throw if none of the attempts succeed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="action">The action to perform.</param>
|
||||||
|
/// <param name="attempts">The number of attempts (250ms wait between each).</param>
|
||||||
|
private static void attemptOperation(Action action, int attempts = 10)
|
||||||
{
|
{
|
||||||
int tries = 5;
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fileInfo.CopyTo(destination, true);
|
action();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
if (tries-- == 0)
|
if (attempts-- == 0)
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.Sleep(50);
|
Thread.Sleep(250);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Overlays.Settings.Sections.Maintenance;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings.Sections.General
|
namespace osu.Game.Overlays.Settings.Sections.General
|
||||||
{
|
{
|
||||||
@ -12,8 +14,8 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
|||||||
{
|
{
|
||||||
protected override string Header => "Updates";
|
protected override string Header => "Updates";
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(Storage storage, OsuConfigManager config)
|
private void load(Storage storage, OsuConfigManager config, OsuGame game)
|
||||||
{
|
{
|
||||||
Add(new SettingsEnumDropdown<ReleaseStream>
|
Add(new SettingsEnumDropdown<ReleaseStream>
|
||||||
{
|
{
|
||||||
@ -28,6 +30,12 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
|||||||
Text = "Open osu! folder",
|
Text = "Open osu! folder",
|
||||||
Action = storage.OpenInNativeExplorer,
|
Action = storage.OpenInNativeExplorer,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Add(new SettingsButton
|
||||||
|
{
|
||||||
|
Text = "Change folder location...",
|
||||||
|
Action = () => game?.PerformFromScreen(menu => menu.Push(new MigrationSelectScreen()))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,115 @@
|
|||||||
|
// 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;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
||||||
|
{
|
||||||
|
public class MigrationRunScreen : OsuScreen
|
||||||
|
{
|
||||||
|
private readonly DirectoryInfo destination;
|
||||||
|
|
||||||
|
[Resolved(canBeNull: true)]
|
||||||
|
private OsuGame game { get; set; }
|
||||||
|
|
||||||
|
public override bool AllowBackButton => false;
|
||||||
|
|
||||||
|
public override bool AllowExternalScreenChange => false;
|
||||||
|
|
||||||
|
public override bool DisallowExternalBeatmapRulesetChanges => true;
|
||||||
|
|
||||||
|
public override bool HideOverlaysOnEnter => true;
|
||||||
|
|
||||||
|
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,
|
||||||
|
Spacing = new Vector2(10),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Text = "Migration in progress",
|
||||||
|
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)
|
||||||
|
},
|
||||||
|
new LoadingSpinner(true)
|
||||||
|
{
|
||||||
|
State = { Value = Visibility.Visible }
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Text = "Please avoid interacting with the game!",
|
||||||
|
Font = OsuFont.Default.With(size: 30)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Beatmap.Value = Beatmap.Default;
|
||||||
|
|
||||||
|
migrationTask = Task.Run(PerformMigration)
|
||||||
|
.ContinueWith(t =>
|
||||||
|
{
|
||||||
|
if (t.IsFaulted)
|
||||||
|
Logger.Log($"Error during migration: {t.Exception?.Message}", level: LogLevel.Error);
|
||||||
|
|
||||||
|
Schedule(this.Exit);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void PerformMigration() => game?.Migrate(destination.FullName);
|
||||||
|
|
||||||
|
public override void OnEntering(IScreen last)
|
||||||
|
{
|
||||||
|
base.OnEntering(last);
|
||||||
|
|
||||||
|
this.FadeOut().Delay(250).Then().FadeIn(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool OnExiting(IScreen next)
|
||||||
|
{
|
||||||
|
// block until migration is finished
|
||||||
|
if (migrationTask?.IsCompleted == false)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return base.OnExiting(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,128 @@
|
|||||||
|
// 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;
|
||||||
|
using System.IO;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Logging;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Screens;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
using osu.Game.Screens;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
||||||
|
{
|
||||||
|
public class MigrationSelectScreen : OsuScreen
|
||||||
|
{
|
||||||
|
private DirectorySelector directorySelector;
|
||||||
|
|
||||||
|
public override bool AllowExternalScreenChange => false;
|
||||||
|
|
||||||
|
public override bool DisallowExternalBeatmapRulesetChanges => true;
|
||||||
|
|
||||||
|
public override bool HideOverlaysOnEnter => true;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader(true)]
|
||||||
|
private void load(OsuGame game, Storage storage, OsuColour colours)
|
||||||
|
{
|
||||||
|
game?.Toolbar.Hide();
|
||||||
|
|
||||||
|
// begin selection in the parent directory of the current storage location
|
||||||
|
var initialPath = new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent?.FullName;
|
||||||
|
|
||||||
|
InternalChild = new Container
|
||||||
|
{
|
||||||
|
Masking = true,
|
||||||
|
CornerRadius = 10,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Size = new Vector2(0.5f, 0.8f),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
Colour = colours.GreySeafoamDark,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
},
|
||||||
|
new GridContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
RowDimensions = new[]
|
||||||
|
{
|
||||||
|
new Dimension(),
|
||||||
|
new Dimension(GridSizeMode.Relative, 0.8f),
|
||||||
|
new Dimension(),
|
||||||
|
},
|
||||||
|
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
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnSuspending(IScreen next)
|
||||||
|
{
|
||||||
|
base.OnSuspending(next);
|
||||||
|
|
||||||
|
this.FadeOut(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void start()
|
||||||
|
{
|
||||||
|
var target = directorySelector.CurrentDirectory.Value;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (target.GetDirectories().Length > 0 || target.GetFiles().Length > 0)
|
||||||
|
target = target.CreateSubdirectory("osu-lazer");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Log($"Error during migration: {e.Message}", level: LogLevel.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ValidForResume = false;
|
||||||
|
BeginMigration(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void BeginMigration(DirectoryInfo target) => this.Push(new MigrationRunScreen(target));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user