2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-07-26 11:22:02 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-02-15 03:56:22 +00:00
|
|
|
|
namespace osu.Game.IO.Archives
|
2017-07-26 11:22:02 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2023-09-14 04:36:07 +00:00
|
|
|
|
/// Reads an archive directly from a directory on disk.
|
2017-07-26 11:22:02 +00:00
|
|
|
|
/// </summary>
|
2023-09-14 04:36:07 +00:00
|
|
|
|
public class DirectoryArchiveReader : ArchiveReader
|
2017-07-26 11:22:02 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly string path;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-09-14 04:36:07 +00:00
|
|
|
|
public DirectoryArchiveReader(string path)
|
2018-06-05 02:28:51 +00:00
|
|
|
|
: base(Path.GetFileName(path))
|
2017-07-26 11:22:02 +00:00
|
|
|
|
{
|
2018-06-06 11:55:42 +00:00
|
|
|
|
// re-get full path to standardise with Directory.GetFiles return values below.
|
|
|
|
|
this.path = Path.GetFullPath(path);
|
2017-07-26 11:22:02 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-08-18 08:56:43 +00:00
|
|
|
|
public override Stream GetStream(string name) => File.OpenRead(GetFullPath(name));
|
2023-08-16 22:49:48 +00:00
|
|
|
|
|
2023-08-18 08:56:43 +00:00
|
|
|
|
public string GetFullPath(string filename) => Path.Combine(path, filename);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-07-26 11:22:02 +00:00
|
|
|
|
public override void Dispose()
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-06-05 02:28:51 +00:00
|
|
|
|
public override IEnumerable<string> Filenames => Directory.GetFiles(path, "*", SearchOption.AllDirectories).Select(f => f.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar)).ToArray();
|
2017-07-26 11:22:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|