summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.c20
-rw-r--r--config.h1
-rw-r--r--menu.c30
-rw-r--r--nuklear_ui/blastem_nuklear.c14
-rw-r--r--util.c16
-rw-r--r--util.h2
6 files changed, 57 insertions, 26 deletions
diff --git a/config.c b/config.c
index bf8c5e0..6b844ed 100644
--- a/config.c
+++ b/config.c
@@ -155,3 +155,23 @@ tern_node *load_config()
//this will never get reached, but the compiler doesn't know that. Let's make it happy
return NULL;
}
+
+char **get_extension_list(tern_node *config, uint32_t *num_exts_out)
+{
+ char *ext_filter = strdup(tern_find_path_default(config, "ui\0extensions\0", (tern_val){.ptrval = "bin gen md smd sms gg"}, TVAL_PTR).ptrval);
+ uint32_t num_exts = 0, ext_storage = 5;
+ char **ext_list = malloc(sizeof(char *) * ext_storage);
+ char *cur_filter = ext_filter;
+ while (*cur_filter)
+ {
+ if (num_exts == ext_storage) {
+ ext_storage *= 2;
+ ext_list = realloc(ext_list, sizeof(char *) * ext_storage);
+ }
+ ext_list[num_exts++] = cur_filter;
+ cur_filter = split_keyval(cur_filter);
+ }
+ free(ext_filter);
+ *num_exts_out = num_exts;
+ return ext_list;
+}
diff --git a/config.h b/config.h
index c24037e..9224606 100644
--- a/config.h
+++ b/config.h
@@ -10,6 +10,7 @@
tern_node *parse_config_file(char *config_path);
tern_node *parse_bundled_config(char *config_name);
tern_node *load_config();
+char **get_extension_list(tern_node *config, uint32_t *num_exts_out);
#endif //CONFIG_H_
diff --git a/menu.c b/menu.c
index 52ea468..c2895cf 100644
--- a/menu.c
+++ b/menu.c
@@ -10,6 +10,7 @@
#include "gst.h"
#include "paths.h"
#include "saves.h"
+#include "config.h"
static menu_context *get_menu(genesis_context *gen)
{
@@ -166,40 +167,17 @@ void * menu_write_w(uint32_t address, void * context, uint16_t value)
dst = copy_dir_entry_to_guest(dst, m68k, "..", 1);
}
#endif
- char *ext_filter = strdup(tern_find_path_default(config, "ui\0extensions\0", (tern_val){.ptrval = "bin gen md smd sms gg"}, TVAL_PTR).ptrval);
- uint32_t num_exts = 0, ext_storage = 5;
- char **ext_list = malloc(sizeof(char *) * ext_storage);
- char *cur_filter = ext_filter;
- while (*cur_filter)
- {
- if (num_exts == ext_storage) {
- ext_storage *= 2;
- ext_list = realloc(ext_list, sizeof(char *) * ext_storage);
- }
- ext_list[num_exts++] = cur_filter;
- cur_filter = split_keyval(cur_filter);
- }
+ uint32_t num_exts;
+ char **ext_list = get_extension_list(config, &num_exts);
for (size_t i = 0; dst && i < num_entries; i++)
{
if (num_exts && !entries[i].is_dir) {
- char *ext = path_extension(entries[i].name);
- if (!ext) {
- continue;
- }
- uint32_t extidx;
- for (extidx = 0; extidx < num_exts; extidx++)
- {
- if (!strcasecmp(ext, ext_list[extidx])) {
- break;
- }
- }
- if (extidx == num_exts) {
+ if (!path_matches_extensions(entries[i].name, ext_list, num_exts)) {
continue;
}
}
dst = copy_dir_entry_to_guest(dst, m68k, entries[i].name, entries[i].is_dir);
}
- free(ext_filter);
free(ext_list);
//terminate list
uint8_t *dest = get_native_pointer(dst, (void **)m68k->mem_pointers, &m68k->options->gen);
diff --git a/nuklear_ui/blastem_nuklear.c b/nuklear_ui/blastem_nuklear.c
index 44861d9..850f70e 100644
--- a/nuklear_ui/blastem_nuklear.c
+++ b/nuklear_ui/blastem_nuklear.c
@@ -10,6 +10,7 @@
#include "../paths.h"
#include "../saves.h"
#include "../blastem.h"
+#include "../config.h"
static struct nk_context *context;
@@ -28,6 +29,9 @@ void view_load(struct nk_context *context)
static dir_entry *entries;
static size_t num_entries;
static uint32_t selected_entry;
+ static char **ext_list;
+ static uint32_t num_exts;
+ static uint8_t got_ext_list;
if (!current_path) {
get_initial_browse_path(&current_path);
}
@@ -37,6 +41,10 @@ void view_load(struct nk_context *context)
sort_dir_list(entries, num_entries);
}
}
+ if (!got_ext_list) {
+ ext_list = get_extension_list(config, &num_exts);
+ got_ext_list = 1;
+ }
uint32_t width = render_width();
uint32_t height = render_height();
if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) {
@@ -45,6 +53,12 @@ void view_load(struct nk_context *context)
nk_layout_row_static(context, 28, width-100, 1);
for (uint32_t i = 0; i < num_entries; i++)
{
+ if (entries[i].name[0] == '.' && entries[i].name[1] != '.') {
+ continue;
+ }
+ if (num_exts && !entries[i].is_dir && !path_matches_extensions(entries[i].name, ext_list, num_exts)) {
+ continue;
+ }
int selected = i == selected_entry;
nk_selectable_label(context, entries[i].name, NK_TEXT_ALIGN_LEFT, &selected);
if (selected) {
diff --git a/util.c b/util.c
index 09128c8..96840e5 100644
--- a/util.c
+++ b/util.c
@@ -270,6 +270,22 @@ char *path_extension(char *path)
return strdup(lastdot+1);
}
+uint8_t path_matches_extensions(char *path, char **ext_list, uint32_t num_exts)
+{
+ char *ext = path_extension(path);
+ if (!ext) {
+ return 0;
+ }
+ uint32_t extidx;
+ for (extidx = 0; extidx < num_exts; extidx++)
+ {
+ if (!strcasecmp(ext, ext_list[extidx])) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
char * path_dirname(char *path)
{
char *lastslash = NULL;
diff --git a/util.h b/util.h
index c8a68eb..516aba3 100644
--- a/util.h
+++ b/util.h
@@ -42,6 +42,8 @@ char is_absolute_path(char *path);
char * basename_no_extension(char *path);
//Returns the extension from a path or NULL if there is no extension
char *path_extension(char *path);
+//Returns true if the given path matches one of the extensions in the list
+uint8_t path_matches_extensions(char *path, char **ext_list, uint32_t num_exts);
//Returns the directory portion of a path or NULL if there is no directory part
char *path_dirname(char *path);
//Gets the smallest power of two that is >= a certain value, won't work for values > 0x80000000