mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 01:03:21 +08:00
Allow cancellation of count operations and bypassing interactive location logic
This commit is contained in:
parent
1666d13d26
commit
13e70eab51
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
@ -49,9 +50,14 @@ namespace osu.Game.Database
|
||||
|
||||
public bool SupportsImportFromStable => RuntimeInfo.IsDesktop;
|
||||
|
||||
public async Task<int> GetImportCount(StableContent content)
|
||||
public async Task<int> GetImportCount(StableContent content, CancellationToken cancellationToken)
|
||||
{
|
||||
var stableStorage = await getStableStorage().ConfigureAwait(false);
|
||||
var stableStorage = GetCurrentStableStorage();
|
||||
|
||||
if (stableStorage == null)
|
||||
return 0;
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
switch (content)
|
||||
{
|
||||
@ -72,9 +78,22 @@ namespace osu.Game.Database
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ImportFromStableAsync(StableContent content)
|
||||
public async Task ImportFromStableAsync(StableContent content, bool interactiveLocateIfNotFound = true)
|
||||
{
|
||||
var stableStorage = await getStableStorage().ConfigureAwait(false);
|
||||
var stableStorage = GetCurrentStableStorage();
|
||||
|
||||
if (stableStorage == null)
|
||||
{
|
||||
if (!interactiveLocateIfNotFound)
|
||||
return;
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
Schedule(() => dialogOverlay.Push(new StableDirectoryLocationDialog(taskCompletionSource)));
|
||||
string stablePath = await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
|
||||
stableStorage = cachedStorage = new StableStorage(stablePath, desktopGameHost);
|
||||
}
|
||||
|
||||
var importTasks = new List<Task>();
|
||||
|
||||
Task beatmapImportTask = Task.CompletedTask;
|
||||
@ -93,7 +112,7 @@ namespace osu.Game.Database
|
||||
await Task.WhenAll(importTasks.ToArray()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task<StableStorage> getStableStorage()
|
||||
public StableStorage GetCurrentStableStorage()
|
||||
{
|
||||
if (cachedStorage != null)
|
||||
return cachedStorage;
|
||||
@ -102,11 +121,7 @@ namespace osu.Game.Database
|
||||
if (stableStorage != null)
|
||||
return cachedStorage = stableStorage;
|
||||
|
||||
var taskCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
Schedule(() => dialogOverlay.Push(new StableDirectoryLocationDialog(taskCompletionSource)));
|
||||
string stablePath = await taskCompletionSource.Task.ConfigureAwait(false);
|
||||
|
||||
return cachedStorage = new StableStorage(stablePath, desktopGameHost);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -10,6 +12,7 @@ using osu.Framework.Localisation;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Overlays.Settings;
|
||||
using osuTK;
|
||||
@ -26,12 +29,16 @@ namespace osu.Game.Overlays.FirstRunSetup
|
||||
private SettingsCheckbox checkboxScores = null!;
|
||||
private SettingsCheckbox checkboxCollections = null!;
|
||||
|
||||
private OsuTextFlowContainer currentStablePath = null!;
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private LegacyImportManager legacyImportManager { get; set; } = null!;
|
||||
|
||||
private CancellationTokenSource? stablePathUpdateCancellation;
|
||||
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load()
|
||||
{
|
||||
@ -47,6 +54,21 @@ namespace osu.Game.Overlays.FirstRunSetup
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y
|
||||
},
|
||||
currentStablePath = new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: HEADER_FONT_SIZE, weight: FontWeight.SemiBold))
|
||||
{
|
||||
Colour = OverlayColourProvider.Content2,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
},
|
||||
new RoundedButton
|
||||
{
|
||||
Size = buttonSize,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
BackgroundColour = colours.Blue3,
|
||||
Text = "Locate osu!(stable) install",
|
||||
Action = locateStable,
|
||||
},
|
||||
checkboxBeatmaps = new SettingsCheckbox
|
||||
{
|
||||
LabelText = "Beatmaps",
|
||||
@ -78,10 +100,65 @@ namespace osu.Game.Overlays.FirstRunSetup
|
||||
},
|
||||
};
|
||||
|
||||
legacyImportManager.GetImportCount(StableContent.Beatmaps).ContinueWith(task => Schedule(() => checkboxBeatmaps.LabelText += $" ({task.GetResultSafely()} items)"));
|
||||
legacyImportManager.GetImportCount(StableContent.Scores).ContinueWith(task => Schedule(() => checkboxScores.LabelText += $" ({task.GetResultSafely()} items)"));
|
||||
legacyImportManager.GetImportCount(StableContent.Skins).ContinueWith(task => Schedule(() => checkboxSkins.LabelText += $" ({task.GetResultSafely()} items)"));
|
||||
legacyImportManager.GetImportCount(StableContent.Collections).ContinueWith(task => Schedule(() => checkboxCollections.LabelText += $" ({task.GetResultSafely()} items)"));
|
||||
updateStablePath();
|
||||
}
|
||||
|
||||
private void locateStable()
|
||||
{
|
||||
legacyImportManager.ImportFromStableAsync(0).ContinueWith(task =>
|
||||
{
|
||||
Schedule(updateStablePath);
|
||||
});
|
||||
}
|
||||
|
||||
private void updateStablePath()
|
||||
{
|
||||
stablePathUpdateCancellation?.Cancel();
|
||||
|
||||
var storage = legacyImportManager.GetCurrentStableStorage();
|
||||
|
||||
if (storage == null)
|
||||
{
|
||||
foreach (var c in Content.Children.OfType<SettingsCheckbox>())
|
||||
c.Current.Disabled = true;
|
||||
currentStablePath.Text = "No installation found";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var c in Content.Children.OfType<SettingsCheckbox>())
|
||||
c.Current.Disabled = false;
|
||||
|
||||
currentStablePath.Text = storage.GetFullPath(string.Empty);
|
||||
stablePathUpdateCancellation = new CancellationTokenSource();
|
||||
|
||||
legacyImportManager.GetImportCount(StableContent.Beatmaps, stablePathUpdateCancellation.Token).ContinueWith(task => Schedule(() =>
|
||||
{
|
||||
if (task.IsCanceled)
|
||||
return;
|
||||
|
||||
checkboxBeatmaps.LabelText = $"Beatmaps ({task.GetResultSafely()} items)";
|
||||
}));
|
||||
legacyImportManager.GetImportCount(StableContent.Scores, stablePathUpdateCancellation.Token).ContinueWith(task => Schedule(() =>
|
||||
{
|
||||
if (task.IsCanceled)
|
||||
return;
|
||||
|
||||
checkboxScores.LabelText = $"Scores ({task.GetResultSafely()} items)";
|
||||
}));
|
||||
legacyImportManager.GetImportCount(StableContent.Skins, stablePathUpdateCancellation.Token).ContinueWith(task => Schedule(() =>
|
||||
{
|
||||
if (task.IsCanceled)
|
||||
return;
|
||||
|
||||
checkboxSkins.LabelText = $"Skins ({task.GetResultSafely()} items)";
|
||||
}));
|
||||
legacyImportManager.GetImportCount(StableContent.Collections, stablePathUpdateCancellation.Token).ContinueWith(task => Schedule(() =>
|
||||
{
|
||||
if (task.IsCanceled)
|
||||
return;
|
||||
|
||||
checkboxCollections.LabelText = $"Collections ({task.GetResultSafely()} items)";
|
||||
}));
|
||||
}
|
||||
|
||||
private void runImport()
|
||||
@ -95,7 +172,7 @@ namespace osu.Game.Overlays.FirstRunSetup
|
||||
if (checkboxSkins.Current.Value) importableContent |= StableContent.Skins;
|
||||
if (checkboxCollections.Current.Value) importableContent |= StableContent.Collections;
|
||||
|
||||
legacyImportManager.ImportFromStableAsync(importableContent)
|
||||
legacyImportManager.ImportFromStableAsync(importableContent, false)
|
||||
.ContinueWith(t => Schedule(() =>
|
||||
{
|
||||
if (t.IsCompletedSuccessfully)
|
||||
|
Loading…
Reference in New Issue
Block a user