51 lines
1.9 KiB
C
51 lines
1.9 KiB
C
// dvxPrefs.h -- INI-based preferences system (read/write)
|
|
//
|
|
// Loads a configuration file at startup and provides typed accessors
|
|
// with caller-supplied defaults. Values can be modified at runtime
|
|
// and saved back to disk. If the file is missing or a key is absent,
|
|
// getters return the default silently.
|
|
|
|
#ifndef DVX_PREFS_H
|
|
#define DVX_PREFS_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
// Load an INI file into memory. Returns true on success, false if the
|
|
// file could not be opened (all getters will return their defaults).
|
|
// Only one file may be loaded at a time; calling again frees the previous.
|
|
bool prefsLoad(const char *filename);
|
|
|
|
// Save the current in-memory state back to the file that was loaded.
|
|
// Returns true on success.
|
|
bool prefsSave(void);
|
|
|
|
// Save the current in-memory state to a specific file.
|
|
bool prefsSaveAs(const char *filename);
|
|
|
|
// Release all memory held by the preferences.
|
|
void prefsFree(void);
|
|
|
|
// Retrieve a string value. Returns defaultVal if the key is not present.
|
|
// The returned pointer is valid until the key is modified or prefsFree().
|
|
const char *prefsGetString(const char *section, const char *key, const char *defaultVal);
|
|
|
|
// Retrieve an integer value.
|
|
int32_t prefsGetInt(const char *section, const char *key, int32_t defaultVal);
|
|
|
|
// Retrieve a boolean value. Recognises "true"/"yes"/"1" and "false"/"no"/"0".
|
|
bool prefsGetBool(const char *section, const char *key, bool defaultVal);
|
|
|
|
// Set a string value. Creates the section and key if they don't exist.
|
|
void prefsSetString(const char *section, const char *key, const char *value);
|
|
|
|
// Set an integer value.
|
|
void prefsSetInt(const char *section, const char *key, int32_t value);
|
|
|
|
// Set a boolean value (stored as "true"/"false").
|
|
void prefsSetBool(const char *section, const char *key, bool value);
|
|
|
|
// Remove a key from a section. No-op if not found.
|
|
void prefsRemove(const char *section, const char *key);
|
|
|
|
#endif
|