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

58 lines
1.7 KiB
C#
Raw Normal View History

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
{
/// <summary>
/// Reads an extracted legacy beatmap from disk.
/// </summary>
public class LegacyFilesystemReader : ArchiveReader
{
static LegacyFilesystemReader()
{
AddReader<LegacyFilesystemReader>((storage, path) => Directory.Exists(path));
}
2016-10-10 18:00:33 +00:00
private string basePath { get; set; }
private string[] beatmaps { get; set; }
private Beatmap firstMap { get; set; }
public LegacyFilesystemReader(string path)
{
2016-10-10 18:00:33 +00:00
basePath = path;
2016-10-12 17:36:10 +00:00
beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray();
2016-10-10 18:00:33 +00:00
if (beatmaps.Length == 0)
2016-10-12 17:36:10 +00:00
throw new FileNotFoundException(@"This directory contains no beatmaps");
2016-10-10 18:00:33 +00:00
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
{
var decoder = BeatmapDecoder.GetDecoder(stream);
2016-10-13 14:29:30 +00:00
firstMap = new Beatmap();
decoder.Decode(stream, firstMap);
}
}
public override string[] ReadBeatmaps()
{
2016-10-10 18:00:33 +00:00
return beatmaps;
}
public override Stream ReadFile(string name)
{
2016-10-10 18:00:33 +00:00
return File.OpenRead(Path.Combine(basePath, name));
}
public override BeatmapMetadata ReadMetadata()
{
2016-10-10 18:00:33 +00:00
return firstMap.Metadata;
}
public override void Dispose()
{
// no-op
} }
}