Table of Contents

Interface IPluginStorage

Namespace
AcDream.Plugin.Abstractions
Assembly
AcDream.Plugin.Abstractions.dll

A small key/value store the host keeps for one plugin, so its settings and data survive between runs. Keys are relative paths; the host decides where they live. A host with nowhere to write answers every call as unavailable.

public interface IPluginStorage
Extension Methods

Properties

IsAvailable

Whether this storage can actually read and write. False on the inert storage a host with no location to write to hands out.

bool IsAvailable { get; }

Property Value

bool

RootPath

The absolute directory keys are written beneath, or null when this storage is not backed by files. Useful for telling a user where their data went; keys still go through this interface.

string? RootPath { get; }

Property Value

string

Methods

Delete(string)

Removes what is stored under key. Returns false when there was nothing to remove or the storage is unavailable.

bool Delete(string key)

Parameters

key string

Returns

bool

EnsureDirectory(string)

Creates the directory named by prefix beneath the storage root, together with every missing parent, so a plugin can lay its folder tree out before it has anything to write into it. The prefix is a slash-separated relative key prefix; a trailing slash is allowed. Returns true when the directory exists afterwards, and false when the storage is unavailable. Throws ArgumentException for a prefix that is absolute or escapes the storage root, exactly as WriteText(string, string) does for such a key.

bool EnsureDirectory(string prefix)

Parameters

prefix string

Returns

bool

List(string)

Relative file keys beneath one relative prefix. An empty prefix lists every key in the storage.

IReadOnlyList<string> List(string prefix)

Parameters

prefix string

Returns

IReadOnlyList<string>

OpenScope(PluginStorageScope)

Opens a child namespace for scoped plugin data, kept apart from the plugin's other scopes. A scope name follows the key rules: forward slashes nest it, and a blank or rooted name, or one containing .. or a backslash, throws ArgumentException.

IPluginStorage OpenScope(PluginStorageScope scope)

Parameters

scope PluginStorageScope

Returns

IPluginStorage

ReadText(string)

Returns the text stored under key, or null when nothing is stored there or the storage is unavailable.

string? ReadText(string key)

Parameters

key string

Returns

string

WriteText(string, string)

Stores content under key, replacing anything already there. Throws NotSupportedException when the storage is unavailable.

void WriteText(string key, string content)

Parameters

key string
content string