mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 15:44:04 +09:00
Initial support code for beatmap loading
This commit is contained in:
51
osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs
Normal file
51
osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs
Normal file
@ -0,0 +1,51 @@
|
||||
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; }
|
||||
private Beatmap FirstMap { get; set; }
|
||||
|
||||
public LegacyFilesystemReader(string path)
|
||||
{
|
||||
BasePath = path;
|
||||
var maps = ReadBeatmaps();
|
||||
if (maps.Length == 0)
|
||||
throw new FileNotFoundException("This directory contains no beatmaps");
|
||||
using (var stream = new StreamReader(ReadFile(maps[0])))
|
||||
{
|
||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||
FirstMap = decoder.Decode(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public override string[] ReadBeatmaps()
|
||||
{
|
||||
return Directory.GetFiles(BasePath, "*.osu").Select(f => Path.GetFileName(f)).ToArray();
|
||||
}
|
||||
|
||||
public override Stream ReadFile(string name)
|
||||
{
|
||||
return File.OpenRead(Path.Combine(BasePath, name));
|
||||
}
|
||||
|
||||
public override Metadata ReadMetadata()
|
||||
{
|
||||
return FirstMap.Metadata;
|
||||
}
|
||||
}
|
@ -135,8 +135,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Beatmaps\IO\LegacyFilesystemReader.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Folder Include="Beatmaps\" />
|
||||
<Folder Include="Beatmaps\IO\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
Reference in New Issue
Block a user