From cd8420bc66c56aa7e686a579ebd9a18634861b45 Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Thu, 15 Dec 2022 23:34:40 +0900 Subject: [PATCH] Handle the case where the file cannot be found --- osu.Game/Database/LegacyModelExporter.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/osu.Game/Database/LegacyModelExporter.cs b/osu.Game/Database/LegacyModelExporter.cs index 824460cdc9..531a6f48da 100644 --- a/osu.Game/Database/LegacyModelExporter.cs +++ b/osu.Game/Database/LegacyModelExporter.cs @@ -143,12 +143,33 @@ namespace osu.Game.Database using (var writer = new ZipWriter(outputStream, new ZipWriterOptions(CompressionType.Deflate))) { float i = 0; + bool fileMissing = false; foreach (var file in model.Files) { notification.CancellationToken.ThrowIfCancellationRequested(); - writer.Write(file.Filename, UserFileStorage.GetStream(file.File.GetStoragePath())); + using (var stream = UserFileStorage.GetStream(file.File.GetStoragePath())) + { + // Sometimes we cannot find the file(probably deleted by the user), so we handle this and post a error. + if (stream == null) + { + // Only pop up once to prevent spam. + if (!fileMissing) + { + PostNotification?.Invoke(new SimpleErrorNotification + { + Text = "Some of your files are missing, they will not be included in the archive" + }); + fileMissing = true; + } + } + else + { + writer.Write(file.Filename, stream); + } + } + i++; notification.Progress = i / model.Files.Count(); notification.Text = $"Exporting... ({i}/{model.Files.Count()})";