Skip to content

Class VirtualFileSystem

Namespace: Apogee.Content.FileSystem
Assembly: Apogee.Content.dll

The engine's view of its files: res:// (the game's content, from folders and packs), user:// (what the player's machine keeps: saves, settings, mods) and mod://<id>/ (a mod's own files), each made of mounted s. A path is looked up in every source mounted at a prefix of it, the one mounted last first, so that a patch pack or a mod's folder overrides what is under it; a source can also a file. Listings are the union of the sources, sorted ordinally. Only a writable source takes writes, and a path that is not valid (see ) is refused, so a script cannot name anything outside its mounts. Paths are case-sensitive, even on a file system that is not: write them as they are on disk.

public sealed class VirtualFileSystem

Inheritance

object ← VirtualFileSystem

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Properties

Mounts

The mounts in the order they were added; later ones override earlier ones.

public IReadOnlyList<Mount> Mounts { get; }

Property Value

IReadOnlyList<Mount>

Methods

CanWrite(string)

Whether a write to path would be accepted: the path is valid and the mount that holds it takes writes. Nothing is written.

public bool CanWrite(string path)

Parameters

path string

Returns

bool

CreateDirectory(string)

public void CreateDirectory(string path)

Parameters

path string

DefaultUserDirectory(string, string)

The folder the player's files of a game go in: <local application data>/<organization>/<game> (~/.local/share on Linux, AppData/Local on Windows, ~/Library/Application Support on macOS).

public static string DefaultUserDirectory(string organization, string game)

Parameters

organization string

game string

Returns

string

Delete(string)

public void Delete(string path)

Parameters

path string

DirectoryExists(string)

public bool DirectoryExists(string path)

Parameters

path string

Returns

bool

EnumerateDirectories(string)

The folders directly inside directory, as full paths, sorted.

public List<string> EnumerateDirectories(string directory)

Parameters

directory string

Returns

List<string>

EnumerateFiles(string, string, bool, int, int)

The files directly in directory (or under it with recursive) whose name matches pattern (* and ?), as full paths, sorted.

public List<string> EnumerateFiles(string directory, string pattern = "*", bool recursive = false, int maxDepth = 2147483647, int maxDirectories = 2147483647)

Parameters

directory string

The folder to list.

pattern string

The names to keep.

recursive bool

Also list the folders below.

maxDepth int

With recursive: the deepest folder to enter (the folder itself is level 0). A link that points back at a folder above it makes a tree without end; a caller that does not trust its folders gives a limit.

maxDirectories int

With recursive: the most folders to enter. Two links back to the same folder make a tree that grows by a power of two for each level, which a depth limit alone does not stop.

Returns

List<string>

Exceptions

VfsException

A limit was passed.

Exists(string)

public bool Exists(string path)

Parameters

path string

Returns

bool

FileExists(string)

public bool FileExists(string path)

Parameters

path string

Returns

bool

KindOf(string)

What is at path: a file, a directory (also the root of a scheme, and the folders above a mount), or . A path that is not valid is None.

public FileKind KindOf(string path)

Parameters

path string

Returns

FileKind

Mount(string, IFileSource)

Mounts source at prefix, over what is mounted there already.

public void Mount(string prefix, IFileSource source)

Parameters

prefix string

source IFileSource

Move(string, string)

Moves the file at from to to, which must have no file or folder yet; the folders above it are made. Inside one source (a game folder) it is a rename; between two sources it is a copy and then a delete. Both paths have to be writable.

public void Move(string from, string to)

Parameters

from string

to string

Exceptions

FileNotFoundException

There is no file at from.

IOException

Something is already at to.

UnauthorizedAccessException

One of the paths is not in a writable source.

OpenRead(string)

public Stream OpenRead(string path)

Parameters

path string

Returns

Stream

ReadAllBytes(string)

public byte[] ReadAllBytes(string path)

Parameters

path string

Returns

byte[]

Exceptions

FileNotFoundException

No source has the file.

VfsException

The path is not valid.

ReadAllText(string)

The file as UTF-8 text, without a byte order mark.

public string ReadAllText(string path)

Parameters

path string

Returns

string

TryGetPhysicalPath(string)

The path of the file in the real file system, when the source that has it is a folder: for watching it, or for a library that only takes a path. Null otherwise.

public string? TryGetPhysicalPath(string path)

Parameters

path string

Returns

string?

Unmount(IFileSource)

Takes source out of every prefix it is mounted at. The source is not disposed.

public bool Unmount(IFileSource source)

Parameters

source IFileSource

Returns

bool

WriteAllBytes(string, ReadOnlySpan<byte>)

public void WriteAllBytes(string path, ReadOnlySpan<byte> bytes)

Parameters

path string

bytes ReadOnlySpan<byte>

Exceptions

UnauthorizedAccessException

The path is not in a writable source (only user:// is one by default).

WriteAllText(string, string)

public void WriteAllText(string path, string text)

Parameters

path string

text string