1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:02:55 +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); => exportZipArchive(model, outputStream, notification, cancellationToken);
/// <summary> /// <summary>
@ -35,7 +35,7 @@ namespace osu.Game.Database
/// <param name="outputStream">The output stream to export to.</param> /// <param name="outputStream">The output stream to export to.</param>
/// <param name="notification">The notification will displayed to the user</param> /// <param name="notification">The notification will displayed to the user</param>
/// <param name="cancellationToken">The Cancellation token that can cancel the exporting.</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 try
{ {
@ -67,8 +67,12 @@ namespace osu.Game.Database
} }
i++; 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) catch (ObjectDisposedException)

View File

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