From 1f4da35c8d75e77d3eadca6bbf7624cf2b63331c Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Sun, 9 Apr 2023 22:11:52 +0900 Subject: [PATCH] notification nullable fix --- osu.Game/Database/LegacyArchiveExporter.cs | 12 ++++++++---- osu.Game/Database/LegacyModelExporter.cs | 9 +++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/osu.Game/Database/LegacyArchiveExporter.cs b/osu.Game/Database/LegacyArchiveExporter.cs index 1af8c454c1..35f09189c9 100644 --- a/osu.Game/Database/LegacyArchiveExporter.cs +++ b/osu.Game/Database/LegacyArchiveExporter.cs @@ -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); /// @@ -35,7 +35,7 @@ namespace osu.Game.Database /// The output stream to export to. /// The notification will displayed to the user /// The Cancellation token that can cancel the exporting. - 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) diff --git a/osu.Game/Database/LegacyModelExporter.cs b/osu.Game/Database/LegacyModelExporter.cs index e8fc25ab84..0f09c2c19b 100644 --- a/osu.Game/Database/LegacyModelExporter.cs +++ b/osu.Game/Database/LegacyModelExporter.cs @@ -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 /// Whether the export was successful public Task 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(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 /// The output stream to export to. /// The notification will displayed to the user /// The Cancellation token that can cancel the exporting. - 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); } }