2016-10-14 11:33:58 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
|
|
|
|
using osu.Game.Beatmaps.IO;
|
|
|
|
|
using osu.Game.Beatmaps;
|
2016-10-19 01:35:01 +08:00
|
|
|
|
using osu.Game.Database;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
|
2016-10-14 11:33:58 +08:00
|
|
|
|
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; }
|
|
|
|
|
private string[] beatmaps { get; set; }
|
2016-10-13 22:15:08 +08:00
|
|
|
|
private Beatmap firstMap { get; set; }
|
2016-10-14 11:33:58 +08:00
|
|
|
|
|
|
|
|
|
public LegacyFilesystemReader(string path)
|
|
|
|
|
{
|
|
|
|
|
basePath = path;
|
|
|
|
|
beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray();
|
|
|
|
|
if (beatmaps.Length == 0)
|
|
|
|
|
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
2016-11-05 19:00:14 +08:00
|
|
|
|
using (var stream = new StreamReader(GetStream(beatmaps[0])))
|
2016-10-14 11:33:58 +08:00
|
|
|
|
{
|
|
|
|
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
2016-10-19 01:35:01 +08:00
|
|
|
|
firstMap = decoder.Decode(stream);
|
2016-10-14 11:33:58 +08:00
|
|
|
|
}
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string[] ReadBeatmaps()
|
|
|
|
|
{
|
2016-10-11 02:00:33 +08:00
|
|
|
|
return beatmaps;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-05 19:00:14 +08:00
|
|
|
|
public override Stream GetStream(string name)
|
2016-10-05 04:29:08 +08:00
|
|
|
|
{
|
2016-10-11 02:00:33 +08:00
|
|
|
|
return File.OpenRead(Path.Combine(basePath, name));
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 01:50:34 +08:00
|
|
|
|
public override BeatmapMetadata ReadMetadata()
|
2016-10-05 04:29:08 +08:00
|
|
|
|
{
|
2016-10-19 01:35:01 +08:00
|
|
|
|
return firstMap.BeatmapInfo.Metadata;
|
2016-10-14 11:33:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-10 21:26:34 +08:00
|
|
|
|
public override void Dispose()
|
2016-10-14 11:33:58 +08:00
|
|
|
|
{
|
2016-10-10 21:26:34 +08:00
|
|
|
|
// no-op
|
2016-10-19 01:35:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-05 04:29:08 +08:00
|
|
|
|
}
|