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-12-21 19:58:30 +01:00
|
|
|
|
2024-04-24 02:45:09 +02:00
|
|
|
static char *settings_path = NULL;
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-12-21 19:58:30 +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,
|
2024-04-24 02:45:09 +02:00
|
|
|
.show_protected_entries = 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
|
|
|
/* 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
|
|
|
|
2024-04-24 02:45:09 +02:00
|
|
|
void settings_init (char *path) {
|
|
|
|
if (settings_path) {
|
|
|
|
free(settings_path);
|
|
|
|
}
|
|
|
|
settings_path = strdup(path);
|
|
|
|
}
|
|
|
|
|
2023-07-16 13:13:02 +02:00
|
|
|
void settings_load (settings_t *settings) {
|
2024-04-24 02:45:09 +02:00
|
|
|
if (!file_exists(settings_path)) {
|
2023-07-16 13:13:02 +02:00
|
|
|
settings_save(&init);
|
|
|
|
}
|
2023-06-08 20:16:48 +02:00
|
|
|
|
2024-04-24 02:45:09 +02:00
|
|
|
mini_t *ini = mini_try_load(settings_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
|
2024-04-24 02:45:09 +02:00
|
|
|
settings->show_protected_entries = mini_get_bool(ini, "menu", "show_protected_entries", init.show_protected_entries);
|
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-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) {
|
2024-04-24 02:45:09 +02:00
|
|
|
mini_t *ini = mini_create(settings_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);
|
2024-04-24 02:45:09 +02:00
|
|
|
mini_set_bool(ini, "menu", "show_protected_entries", settings->show_protected_entries);
|
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-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
|
|
|
}
|