N64FlashcartMenu/src/menu/settings.c

46 lines
1.3 KiB
C
Raw Normal View History

2023-02-24 15:24:59 +01:00
#include <libdragon.h>
#include <mini.c/src/mini.h>
2023-02-24 15:24:59 +01:00
#include "settings.h"
#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
static settings_t init = {
.pal60 = false,
.show_hidden_files = false,
.default_directory = "/",
.use_saves_folder = false,
};
2023-02-24 15:24:59 +01:00
void settings_load (settings_t *settings) {
if (!file_exists(SETTINGS_FILE_PATH)) {
settings_save(&init);
}
2023-07-28 21:23:15 +02:00
mini_t *ini = mini_try_load(SETTINGS_FILE_PATH);
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));
settings->use_saves_folder = mini_get_bool(ini, "menu", "use_saves_folder", init.use_saves_folder);
2023-02-24 15:24:59 +01:00
mini_free(ini);
}
2023-02-24 15:24:59 +01:00
void settings_save (settings_t *settings) {
2023-07-28 21:23:15 +02:00
mini_t *ini = mini_create(SETTINGS_FILE_PATH);
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);
mini_set_bool(ini, "menu", "use_saves_folder", settings->use_saves_folder);
2023-02-24 15:24:59 +01:00
mini_save(ini);
2023-02-24 15:24:59 +01:00
mini_free(ini);
2023-02-24 15:24:59 +01:00
}