Skip to content
EvilEngine.Mounts

VirtualPath record struct

public readonly record struct VirtualPath : IComparable<VirtualPath>

A path inside an IFileSource: relative to the source’s root, with forward slashes, no leading slash and no . or ... It can’t name a drive or leave its tree, so a path read from a game’s files is safe to follow. It’s a small value type, and a string converts to one implicitly, so "id1/PAK0.PAK" works wherever a path is asked for.

A path keeps the case it was written in. Whether two paths are the same file depends on the source’s CaseRule, so compare them through a Comparer, never by their text alone.

Assembly
EvilEngine.Mounts
Commit
4ff877b1

Members

Separator field

public const char Separator = '/'

/.

Root property

public static VirtualPath Root { get; }

The source’s root, the empty path. It’s also default.

Value property

public string Value { get; }

The path as text, empty for Root.

IsRoot property

public bool IsRoot { get; }

Whether this is Root.

Name property

public string Name { get; }

The last segment, as in e1m1.bsp for id1/maps/e1m1.bsp.

Extension property

public string Extension { get; }

The text after the last . in Name, without the dot, or empty when there’s none. A name starting with its only dot, like .gitignore, has none.

Parent property

public VirtualPath Parent { get; }

The folder holding this path, Root for a path at the top.

WithoutExtension property

public VirtualPath WithoutExtension { get; }

The path with its Extension and its dot taken off.

CompareTo method

public int CompareTo(VirtualPath other)

Orders paths by their text, ordinally, whatever the case rule.

Parse method

public static VirtualPath Parse(string path)

Makes a path from text. Backslashes and doubled slashes are cleaned up and . segments dropped, so .\maps\\e1m1.bsp makes maps/e1m1.bsp. Throws ArgumentException when a segment is .. or holds a : or a null character.

TryParse method

public static bool TryParse(string path, out VirtualPath result)

Parse, returning false rather than throwing.

Join method

public VirtualPath Join(string relative)
public VirtualPath Join(VirtualPath relative)

Appends a relative path, as in "id1".Join("maps/e1m1.bsp"). Joining text parses it first, so it throws as Parse does.

TryRelativeTo method

public bool TryRelativeTo(VirtualPath directory, CaseRule caseRule, out VirtualPath relative)

Gets this path relative to directory, under a case rule, or returns false when it isn’t inside it. Everything is inside Root.

IsUnder method

public bool IsUnder(VirtualPath directory, CaseRule caseRule, bool recursive)

Whether this path is inside directory under a case rule: anywhere beneath it with recursive, or directly in it without.

Comparer method

public static StringComparer Comparer(CaseRule caseRule)

A StringComparer for paths’ Values under a case rule, for dictionaries and sets keyed by path. The Equals overload that takes a case rule compares two paths the same way.

Comparison method

public static StringComparison Comparison(CaseRule caseRule)

The StringComparison for a case rule, for comparing paths’ text yourself.