/// <summary> /// Create all required <see cref="BeatmapInfo"/>s for the provided archive. /// </summary> private List <BeatmapInfo> createBeatmapDifficulties(BeatmapSetInfo model, ArchiveReader reader) { var beatmapInfos = new List <BeatmapInfo>(); foreach (var name in reader.Filenames.Where(f => f.EndsWith(".osu"))) { using (var raw = reader.GetStream(name)) using (var ms = new MemoryStream()) //we need a memory stream so we can seek and shit using (var sr = new StreamReader(ms)) { raw.CopyTo(ms); ms.Position = 0; var decoder = Decoder.GetDecoder <Beatmap>(sr); IBeatmap beatmap = decoder.Decode(sr); beatmap.BeatmapInfo.Path = name; beatmap.BeatmapInfo.Hash = ms.ComputeSHA2Hash(); beatmap.BeatmapInfo.MD5Hash = ms.ComputeMD5Hash(); // ensure we have the same online set ID as the set itself. beatmap.BeatmapInfo.OnlineBeatmapSetID = model.OnlineBeatmapSetID; beatmap.BeatmapInfo.Metadata.OnlineBeatmapSetID = model.OnlineBeatmapSetID; // 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; } RulesetInfo ruleset = rulesets.GetRuleset(beatmap.BeatmapInfo.RulesetID); beatmap.BeatmapInfo.Ruleset = ruleset; if (ruleset != null) { // TODO: this should be done in a better place once we actually need to dynamically update it. var converted = new DummyConversionBeatmap(beatmap).GetPlayableBeatmap(ruleset); beatmap.BeatmapInfo.StarDifficulty = ruleset.CreateInstance().CreateDifficultyCalculator(converted).Calculate(); } else { beatmap.BeatmapInfo.StarDifficulty = 0; } beatmapInfos.Add(beatmap.BeatmapInfo); } } return(beatmapInfos); }
/// <summary> /// Create all required <see cref="BeatmapInfo"/>s for the provided archive. /// </summary> private List <BeatmapInfo> createBeatmapDifficulties(ArchiveReader reader) { var beatmapInfos = new List <BeatmapInfo>(); foreach (var name in reader.Filenames.Where(f => f.EndsWith(".osu"))) { using (var raw = reader.GetStream(name)) using (var ms = new MemoryStream()) //we need a memory stream so we can seek and shit using (var sr = new StreamReader(ms)) { raw.CopyTo(ms); ms.Position = 0; var decoder = Decoder.GetDecoder <Beatmap>(sr); IBeatmap beatmap = decoder.Decode(sr); beatmap.BeatmapInfo.Path = name; beatmap.BeatmapInfo.Hash = ms.ComputeSHA2Hash(); beatmap.BeatmapInfo.MD5Hash = ms.ComputeMD5Hash(); RulesetInfo ruleset = rulesets.GetRuleset(beatmap.BeatmapInfo.RulesetID); beatmap.BeatmapInfo.Ruleset = ruleset; if (ruleset != null) { // TODO: this should be done in a better place once we actually need to dynamically update it. var converted = new DummyConversionBeatmap(beatmap).GetPlayableBeatmap(ruleset); beatmap.BeatmapInfo.StarDifficulty = ruleset.CreateInstance().CreateDifficultyCalculator(converted).Calculate(); } else { beatmap.BeatmapInfo.StarDifficulty = 0; } beatmapInfos.Add(beatmap.BeatmapInfo); } } return(beatmapInfos); }