2017-02-07 04:59:30 +00:00
|
|
|
|
// 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
|
|
|
|
|
2016-10-14 03:33:58 +00:00
|
|
|
|
using System.IO;
|
2016-10-04 20:29:08 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Game.Beatmaps.IO;
|
|
|
|
|
|
2016-10-14 03:33:58 +00:00
|
|
|
|
namespace osu.Desktop.Beatmaps.IO
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reads an extracted legacy beatmap from disk.
|
|
|
|
|
/// </summary>
|
2017-03-14 02:46:34 +00:00
|
|
|
|
public class LegacyFilesystemReader : ArchiveReader
|
2016-10-14 03:33:58 +00:00
|
|
|
|
{
|
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
|
|
|
|
|
2017-05-08 10:56:04 +00:00
|
|
|
|
private readonly string basePath;
|
2016-10-14 03:33:58 +00:00
|
|
|
|
|
|
|
|
|
public LegacyFilesystemReader(string path)
|
|
|
|
|
{
|
|
|
|
|
basePath = path;
|
2017-04-03 11:26:46 +00:00
|
|
|
|
|
2017-03-07 01:59:19 +00:00
|
|
|
|
BeatmapFilenames = Directory.GetFiles(basePath, @"*.osu").Select(Path.GetFileName).ToArray();
|
2017-04-03 11:26:46 +00:00
|
|
|
|
|
2017-02-13 09:30:47 +00:00
|
|
|
|
if (BeatmapFilenames.Length == 0)
|
2016-10-14 03:33:58 +00:00
|
|
|
|
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
2017-04-03 11:26:46 +00:00
|
|
|
|
|
2017-03-07 01:59:19 +00:00
|
|
|
|
StoryboardFilename = Directory.GetFiles(basePath, @"*.osb").Select(Path.GetFileName).FirstOrDefault();
|
2016-10-04 20:29:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-05 11:00:14 +00:00
|
|
|
|
public override Stream GetStream(string name)
|
2016-10-04 20:29:08 +00:00
|
|
|
|
{
|
2016-10-10 18:00:33 +00:00
|
|
|
|
return File.OpenRead(Path.Combine(basePath, name));
|
2016-10-04 20:29:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-10 13:26:34 +00:00
|
|
|
|
public override void Dispose()
|
2016-10-14 03:33:58 +00:00
|
|
|
|
{
|
2016-10-10 13:26:34 +00:00
|
|
|
|
// no-op
|
2016-10-18 17:35:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-14 18:08:02 +00:00
|
|
|
|
}
|