# ConfigManager

`com.jsmacrosce.jsmacros.core.config.ConfigManager`

Manages registered configuration-option classes and the JSON data loaded for them.  
Scripts can obtain the manager from `JsMacros.getConfig()`:  
```js
const config = JsMacros.getConfig();  
Chat.log(config.configFile.getPath());  
```

## Constructors

### new ConfigManager {#com.jsmacrosce.jsmacros.core.config.ConfigManager_constructor-Core-File-File-Logger-}

```js
new ConfigManager(Core<?, ?> runner, File configFolder, File macroFolder, Logger logger)
```

Initializes the core option registration and loads configuration, attempting to create the supplied directories when missing.  
 If the macro directory is initially missing, also attempts to create its `index.js`; directory and file creation are best-effort.  
 Checked failures from configuration loading are wrapped in `RuntimeException`.

**Parameters:**
- `runner`: runtime retained for option setup
- `configFolder`: directory used to locate the options file
- `macroFolder`: directory for macros
- `logger`: logger for configuration operations

## Fields

### configFile {#com.jsmacrosce.jsmacros.core.config.ConfigManager_configFile}

```js
configFile: File
```

Configuration JSON file, named `options.json` under the constructor's configuration-directory argument.

### configFolder {#com.jsmacrosce.jsmacros.core.config.ConfigManager_configFolder}

```js
configFolder: File
```

Absolute configuration directory retained by this manager.

### LOGGER {#com.jsmacrosce.jsmacros.core.config.ConfigManager_LOGGER}

```js
LOGGER: Logger
```

Logger used for configuration operations.

### macroFolder {#com.jsmacrosce.jsmacros.core.config.ConfigManager_macroFolder}

```js
macroFolder: File
```

Absolute macro directory retained by this manager.

### optionClasses {#com.jsmacrosce.jsmacros.core.config.ConfigManager_optionClasses}

```js
optionClasses: Map<String, Class<?>>
```

Maps JSON root property names to registered option classes.

### options {#com.jsmacrosce.jsmacros.core.config.ConfigManager_options}

```js
options: Map<Class<?>, Object>
```

Maps registered option classes to their loaded or default option values.

### rawOptions {#com.jsmacrosce.jsmacros.core.config.ConfigManager_rawOptions}

```js
rawOptions: JsonObject
```

Raw JSON data most recently read or built; initially `null` and not automatically synchronized with `options`.

### TARGET_VERSION {#com.jsmacrosce.jsmacros.core.config.ConfigManager_TARGET_VERSION}

```js
static TARGET_VERSION: int
```

Schema version written to configuration data; this is not the JsMacros release version.

## Methods

### addOptions {#com.jsmacrosce.jsmacros.core.config.ConfigManager_addOptions-String-Class-}

```js
addOptions(String key, Class<?> optionClass): void
```

Registers an option class and loads its value, falling back to a new default instance if loading fails.  
Registration occurs before loading and is retained if loading fails. Only a duplicate JSON key is rejected; the same class may be registered under another key, replacing its value in `options`.  
A declared `runner` field is injected when present. Default construction requires an accessible public no-argument constructor.

**Parameters:**
- `key`: JSON root property name; must not already be registered
- `optionClass`: option class to register and load

### backupConfig {#com.jsmacrosce.jsmacros.core.config.ConfigManager_backupConfig-}

```js
backupConfig(): void
```

Moves the current file to `options.json.vN.bak`, where N is the loaded config version, then attempts to save current state. Moving can fail with IOException; saveConfig catches save failures.

### getOptions {#com.jsmacrosce.jsmacros.core.config.ConfigManager_getOptions-Class-}

```js
getOptions(Class<T> optionClass): T
```

Returns the stored option value for a registered class; does not instantiate or reload it.

**Parameters:**
- `optionClass`: class used as the option-value key

**Type Parameters:**
- `T`: option value type

**Returns:** stored value, or `null` if absent or stored as `null`

### loadConfig {#com.jsmacrosce.jsmacros.core.config.ConfigManager_loadConfig-}

```js
loadConfig(): void
```

Clears existing instances and reloads them from disk, converting older data when supported. Loading failures caught per option fall back to that option's defaults; an InvocationTargetException or NoSuchMethodException escaping conversion or default construction instead resets all registered options to defaults. If no method named `fromV` followed by the loaded version exists, Gson loads the option instead of using the outer fallback. Backs up when the loaded version differs.

### loadDefaults {#com.jsmacrosce.jsmacros.core.config.ConfigManager_loadDefaults-}

```js
loadDefaults(): void
```

Instantiates defaults for registered option classes and resets raw data to an empty current-version JSON object.  
Does not inject runner fields or write the config file.

### reloadRawConfigFromFile {#com.jsmacrosce.jsmacros.core.config.ConfigManager_reloadRawConfigFromFile-}

```js
reloadRawConfigFromFile(): void
```

Reads raw JSON and its schema version without rebuilding typed option values; if the file is missing, builds registered defaults.  
 A missing version is treated as `1`. Read, parse, and default-construction failures propagate.

### saveConfig {#com.jsmacrosce.jsmacros.core.config.ConfigManager_saveConfig-}

```js
saveConfig(): void
```

Attempts to serialize registered options into the raw JSON data and write it to the config file.  
Exceptions during serialization or writing are logged and not propagated.
