mirror of
https://github.com/ppy/osu
synced 2024-12-17 20:35:21 +00:00
Merge pull request #30402 from peppy/import-paused-visibility
Update notification text when import is paused due to gameplay
This commit is contained in:
commit
53f0befc05
@ -40,15 +40,13 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
AddStep("import score", () =>
|
||||
{
|
||||
using (var resourceStream = TestResources.OpenResource("Replays/mania-replay.osr"))
|
||||
{
|
||||
var resourceStream = TestResources.OpenResource("Replays/mania-replay.osr");
|
||||
var importTask = new ImportTask(resourceStream, "replay.osr");
|
||||
|
||||
Game.ScoreManager.Import(new[] { importTask });
|
||||
}
|
||||
});
|
||||
|
||||
AddUntilStep("Replay missing notification show", () => Game.Notifications.ChildrenOfType<MissingBeatmapNotification>().Any());
|
||||
AddUntilStep("Replay missing notification shown", () => Game.Notifications.ChildrenOfType<MissingBeatmapNotification>().Any());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -58,15 +56,13 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
AddStep("import score", () =>
|
||||
{
|
||||
using (var resourceStream = TestResources.OpenResource("Replays/mania-replay.osr"))
|
||||
{
|
||||
var resourceStream = TestResources.OpenResource("Replays/mania-replay.osr");
|
||||
var importTask = new ImportTask(resourceStream, "replay.osr");
|
||||
|
||||
Game.ScoreManager.Import(new[] { importTask });
|
||||
}
|
||||
});
|
||||
|
||||
AddUntilStep("Replay missing notification not show", () => !Game.Notifications.ChildrenOfType<MissingBeatmapNotification>().Any());
|
||||
AddUntilStep("Replay missing notification not shown", () => !Game.Notifications.ChildrenOfType<MissingBeatmapNotification>().Any());
|
||||
}
|
||||
|
||||
private void setupBeatmapResponse(APIBeatmap b)
|
||||
|
@ -68,18 +68,23 @@ namespace osu.Game.Database
|
||||
{
|
||||
Task.Factory.StartNew(async () =>
|
||||
{
|
||||
bool importSuccessful;
|
||||
bool importSuccessful = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (originalModel != null)
|
||||
importSuccessful = (await importer.ImportAsUpdate(notification, new ImportTask(filename), originalModel).ConfigureAwait(false)) != null;
|
||||
else
|
||||
importSuccessful = (await importer.Import(notification, new[] { new ImportTask(filename) }).ConfigureAwait(false)).Any();
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
// for now a failed import will be marked as a failed download for simplicity.
|
||||
if (!importSuccessful)
|
||||
DownloadFailed?.Invoke(request);
|
||||
|
||||
CurrentDownloads.Remove(request);
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
};
|
||||
|
||||
|
@ -105,7 +105,6 @@ namespace osu.Game.Database
|
||||
}
|
||||
|
||||
notification.Progress = 0;
|
||||
notification.Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import is initialising...";
|
||||
|
||||
int current = 0;
|
||||
|
||||
@ -113,14 +112,22 @@ namespace osu.Game.Database
|
||||
|
||||
parameters.Batch |= tasks.Length >= minimum_items_considered_batch_import;
|
||||
|
||||
await Task.WhenAll(tasks.Select(async task =>
|
||||
{
|
||||
if (notification.CancellationToken.IsCancellationRequested)
|
||||
return;
|
||||
notification.Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import is initialising...";
|
||||
notification.State = ProgressNotificationState.Active;
|
||||
|
||||
await pauseIfNecessaryAsync(parameters, notification, notification.CancellationToken).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
var model = await Import(task, parameters, notification.CancellationToken).ConfigureAwait(false);
|
||||
await Parallel.ForEachAsync(tasks, notification.CancellationToken, async (task, cancellation) =>
|
||||
{
|
||||
cancellation.ThrowIfCancellationRequested();
|
||||
|
||||
try
|
||||
{
|
||||
await pauseIfNecessaryAsync(parameters, notification, cancellation).ConfigureAwait(false);
|
||||
|
||||
var model = await Import(task, parameters, cancellation).ConfigureAwait(false);
|
||||
|
||||
lock (imported)
|
||||
{
|
||||
@ -134,24 +141,28 @@ namespace osu.Game.Database
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, $@"Could not import ({task})", LoggingTarget.Database);
|
||||
}
|
||||
})).ConfigureAwait(false);
|
||||
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (imported.Count == 0)
|
||||
{
|
||||
if (notification.CancellationToken.IsCancellationRequested)
|
||||
{
|
||||
notification.State = ProgressNotificationState.Cancelled;
|
||||
return imported;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
notification.Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import failed! Check logs for more information.";
|
||||
notification.State = ProgressNotificationState.Cancelled;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tasks.Length > imported.Count)
|
||||
@ -173,6 +184,7 @@ namespace osu.Game.Database
|
||||
|
||||
notification.State = ProgressNotificationState.Completed;
|
||||
}
|
||||
}
|
||||
|
||||
return imported;
|
||||
}
|
||||
@ -286,8 +298,6 @@ namespace osu.Game.Database
|
||||
/// <param name="cancellationToken">An optional cancellation token.</param>
|
||||
public virtual Live<TModel>? ImportModel(TModel item, ArchiveReader? archive = null, ImportParameters parameters = default, CancellationToken cancellationToken = default) => Realm.Run(realm =>
|
||||
{
|
||||
pauseIfNecessary(parameters, cancellationToken);
|
||||
|
||||
TModel? existing;
|
||||
|
||||
if (parameters.Batch && archive != null)
|
||||
@ -528,7 +538,8 @@ namespace osu.Game.Database
|
||||
/// <param name="model">The new model proposed for import.</param>
|
||||
/// <param name="realm">The current realm context.</param>
|
||||
/// <returns>An existing model which matches the criteria to skip importing, else null.</returns>
|
||||
protected TModel? CheckForExisting(TModel model, Realm realm) => string.IsNullOrEmpty(model.Hash) ? null : realm.All<TModel>().OrderBy(b => b.DeletePending).FirstOrDefault(b => b.Hash == model.Hash);
|
||||
protected TModel? CheckForExisting(TModel model, Realm realm) =>
|
||||
string.IsNullOrEmpty(model.Hash) ? null : realm.All<TModel>().OrderBy(b => b.DeletePending).FirstOrDefault(b => b.Hash == model.Hash);
|
||||
|
||||
/// <summary>
|
||||
/// Whether import can be skipped after finding an existing import early in the process.
|
||||
@ -575,21 +586,29 @@ namespace osu.Game.Database
|
||||
/// <returns>Whether to perform deletion.</returns>
|
||||
protected virtual bool ShouldDeleteArchive(string path) => false;
|
||||
|
||||
private void pauseIfNecessary(ImportParameters importParameters, CancellationToken cancellationToken)
|
||||
private async Task pauseIfNecessaryAsync(ImportParameters importParameters, ProgressNotification notification, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!PauseImports || importParameters.ImportImmediately)
|
||||
return;
|
||||
|
||||
Logger.Log($@"{GetType().Name} is being paused.");
|
||||
|
||||
// A paused state could obviously be entered mid-import (during the `Task.WhenAll` below),
|
||||
// but in order to keep things simple let's focus on the most common scenario.
|
||||
notification.Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import is paused due to gameplay...";
|
||||
notification.State = ProgressNotificationState.Queued;
|
||||
|
||||
while (PauseImports)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
Thread.Sleep(500);
|
||||
await Task.Delay(500, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
Logger.Log($@"{GetType().Name} is being resumed.");
|
||||
|
||||
notification.Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import is resuming...";
|
||||
notification.State = ProgressNotificationState.Active;
|
||||
}
|
||||
|
||||
private IEnumerable<string> getIDs(IEnumerable<INamedFile> files)
|
||||
|
Loading…
Reference in New Issue
Block a user