1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:07:52 +08:00

Inline all archive reader pathing

This commit is contained in:
Dean Herbert 2023-09-14 13:38:23 +09:00
parent 541cd972e1
commit 364094fcf2

View File

@ -47,7 +47,16 @@ namespace osu.Game.Database
public ArchiveReader GetReader()
{
if (Stream == null)
return getReaderFromPath(Path);
{
if (ZipUtils.IsZipArchive(Path))
return new ZipArchiveReader(File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.Read), System.IO.Path.GetFileName(Path));
if (Directory.Exists(Path))
return new DirectoryArchiveReader(Path);
if (File.Exists(Path))
return new SingleFileArchiveReader(Path);
throw new InvalidFormatException($"{Path} is not a valid archive");
}
if (Stream is MemoryStream memoryStream)
{
@ -70,23 +79,6 @@ namespace osu.Game.Database
File.Delete(Path);
}
/// <summary>
/// Creates an <see cref="ArchiveReader"/> from a valid storage path.
/// </summary>
/// <param name="path">A file or folder path resolving the archive content.</param>
/// <returns>A reader giving access to the archive's content.</returns>
private ArchiveReader getReaderFromPath(string path)
{
if (ZipUtils.IsZipArchive(path))
return new ZipArchiveReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read), System.IO.Path.GetFileName(path));
if (Directory.Exists(path))
return new DirectoryArchiveReader(path);
if (File.Exists(path))
return new SingleFileArchiveReader(path);
throw new InvalidFormatException($"{path} is not a valid archive");
}
public override string ToString() => System.IO.Path.GetFileName(Path);
}
}