2017-02-07 04:59:30 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-06 09:56:20 +00:00
|
|
|
|
|
2016-10-04 20:29:08 +00:00
|
|
|
|
using System.IO;
|
2016-10-04 21:08:43 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Ionic.Zip;
|
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
2016-10-04 20:29:08 +00:00
|
|
|
|
|
2016-10-14 03:33:58 +00:00
|
|
|
|
namespace osu.Game.Beatmaps.IO
|
|
|
|
|
{
|
2017-03-14 02:46:34 +00:00
|
|
|
|
public sealed class OszArchiveReader : ArchiveReader
|
2016-10-14 03:33:58 +00:00
|
|
|
|
{
|
|
|
|
|
public static void Register()
|
|
|
|
|
{
|
2016-10-04 20:29:08 +00:00
|
|
|
|
AddReader<OszArchiveReader>((storage, path) =>
|
2016-10-14 03:33:58 +00:00
|
|
|
|
{
|
|
|
|
|
using (var stream = storage.GetStream(path))
|
2017-03-14 02:46:34 +00:00
|
|
|
|
return ZipFile.IsZipFile(stream, false);
|
2016-10-14 03:33:58 +00:00
|
|
|
|
});
|
|
|
|
|
OsuLegacyDecoder.Register();
|
|
|
|
|
}
|
2016-10-19 15:00:11 +00:00
|
|
|
|
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly Stream archiveStream;
|
|
|
|
|
private readonly ZipFile archive;
|
2017-02-09 14:09:48 +00:00
|
|
|
|
|
2016-10-14 03:33:58 +00:00
|
|
|
|
public OszArchiveReader(Stream archiveStream)
|
|
|
|
|
{
|
2016-10-19 15:00:11 +00:00
|
|
|
|
this.archiveStream = archiveStream;
|
2016-10-14 03:33:58 +00:00
|
|
|
|
archive = ZipFile.Read(archiveStream);
|
2017-04-03 11:26:46 +00:00
|
|
|
|
|
|
|
|
|
BeatmapFilenames = archive.Entries.Where(e => e.FileName.EndsWith(@".osu")).Select(e => e.FileName).ToArray();
|
|
|
|
|
|
2017-02-13 09:30:47 +00:00
|
|
|
|
if (BeatmapFilenames.Length == 0)
|
2016-10-14 03:33:58 +00:00
|
|
|
|
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
2017-04-03 11:26:46 +00:00
|
|
|
|
|
|
|
|
|
StoryboardFilename = archive.Entries.Where(e => e.FileName.EndsWith(@".osb")).Select(e => e.FileName).FirstOrDefault();
|
2016-10-04 20:29:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-05 11:00:14 +00:00
|
|
|
|
public override Stream GetStream(string name)
|
2016-10-04 20:29:08 +00:00
|
|
|
|
{
|
2016-10-14 03:33:58 +00:00
|
|
|
|
ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name);
|
|
|
|
|
if (entry == null)
|
|
|
|
|
throw new FileNotFoundException();
|
2016-10-04 21:08:43 +00:00
|
|
|
|
return entry.OpenReader();
|
2016-10-04 20:29:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-18 17:35:01 +00:00
|
|
|
|
public override void Dispose()
|
2016-10-14 03:33:58 +00:00
|
|
|
|
{
|
|
|
|
|
archive.Dispose();
|
2016-10-19 15:00:11 +00:00
|
|
|
|
archiveStream.Dispose();
|
2016-10-10 13:26:34 +00:00
|
|
|
|
}
|
2016-10-14 03:33:58 +00:00
|
|
|
|
}
|
2016-10-04 20:29:08 +00:00
|
|
|
|
}
|