Improve settings handling

This commit is contained in:
Robin Jones 2023-02-25 02:24:19 +00:00
parent 3e1dc34369
commit abcff3feaf

View File

@ -44,73 +44,88 @@ void settings_load_from_file (settings_t *settings) {
assertf(!fclose(fp), "Couldn't close toml config file"); // TODO: work out why and handle appropriately.
fp = NULL;
// Handle last_rom
toml_table_t *last_rom = toml_table_in(conf, "last_rom");
if (!last_rom) {
printf("Missing '[last_rom]' header in config\n");
wait_ms(10000);
}
toml_datum_t rom_path = toml_string_in(last_rom, "rom_path");
if (!rom_path.ok) {
printf("Couldn't read 'rom_path' value in config\n");
wait_ms(10000);
}
else {
printf("Found rom path: %s\n", rom_path.u.s);
settings->last_rom.rom_path = rom_path.u.s;
}
toml_datum_t rom_path = toml_string_in(last_rom, "rom_path");
if (!rom_path.ok) {
printf("Couldn't read 'rom_path' value in config\n");
wait_ms(10000);
}
else {
printf("Found rom path: %s\n", rom_path.u.s);
settings->last_rom.rom_path = rom_path.u.s;
}
toml_datum_t save_path = toml_string_in(last_rom, "save_path");
if (!save_path.ok) {
printf("Couldn't read 'save_path' value in config\n");
wait_ms(10000);
}
else {
printf("Found save path: %s\n", save_path.u.s );
settings->last_rom.save_path = save_path.u.s;
}
toml_datum_t save_path = toml_string_in(last_rom, "save_path");
if (!save_path.ok) {
printf("Couldn't read 'save_path' value in config\n");
wait_ms(10000);
}
else {
printf("Found save path: %s\n", save_path.u.s );
settings->last_rom.save_path = save_path.u.s;
}
toml_datum_t tmp_save_type = toml_int_in(last_rom, "save_type");
if (!tmp_save_type.ok) {
printf("Couldn't read 'save_type' value in config\n");
wait_ms(10000);
}
else {
assertf((int)tmp_save_type.u.i < __FLASHCART_SAVE_TYPE_END, "Invalid save type in config file");
printf("Found save type: %d\n", (int)tmp_save_type.u.i );
settings->last_rom.save_type = (int)tmp_save_type.u.i;
toml_datum_t tmp_save_type = toml_int_in(last_rom, "save_type");
if (!tmp_save_type.ok) {
printf("Couldn't read 'save_type' value in config\n");
wait_ms(10000);
}
else {
assertf((int)tmp_save_type.u.i < __FLASHCART_SAVE_TYPE_END, "Invalid save type in config file");
printf("Found save type: %d\n", (int)tmp_save_type.u.i );
settings->last_rom.save_type = (int)tmp_save_type.u.i;
}
}
// Handle last_state
toml_table_t* last_state = toml_table_in(conf, "last_state");
if (!last_state) {
printf("Missing '[last_state]' header in config\n");
wait_ms(10000);
}
else {
// toml_datum_t current_directory = toml_string_in(last_state, "current_directory");
// if (!current_directory.ok) {
// printf("Couldn't read 'current_directory' value in config\n");
// printf("Defaulting to root directory.\n");
// settings->last_state.current_directory = "sd://";
// wait_ms(5000);
// }
// else {
// printf("Found current directory: %s\n", current_directory.u.s );
// settings->last_state.current_directory = current_directory.u.s;
// }
// toml_datum_t current_directory = toml_string_in(last_state, "current_directory");
// if (!current_directory.ok) {
// printf("Couldn't read 'current_directory' value in config\n");
// printf("Defaulting to root directory.\n");
// settings->last_state.current_directory = "sd://";
// wait_ms(5000);
// }
// else {
// printf("Found current directory: %s\n", current_directory.u.s );
// settings->last_state.current_directory = current_directory.u.s;
// }
// toml_datum_t tmp_auto_load_last_rom = toml_bool_in(last_state, "auto_load");
// if (!tmp_auto_load_last_rom.ok) {
// printf("Couldn't read 'auto_load' value in config\n");
// printf("Defaulting to false.\n");
// wait_ms(5000);
// settings->last_state.auto_load_last_rom = false;
// }
// else {
// printf("Found autoload: %s\n", tmp_auto_load_last_rom.u.b ? "true" : "false");
// settings->last_state.auto_load_last_rom = tmp_auto_load_last_rom.u.b;
// }
// toml_datum_t tmp_auto_load_last_rom = toml_bool_in(last_state, "auto_load");
// if (!tmp_auto_load_last_rom.ok) {
// printf("Couldn't read 'auto_load' value in config\n");
// printf("Defaulting to false.\n");
// wait_ms(5000);
// settings->last_state.auto_load_last_rom = false;
// }
// else {
// printf("Found autoload: %s\n", tmp_auto_load_last_rom.u.b ? "true" : "false");
// settings->last_state.auto_load_last_rom = tmp_auto_load_last_rom.u.b;
// }
}
// Handle boot_params
toml_table_t* boot_params = toml_table_in(conf, "boot_params");
if (!boot_params) {
printf("Missing '[boot_params]' header in config\n");
wait_ms(10000);
}
else {
}
toml_free(conf);