mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
don't passing stream by exception
This commit is contained in:
parent
6637a5e7bc
commit
0e7e36f114
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user