From bc69aa1455825591943f20459895701c9ae0e155 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 4 Oct 2016 16:29:08 -0400 Subject: [PATCH] Initial support code for beatmap loading --- .../Beatmaps/IO/LegacyFilesystemReader.cs | 51 +++++++++++++++++++ osu.Desktop/osu.Desktop.csproj | 5 ++ osu.Game/Beatmaps/Beatmap.cs | 9 ++-- osu.Game/Beatmaps/BeatmapSet.cs | 2 + osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 25 +++++++++ osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 34 +++++++++++++ osu.Game/Beatmaps/IO/ArchiveReader.cs | 46 +++++++++++++++++ osu.Game/Beatmaps/IO/OszArchiveReader.cs | 42 +++++++++++++++ osu.Game/Beatmaps/Metadata.cs | 16 +++++- osu.Game/Database/BeatmapDatabase.cs | 44 ++++++++++++++++ osu.Game/osu.Game.csproj | 6 +++ 11 files changed, 274 insertions(+), 6 deletions(-) create mode 100644 osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs create mode 100644 osu.Game/Beatmaps/Formats/BeatmapDecoder.cs create mode 100644 osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs create mode 100644 osu.Game/Beatmaps/IO/ArchiveReader.cs create mode 100644 osu.Game/Beatmaps/IO/OszArchiveReader.cs diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs new file mode 100644 index 0000000000..711607b9df --- /dev/null +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -0,0 +1,51 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using osu.Game.Beatmaps.Formats; +using osu.Game.Beatmaps.IO; +using osu.Game.Beatmaps; + +namespace osu.Desktop.Beatmaps.IO +{ + /// + /// Reads an extracted legacy beatmap from disk. + /// + public class LegacyFilesystemReader : ArchiveReader + { + static LegacyFilesystemReader() + { + AddReader((storage, path) => Directory.Exists(path)); + } + + private string BasePath { get; set; } + private Beatmap FirstMap { get; set; } + + public LegacyFilesystemReader(string path) + { + BasePath = path; + var maps = ReadBeatmaps(); + if (maps.Length == 0) + throw new FileNotFoundException("This directory contains no beatmaps"); + using (var stream = new StreamReader(ReadFile(maps[0]))) + { + var decoder = BeatmapDecoder.GetDecoder(stream); + FirstMap = decoder.Decode(stream); + } + } + + public override string[] ReadBeatmaps() + { + return Directory.GetFiles(BasePath, "*.osu").Select(f => Path.GetFileName(f)).ToArray(); + } + + public override Stream ReadFile(string name) + { + return File.OpenRead(Path.Combine(BasePath, name)); + } + + public override Metadata ReadMetadata() + { + return FirstMap.Metadata; + } } +} \ No newline at end of file diff --git a/osu.Desktop/osu.Desktop.csproj b/osu.Desktop/osu.Desktop.csproj index 5553f12019..d8463dbc35 100644 --- a/osu.Desktop/osu.Desktop.csproj +++ b/osu.Desktop/osu.Desktop.csproj @@ -135,8 +135,13 @@ + + + + +