2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-07 12:59:30 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-06 17:56:20 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2016-11-05 19:00:14 +08:00
|
|
|
|
using osu.Framework.IO.Stores;
|
2016-10-05 04:29:08 +08:00
|
|
|
|
|
2018-02-15 11:56:22 +08:00
|
|
|
|
namespace osu.Game.IO.Archives
|
2016-10-14 11:33:58 +08:00
|
|
|
|
{
|
2016-11-05 19:00:14 +08:00
|
|
|
|
public abstract class ArchiveReader : IDisposable, IResourceStore<byte[]>
|
2016-10-14 11:33:58 +08:00
|
|
|
|
{
|
2017-02-09 22:09:48 +08:00
|
|
|
|
/// <summary>
|
2016-10-14 11:33:58 +08:00
|
|
|
|
/// Opens a stream for reading a specific file from this archive.
|
|
|
|
|
/// </summary>
|
2016-11-05 19:00:14 +08:00
|
|
|
|
public abstract Stream GetStream(string name);
|
2016-10-10 21:26:34 +08:00
|
|
|
|
|
2016-10-14 11:33:58 +08:00
|
|
|
|
public abstract void Dispose();
|
2016-11-05 19:00:14 +08:00
|
|
|
|
|
2018-02-15 09:20:23 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The name of this archive (usually the containing filename).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly string Name;
|
|
|
|
|
|
|
|
|
|
protected ArchiveReader(string name)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-26 19:22:02 +08:00
|
|
|
|
public abstract IEnumerable<string> Filenames { get; }
|
|
|
|
|
|
2016-11-05 19:00:14 +08:00
|
|
|
|
public virtual byte[] Get(string name)
|
|
|
|
|
{
|
|
|
|
|
using (Stream input = GetStream(name))
|
|
|
|
|
{
|
|
|
|
|
if (input == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2017-05-08 19:41:22 +08:00
|
|
|
|
byte[] buffer = new byte[input.Length];
|
|
|
|
|
input.Read(buffer, 0, buffer.Length);
|
|
|
|
|
return buffer;
|
2016-11-05 19:00:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-23 15:26:51 +08:00
|
|
|
|
|
|
|
|
|
public abstract Stream GetUnderlyingStream();
|
2016-10-14 11:33:58 +08:00
|
|
|
|
}
|
2018-01-05 19:21:19 +08:00
|
|
|
|
}
|