mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Implement OszArchiveReader
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Ionic.Zip;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
|
||||
namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
@ -11,32 +14,48 @@ namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
using (var stream = storage.GetStream(path))
|
||||
{
|
||||
// TODO: detect if osz
|
||||
return false;
|
||||
if (!ZipFile.IsZipFile(stream, false))
|
||||
return false;
|
||||
using (ZipFile zip = ZipFile.Read(stream))
|
||||
return zip.Entries.Any(e => e.FileName.EndsWith(".osu"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Stream Archive { get; set; }
|
||||
private ZipFile Archive { get; set; }
|
||||
private string[] Beatmaps { get; set; }
|
||||
private Beatmap FirstMap { get; set; }
|
||||
|
||||
public OszArchiveReader(Stream archive)
|
||||
{
|
||||
Archive = archive;
|
||||
Archive = ZipFile.Read(archive);
|
||||
Beatmaps = Archive.Entries.Where(e => e.FileName.EndsWith(".osu"))
|
||||
.Select(e => e.FileName).ToArray();
|
||||
if (Beatmaps.Length == 0)
|
||||
throw new FileNotFoundException("This directory contains no beatmaps");
|
||||
using (var stream = new StreamReader(ReadFile(Beatmaps[0])))
|
||||
{
|
||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||
FirstMap = decoder.Decode(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public override string[] ReadBeatmaps()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Beatmaps;
|
||||
}
|
||||
|
||||
public override Stream ReadFile(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
ZipEntry entry = Archive.Entries.SingleOrDefault(e => e.FileName == name);
|
||||
if (entry == null)
|
||||
throw new FileNotFoundException();
|
||||
return entry.OpenReader();
|
||||
}
|
||||
|
||||
public override Metadata ReadMetadata()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return FirstMap.Metadata;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user