diff --git a/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs b/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs index a191220b37..8c00110909 100644 --- a/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs +++ b/osu.Game/Scoring/Legacy/LegacyScoreDecoder.cs @@ -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); - } } } } diff --git a/osu.Game/Scoring/ScoreImporter.cs b/osu.Game/Scoring/ScoreImporter.cs index db4c0aff89..64394800cd 100644 --- a/osu.Game/Scoring/ScoreImporter.cs +++ b/osu.Game/Scoring/ScoreImporter.cs @@ -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); }