// Settings: the TOTK_* environment variables, with totk.ini next to totk.exe behind them. #pragma once // getenv for a setting: the environment variable when set, else the totk.ini key (the name without "TOTK_", any // case), else NULL. Same string semantics as getenv; the pointer stays valid for the process (a value cfg_set replaces // is kept). A name without the TOTK_ prefix goes to getenv unchanged. Safe from any thread once cfg_init has returned. const char *cfg_get(const char *name); // Reads totk.ini once, first thing in main. Logs the file, its key count, unknown keys and environment overrides. void cfg_init(void); // Replaces the loaded keys with those of the file at path (tests). 1 when the file was read, 0 when missing. // Not thread-safe: nothing else may call cfg_get meanwhile. int cfg_load(const char *path); // Live settings (the in-game menu). cfg_set stores value as the totk.ini value of name (TOTK_ prefixed), marks it for // cfg_save and bumps cfg_version. cfg_get returns it unless the environment sets name. Any thread. void cfg_set(const char *name, const char *value); // Bumped by every cfg_set. A consumer that keeps a parsed value compares this with the number it last saw (one atomic // load) and parses again when it changed. unsigned cfg_version(void); // 1 when the environment sets name: cfg_set cannot change what cfg_get returns (the menu greys the setting out). int cfg_from_env(const char *name); // Writes the keys cfg_set changed since the last save into totk.ini next to totk.exe (cfg_save_to: the file at path). // Only those lines change: the last line of a changed key gets the new value, a missing key goes under its section // (after the commented example line of the key when the section has one; the section is added at the end of the file // when missing), comments and every other line stay byte for byte. 1 on success or with nothing to write. int cfg_save(void); int cfg_save_to(const char *path);