osu/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs

53 lines
1.8 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-12-06 09:56:20 +00:00
using System.IO;
using System.Linq;
using osu.Game.Beatmaps.Formats;
using osu.Game.Beatmaps.IO;
using osu.Game.Beatmaps;
2016-10-18 17:35:01 +00:00
using osu.Game.Database;
namespace osu.Desktop.Beatmaps.IO
{
/// <summary>
/// Reads an extracted legacy beatmap from disk.
/// </summary>
public class LegacyFilesystemReader : ArchiveReader
{
2016-11-16 02:53:10 +00:00
public static void Register() => AddReader<LegacyFilesystemReader>((storage, path) => Directory.Exists(path));
2016-11-14 18:08:02 +00:00
private string basePath { get; set; }
private Beatmap firstMap { get; set; }
public LegacyFilesystemReader(string path)
{
basePath = path;
BeatmapFilenames = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray();
if (BeatmapFilenames.Length == 0)
throw new FileNotFoundException(@"This directory contains no beatmaps");
StoryboardFilename = Directory.GetFiles(basePath, @"*.osb").Select(f => Path.GetFileName(f)).FirstOrDefault();
using (var stream = new StreamReader(GetStream(BeatmapFilenames[0])))
{
var decoder = BeatmapDecoder.GetDecoder(stream);
2016-10-18 17:35:01 +00:00
firstMap = decoder.Decode(stream);
}
}
2016-11-05 11:00:14 +00:00
public override Stream GetStream(string name)
{
2016-10-10 18:00:33 +00:00
return File.OpenRead(Path.Combine(basePath, name));
}
public override BeatmapMetadata ReadMetadata()
{
2016-10-18 17:35:01 +00:00
return firstMap.BeatmapInfo.Metadata;
}
2016-11-14 18:08:02 +00:00
public override void Dispose()
{
// no-op
2016-10-18 17:35:01 +00:00
}
}
2016-11-14 18:08:02 +00:00
}