mirror of
https://github.com/ppy/osu.git
synced 2026-05-21 05:09:57 +08:00
Apply more granular copying from database when retrieving working beatmap
This commit is contained in:
@@ -235,11 +235,18 @@ namespace osu.Game.Beatmaps
|
||||
// Todo: Handle cancellation during beatmap parsing
|
||||
var b = GetBeatmap() ?? new Beatmap();
|
||||
|
||||
// The original beatmap version needs to be preserved as the database doesn't contain it
|
||||
BeatmapInfo.BeatmapVersion = b.BeatmapInfo.BeatmapVersion;
|
||||
|
||||
// Use the database-backed info for more up-to-date values (beatmap id, ranked status, etc)
|
||||
b.BeatmapInfo = BeatmapInfo;
|
||||
// Copy across values of key properties for which the database-backed model has data that the decoded beatmap isn't going to.
|
||||
b.BeatmapInfo.ID = BeatmapInfo.ID;
|
||||
b.BeatmapInfo.UserSettings = BeatmapInfo.UserSettings;
|
||||
b.BeatmapInfo.BeatmapSet = BeatmapInfo.BeatmapSet;
|
||||
b.BeatmapInfo.Status = BeatmapInfo.Status;
|
||||
b.BeatmapInfo.OnlineID = BeatmapInfo.OnlineID;
|
||||
b.BeatmapInfo.OnlineMD5Hash = BeatmapInfo.OnlineMD5Hash;
|
||||
b.BeatmapInfo.LastLocalUpdate = BeatmapInfo.LastLocalUpdate;
|
||||
b.BeatmapInfo.LastOnlineUpdate = BeatmapInfo.LastOnlineUpdate;
|
||||
b.BeatmapInfo.LastPlayed = BeatmapInfo.LastPlayed;
|
||||
b.BeatmapInfo.EditorTimestamp = BeatmapInfo.EditorTimestamp;
|
||||
b.BeatmapInfo.StarRating = BeatmapInfo.StarRating; // this could be recomputed in the decoding process but it's a bit annoying to do.
|
||||
|
||||
return b;
|
||||
}, loadCancellationSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||
|
||||
@@ -21,6 +21,7 @@ using osu.Framework.Statistics;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Storyboards;
|
||||
|
||||
@@ -152,14 +153,28 @@ namespace osu.Game.Beatmaps
|
||||
return null;
|
||||
}
|
||||
|
||||
if (stream.ComputeMD5Hash() != BeatmapInfo.MD5Hash)
|
||||
string streamMD5 = stream.ComputeMD5Hash();
|
||||
string streamSHA2 = stream.ComputeSHA2Hash();
|
||||
|
||||
if (streamMD5 != BeatmapInfo.MD5Hash)
|
||||
{
|
||||
Logger.Log($"Beatmap failed to load (file {BeatmapInfo.Path} does not have the expected hash).", level: LogLevel.Error);
|
||||
return null;
|
||||
}
|
||||
|
||||
using (var reader = new LineBufferedReader(stream))
|
||||
return Decoder.GetDecoder<Beatmap>(reader).Decode(reader);
|
||||
{
|
||||
var beatmap = Decoder.GetDecoder<Beatmap>(reader).Decode(reader);
|
||||
|
||||
beatmap.BeatmapInfo.MD5Hash = streamMD5;
|
||||
beatmap.BeatmapInfo.Hash = streamSHA2;
|
||||
beatmap.BeatmapInfo.Length = beatmap.CalculatePlayableLength();
|
||||
beatmap.BeatmapInfo.BPM = 60000 / beatmap.GetMostCommonBeatLength();
|
||||
beatmap.BeatmapInfo.EndTimeObjectCount = beatmap.HitObjects.Count(h => h is IHasDuration);
|
||||
beatmap.BeatmapInfo.TotalObjectCount = beatmap.HitObjects.Count;
|
||||
|
||||
return beatmap;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user