ServerConfigFile<T>
An abstract class in TavernLib, TavernLib.Backend.Server.Configs.
The base class for TavernLib's JSON files. Reads into a T, writes through a temp file with a .bak, and holds a per-object lock so changes don't interleave. Subclass it for your own mod's file.
- Listed in TavernLib.Backend.Server.Configs
- Derived types
ConsoleTokenFile,ModsListConfig,ServerSettingsConfig,TavernServerConfig,TrustedReposConfig,UserConfigFile,WhitelistRequestsConfigFile - Documented in ServerConfigFile
Constructors
| Member | What it is |
|---|---|
protected ServerConfigFile(string filePath) | Stores the path of the config file. |
Fields
1 private and internal field
Properties
2 private and internal properties
Methods
| Member | What it is |
|---|---|
T Read() | Reads the file into a new object and makes it LastRead. A missing file is created with defaults; an empty or broken one throws. |
virtual void ReadFromFile() | Calls Read. Subclasses may add to it, as ServerSettingsConfig does. |
void Update(Func<T, bool> change) | Reads the file, passes it to the change, and writes it back if the change returns true, all under the lock. |
virtual void WriteToFile() | Writes LastRead as it is, which can throw away changes made to the file since. Prefer Update. |
protected virtual bool Tidy(T config) | Called after each read to fix the object up. Return true to have it written back. Does nothing in the base. |