From c6c8051e8e956bb71b3b5458d44c76d7bc7765bd Mon Sep 17 00:00:00 2001 From: AKuHAK <621640+AKuHAK@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:32:01 +0300 Subject: [PATCH] loader: replace overwrite functions with initialize function. Key change: set value only if it is not set. --- ee/loader/src/main.c | 61 +++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/ee/loader/src/main.c b/ee/loader/src/main.c index 11113ca..6842cfc 100644 --- a/ee/loader/src/main.c +++ b/ee/loader/src/main.c @@ -186,7 +186,12 @@ struct SSystemSettings { uint8_t disk_id[5]; uint64_t disk_id_int; // 8 bytes, but that's ok for compare reasons }; -} sys; +} sys = { + .bDebugColors = -1, + .bLogo = -1, + .eecore_mod_base = -1, + .fs_sectors = -1, +}; struct SDriver { // All modules @@ -652,25 +657,29 @@ int fakelist_add_array(struct SFakeList *fl, toml_table_t *tbl_root) return 0; } -void toml_string_in_overwrite(toml_table_t *t, const char *name, char **dest) +void toml_string_in_initialize(toml_table_t *t, const char *name, char **dest) { + if (*dest != NULL) + return; toml_datum_t v = toml_string_in(t, name); if (v.ok) { - if (*dest != NULL) - free (*dest); *dest = v.u.s; } } -void toml_bool_in_overwrite(toml_table_t *t, const char *name, int *dest) +void toml_bool_in_initialize(toml_table_t *t, const char *name, int *dest) { + if (*dest != -1) + return; toml_datum_t v = toml_bool_in(t, name); if (v.ok) *dest = v.u.b; } -void toml_int_in_overwrite(toml_table_t *t, const char *name, int *dest) +void toml_int_in_initialize(toml_table_t *t, const char *name, int *dest) { + if (*dest != -1) + return; toml_datum_t v = toml_int_in(t, name); if (v.ok) *dest = v.u.i; @@ -722,26 +731,26 @@ int load_driver(const char * type, const char * subtype) free(v.u.s); } - toml_string_in_overwrite(tbl_root, "default_bsd", &sys.sBSD); - toml_string_in_overwrite(tbl_root, "default_bsdfs", &sys.sBSDFS); - toml_string_in_overwrite(tbl_root, "default_dvd", &sys.sDVDMode); - toml_string_in_overwrite(tbl_root, "default_ata0", &sys.sATA0File); - toml_string_in_overwrite(tbl_root, "default_ata0id", &sys.sATA0IDFile); - toml_string_in_overwrite(tbl_root, "default_ata1", &sys.sATA1File); - toml_string_in_overwrite(tbl_root, "default_mc0", &sys.sMC0File); - toml_string_in_overwrite(tbl_root, "default_mc1", &sys.sMC1File); - toml_string_in_overwrite(tbl_root, "default_elf", &sys.sELFFile); - toml_string_in_overwrite(tbl_root, "default_mt", &sys.sMT); - toml_string_in_overwrite(tbl_root, "default_gc", &sys.sGC); - toml_string_in_overwrite(tbl_root, "default_cwd", &sys.sCWDpath); - toml_string_in_overwrite(tbl_root, "default_cfg", &sys.sCFGFile); - toml_bool_in_overwrite (tbl_root, "default_dbc", &sys.bDebugColors); - toml_bool_in_overwrite (tbl_root, "default_logo", &sys.bLogo); - - toml_string_in_overwrite(tbl_root, "eecore_elf", &sys.eecore_elf); - toml_int_in_overwrite (tbl_root, "eecore_mod_base", &sys.eecore_mod_base); - - toml_int_in_overwrite (tbl_root, "cdvdman_fs_sectors", &sys.fs_sectors); + toml_string_in_initialize(tbl_root, "default_bsd", &sys.sBSD); + toml_string_in_initialize(tbl_root, "default_bsdfs", &sys.sBSDFS); + toml_string_in_initialize(tbl_root, "default_dvd", &sys.sDVDMode); + toml_string_in_initialize(tbl_root, "default_ata0", &sys.sATA0File); + toml_string_in_initialize(tbl_root, "default_ata0id", &sys.sATA0IDFile); + toml_string_in_initialize(tbl_root, "default_ata1", &sys.sATA1File); + toml_string_in_initialize(tbl_root, "default_mc0", &sys.sMC0File); + toml_string_in_initialize(tbl_root, "default_mc1", &sys.sMC1File); + toml_string_in_initialize(tbl_root, "default_elf", &sys.sELFFile); + toml_string_in_initialize(tbl_root, "default_mt", &sys.sMT); + toml_string_in_initialize(tbl_root, "default_gc", &sys.sGC); + toml_string_in_initialize(tbl_root, "default_cwd", &sys.sCWDpath); + toml_string_in_initialize(tbl_root, "default_cfg", &sys.sCFGFile); + toml_bool_in_initialize (tbl_root, "default_dbc", &sys.bDebugColors); + toml_bool_in_initialize (tbl_root, "default_logo", &sys.bLogo); + + toml_string_in_initialize(tbl_root, "eecore_elf", &sys.eecore_elf); + toml_int_in_initialize (tbl_root, "eecore_mod_base", &sys.eecore_mod_base); + + toml_int_in_initialize (tbl_root, "cdvdman_fs_sectors", &sys.fs_sectors); arr = toml_array_in(tbl_root, "ilink_id"); if (arr != NULL) {