2021-05-08 11:00:22 +02: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.
|
|
|
|
|
|
2023-12-15 15:42:19 +01:00
|
|
|
|
using System;
|
2021-05-08 11:00:22 +02:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-12-15 15:42:19 +01:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-05-17 13:04:49 +02:00
|
|
|
|
using osu.Framework.Localisation;
|
2021-05-08 11:00:22 +02:00
|
|
|
|
using osu.Framework.Screens;
|
2023-12-15 15:42:19 +01:00
|
|
|
|
using osu.Game.Database;
|
2021-05-08 11:00:22 +02:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|
|
|
|
{
|
|
|
|
|
public partial class StableDirectorySelectScreen : DirectorySelectScreen
|
|
|
|
|
{
|
|
|
|
|
private readonly TaskCompletionSource<string> taskCompletionSource;
|
|
|
|
|
|
2023-12-15 15:42:19 +01:00
|
|
|
|
[Resolved]
|
|
|
|
|
private LegacyImportManager legacyImportManager { get; set; } = null!;
|
|
|
|
|
|
2021-05-17 13:28:59 +02:00
|
|
|
|
protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled;
|
|
|
|
|
|
2023-12-15 15:42:19 +01:00
|
|
|
|
protected override bool IsValidDirectory(DirectoryInfo? info) => legacyImportManager.IsUsableForStableImport(info, out _);
|
2021-05-08 11:00:22 +02:00
|
|
|
|
|
2021-05-17 13:04:49 +02:00
|
|
|
|
public override LocalisableString HeaderText => "Please select your osu!stable install location";
|
2021-05-08 11:00:22 +02:00
|
|
|
|
|
|
|
|
|
public StableDirectorySelectScreen(TaskCompletionSource<string> taskCompletionSource)
|
|
|
|
|
{
|
|
|
|
|
this.taskCompletionSource = taskCompletionSource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnSelection(DirectoryInfo directory)
|
2021-05-10 12:21:51 +02:00
|
|
|
|
{
|
2023-12-15 15:42:19 +01:00
|
|
|
|
if (!legacyImportManager.IsUsableForStableImport(directory, out var stableRoot))
|
|
|
|
|
throw new InvalidOperationException($@"{nameof(OnSelection)} was called on an invalid directory. This should never happen.");
|
|
|
|
|
|
|
|
|
|
taskCompletionSource.TrySetResult(stableRoot.FullName);
|
2021-05-08 11:00:22 +02:00
|
|
|
|
this.Exit();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 00:52:44 +09:00
|
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2021-05-08 11:00:22 +02:00
|
|
|
|
{
|
|
|
|
|
taskCompletionSource.TrySetCanceled();
|
2022-04-22 00:52:44 +09:00
|
|
|
|
return base.OnExiting(e);
|
2021-05-08 11:00:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|