mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 11:52:54 +08:00
Pass ArchiveReader
instead of Stream
to simplify resolution code
This commit is contained in:
parent
0593c76c57
commit
f726c38215
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -9,6 +8,7 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Tests.Scores.IO;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
@ -27,7 +27,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Child = new MissingBeatmapNotification(CreateAPIBeatmapSet(Ruleset.Value).Beatmaps.First(), new MemoryStream(), "deadbeef")
|
Child = new MissingBeatmapNotification(CreateAPIBeatmapSet(Ruleset.Value).Beatmaps.First(), new ImportScoreTest.TestArchiveReader(), "deadbeef")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,18 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Drawables.Cards;
|
using osu.Game.Beatmaps.Drawables.Cards;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.IO.Archives;
|
||||||
|
using osu.Game.Localisation;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using Realms;
|
using Realms;
|
||||||
using osu.Game.Localisation;
|
|
||||||
|
|
||||||
namespace osu.Game.Database
|
namespace osu.Game.Database
|
||||||
{
|
{
|
||||||
@ -29,7 +28,7 @@ namespace osu.Game.Database
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private RealmAccess realm { get; set; } = null!;
|
private RealmAccess realm { get; set; } = null!;
|
||||||
|
|
||||||
private readonly MemoryStream scoreStream;
|
private readonly ArchiveReader scoreArchive;
|
||||||
private readonly APIBeatmapSet beatmapSetInfo;
|
private readonly APIBeatmapSet beatmapSetInfo;
|
||||||
private readonly string beatmapHash;
|
private readonly string beatmapHash;
|
||||||
|
|
||||||
@ -39,12 +38,12 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
private IDisposable? realmSubscription;
|
private IDisposable? realmSubscription;
|
||||||
|
|
||||||
public MissingBeatmapNotification(APIBeatmap beatmap, MemoryStream scoreStream, string beatmapHash)
|
public MissingBeatmapNotification(APIBeatmap beatmap, ArchiveReader scoreArchive, string beatmapHash)
|
||||||
{
|
{
|
||||||
beatmapSetInfo = beatmap.BeatmapSet!;
|
beatmapSetInfo = beatmap.BeatmapSet!;
|
||||||
|
|
||||||
this.beatmapHash = beatmapHash;
|
this.beatmapHash = beatmapHash;
|
||||||
this.scoreStream = scoreStream;
|
this.scoreArchive = scoreArchive;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -89,7 +88,8 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
if (sender.Any(s => s.Beatmaps.Any(b => b.MD5Hash == beatmapHash)))
|
if (sender.Any(s => s.Beatmaps.Any(b => b.MD5Hash == beatmapHash)))
|
||||||
{
|
{
|
||||||
var importTask = new ImportTask(scoreStream, "score.osr");
|
string name = scoreArchive.Filenames.First(f => f.EndsWith(".osr", StringComparison.OrdinalIgnoreCase));
|
||||||
|
var importTask = new ImportTask(scoreArchive.GetStream(name), name);
|
||||||
scoreManager.Import(new[] { importTask });
|
scoreManager.Import(new[] { importTask });
|
||||||
realmSubscription?.Dispose();
|
realmSubscription?.Dispose();
|
||||||
Close(false);
|
Close(false);
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
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;
|
||||||
@ -55,36 +54,17 @@ namespace osu.Game.Scoring
|
|||||||
}
|
}
|
||||||
catch (LegacyScoreDecoder.BeatmapNotFoundException e)
|
catch (LegacyScoreDecoder.BeatmapNotFoundException e)
|
||||||
{
|
{
|
||||||
onMissingBeatmap(e, archive, name);
|
|
||||||
Logger.Log($@"Score '{archive.Name}' failed to import: no corresponding beatmap with the hash '{e.Hash}' could be found.", LoggingTarget.Database);
|
Logger.Log($@"Score '{archive.Name}' failed to import: no corresponding beatmap with the hash '{e.Hash}' could be found.", LoggingTarget.Database);
|
||||||
|
|
||||||
|
// In the case of a missing beatmap, let's attempt to resolve it and show a prompt to the user to download the required beatmap.
|
||||||
|
var req = new GetBeatmapRequest(new BeatmapInfo { MD5Hash = e.Hash });
|
||||||
|
req.Success += res => PostNotification?.Invoke(new MissingBeatmapNotification(res, archive, e.Hash));
|
||||||
|
api.Queue(req);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onMissingBeatmap(LegacyScoreDecoder.BeatmapNotFoundException e, ArchiveReader archive, string name)
|
|
||||||
{
|
|
||||||
var stream = new MemoryStream();
|
|
||||||
|
|
||||||
// stream will be closed after the exception was thrown, so fetch the stream again.
|
|
||||||
using (var scoreStream = archive.GetStream(name))
|
|
||||||
{
|
|
||||||
scoreStream.CopyTo(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
var req = new GetBeatmapRequest(new BeatmapInfo
|
|
||||||
{
|
|
||||||
MD5Hash = e.Hash
|
|
||||||
});
|
|
||||||
|
|
||||||
req.Success += res =>
|
|
||||||
{
|
|
||||||
PostNotification?.Invoke(new MissingBeatmapNotification(res, stream, e.Hash));
|
|
||||||
};
|
|
||||||
|
|
||||||
api.Queue(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Score GetScore(ScoreInfo score) => new LegacyDatabasedScore(score, rulesets, beatmaps(), Files.Store);
|
public Score GetScore(ScoreInfo score) => new LegacyDatabasedScore(score, rulesets, beatmaps(), Files.Store);
|
||||||
|
|
||||||
protected override void Populate(ScoreInfo model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
|
protected override void Populate(ScoreInfo model, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
|
||||||
|
Loading…
Reference in New Issue
Block a user