2016-10-04 20:29:08 +00:00
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string BasePath { get; set; }
|
2016-10-04 21:08:43 +00:00
|
|
|
|
private string[] Beatmaps { get; set; }
|
2016-10-04 20:29:08 +00:00
|
|
|
|
private Beatmap FirstMap { get; set; }
|
|
|
|
|
|
|
|
|
|
public LegacyFilesystemReader(string path)
|
|
|
|
|
{
|
|
|
|
|
BasePath = path;
|
2016-10-04 21:08:43 +00:00
|
|
|
|
Beatmaps = Directory.GetFiles(BasePath, "*.osu").Select(f => Path.GetFileName(f)).ToArray();
|
|
|
|
|
if (Beatmaps.Length == 0)
|
2016-10-04 20:29:08 +00:00
|
|
|
|
throw new FileNotFoundException("This directory contains no beatmaps");
|
2016-10-04 21:08:43 +00:00
|
|
|
|
using (var stream = new StreamReader(ReadFile(Beatmaps[0])))
|
2016-10-04 20:29:08 +00:00
|
|
|
|
{
|
|
|
|
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
|
|
|
|
FirstMap = decoder.Decode(stream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string[] ReadBeatmaps()
|
|
|
|
|
{
|
2016-10-04 21:08:43 +00:00
|
|
|
|
return Beatmaps;
|
2016-10-04 20:29:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Stream ReadFile(string name)
|
|
|
|
|
{
|
|
|
|
|
return File.OpenRead(Path.Combine(BasePath, name));
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 17:50:34 +00:00
|
|
|
|
public override BeatmapMetadata ReadMetadata()
|
2016-10-04 20:29:08 +00:00
|
|
|
|
{
|
|
|
|
|
return FirstMap.Metadata;
|
|
|
|
|
}
}
|
|
|
|
|
}
|