0.2.0-dev Download ZIP
26 lines ·846 B Raw
| 1 | using EvilEngine.Mounts; |
| 2 | |
| 3 | namespace EvilEngine.Adapters.UnityFs; |
| 4 | |
| 5 | public sealed class UnityFsContainer : IContainerAdapter |
| 6 | { |
| 7 | public string Id => "unityfs"; |
| 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[UnityFsArchive.Signature.Length]; |
| 16 | return stream.ReadAtLeast(head, head.Length, false) == head.Length && UnityFsArchive.IsSignature(head); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | public IFileSource Open(IFileSource parent, VirtualPath path) |
| 21 | { |
| 22 | var location = $"{parent.Location}/{path}"; |
| 23 | using var stream = parent.Open(path); |
| 24 | return new UnityFsSource(location, UnityFsArchive.Read(stream, location), () => parent.OpenAccess(path)); |
| 25 | } |
| 26 | } |