2023-02-24 15:24:59 +01:00
|
|
|
#include <libdragon.h>
|
2023-07-25 19:20:29 +02:00
|
|
|
#include <mini.c/src/mini.h>
|
2023-02-24 15:24:59 +01:00
|
|
|
|
|
|
|
#include "settings.h"
|
2023-07-11 18:00:18 +02:00
|
|
|
#include "utils/fs.h"
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-10-10 21:12:53 +02:00
|
|
|
#ifndef SETTINGS_FILE_PATH
|
|
|
|
#define SETTINGS_FILE_PATH "sd:/menu/config.ini"
|
|
|
|
#endif
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-07-16 13:13:02 +02:00
|
|
|
static settings_t init = {
|
2023-10-10 21:12:53 +02:00
|
|
|
.pal60_enabled = false,
|
|
|
|
.hidden_files_enabled = false,
|
2023-07-16 13:13:02 +02:00
|
|
|
.default_directory = "/",
|
2023-10-10 21:12:53 +02:00
|
|
|
.use_saves_folder = true,
|
2023-12-17 17:51:24 +01:00
|
|
|
.autodetect_rom_region = true,
|
2023-10-10 21:12:53 +02:00
|
|
|
|
2023-12-17 17:51:24 +01:00
|
|
|
/* Beta feature flags (should always init to off) */
|
2023-10-10 21:12:53 +02:00
|
|
|
.bgm_enabled = false,
|
|
|
|
.sound_enabled = false,
|
2023-12-17 17:51:24 +01:00
|
|
|
.rumble_enabled = false,
|
2023-07-16 13:13:02 +02:00
|
|
|
};
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-06-08 20:16:48 +02:00
|
|
|
|
2023-07-16 13:13:02 +02:00
|
|
|
void settings_load (settings_t *settings) {
|
|
|
|
if (!file_exists(SETTINGS_FILE_PATH)) {
|
|
|
|
settings_save(&init);
|
|
|
|
}
|
2023-06-08 20:16:48 +02:00
|
|
|
|
2023-07-28 21:23:15 +02:00
|
|
|
mini_t *ini = mini_try_load(SETTINGS_FILE_PATH);
|
2023-06-08 20:16:48 +02:00
|
|
|
|
2023-10-10 21:12:53 +02:00
|
|
|
settings->pal60_enabled = mini_get_bool(ini, "menu", "pal60", init.pal60_enabled); // TODO: consider changing file setting name
|
|
|
|
settings->hidden_files_enabled = mini_get_bool(ini, "menu", "show_hidden_files", init.hidden_files_enabled);
|
2023-07-16 13:13:02 +02:00
|
|
|
settings->default_directory = strdup(mini_get_string(ini, "menu", "default_directory", init.default_directory));
|
2023-08-18 22:19:01 +02:00
|
|
|
settings->use_saves_folder = mini_get_bool(ini, "menu", "use_saves_folder", init.use_saves_folder);
|
2023-12-17 17:51:24 +01:00
|
|
|
settings->autodetect_rom_region = mini_get_bool(ini, "menu", "autodetect_rom_region", init.autodetect_rom_region);
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-10-10 21:12:53 +02:00
|
|
|
/* Beta feature flags, they might not be in the file */
|
|
|
|
settings->bgm_enabled = mini_get_bool(ini, "menu_beta_flag", "bgm_enabled", init.bgm_enabled);
|
|
|
|
settings->sound_enabled = mini_get_bool(ini, "menu_beta_flag", "sound_enabled", init.sound_enabled);
|
|
|
|
settings->rumble_enabled = mini_get_bool(ini, "menu_beta_flag", "rumble_enabled", init.rumble_enabled);
|
|
|
|
|
|
|
|
|
2023-07-16 13:13:02 +02:00
|
|
|
mini_free(ini);
|
|
|
|
}
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-07-16 13:13:02 +02:00
|
|
|
void settings_save (settings_t *settings) {
|
2023-07-28 21:23:15 +02:00
|
|
|
mini_t *ini = mini_create(SETTINGS_FILE_PATH);
|
2023-06-08 20:16:48 +02:00
|
|
|
|
2023-10-10 21:12:53 +02:00
|
|
|
mini_set_bool(ini, "menu", "pal60", settings->pal60_enabled);
|
|
|
|
mini_set_bool(ini, "menu", "show_hidden_files", settings->hidden_files_enabled);
|
2023-07-16 13:13:02 +02:00
|
|
|
mini_set_string(ini, "menu", "default_directory", settings->default_directory);
|
2023-08-18 22:19:01 +02:00
|
|
|
mini_set_bool(ini, "menu", "use_saves_folder", settings->use_saves_folder);
|
2023-12-17 17:51:24 +01:00
|
|
|
mini_set_bool(ini, "menu", "autodetect_rom_region", settings->autodetect_rom_region);
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-10-10 21:12:53 +02:00
|
|
|
/* Beta feature flags, they should not save until production ready! */
|
2023-12-17 17:51:24 +01:00
|
|
|
// mini_set_bool(ini, "menu_beta_flag", "bgm_enabled", settings->bgm_enabled);
|
|
|
|
// mini_set_bool(ini, "menu_beta_flag", "sound_enabled", settings->sound_enabled);
|
|
|
|
// mini_set_bool(ini, "menu_beta_flag", "rumble_enabled", settings->rumble_enabled);
|
2023-10-10 21:12:53 +02:00
|
|
|
|
2023-11-01 22:18:26 +01:00
|
|
|
mini_save(ini, MINI_FLAGS_SKIP_EMPTY_GROUPS);
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
mini_free(ini);
|
2023-02-24 15:24:59 +01:00
|
|
|
}
|