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-07-28 21:23:15 +02:00
|
|
|
#define SETTINGS_FILE_PATH "sd:/config.ini"
|
2023-02-24 15:24:59 +01:00
|
|
|
|
|
|
|
|
2023-07-16 13:13:02 +02:00
|
|
|
static settings_t init = {
|
|
|
|
.pal60 = false,
|
|
|
|
.show_hidden_files = false,
|
|
|
|
.default_directory = "/",
|
|
|
|
};
|
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-07-16 13:13:02 +02:00
|
|
|
settings->pal60 = mini_get_bool(ini, "menu", "pal60", init.pal60);
|
|
|
|
settings->show_hidden_files = mini_get_bool(ini, "menu", "show_hidden_files", init.show_hidden_files);
|
|
|
|
settings->default_directory = strdup(mini_get_string(ini, "menu", "default_directory", init.default_directory));
|
2023-02-24 15:24:59 +01:00
|
|
|
|
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-07-16 13:13:02 +02:00
|
|
|
mini_set_bool(ini, "menu", "pal60", settings->pal60);
|
|
|
|
mini_set_bool(ini, "menu", "show_hidden_files", settings->show_hidden_files);
|
|
|
|
mini_set_string(ini, "menu", "default_directory", settings->default_directory);
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-07-16 13:13:02 +02:00
|
|
|
mini_save(ini);
|
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
|
|
|
}
|