Skip to content

KernelAPI reference

Class ContentFolder

Namespace: MicroEngine.Core
Assembly: MicroEngine.dll
Guide: Assets

Locates a game’s asset files. By default the root is the Content folder next to the executable (games copy it there at build time). Missing files fail with the full path so a broken install or a typo is obvious. A content source (IContentSource) over a FolderContentSource.

C#
public sealed class ContentFolder : IContentSource

Inheritance

object ← ContentFolder

Implements

IContentSource

Constructors

ContentFolder(string?)

Opens a content folder.

C#
public ContentFolder(string? root = null)

Parameters

root string?

The folder, absolute or relative to the working directory; null uses the Content folder next to the executable. A host whose files live elsewhere (a phone app, a macOS bundle) composes its folder instead (Content).

Exceptions

DirectoryNotFoundException

The folder does not exist.

Properties

DefaultRoot

The folder used when a game and its composition name none: Content next to the executable. A rule, not a setting: a host whose files live elsewhere (a phone app, a macOS bundle) composes its folder (Content).

C#
public static string DefaultRoot { get; }

Property Value

string

Location

The same as Root.

C#
public string Location { get; }

Property Value

string

Root

The absolute path of the content folder.

C#
public string Root { get; }

Property Value

string

Methods

Exists(string)

Whether a file exists at relative (relative to Root, ‘/’ separators). False for a missing file and for a path outside the folder.

C#
public bool Exists(string relative)

Parameters

relative string

Returns

bool

Files(string)

The files directly inside folder (relative to the root, ‘/’ separators; “” for the root), as ‘/’-separated paths relative to the root, in ordinal order.

C#
public IReadOnlyList<string> Files(string folder)

Parameters

folder string

Returns

IReadOnlyList<string>

Exceptions

DirectoryNotFoundException

The folder does not exist.

Image(string)

Decodes a PNG file into an image (see Load).

C#
public PixelImage Image(string relative)

Parameters

relative string

Returns

PixelImage

Exceptions

FileNotFoundException

The file does not exist.

Open(string)

Opens a file for reading, after the checks of PathOf.

C#
public Stream Open(string relative)

Parameters

relative string

Returns

Stream

PathOf(string)

Full path of a file given relative to the root with ‘/’ separators. The name must match the file’s letter case exactly, on every system: “Hero.png” for “hero.png” works on Windows and macOS but not on Linux, Android or in browsers, so it fails everywhere, naming the file’s real spelling.

C#
public string PathOf(string relative)

Parameters

relative string

Returns

string

Exceptions

ArgumentException

The path leaves the content folder.

FileNotFoundException

No such file, or its name is spelled with another letter case.

ReadBytes(string)

Reads a whole file.

C#
public byte[] ReadBytes(string relative)

Parameters

relative string

Returns

byte[]

Exceptions

FileNotFoundException

The file does not exist.