1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 13:22:55 +08:00

Handle the case where the file cannot be found

This commit is contained in:
cdwcgt 2022-12-15 23:34:40 +09:00
parent dadadaff65
commit cd8420bc66
No known key found for this signature in database
GPG Key ID: 144396D01095C3A2

View File

@ -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()})";