Revert "Merge pull request #441 from tacchinotacchi/archive-reader"

This reverts commit 6f20473e65, reversing
changes made to c76a495d3d.
This commit is contained in:
Dean Herbert
2017-03-14 11:46:34 +09:00
parent 29eeebefb0
commit ba10c3a8db
10 changed files with 37 additions and 68 deletions

View File

@ -0,0 +1,75 @@
// 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();
}
}
}
}
}

View File

@ -1,44 +0,0 @@
// 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 osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Game.Database;
using osu.Game.IO;
namespace osu.Game.Beatmaps.IO
{
public abstract class BeatmapArchiveReader : ArchiveReader
{
public const string OSZ_EXTENSION = @".osz";
public static BeatmapArchiveReader GetBeatmapArchiveReader(Storage storage, string path)
{
try
{
return (BeatmapArchiveReader)GetReader(storage, path);
}
catch (InvalidCastException e)
{
Logger.Error(e, "A tricky " + $@"{nameof(ArchiveReader)}" + " instance passed the test to be a " + $@"{nameof(BeatmapArchiveReader)}" + ", but it's really not");
throw;
}
}
/// <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; }
}
}

View File

@ -9,14 +9,14 @@ using osu.Game.Database;
namespace osu.Game.Beatmaps.IO
{
public sealed class OszArchiveReader : BeatmapArchiveReader
public sealed class OszArchiveReader : ArchiveReader
{
public static void Register()
{
AddReader<OszArchiveReader>((storage, path) =>
{
using (var stream = storage.GetStream(path))
return Path.GetExtension(path) == OSZ_EXTENSION && ZipFile.IsZipFile(stream, false);
return ZipFile.IsZipFile(stream, false);
});
OsuLegacyDecoder.Register();
}

View File

@ -32,7 +32,7 @@ namespace osu.Game.Beatmaps
public readonly bool WithStoryboard;
protected abstract BeatmapArchiveReader GetReader();
protected abstract ArchiveReader GetReader();
protected WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, bool withStoryboard = false)
{
@ -100,7 +100,7 @@ namespace osu.Game.Beatmaps
set { lock (beatmapLock) beatmap = value; }
}
private BeatmapArchiveReader trackReader;
private ArchiveReader trackReader;
private Track track;
private object trackLock = new object();
public Track Track