S9SourceNine Labs / CMAPI Docs 1.0
CMAPI / API reference

IModStorage

Provides paths and JSON storage isolated to the current mod.

View source ↗
CMAPI 1.0.0Standalone runtimeWindows x64Tested with Planet Crafter 2.008
Namespace CMAPIInterfaceAssembly CMAPI.API.dll
public interface IModStorage

Provides paths and JSON storage isolated to the current mod.

Members

ModDirectoryPath

property
string ModDirectoryPath

Gets the read-only folder containing this mod and its assets.

DataDirectoryPath

property
string DataDirectoryPath

Gets this mod's private persistent-data folder.

The folder is created on the first write. CMAPI installers, updates, repairs, and uninstalls preserve it.

CacheDirectoryPath

property
string CacheDirectoryPath

Gets this mod's private, disposable cache folder.

Mods may recreate cached files at any time. Do not store player progress or configuration here.

ReadConfig

method
T ReadConfig<T>() where T : class, new()

Reads this mod's typed configuration from config.json.

The configuration type must have a public parameterless constructor. A missing file is created automatically. An unreadable file is kept beside it with a timestamped .broken name before defaults are restored, and CMAPI writes a warning attributed to the mod.

WriteConfig

method
void WriteConfig<T>(T config) where T : class

Atomically writes this mod's typed config.json.

DataExists

method
bool DataExists(string relativePath)

Returns whether a private JSON data file exists.

ReadJson

method
T ReadJson<T>(string relativePath) where T : class, new()

Reads a typed private JSON data file.

Invalid JSON is preserved with a timestamped .broken name and reported through the mod's monitor. Unlike configuration, missing or repaired data is not written until WriteJson{T} is called.

WriteJson

method
void WriteJson<T>(string relativePath, T value) where T : class

Atomically writes a typed private JSON data file.

DeleteData

method
bool DeleteData(string relativePath)

Deletes a private JSON data file if it exists.