102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
io.c File Reference
#include "config_internal.h"
#include "sds.h"
#include "yyjson.h"
#include <dttr_log.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include "dttr_errors.h"

Go to the source code of this file.

Data Structures

struct  config_json_objects

Functions

static void errors_clear ()
static void errors_addf (const char *fmt,...)
static bool errors_show ()
const char * DTTR_Config_LastError ()
 Returns details from the most recent config load failure, or NULL when none exist.
static void errors_add_invalid_value (const char *section, const char *key, const char *value)
static void config_apply_buttons (DTTR_Config *config, yyjson_val *buttons)
static void config_apply_disabled_mods (DTTR_Config *config, yyjson_val *disabled_mods)
static bool validate_schema_major_version (yyjson_val *root, const char *filename)
static bool config_apply_json_value (DTTR_Config *config, const DTTR_ConfigFieldSpec *spec, yyjson_val *val)
static void apply_section (yyjson_val *obj, const char *section)
bool DTTR_Config_Load (const char *filename)
 Loads config values from a strict JSON file into the global config object.
static bool obj_add_strcpy (yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *value)
static yyjson_mut_val * config_object_for_section (const config_json_objects *objects, const char *section)
static const char * config_format_field_string (const DTTR_Config *config, const DTTR_ConfigFieldSpec *spec)
static bool config_add_schema_field (yyjson_mut_doc *doc, const config_json_objects *objects, const DTTR_Config *config, const DTTR_ConfigFieldSpec *spec)
static bool config_add_schema_fields (yyjson_mut_doc *doc, const config_json_objects *objects, const DTTR_Config *config)
static bool config_add_disabled_mods (yyjson_mut_doc *doc, yyjson_mut_val *modding, const DTTR_Config *config)
static bool config_add_gamepad_buttons (yyjson_mut_doc *doc, yyjson_mut_val *buttons, const DTTR_Config *config)
bool DTTR_Config_Save (const char *filename, const DTTR_Config *config)
 Saves config values back to a strict JSON file.

Variables

static sds errors

Function Documentation

◆ apply_section()

void apply_section ( yyjson_val * obj,
const char * section )
static

◆ config_add_disabled_mods()

bool config_add_disabled_mods ( yyjson_mut_doc * doc,
yyjson_mut_val * modding,
const DTTR_Config * config )
static

Definition at line 440 of file io.c.

References DTTR_Config::disabled_mod_count, and DTTR_Config::disabled_mods.

Referenced by DTTR_Config_Save().

◆ config_add_gamepad_buttons()

bool config_add_gamepad_buttons ( yyjson_mut_doc * doc,
yyjson_mut_val * buttons,
const DTTR_Config * config )
static

◆ config_add_schema_field()

◆ config_add_schema_fields()

bool config_add_schema_fields ( yyjson_mut_doc * doc,
const config_json_objects * objects,
const DTTR_Config * config )
static

Definition at line 424 of file io.c.

References config_add_schema_field(), count, DTTR_Config_SchemaCount(), and DTTR_Config_SchemaGet().

Referenced by DTTR_Config_Save().

◆ config_apply_buttons()

void config_apply_buttons ( DTTR_Config * config,
yyjson_val * buttons )
static

◆ config_apply_disabled_mods()

void config_apply_disabled_mods ( DTTR_Config * config,
yyjson_val * disabled_mods )
static

Definition at line 99 of file io.c.

References DTTR_Config::disabled_mod_count, DTTR_Config_SetModEnabled(), and errors_addf().

Referenced by DTTR_Config_Load().

◆ config_apply_json_value()

bool config_apply_json_value ( DTTR_Config * config,
const DTTR_ConfigFieldSpec * spec,
yyjson_val * val )
static

◆ config_format_field_string()

◆ config_object_for_section()

yyjson_mut_val * config_object_for_section ( const config_json_objects * objects,
const char * section )
static

◆ DTTR_Config_LastError()

const char * DTTR_Config_LastError ( )

Returns details from the most recent config load failure, or NULL when none exist.

Definition at line 46 of file io.c.

References errors, and NULL.

Referenced by dttr_launcher_main(), and load_config().

◆ DTTR_Config_Load()

bool DTTR_Config_Load ( const char * filename)

◆ DTTR_Config_Save()

bool DTTR_Config_Save ( const char * filename,
const DTTR_Config * config )

◆ errors_add_invalid_value()

void errors_add_invalid_value ( const char * section,
const char * key,
const char * value )
static

Definition at line 50 of file io.c.

References errors_addf().

Referenced by apply_section().

◆ errors_addf()

void errors_addf ( const char * fmt,
... )
static

◆ errors_clear()

void errors_clear ( )
static

Definition at line 17 of file io.c.

References errors.

Referenced by DTTR_Config_Load().

◆ errors_show()

bool errors_show ( )
static

Definition at line 37 of file io.c.

References DTTR_LOG_ERROR, and errors.

Referenced by DTTR_Config_Load(), and validate_schema_major_version().

◆ obj_add_strcpy()

bool obj_add_strcpy ( yyjson_mut_doc * doc,
yyjson_mut_val * obj,
const char * key,
const char * value )
static

Definition at line 322 of file io.c.

Referenced by config_add_gamepad_buttons(), and config_add_schema_field().

◆ validate_schema_major_version()

bool validate_schema_major_version ( yyjson_val * root,
const char * filename )
static

Definition at line 126 of file io.c.

References DTTR_CONFIG_SCHEMA_MAJOR_VERSION, errors_addf(), and errors_show().

Referenced by DTTR_Config_Load().

Variable Documentation

◆ errors

sds errors
static

Definition at line 15 of file io.c.

Referenced by DTTR_Config_LastError(), errors_addf(), errors_clear(), and errors_show().