mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 19:27:31 +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.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
@ -62,7 +61,7 @@ namespace osu.Game.Scoring.Legacy
|
|||||||
workingBeatmap = GetBeatmap(beatmapHash);
|
workingBeatmap = GetBeatmap(beatmapHash);
|
||||||
|
|
||||||
if (workingBeatmap is DummyWorkingBeatmap)
|
if (workingBeatmap is DummyWorkingBeatmap)
|
||||||
throw new BeatmapNotFoundException(beatmapHash, stream);
|
throw new BeatmapNotFoundException(beatmapHash);
|
||||||
|
|
||||||
scoreInfo.User = new APIUser { Username = sr.ReadString() };
|
scoreInfo.User = new APIUser { Username = sr.ReadString() };
|
||||||
|
|
||||||
@ -350,19 +349,9 @@ namespace osu.Game.Scoring.Legacy
|
|||||||
{
|
{
|
||||||
public string Hash { get; }
|
public string Hash { get; }
|
||||||
|
|
||||||
[CanBeNull]
|
public BeatmapNotFoundException(string hash)
|
||||||
public MemoryStream ScoreStream { get; }
|
|
||||||
|
|
||||||
public BeatmapNotFoundException(string hash, [CanBeNull] Stream scoreStream)
|
|
||||||
{
|
{
|
||||||
Hash = hash;
|
Hash = hash;
|
||||||
|
|
||||||
if (scoreStream != null)
|
|
||||||
{
|
|
||||||
ScoreStream = new MemoryStream();
|
|
||||||
scoreStream.Position = 0;
|
|
||||||
scoreStream.CopyTo(ScoreStream);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -59,19 +60,24 @@ namespace osu.Game.Scoring
|
|||||||
}
|
}
|
||||||
catch (LegacyScoreDecoder.BeatmapNotFoundException e)
|
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);
|
Logger.Log($@"Score '{name}' failed to import: no corresponding beatmap with the hash '{e.Hash}' could be found.", LoggingTarget.Database);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onMissingBeatmap(LegacyScoreDecoder.BeatmapNotFoundException e)
|
private void onMissingBeatmap(LegacyScoreDecoder.BeatmapNotFoundException e, ArchiveReader archive, string name)
|
||||||
{
|
{
|
||||||
if (Performer == null)
|
if (Performer == null)
|
||||||
{
|
|
||||||
e.ScoreStream?.Dispose();
|
|
||||||
return;
|
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
|
var req = new GetBeatmapRequest(new BeatmapInfo
|
||||||
@ -81,10 +87,10 @@ namespace osu.Game.Scoring
|
|||||||
|
|
||||||
req.Success += res =>
|
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);
|
api.Queue(req);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user