1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:52:53 +08:00

notification nullable fix

This commit is contained in:
cdwcgt 2023-04-09 22:11:52 +09:00
parent 13b522e825
commit 1f4da35c8d
No known key found for this signature in database
GPG Key ID: 144396D01095C3A2
2 changed files with 11 additions and 10 deletions

View File

@ -25,7 +25,7 @@ namespace osu.Game.Database
{
}
protected override void ExportToStream(TModel model, Stream outputStream, ProgressNotification notification, CancellationToken cancellationToken = default)
protected override void ExportToStream(TModel model, Stream outputStream, ProgressNotification? notification, CancellationToken cancellationToken = default)
=> exportZipArchive(model, outputStream, notification, cancellationToken);
/// <summary>
@ -35,7 +35,7 @@ namespace osu.Game.Database
/// <param name="outputStream">The output stream to export to.</param>
/// <param name="notification">The notification will displayed to the user</param>
/// <param name="cancellationToken">The Cancellation token that can cancel the exporting.</param>
private void exportZipArchive(TModel model, Stream outputStream, ProgressNotification notification, CancellationToken cancellationToken = default)
private void exportZipArchive(TModel model, Stream outputStream, ProgressNotification? notification, CancellationToken cancellationToken = default)
{
try
{
@ -67,8 +67,12 @@ namespace osu.Game.Database
}
i++;
notification.Progress = i / model.Files.Count();
notification.Text = $"Exporting... ({i}/{model.Files.Count()})";
if (notification != null)
{
notification.Progress = i / model.Files.Count();
notification.Text = $"Exporting... ({i}/{model.Files.Count()})";
}
}
}
catch (ObjectDisposedException)

View File

@ -105,6 +105,7 @@ namespace osu.Game.Database
// cleanup if export is failed or canceled.
if (!success)
{
notification.State = ProgressNotificationState.Cancelled;
exportStorage.Delete(filename);
}
else
@ -129,27 +130,23 @@ namespace osu.Game.Database
/// <returns>Whether the export was successful</returns>
public Task<bool> ExportToStreamAsync(TModel model, Stream stream, ProgressNotification? notification = null, CancellationToken cancellationToken = default)
{
ProgressNotification notify = notification ?? new ProgressNotification();
Guid id = model.ID;
return Task.Run(() =>
{
realmAccess.Run(r =>
{
TModel refetchModel = r.Find<TModel>(id);
ExportToStream(refetchModel, stream, notify, cancellationToken);
ExportToStream(refetchModel, stream, notification, cancellationToken);
});
}, cancellationToken).ContinueWith(t =>
{
if (cancellationToken.IsCancellationRequested)
{
notify.State = ProgressNotificationState.Cancelled;
return false;
}
if (t.IsFaulted)
{
notify.State = ProgressNotificationState.Cancelled;
Logger.Error(t.Exception, "An error occurred while exporting", LoggingTarget.Database);
return false;
}
@ -165,6 +162,6 @@ namespace osu.Game.Database
/// <param name="outputStream">The output stream to export to.</param>
/// <param name="notification">The notification will displayed to the user</param>
/// <param name="cancellationToken">The Cancellation token that can cancel the exporting.</param>
protected abstract void ExportToStream(TModel model, Stream outputStream, ProgressNotification notification, CancellationToken cancellationToken = default);
protected abstract void ExportToStream(TModel model, Stream outputStream, ProgressNotification? notification, CancellationToken cancellationToken = default);
}
}