Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[develop] Add rom override config folder setting #142

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ static void menu_init (boot_params_t *boot_params) {

sound_use_sfx(menu->settings.sound_enabled);

rom_info_use_config_folder(menu->settings.use_gamepak_custom_config_folder);

menu->browser.directory = path_init(menu->storage_prefix, menu->settings.default_directory);
if (!directory_exists(path_get(menu->browser.directory))) {
path_free(menu->browser.directory);
Expand Down
52 changes: 46 additions & 6 deletions src/menu/rom_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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)) {
Expand Down Expand Up @@ -606,6 +610,19 @@ static const match_t database[] = {
// clang-format on


static bool gamepak_config_folder_enabled = false;


void rom_info_use_config_folder(bool state) {
if (state) {
gamepak_config_folder_enabled = true;
}
else {
gamepak_config_folder_enabled = false;
}
}


static void fix_rom_header_endianness (rom_header_t *rom_header, rom_info_t *rom_info) {
uint8_t *raw = (uint8_t *) (rom_header);

Expand Down Expand Up @@ -794,7 +811,21 @@ static void extract_rom_info (match_t *match, rom_header_t *rom_header, rom_info
}
}

static void load_overrides (path_t *path, rom_info_t *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_rom_config_overrides (path_t *path, rom_info_t *rom_info) {

if ( gamepak_config_folder_enabled ) {
path_push_subdir(path, GAMEPAK_CONFIG_SUBDIRECTORY);
}

path_t *overrides_path = path_clone(path);

path_ext_replace(overrides_path, "ini");
Expand Down Expand Up @@ -827,7 +858,16 @@ static void load_overrides (path_t *path, rom_info_t *rom_info) {
path_free(overrides_path);
}

static rom_err_t save_override (path_t *path, const char *id, int value, int default_value) {
static rom_err_t save_rom_config_overrides (path_t *path, const char *id, int value, int default_value) {

if ( gamepak_config_folder_enabled ) {
// 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");
Expand Down Expand Up @@ -914,7 +954,7 @@ rom_err_t rom_info_override_cic_type (path_t *path, rom_info_t *rom_info, rom_ci
rom_info->override.cic = (cic_type != ROM_CIC_TYPE_AUTOMATIC);
rom_info->override.cic_type = cic_type;

return save_override(path, "cic_type", rom_info->override.cic_type, ROM_CIC_TYPE_AUTOMATIC);
return save_rom_config_overrides(path, "cic_type", rom_info->override.cic_type, ROM_CIC_TYPE_AUTOMATIC);
}

rom_save_type_t rom_info_get_save_type (rom_info_t *rom_info) {
Expand All @@ -929,7 +969,7 @@ rom_err_t rom_info_override_save_type (path_t *path, rom_info_t *rom_info, rom_s
rom_info->override.save = (save_type != SAVE_TYPE_AUTOMATIC);
rom_info->override.save_type = save_type;

return save_override(path, "save_type", rom_info->override.save_type, SAVE_TYPE_AUTOMATIC);
return save_rom_config_overrides(path, "save_type", rom_info->override.save_type, SAVE_TYPE_AUTOMATIC);
}

rom_tv_type_t rom_info_get_tv_type (rom_info_t *rom_info) {
Expand All @@ -944,7 +984,7 @@ rom_err_t rom_info_override_tv_type (path_t *path, rom_info_t *rom_info, rom_tv_
rom_info->override.tv = (tv_type != ROM_TV_TYPE_AUTOMATIC);
rom_info->override.tv_type = tv_type;

return save_override(path, "tv_type", rom_info->override.tv_type, ROM_TV_TYPE_AUTOMATIC);
return save_rom_config_overrides(path, "tv_type", rom_info->override.tv_type, ROM_TV_TYPE_AUTOMATIC);
}

rom_err_t rom_info_load (path_t *path, rom_info_t *rom_info) {
Expand All @@ -969,7 +1009,7 @@ rom_err_t rom_info_load (path_t *path, rom_info_t *rom_info) {

extract_rom_info(&match, &rom_header, rom_info);

load_overrides(path, rom_info);
load_rom_config_overrides(path, rom_info);

return ROM_OK;
}
2 changes: 2 additions & 0 deletions src/menu/rom_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,7 @@ rom_err_t rom_info_override_tv_type (path_t *path, rom_info_t *rom_info, rom_tv_

rom_err_t rom_info_load (path_t *path, rom_info_t *rom_info);

void rom_info_use_config_folder(bool state);


#endif
3 changes: 3 additions & 0 deletions src/menu/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand All @@ -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 */
Expand All @@ -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! */
Expand Down
3 changes: 3 additions & 0 deletions src/menu/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 15 additions & 0 deletions src/menu/views/settings_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ 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);
rom_info_use_config_folder(menu->settings.use_gamepak_custom_config_folder);
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);
Expand Down Expand Up @@ -76,6 +82,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) },
Expand All @@ -95,6 +107,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 },
Expand Down Expand Up @@ -140,6 +153,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"
Expand All @@ -151,6 +165,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
,
Expand Down