mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 16:25:32 +08:00
ba10c3a8db
This reverts commit6f20473e65
, reversing changes made toc76a495d3d
.
75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using osu.Framework.IO.Stores;
|
|
using osu.Framework.Platform;
|
|
using osu.Game.Database;
|
|
|
|
namespace osu.Game.Beatmaps.IO
|
|
{
|
|
public abstract class ArchiveReader : IDisposable, IResourceStore<byte[]>
|
|
{
|
|
private class Reader
|
|
{
|
|
public Func<Storage, string, bool> Test { get; set; }
|
|
public Type Type { get; set; }
|
|
}
|
|
|
|
private static List<Reader> readers { get; } = new List<Reader>();
|
|
|
|
public static ArchiveReader GetReader(Storage storage, string path)
|
|
{
|
|
foreach (var reader in readers)
|
|
{
|
|
if (reader.Test(storage, path))
|
|
return (ArchiveReader)Activator.CreateInstance(reader.Type, storage.GetStream(path));
|
|
}
|
|
throw new IOException(@"Unknown file format");
|
|
}
|
|
|
|
protected static void AddReader<T>(Func<Storage, string, bool> test) where T : ArchiveReader
|
|
{
|
|
readers.Add(new Reader { Test = test, Type = typeof(T) });
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reads the beatmap metadata from this archive.
|
|
/// </summary>
|
|
public abstract BeatmapMetadata ReadMetadata();
|
|
|
|
/// <summary>
|
|
/// Gets a list of beatmap file names.
|
|
/// </summary>
|
|
public string[] BeatmapFilenames { get; protected set; }
|
|
|
|
/// <summary>
|
|
/// The storyboard filename. Null if no storyboard is present.
|
|
/// </summary>
|
|
public string StoryboardFilename { get; protected set; }
|
|
|
|
/// <summary>
|
|
/// Opens a stream for reading a specific file from this archive.
|
|
/// </summary>
|
|
public abstract Stream GetStream(string name);
|
|
|
|
public abstract void Dispose();
|
|
|
|
public virtual byte[] Get(string name)
|
|
{
|
|
using (Stream input = GetStream(name))
|
|
{
|
|
if (input == null)
|
|
return null;
|
|
|
|
using (MemoryStream ms = new MemoryStream())
|
|
{
|
|
input.CopyTo(ms);
|
|
return ms.ToArray();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |