2023-02-24 15:24:59 +01:00
|
|
|
#include <libdragon.h>
|
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
#include "libs/mini.c/src/mini.h"
|
|
|
|
#include "path.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-11 18:00:18 +02:00
|
|
|
void settings_set_default_state (settings_t *settings) {
|
|
|
|
settings->pal60 = false;
|
|
|
|
settings->show_hidden_files = false;
|
|
|
|
settings->default_directory = "/";
|
2023-02-24 15:24:59 +01:00
|
|
|
}
|
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
void settings_save_to_file (char *path, settings_t *settings) {
|
|
|
|
path_t *config_file_path = path_init("sd:/");
|
|
|
|
path_append(config_file_path, path);
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
mini_t *ini = mini_create(path_get(config_file_path));
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-07-11 18:00:18 +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-06-08 20:16:48 +02:00
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
mini_save(ini);
|
2023-06-08 20:16:48 +02:00
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
mini_free(ini);
|
2023-06-08 20:16:48 +02:00
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
path_free(config_file_path);
|
2023-02-24 15:24:59 +01:00
|
|
|
}
|
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
void settings_load_from_file (char *path, settings_t *settings) {
|
|
|
|
if (!file_exists(path)) {
|
|
|
|
settings_save_to_file(path, settings);
|
|
|
|
}
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
path_t *config_file_path = path_init("sd:/");
|
|
|
|
path_append(config_file_path, path);
|
2023-06-08 20:16:48 +02:00
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
mini_t *ini = mini_try_load(path_get(config_file_path));
|
2023-02-24 15:24:59 +01:00
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
settings->pal60 = mini_get_bool(ini, "menu", "pal60", false);
|
|
|
|
settings->show_hidden_files = mini_get_bool(ini, "menu", "show_hidden_files", false);
|
|
|
|
settings->default_directory = strdup(mini_get_string(ini, "menu", "default_directory", "/"));
|
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
|
|
|
|
2023-07-11 18:00:18 +02:00
|
|
|
path_free(config_file_path);
|
2023-02-24 15:24:59 +01:00
|
|
|
}
|