/// <summary> /// Create all required <see cref="BeatmapInfo"/>s for the provided archive. /// </summary> private List <BeatmapInfo> createBeatmapDifficulties(List <BeatmapSetFileInfo> files) { var beatmapInfos = new List <BeatmapInfo>(); foreach (var file in files.Where(f => f.Filename.EndsWith(".osu"))) { using (var raw = Files.Store.GetStream(file.FileInfo.StoragePath)) using (var ms = new MemoryStream()) //we need a memory stream so we can seek using (var sr = new LineBufferedReader(ms)) { raw.CopyTo(ms); ms.Position = 0; var decoder = Decoder.GetDecoder <Beatmap>(sr); IBeatmap beatmap = decoder.Decode(sr); string hash = ms.ComputeSHA2Hash(); if (beatmapInfos.Any(b => b.Hash == hash)) { continue; } beatmap.BeatmapInfo.Path = file.Filename; beatmap.BeatmapInfo.Hash = hash; beatmap.BeatmapInfo.MD5Hash = ms.ComputeMD5Hash(); var ruleset = rulesets.GetRuleset(beatmap.BeatmapInfo.RulesetID); beatmap.BeatmapInfo.Ruleset = ruleset; // TODO: this should be done in a better place once we actually need to dynamically update it. beatmap.BeatmapInfo.StarDifficulty = ruleset?.CreateInstance().CreateDifficultyCalculator(new DummyConversionBeatmap(beatmap)).Calculate().StarRating ?? 0; beatmap.BeatmapInfo.Length = calculateLength(beatmap); beatmap.BeatmapInfo.BPM = beatmap.ControlPointInfo.BPMMode; beatmapInfos.Add(beatmap.BeatmapInfo); } } return(beatmapInfos); }
protected override BeatmapSetInfo CreateModel(ArchiveReader reader) { // let's make sure there are actually .osu files to import. string mapName = reader.Filenames.FirstOrDefault(f => f.EndsWith(".osu", StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(mapName)) { Logger.Log($"No beatmap files found in the beatmap archive ({reader.Name}).", LoggingTarget.Database); return(null); } Beatmap beatmap; using (var stream = new LineBufferedReader(reader.GetStream(mapName))) beatmap = Decoder.GetDecoder <Beatmap>(stream).Decode(stream); return(new BeatmapSetInfo { OnlineID = beatmap.BeatmapInfo.BeatmapSet?.OnlineID, Metadata = beatmap.Metadata, DateAdded = DateTimeOffset.UtcNow }); }
private IBeatmap decode(byte[] state) { using (var stream = new MemoryStream(state)) using (var reader = new LineBufferedReader(stream)) return(Decoder.GetDecoder <Beatmap>(reader).Decode(reader)); }
private LoaderWorkingBeatmap(LineBufferedReader reader) : this(Decoder.GetDecoder <Beatmap>(reader).Decode(reader)) { }