IContainerAdapter interface
public interface IContainerAdapter Opens one archive or disc image format, such as id’s PAK, Valve’s VPK, ZIP or an ISO 9660 image, as a read-only IFileSource. An adapter registers one with AddContainer.
The mount core uses containers in three places. A pointer to a file, like a disc image, opens through the first container that recognises it. When no game recognises a folder, each file at its top level that a container recognises is opened and probed in turn, up to three levels deep. And a game’s mount plan can name a container inside its tree as a layer, which opens the first time something reads from it.
A container can also implement IIndexedContainer, which adds ReadIndex for the archive’s own directory bytes, so a mount can fingerprint the archive by its index instead of its data.
The pak adapter’s container:
public sealed class PakContainer : IIndexedContainer
{
public string Id => "pak";
public bool Recognises(IFileSource parent, VirtualPath path)
{
if (!parent.TryOpen(path, out var stream))
return false;
using (stream)
{
Span<byte> head = stackalloc byte[4];
return stream.ReadAtLeast(head, 4, false) == 4 && head.SequenceEqual(PakArchive.Signature);
}
}
public byte[] ReadIndex(IFileSource parent, VirtualPath path)
{
using var access = parent.OpenAccess(path);
return PakArchive.ReadIndex(access, $"{parent.Location}/{path}");
}
public IFileSource Open(IFileSource parent, VirtualPath path)
{
return OpenPak(parent, path);
}
}
- Assembly
- EvilEngine.Mounts
- Commit
- 4ff877b1