Fix import failures if single set has multiple conflicting OnlineBeatmapIDs

Resolves #2970.
This commit is contained in:
Dean Herbert 2018-07-09 00:24:55 +09:00
parent 27311ce1fc
commit e223074876
1 changed files with 17 additions and 3 deletions

View File

@ -339,6 +339,8 @@ private List<BeatmapInfo> createBeatmapDifficulties(ArchiveReader reader)
{
var beatmapInfos = new List<BeatmapInfo>();
bool invalidateOnlineIDs = false;
foreach (var name in reader.Filenames.Where(f => f.EndsWith(".osu")))
{
using (var raw = reader.GetStream(name))
@ -355,9 +357,18 @@ private List<BeatmapInfo> createBeatmapDifficulties(ArchiveReader reader)
beatmap.BeatmapInfo.Hash = ms.ComputeSHA2Hash();
beatmap.BeatmapInfo.MD5Hash = ms.ComputeMD5Hash();
// check that no existing beatmap exists that is imported with the same online beatmap ID. if so, give it precedence.
if (beatmap.BeatmapInfo.OnlineBeatmapID.HasValue && QueryBeatmap(b => b.OnlineBeatmapID.Value == beatmap.BeatmapInfo.OnlineBeatmapID.Value) != null)
beatmap.BeatmapInfo.OnlineBeatmapID = null;
if (beatmap.BeatmapInfo.OnlineBeatmapID.HasValue)
{
var ourId = beatmap.BeatmapInfo.OnlineBeatmapID;
// check that no existing beatmap in database exists that is imported with the same online beatmap ID. if so, give it precedence.
if (QueryBeatmap(b => b.OnlineBeatmapID.Value == ourId) != null)
beatmap.BeatmapInfo.OnlineBeatmapID = null;
// check that no other beatmap in this imported set has a conflicting online beatmap ID. If so, presume *all* are incorrect.
if (beatmapInfos.Any(b => b.OnlineBeatmapID == ourId))
invalidateOnlineIDs = true;
}
RulesetInfo ruleset = rulesets.GetRuleset(beatmap.BeatmapInfo.RulesetID);
@ -375,6 +386,9 @@ private List<BeatmapInfo> createBeatmapDifficulties(ArchiveReader reader)
}
}
if (invalidateOnlineIDs)
beatmapInfos.ForEach(b => b.OnlineBeatmapID = null);
return beatmapInfos;
}