Skip to content
EvilEngine.Mounts

IFileSource interface

public interface IFileSource

A read-only tree of files addressed by VirtualPath. Every folder, archive, disc image and whole mount the engine reads is one, and it’s what game adapters probe and containers return.

Paths are relative to the source’s root, with forward slashes and no leading slash. VirtualPath.Root is the root itself, and VirtualPath refuses .. and drive letters, so a path can’t leave its tree. Sources stack: a mount is a LayeredSource over its layers, a SubtreeSource shows one folder of another source as its root, and a PlacedSource puts a source at a folder. The engine has FolderSource for host folders and MemorySource for files held in memory, and IndexedSource is a base for archive readers.

An implementation needs Location, CaseRule, Exists, TryOpen and Enumerate. The rest have default bodies built on those, so override them when your format can answer faster. Extension methods add EnumerateAll, and Open, OpenAccess, ReadAllBytes and ReadAllText, which throw FileNotFoundException where the Try forms return false.

Assembly
EvilEngine.Mounts
Commit
4ff877b1

Members

Location property

string Location { get; }

Where the source came from, for messages: a host path for a folder, or the parent’s location and the archive’s path inside it for an archive, as in /games/Quake/id1/PAK0.PAK. Make it readable.

CaseRule property

CaseRule CaseRule { get; }

CaseRule.Sensitive or CaseRule.Insensitive: whether maps/E1M1.bsp and maps/e1m1.bsp are the same file here. Match the format, or the platform for loose folders. The mount core probes host folders case-insensitively, and Quake’s mount plan takes the pc platform’s rule, which is insensitive.

Exists method

bool Exists(VirtualPath path)

Returns whether a file is at path. Folders don’t count.

TryOpen method

bool TryOpen(VirtualPath path, out Stream? stream)

Opens the file at path as a readable Stream, or returns false if there’s no file there. The caller disposes the stream. A file that’s listed but can’t be read throws rather than returning false, so a damaged file is never taken for a missing one: MountException for an entry its archive can’t give, such as one that’s encrypted, past the end of its archive or bigger than its compression can make, and the host’s IOException or UnauthorizedAccessException for a loose file.

Enumerate method

IEnumerable<FileEntry> Enumerate(VirtualPath directory, bool recursive)

Lists the files under directory, each as a FileEntry with its full path from the source’s root and its length in bytes. With recursive false it lists only the files directly in directory, and with it true every file at any depth. A directory with nothing in it, or that doesn’t exist, lists nothing.

The mount core lists every layer once to build a mount’s index, so this is the call to make quick.

TryOpenAccess method

bool TryOpenAccess(VirtualPath path, out IRandomAccess? access)

Opens the file at path for random access, reading at any offset without seeking, or returns false if it isn’t there. The default wraps TryOpen’s stream. Override it when the format can read at an offset directly, as archives that keep one shared handle per archive do, since many threads read files at once.

DirectoryExists method

bool DirectoryExists(VirtualPath directory)

Returns whether directory holds anything. The default says yes for the root and otherwise lists the directory recursively until it finds a file, so an empty folder counts as missing.

EnumerateRemoved method

IEnumerable<VirtualPath> EnumerateRemoved()

Paths this source deletes from the layers under it in a mount. A file listed here is hidden in every layer below this one, though not in this layer or the ones above it. The default is none. The Sims 4’s package reader uses it for the deletion records its packages carry.

EnumerateDirectories method

IEnumerable<VirtualPath> EnumerateDirectories(VirtualPath directory)

Lists the folders directly inside directory, as full paths from the root. The default works them out from a recursive Enumerate, so it only finds folders with a file somewhere under them.