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

don't passing stream by exception

This commit is contained in:
cdwcgt 2023-08-02 21:53:14 +09:00
parent 6637a5e7bc
commit 0e7e36f114
No known key found for this signature in database
GPG Key ID: 144396D01095C3A2
2 changed files with 14 additions and 19 deletions

View File

@ -7,7 +7,6 @@ using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using Newtonsoft.Json;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
@ -62,7 +61,7 @@ namespace osu.Game.Scoring.Legacy
workingBeatmap = GetBeatmap(beatmapHash);
if (workingBeatmap is DummyWorkingBeatmap)
throw new BeatmapNotFoundException(beatmapHash, stream);
throw new BeatmapNotFoundException(beatmapHash);
scoreInfo.User = new APIUser { Username = sr.ReadString() };
@ -350,19 +349,9 @@ namespace osu.Game.Scoring.Legacy
{
public string Hash { get; }
[CanBeNull]
public MemoryStream ScoreStream { get; }
public BeatmapNotFoundException(string hash, [CanBeNull] Stream scoreStream)
public BeatmapNotFoundException(string hash)
{
Hash = hash;
if (scoreStream != null)
{
ScoreStream = new MemoryStream();
scoreStream.Position = 0;
scoreStream.CopyTo(ScoreStream);
}
}
}
}

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using Newtonsoft.Json;
@ -59,19 +60,24 @@ namespace osu.Game.Scoring
}
catch (LegacyScoreDecoder.BeatmapNotFoundException e)
{
onMissingBeatmap(e);
onMissingBeatmap(e, archive, name);
Logger.Log($@"Score '{name}' failed to import: no corresponding beatmap with the hash '{e.Hash}' could be found.", LoggingTarget.Database);
return null;
}
}
}
private void onMissingBeatmap(LegacyScoreDecoder.BeatmapNotFoundException e)
private void onMissingBeatmap(LegacyScoreDecoder.BeatmapNotFoundException e, ArchiveReader archive, string name)
{
if (Performer == null)
{
e.ScoreStream?.Dispose();
return;
var stream = new MemoryStream();
// stream will close after exception throw, so fetch the stream again.
using (var scoreStream = archive.GetStream(name))
{
scoreStream.CopyTo(stream);
}
var req = new GetBeatmapRequest(new BeatmapInfo
@ -81,10 +87,10 @@ namespace osu.Game.Scoring
req.Success += res =>
{
Performer.PerformFromScreen(screen => screen.Push(new ReplayMissingBeatmapScreen(res, e.ScoreStream)));
Performer.PerformFromScreen(screen => screen.Push(new ReplayMissingBeatmapScreen(res, stream)));
};
req.Failure += _ => e.ScoreStream?.Dispose();
req.Failure += _ => stream.Dispose();
api.Queue(req);
}