public interface IModStorageProvides paths and JSON storage isolated to the current mod.
Members
ModDirectoryPathGets the read-only folder containing this mod and its assets.propertyDataDirectoryPathGets this mod's private persistent-data folder.propertyCacheDirectoryPathGets this mod's private, disposable cache folder.propertyReadConfigReads this mod's typed configuration from config.json.methodWriteConfigAtomically writes this mod's typed config.json.methodDataExistsReturns whether a private JSON data file exists.methodReadJsonReads a typed private JSON data file.methodWriteJsonAtomically writes a typed private JSON data file.methodDeleteDataDeletes a private JSON data file if it exists.methodModDirectoryPath
propertystring ModDirectoryPathGets the read-only folder containing this mod and its assets.
DataDirectoryPath
propertystring DataDirectoryPathGets this mod's private persistent-data folder.
The folder is created on the first write. CMAPI installers, updates, repairs, and uninstalls preserve it.
CacheDirectoryPath
propertystring CacheDirectoryPathGets this mod's private, disposable cache folder.
Mods may recreate cached files at any time. Do not store player progress or configuration here.
ReadConfig
methodT 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
methodvoid WriteConfig<T>(T config) where T : classAtomically writes this mod's typed config.json.
DataExists
methodbool DataExists(string relativePath)Returns whether a private JSON data file exists.
ReadJson
methodT 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
methodvoid WriteJson<T>(string relativePath, T value) where T : classAtomically writes a typed private JSON data file.
DeleteData
methodbool DeleteData(string relativePath)Deletes a private JSON data file if it exists.