diff --git a/src/menu/settings.c b/src/menu/settings.c index f9846d9b9..a50795697 100644 --- a/src/menu/settings.c +++ b/src/menu/settings.c @@ -18,6 +18,8 @@ static settings_t init = { .default_directory = "/", .use_saves_folder = true, .show_saves_folder = false, + .hide_extension = false, + .hide_rom_tags = false, .soundfx_enabled = false, #ifdef FEATURE_AUTOLOAD_ROM_ENABLED .rom_autoload_enabled = false, @@ -56,6 +58,8 @@ void settings_load (settings_t *settings) { 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->show_saves_folder = mini_get_bool(ini, "menu", "show_saves_folder", init.show_saves_folder); + settings->hide_extension = mini_get_bool(ini, "menu", "hide_extension", init.hide_extension); + settings->hide_rom_tags = mini_get_bool(ini, "menu", "hide_rom_tags", init.hide_rom_tags); settings->soundfx_enabled = mini_get_bool(ini, "menu", "soundfx_enabled", init.soundfx_enabled); #ifdef FEATURE_AUTOLOAD_ROM_ENABLED @@ -85,6 +89,8 @@ void settings_save (settings_t *settings) { 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", "show_saves_folder", settings->show_saves_folder); + mini_set_bool(ini, "menu", "hide_extension", settings->hide_extension); + mini_set_bool(ini, "menu", "hide_rom_tags", settings->hide_rom_tags); mini_set_bool(ini, "menu", "soundfx_enabled", settings->soundfx_enabled); #ifdef FEATURE_AUTOLOAD_ROM_ENABLED mini_set_bool(ini, "menu", "autoload_rom_enabled", settings->rom_autoload_enabled); diff --git a/src/menu/settings.h b/src/menu/settings.h index ec06457a0..20058d6b5 100644 --- a/src/menu/settings.h +++ b/src/menu/settings.h @@ -37,6 +37,12 @@ typedef struct { /** @brief Show saves folder in file browser */ bool show_saves_folder; + /** @brief Hide file extensions */ + bool hide_extension; + + /** @brief Hide rom tags */ + bool hide_rom_tags; + /** @brief Enable Background music */ bool bgm_enabled; diff --git a/src/menu/ui_components/file_list.c b/src/menu/ui_components/file_list.c index 9b2fbd8c5..ffaeb4c0f 100644 --- a/src/menu/ui_components/file_list.c +++ b/src/menu/ui_components/file_list.c @@ -10,7 +10,6 @@ #include "../fonts.h" #include "constants.h" -static const char *dir_prefix = "/"; /** * @brief Format the file size into a human-readable string. @@ -77,7 +76,7 @@ void ui_components_file_list_draw (entry_t *list, int entries, int selected) { } else { size_t length = strlen(list[entry_index].name); name_lengths[i] = length; - total_length += length + (list[entry_index].type == ENTRY_TYPE_DIR ? strlen(dir_prefix) : 0); + total_length += length; } } @@ -118,9 +117,6 @@ void ui_components_file_list_draw (entry_t *list, int entries, int selected) { rdpq_paragraph_builder_style(style); - if (entry->type == ENTRY_TYPE_DIR) { - rdpq_paragraph_builder_span(dir_prefix, strlen(dir_prefix)); - } rdpq_paragraph_builder_span(entry->name, name_lengths[i]); diff --git a/src/menu/views/browser.c b/src/menu/views/browser.c index a7d3b9c95..8ba982841 100644 --- a/src/menu/views/browser.c +++ b/src/menu/views/browser.c @@ -54,6 +54,30 @@ static const struct substr hidden_prefixes[] = { }; #define HIDDEN_PREFIXES_COUNT (sizeof(hidden_prefixes) / sizeof(hidden_prefixes[0])) +static char *strip_extension(const char *filename) { + char *copy = strdup(filename); + if (!copy) return NULL; + + char *dot = strrchr(copy, '.'); + if (dot) *dot = '\0'; + + return copy; +} + +static char *strip_rom_tags (const char *filename) { + char *name = strdup(filename); + for (char *p = name; *p; ++p) { + if (*p == '(' || *p == '[') { + *p = '\0'; + break; + } + } + // Trim trailing space + for (char *end = name + strlen(name) - 1; end > name && *end == ' '; --end) { + *end = '\0'; + } + return name; +} static bool path_is_hidden (path_t *path) { char *stripped_path = strip_fs_prefix(path_get(path)); @@ -158,6 +182,14 @@ static bool load_directory (menu_t *menu) { path_t *path = path_clone(menu->browser.directory); + if (!path_is_root(menu->browser.directory)) { + menu->browser.list = malloc(sizeof(entry_t)); + entry_t *up = &menu->browser.list[0]; + up->name = strdup(".."); + up->type = ENTRY_TYPE_DIR; + up->size = 0; + menu->browser.entries = 1; + } result = dir_findfirst(path_get(path), &info); while (result == 0) { @@ -222,18 +254,23 @@ static bool load_directory (menu_t *menu) { path_free(path); - if (result < -1) { - browser_list_free(menu); - return true; + { + int offset = path_is_root(menu->browser.directory) ? 0 : 1; + if (menu->browser.entries > offset) { + qsort( + menu->browser.list + offset, + menu->browser.entries - offset, + sizeof(entry_t), + compare_entry + ); + } } if (menu->browser.entries > 0) { menu->browser.selected = 0; - menu->browser.entry = &menu->browser.list[menu->browser.selected]; + menu->browser.entry = &menu->browser.list[0]; } - qsort(menu->browser.list, menu->browser.entries, sizeof(entry_t), compare_entry); - return false; } @@ -360,6 +397,7 @@ static void process (menu_t *menu) { } int scroll_speed = menu->actions.go_fast ? 10 : 1; + int min_index = 0; if (menu->browser.entries > 1) { if (menu->actions.go_up) { @@ -380,6 +418,10 @@ static void process (menu_t *menu) { if (menu->actions.enter && menu->browser.entry) { sound_play_effect(SFX_ENTER); + if (menu->browser.selected == 0 && !path_is_root(menu->browser.directory)) { + pop_directory(menu); + return; + } switch (menu->browser.entry->type) { case ENTRY_TYPE_DIR: if (push_directory(menu, menu->browser.entry->name)) { @@ -446,8 +488,39 @@ static void draw (menu_t *menu, surface_t *d) { ui_components_layout_draw_tabbed(); - ui_components_file_list_draw(menu->browser.list, menu->browser.entries, menu->browser.selected); - + if (menu->settings.hide_extension || menu->settings.hide_rom_tags) { + entry_t *stripped_entries = malloc(sizeof(entry_t) * menu->browser.entries); + for (int i = 0; i < menu->browser.entries; i++) { + stripped_entries[i] = menu->browser.list[i]; + char *name = menu->browser.list[i].name; + + if (menu->settings.hide_extension && + (menu->browser.list[i].type == ENTRY_TYPE_ROM || menu->browser.list[i].type == ENTRY_TYPE_DISK || menu->browser.list[i].type == ENTRY_TYPE_EMULATOR)) { + name = strip_extension(name); + } else { + name = strdup(name); + } + + if (menu->settings.hide_rom_tags && + (menu->browser.list[i].type == ENTRY_TYPE_ROM || menu->browser.list[i].type == ENTRY_TYPE_DISK || menu->browser.list[i].type == ENTRY_TYPE_EMULATOR)) { + char *stripped = strip_rom_tags(name); + free(name); + name = stripped; + } + + stripped_entries[i].name = name; + } + + ui_components_file_list_draw(stripped_entries, menu->browser.entries, menu->browser.selected); + + for (int i = 0; i < menu->browser.entries; i++) { + free(stripped_entries[i].name); + } + free(stripped_entries); + } else { + ui_components_file_list_draw(menu->browser.list, menu->browser.entries, menu->browser.selected); + } + const char *action = NULL; if (menu->browser.entry) { diff --git a/src/menu/views/settings_editor.c b/src/menu/views/settings_editor.c index fc9171458..600086abd 100644 --- a/src/menu/views/settings_editor.c +++ b/src/menu/views/settings_editor.c @@ -51,6 +51,17 @@ static void set_use_rom_fast_reboot_enabled_type (menu_t *menu, void *arg) { } #endif +static void set_hide_extension_type(menu_t *menu, void *arg) { + menu->settings.hide_extension = (bool)(uintptr_t)(arg); + settings_save(&menu->settings); + menu->browser.reload = true; +} + +static void set_hide_rom_tags_type (menu_t *menu, void *arg) { + menu->settings.hide_rom_tags = (bool)(uintptr_t)(arg); + settings_save(&menu->settings); +} + #ifdef BETA_SETTINGS static void set_pal60_type (menu_t *menu, void *arg) { menu->settings.pal60_enabled = (bool)(uintptr_t)(arg); @@ -118,6 +129,18 @@ static component_context_menu_t set_use_rom_fast_reboot_context_menu = { .list = }}; #endif +static component_context_menu_t set_hide_extension_context_menu = { .list = { + { .text = "On", .action = set_hide_extension_type, .arg = (void *)(uintptr_t)(true) }, + { .text = "Off", .action = set_hide_extension_type, .arg = (void *)(uintptr_t)(false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + +static component_context_menu_t set_hide_rom_tags_context_menu = { .list = { + {.text = "On", .action = set_hide_rom_tags_type, .arg = (void *)(uintptr_t)(true) }, + {.text = "Off", .action = set_hide_rom_tags_type, .arg = (void *)(uintptr_t)(false) }, + COMPONENT_CONTEXT_MENU_LIST_END, +}}; + #ifdef BETA_SETTINGS static component_context_menu_t set_pal60_type_context_menu = { .list = { {.text = "On", .action = set_pal60_type, .arg = (void *)(uintptr_t)(true) }, @@ -146,7 +169,6 @@ static component_context_menu_t set_rumble_enabled_type_context_menu = { .list = 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_soundfx_enabled_type_context_menu }, { .text = "Use Saves Folder", .submenu = &set_use_saves_folder_type_context_menu }, { .text = "Show Saves Folder", .submenu = &set_show_saves_folder_type_context_menu }, #ifdef FEATURE_AUTOLOAD_ROM_ENABLED @@ -154,6 +176,9 @@ static component_context_menu_t options_context_menu = { .list = { #else { .text = "Fast Reboot ROM", .submenu = &set_use_rom_fast_reboot_context_menu }, #endif + { .text = "Sound Effects", .submenu = &set_soundfx_enabled_type_context_menu }, + { .text = "Hide Extensions", .submenu = &set_hide_extension_context_menu }, + { .text = "Hide ROM Tags", .submenu = &set_hide_rom_tags_context_menu }, #ifdef BETA_SETTINGS { .text = "PAL60 Mode", .submenu = &set_pal60_type_context_menu }, { .text = "PAL60 Compatibility", .submenu = &set_pal60_mod_compatibility_type_context_menu }, @@ -224,6 +249,8 @@ static void draw (menu_t *menu, surface_t *d) { " Use Saves folder : %s\n" " Show Saves folder : %s\n" " Sound Effects : %s\n" + " Hide Extensions : %s\n" + " Hide ROM Tags : %s\n" #ifdef BETA_SETTINGS "* PAL60 Mode : %s\n" "* PAL60 Mod Compat : %s\n" @@ -244,7 +271,9 @@ static void draw (menu_t *menu, surface_t *d) { format_switch(menu->settings.show_protected_entries), format_switch(menu->settings.use_saves_folder), format_switch(menu->settings.show_saves_folder), - format_switch(menu->settings.soundfx_enabled) + format_switch(menu->settings.soundfx_enabled), + format_switch(menu->settings.hide_extension), + format_switch(menu->settings.hide_rom_tags) #ifdef BETA_SETTINGS , format_switch(menu->settings.pal60_enabled),