mirror of
https://github.com/ppy/osu.git
synced 2024-11-07 16:47:24 +08:00
Display import state in a notification.
This commit is contained in:
parent
827e957568
commit
825120fed3
@ -218,7 +218,42 @@ namespace osu.Game.Database
|
|||||||
/// <param name="stream">The stream to import files from.</param>
|
/// <param name="stream">The stream to import files from.</param>
|
||||||
/// <param name="filename">The filename of the archive being imported.</param>
|
/// <param name="filename">The filename of the archive being imported.</param>
|
||||||
public async Task Import(Stream stream, string filename)
|
public async Task Import(Stream stream, string filename)
|
||||||
=> await Import(new ZipArchiveReader(stream, filename)); // we need to keep around the filename as some model managers (namely SkinManager) use the archive name to populate skin info
|
{
|
||||||
|
var notification = new ProgressNotification
|
||||||
|
{
|
||||||
|
Progress = 0,
|
||||||
|
State = ProgressNotificationState.Active,
|
||||||
|
Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import is initialising...",
|
||||||
|
};
|
||||||
|
|
||||||
|
PostNotification.Invoke(notification);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// we need to keep around the filename as some model managers (namely SkinManager) use the archive name to populate skin info
|
||||||
|
var imported = await Import(new ZipArchiveReader(stream, filename), notification.CancellationToken);
|
||||||
|
|
||||||
|
notification.CompletionText = $"Imported {imported}! Click to view.";
|
||||||
|
notification.CompletionClickAction += () =>
|
||||||
|
{
|
||||||
|
PresentImport?.Invoke(new[] { imported });
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
notification.State = ProgressNotificationState.Completed;
|
||||||
|
}
|
||||||
|
catch (TaskCanceledException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
notification.Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import failed!";
|
||||||
|
notification.State = ProgressNotificationState.Cancelled;
|
||||||
|
Logger.Error(e, $@"Could not import ({filename})", LoggingTarget.Database);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fired when the user requests to view the resulting import.
|
/// Fired when the user requests to view the resulting import.
|
||||||
|
Loading…
Reference in New Issue
Block a user