0.2.0-dev Download ZIP
35 lines ·1.0 KB Raw
| 1 | using EvilEngine.Mounts; |
| 2 | |
| 3 | namespace EvilEngine.Adapters.Gma; |
| 4 | |
| 5 | public sealed class GmaContainer : IIndexedContainer |
| 6 | { |
| 7 | public string Id => "gma"; |
| 8 | |
| 9 | public bool Recognises(IFileSource parent, VirtualPath path) |
| 10 | { |
| 11 | if (!parent.TryOpen(path, out var stream)) |
| 12 | return false; |
| 13 | using (stream) |
| 14 | { |
| 15 | Span<byte> head = stackalloc byte[4]; |
| 16 | return stream.ReadAtLeast(head, 4, false) == 4 && head.SequenceEqual(GmaArchive.Signature); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | public byte[] ReadIndex(IFileSource parent, VirtualPath path) |
| 21 | { |
| 22 | using var stream = parent.Open(path); |
| 23 | var archive = GmaArchive.Read(stream, $"{parent.Location}/{path}"); |
| 24 | var index = new byte[archive.DataOffset]; |
| 25 | stream.Position = 0; |
| 26 | stream.ReadExactly(index); |
| 27 | return index; |
| 28 | } |
| 29 | |
| 30 | public IFileSource Open(IFileSource parent, VirtualPath path) |
| 31 | { |
| 32 | using var stream = parent.Open(path); |
| 33 | return new GmaSource(parent, path, GmaArchive.Read(stream, $"{parent.Location}/{path}")); |
| 34 | } |
| 35 | } |