0.2.0-dev Download ZIP
25 lines ·712 B Raw
| 1 | using EvilEngine.Mounts; |
| 2 | |
| 3 | namespace EvilEngine.Adapters.Vpk; |
| 4 | |
| 5 | public sealed class VpkContainer : IContainerAdapter |
| 6 | { |
| 7 | public string Id => "vpk"; |
| 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 && VpkArchive.IsSignature(head); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | public IFileSource Open(IFileSource parent, VirtualPath path) |
| 21 | { |
| 22 | using var stream = parent.Open(path); |
| 23 | return new VpkSource(parent, path, VpkArchive.Read(stream, $"{parent.Location}/{path}")); |
| 24 | } |
| 25 | } |