1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Add LegacyFileArchiveReader

Treats files as "archives" for import.
This commit is contained in:
smoogipoo 2018-11-28 16:13:16 +09:00
parent 5fd6e6ca77
commit a783fdb501
2 changed files with 36 additions and 0 deletions

View File

@ -486,6 +486,8 @@ namespace osu.Game.Database
return new ZipArchiveReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read), Path.GetFileName(path));
if (Directory.Exists(path))
return new LegacyDirectoryArchiveReader(path);
if (File.Exists(path))
return new LegacyFileArchiveReader(path);
throw new InvalidFormatException($"{path} is not a valid archive");
}
}

View File

@ -0,0 +1,34 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.IO;
namespace osu.Game.IO.Archives
{
/// <summary>
/// Reads a file on disk as an archive.
/// Note: In this case, the file is not an extractable archive, use <see cref="ZipArchiveReader"/> instead.
/// </summary>
public class LegacyFileArchiveReader : ArchiveReader
{
private readonly string path;
public LegacyFileArchiveReader(string path)
: base(Path.GetFileName(path))
{
// re-get full path to standardise
this.path = Path.GetFullPath(path);
}
public override Stream GetStream(string name) => File.OpenRead(path);
public override void Dispose()
{
}
public override IEnumerable<string> Filenames => new[] { Name };
public override Stream GetUnderlyingStream() => null;
}
}