Skip to content

Commit c80b809

Browse files
committed
add gamepak config dir
1 parent 55e7663 commit c80b809

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

src/menu/rom_info.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include <mini.c/src/mini.h>
66

7+
#include "views/views.h"
8+
79
#include "boot/cic.h"
810
#include "rom_info.h"
911
#include "utils/fs.h"
@@ -18,6 +20,10 @@
1820

1921
#define CLOCK_RATE_DEFAULT (0x0000000F)
2022

23+
#ifndef GAMEPAK_CONFIG_SUBDIRECTORY
24+
#define GAMEPAK_CONFIG_SUBDIRECTORY "config"
25+
#endif
26+
2127

2228
/** @brief ROM File Information Structure. */
2329
typedef struct __attribute__((packed)) {
@@ -794,7 +800,21 @@ static void extract_rom_info (match_t *match, rom_header_t *rom_header, rom_info
794800
}
795801
}
796802

803+
static bool create_gamepak_config_subdirectory (path_t *path) {
804+
path_t *gamepak_config_path = path_clone(path);
805+
path_pop(gamepak_config_path);
806+
path_push(gamepak_config_path, GAMEPAK_CONFIG_SUBDIRECTORY);
807+
bool error = directory_create(path_get(gamepak_config_path));
808+
path_free(gamepak_config_path);
809+
return error;
810+
}
811+
797812
static void load_overrides (path_t *path, rom_info_t *rom_info) {
813+
814+
if ( menu->settings.use_gamepak_config_folder) {
815+
path_push_subdir(path, GAMEPAK_CONFIG_SUBDIRECTORY)
816+
}
817+
798818
path_t *overrides_path = path_clone(path);
799819

800820
path_ext_replace(overrides_path, "ini");
@@ -828,6 +848,15 @@ static void load_overrides (path_t *path, rom_info_t *rom_info) {
828848
}
829849

830850
static rom_err_t save_override (path_t *path, const char *id, int value, int default_value) {
851+
852+
if ( menu->settings.use_gamepak_config_folder) {
853+
// if the sub dir does not exist, create it
854+
// TODO: would it be quicker to check it exists first?
855+
create_gamepak_config_subdirectory(path);
856+
857+
path_push_subdir(path, GAMEPAK_CONFIG_SUBDIRECTORY)
858+
}
859+
831860
path_t *overrides_path = path_clone(path);
832861

833862
path_ext_replace(overrides_path, "ini");

src/menu/settings.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static settings_t init = {
1313
.show_protected_entries = false,
1414
.default_directory = "/",
1515
.use_saves_folder = true,
16+
.use_gamepak_custom_config_folder = false,
1617
.sound_enabled = true,
1718

1819
/* Beta feature flags (should always init to off) */
@@ -39,6 +40,7 @@ void settings_load (settings_t *settings) {
3940
settings->show_protected_entries = mini_get_bool(ini, "menu", "show_protected_entries", init.show_protected_entries);
4041
settings->default_directory = strdup(mini_get_string(ini, "menu", "default_directory", init.default_directory));
4142
settings->use_saves_folder = mini_get_bool(ini, "menu", "use_saves_folder", init.use_saves_folder);
43+
settings->use_gamepak_custom_config_folder = mini_get_bool(ini, "menu", "use_gamepak_custom_config_folder", init.use_gamepak_custom_config_folder);
4244
settings->sound_enabled = mini_get_bool(ini, "menu", "sound_enabled", init.sound_enabled);
4345

4446
/* Beta feature flags, they might not be in the file */
@@ -55,6 +57,7 @@ void settings_save (settings_t *settings) {
5557
mini_set_bool(ini, "menu", "show_protected_entries", settings->show_protected_entries);
5658
mini_set_string(ini, "menu", "default_directory", settings->default_directory);
5759
mini_set_bool(ini, "menu", "use_saves_folder", settings->use_saves_folder);
60+
mini_set_bool(ini, "menu", "use_gamepak_custom_config_folder", settings->use_gamepak_custom_config_folder);
5861
mini_set_bool(ini, "menu", "sound_enabled", settings->sound_enabled);
5962

6063
/* Beta feature flags, they should not save until production ready! */

src/menu/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ typedef struct {
2222
/** @brief Put saves into separate directory */
2323
bool use_saves_folder;
2424

25+
/** @brief Put custom GamePak configs into separate directory */
26+
bool use_gamepak_custom_config_folder;
27+
2528
/** @brief Enable Background music */
2629
bool bgm_enabled;
2730

src/menu/views/settings_editor.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ static void set_use_saves_folder_type (menu_t *menu, void *arg) {
2828
settings_save(&menu->settings);
2929
}
3030

31+
static void set_use_gamepak_custom_config_folder_type (menu_t *menu, void *arg) {
32+
menu->settings.use_gamepak_custom_config_folder = (bool) (arg);
33+
settings_save(&menu->settings);
34+
}
35+
3136
static void set_sound_enabled_type (menu_t *menu, void *arg) {
3237
menu->settings.sound_enabled = (bool) (arg);
3338
sound_use_sfx(menu->settings.sound_enabled);
@@ -76,6 +81,12 @@ static component_context_menu_t set_use_saves_folder_type_context_menu = { .list
7681
COMPONENT_CONTEXT_MENU_LIST_END,
7782
}};
7883

84+
static component_context_menu_t set_use_gamepak_custom_config_folder_type_context_menu = { .list = {
85+
{.text = "On", .action = set_use_gamepak_custom_config_folder_type, .arg = (void *) (true) },
86+
{.text = "Off", .action = set_use_gamepak_custom_config_folder_type, .arg = (void *) (false) },
87+
COMPONENT_CONTEXT_MENU_LIST_END,
88+
}};
89+
7990
#ifdef BETA_SETTINGS
8091
static component_context_menu_t set_bgm_enabled_type_context_menu = { .list = {
8192
{.text = "On", .action = set_bgm_enabled_type, .arg = (void *) (true) },
@@ -95,6 +106,7 @@ static component_context_menu_t options_context_menu = { .list = {
95106
{ .text = "Show Hidden Files", .submenu = &set_protected_entries_type_context_menu },
96107
{ .text = "Sound Effects", .submenu = &set_sound_enabled_type_context_menu },
97108
{ .text = "Use Saves Folder", .submenu = &set_use_saves_folder_type_context_menu },
109+
{ .text = "Use Game Config Folder", .submenu = &set_use_gamepak_custom_config_folder_type_context_menu },
98110
#ifdef BETA_SETTINGS
99111
{ .text = "Background Music", .submenu = &set_bgm_enabled_type_context_menu },
100112
{ .text = "Rumble Feedback", .submenu = &set_rumble_enabled_type_context_menu },
@@ -140,6 +152,7 @@ static void draw (menu_t *menu, surface_t *d) {
140152
"* PAL60 Mode : %s\n"
141153
" Show Hidden Files : %s\n"
142154
" Use Saves folder : %s\n"
155+
" Use config folder : %s\n"
143156
" Sound Effects : %s\n"
144157
#ifdef BETA_SETTINGS
145158
" Background Music : %s\n"
@@ -151,6 +164,7 @@ static void draw (menu_t *menu, surface_t *d) {
151164
format_switch(menu->settings.pal60_enabled),
152165
format_switch(menu->settings.show_protected_entries),
153166
format_switch(menu->settings.use_saves_folder),
167+
format_switch(menu->settings.use_gamepak_custom_config_folder),
154168
format_switch(menu->settings.sound_enabled)
155169
#ifdef BETA_SETTINGS
156170
,

0 commit comments

Comments
 (0)