1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 06:42:54 +08:00

catch ObjectDisposedException

This commit is contained in:
cdwcgt 2023-02-19 02:06:07 +09:00
parent d611603742
commit 30985f192e

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@ -39,34 +40,45 @@ namespace osu.Game.Database
float i = 0; float i = 0;
bool fileMissing = false; bool fileMissing = false;
foreach (var file in model.Files) try
{ {
cancellationToken.ThrowIfCancellationRequested(); foreach (var file in model.Files)
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. cancellationToken.ThrowIfCancellationRequested();
if (stream == null)
using (var stream = UserFileStorage.GetStream(file.File.GetStoragePath()))
{ {
// Only pop up once to prevent spam. // Sometimes we cannot find the file(probably deleted by the user), so we handle this and post a error.
if (!fileMissing) if (stream == null)
{ {
PostNotification?.Invoke(new SimpleErrorNotification // Only pop up once to prevent spam.
if (!fileMissing)
{ {
Text = "Some of your files are missing, they will not be included in the archive" PostNotification?.Invoke(new SimpleErrorNotification
}); {
fileMissing = true; Text = "Some of your files are missing, they will not be included in the archive"
});
fileMissing = true;
}
}
else
{
writer.Write(file.Filename, stream);
} }
} }
else
{
writer.Write(file.Filename, stream);
}
}
i++; i++;
notification.Progress = i / model.Files.Count(); notification.Progress = i / model.Files.Count();
notification.Text = $"Exporting... ({i}/{model.Files.Count()})"; notification.Text = $"Exporting... ({i}/{model.Files.Count()})";
}
}
catch (ObjectDisposedException)
{
// outputStream may close before writing when request cancel
if (cancellationToken.IsCancellationRequested)
return;
throw;
} }
} }
} }