From d69a0c64a9cb4809f1a7d0014fae564f0b79bce5 Mon Sep 17 00:00:00 2001 From: Robin Jones Date: Sat, 28 Sep 2024 22:32:55 +0100 Subject: [PATCH] add gamepak config dir --- src/menu/rom_info.c | 29 +++++++++++++++++++++++++++++ src/menu/settings.c | 3 +++ src/menu/settings.h | 3 +++ src/menu/views/settings_editor.c | 14 ++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/src/menu/rom_info.c b/src/menu/rom_info.c index e5b750ce..4b54c14d 100644 --- a/src/menu/rom_info.c +++ b/src/menu/rom_info.c @@ -4,6 +4,8 @@ #include +#include "views/views.h" + #include "boot/cic.h" #include "rom_info.h" #include "utils/fs.h" @@ -18,6 +20,10 @@ #define CLOCK_RATE_DEFAULT (0x0000000F) +#ifndef GAMEPAK_CONFIG_SUBDIRECTORY +#define GAMEPAK_CONFIG_SUBDIRECTORY "config" +#endif + /** @brief ROM File Information Structure. */ typedef struct __attribute__((packed)) { @@ -794,7 +800,21 @@ static void extract_rom_info (match_t *match, rom_header_t *rom_header, rom_info } } +static bool create_gamepak_config_subdirectory (path_t *path) { + path_t *gamepak_config_path = path_clone(path); + path_pop(gamepak_config_path); + path_push(gamepak_config_path, GAMEPAK_CONFIG_SUBDIRECTORY); + bool error = directory_create(path_get(gamepak_config_path)); + path_free(gamepak_config_path); + return error; +} + static void load_overrides (path_t *path, rom_info_t *rom_info) { + + if ( menu->settings.use_gamepak_config_folder) { + path_push_subdir(path, GAMEPAK_CONFIG_SUBDIRECTORY); + } + path_t *overrides_path = path_clone(path); path_ext_replace(overrides_path, "ini"); @@ -828,6 +848,15 @@ static void load_overrides (path_t *path, rom_info_t *rom_info) { } static rom_err_t save_override (path_t *path, const char *id, int value, int default_value) { + + if ( menu->settings.use_gamepak_config_folder) { + // if the sub dir does not exist, create it + // TODO: would it be quicker to check it exists first? + create_gamepak_config_subdirectory(path); + + path_push_subdir(path, GAMEPAK_CONFIG_SUBDIRECTORY); + } + path_t *overrides_path = path_clone(path); path_ext_replace(overrides_path, "ini"); diff --git a/src/menu/settings.c b/src/menu/settings.c index 0b372531..295aadc6 100644 --- a/src/menu/settings.c +++ b/src/menu/settings.c @@ -13,6 +13,7 @@ static settings_t init = { .show_protected_entries = false, .default_directory = "/", .use_saves_folder = true, + .use_gamepak_custom_config_folder = false, .sound_enabled = true, /* Beta feature flags (should always init to off) */ @@ -39,6 +40,7 @@ void settings_load (settings_t *settings) { settings->show_protected_entries = mini_get_bool(ini, "menu", "show_protected_entries", init.show_protected_entries); 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); + settings->use_gamepak_custom_config_folder = mini_get_bool(ini, "menu", "use_gamepak_custom_config_folder", init.use_gamepak_custom_config_folder); settings->sound_enabled = mini_get_bool(ini, "menu", "sound_enabled", init.sound_enabled); /* Beta feature flags, they might not be in the file */ @@ -55,6 +57,7 @@ void settings_save (settings_t *settings) { mini_set_bool(ini, "menu", "show_protected_entries", settings->show_protected_entries); mini_set_string(ini, "menu", "default_directory", settings->default_directory); mini_set_bool(ini, "menu", "use_saves_folder", settings->use_saves_folder); + mini_set_bool(ini, "menu", "use_gamepak_custom_config_folder", settings->use_gamepak_custom_config_folder); mini_set_bool(ini, "menu", "sound_enabled", settings->sound_enabled); /* Beta feature flags, they should not save until production ready! */ diff --git a/src/menu/settings.h b/src/menu/settings.h index e9931b05..912e4d1d 100644 --- a/src/menu/settings.h +++ b/src/menu/settings.h @@ -22,6 +22,9 @@ typedef struct { /** @brief Put saves into separate directory */ bool use_saves_folder; + /** @brief Put custom GamePak configs into separate directory */ + bool use_gamepak_custom_config_folder; + /** @brief Enable Background music */ bool bgm_enabled; diff --git a/src/menu/views/settings_editor.c b/src/menu/views/settings_editor.c index 55feffea..28cb3608 100644 --- a/src/menu/views/settings_editor.c +++ b/src/menu/views/settings_editor.c @@ -28,6 +28,11 @@ static void set_use_saves_folder_type (menu_t *menu, void *arg) { settings_save(&menu->settings); } +static void set_use_gamepak_custom_config_folder_type (menu_t *menu, void *arg) { + menu->settings.use_gamepak_custom_config_folder = (bool) (arg); + settings_save(&menu->settings); +} + static void set_sound_enabled_type (menu_t *menu, void *arg) { menu->settings.sound_enabled = (bool) (arg); sound_use_sfx(menu->settings.sound_enabled); @@ -76,6 +81,12 @@ static component_context_menu_t set_use_saves_folder_type_context_menu = { .list COMPONENT_CONTEXT_MENU_LIST_END, }}; +static component_context_menu_t set_use_gamepak_custom_config_folder_type_context_menu = { .list = { + {.text = "On", .action = set_use_gamepak_custom_config_folder_type, .arg = (void *) (true) }, + {.text = "Off", .action = set_use_gamepak_custom_config_folder_type, .arg = (void *) (false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + #ifdef BETA_SETTINGS static component_context_menu_t set_bgm_enabled_type_context_menu = { .list = { {.text = "On", .action = set_bgm_enabled_type, .arg = (void *) (true) }, @@ -95,6 +106,7 @@ static component_context_menu_t options_context_menu = { .list = { { .text = "Show Hidden Files", .submenu = &set_protected_entries_type_context_menu }, { .text = "Sound Effects", .submenu = &set_sound_enabled_type_context_menu }, { .text = "Use Saves Folder", .submenu = &set_use_saves_folder_type_context_menu }, + { .text = "Use Game Config Folder", .submenu = &set_use_gamepak_custom_config_folder_type_context_menu }, #ifdef BETA_SETTINGS { .text = "Background Music", .submenu = &set_bgm_enabled_type_context_menu }, { .text = "Rumble Feedback", .submenu = &set_rumble_enabled_type_context_menu }, @@ -140,6 +152,7 @@ static void draw (menu_t *menu, surface_t *d) { "* PAL60 Mode : %s\n" " Show Hidden Files : %s\n" " Use Saves folder : %s\n" + " Use config folder : %s\n" " Sound Effects : %s\n" #ifdef BETA_SETTINGS " Background Music : %s\n" @@ -151,6 +164,7 @@ static void draw (menu_t *menu, surface_t *d) { format_switch(menu->settings.pal60_enabled), format_switch(menu->settings.show_protected_entries), format_switch(menu->settings.use_saves_folder), + format_switch(menu->settings.use_gamepak_custom_config_folder), format_switch(menu->settings.sound_enabled) #ifdef BETA_SETTINGS ,