Sort results for libretro cores correctly.
This commit is contained in:
parent
4e7abfb6ad
commit
a3ddf8ed26
|
@ -257,6 +257,20 @@ void rgui_list_get_alt_at_offset(const rgui_list_t *list, size_t index,
|
|||
*alt = list->list[index].alt ? list->list[index].alt : list->list[index].path;
|
||||
}
|
||||
|
||||
static int rgui_list_alt_cmp(const void *a_, const void *b_)
|
||||
{
|
||||
const struct rgui_file *a = (const struct rgui_file*)a_;
|
||||
const struct rgui_file *b = (const struct rgui_file*)b_;
|
||||
const char *cmp_a = a->alt ? a->alt : a->path;
|
||||
const char *cmp_b = b->alt ? b->alt : b->path;
|
||||
return strcasecmp(cmp_a, cmp_b);
|
||||
}
|
||||
|
||||
void rgui_list_sort_on_alt(rgui_list_t *list)
|
||||
{
|
||||
qsort(list->list, list->size, sizeof(list->list[0]), rgui_list_alt_cmp);
|
||||
}
|
||||
|
||||
void rgui_list_get_at_offset(const rgui_list_t *list, size_t index,
|
||||
const char **path, unsigned *file_type)
|
||||
{
|
||||
|
@ -956,6 +970,8 @@ void menu_resolve_libretro_names(rgui_list_t *list, const char *dir)
|
|||
core_path, display_name, sizeof(display_name)))
|
||||
rgui_list_set_alt_at_offset(list, i, display_name);
|
||||
}
|
||||
|
||||
rgui_list_sort_on_alt(rgui->selection_buf);
|
||||
}
|
||||
|
||||
void menu_resolve_supported_cores(rgui_handle_t *rgui)
|
||||
|
@ -968,6 +984,7 @@ void menu_resolve_supported_cores(rgui_handle_t *rgui)
|
|||
rgui_list_push(rgui->selection_buf, info[i].path, RGUI_FILE_PLAIN, 0);
|
||||
rgui_list_set_alt_at_offset(rgui->selection_buf, i, info[i].display_name);
|
||||
}
|
||||
|
||||
rgui_list_sort_on_alt(rgui->selection_buf);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -997,8 +997,7 @@ static inline bool rgui_list_elem_is_dir(rgui_list_t *buf, unsigned offset)
|
|||
static inline int rgui_list_get_first_char(rgui_list_t *buf, unsigned offset)
|
||||
{
|
||||
const char *path = NULL;
|
||||
unsigned type = 0;
|
||||
rgui_list_get_at_offset(buf, offset, &path, &type);
|
||||
rgui_list_get_alt_at_offset(buf, offset, &path);
|
||||
int ret = tolower(*path);
|
||||
|
||||
// "Normalize" non-alphabetical entries so they are lumped together for purposes of jumping.
|
||||
|
@ -1173,7 +1172,6 @@ static bool rgui_directory_parse(rgui_handle_t *rgui, const char *directory, uns
|
|||
}
|
||||
|
||||
string_list_free(list);
|
||||
rgui_build_scroll_indices(rgui, (rgui_list_t*)ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1531,7 +1529,6 @@ static int rgui_iterate(void *data, unsigned action)
|
|||
rgui->need_refresh = false;
|
||||
rgui_list_clear(rgui->selection_buf);
|
||||
|
||||
rgui->scroll_indices_size = 0;
|
||||
if (menu_type == RGUI_SETTINGS_OPEN_HISTORY)
|
||||
history_parse(rgui);
|
||||
else if (menu_type != RGUI_SETTINGS_DEFERRED_CORE)
|
||||
|
@ -1542,6 +1539,10 @@ static int rgui_iterate(void *data, unsigned action)
|
|||
else if (menu_type == RGUI_SETTINGS_DEFERRED_CORE)
|
||||
menu_resolve_supported_cores(rgui);
|
||||
|
||||
rgui->scroll_indices_size = 0;
|
||||
if (menu_type != RGUI_SETTINGS_OPEN_HISTORY)
|
||||
rgui_build_scroll_indices(rgui, rgui->selection_buf);
|
||||
|
||||
// Before a refresh, we could have deleted a file on disk, causing
|
||||
// selection_ptr to suddendly be out of range. Ensure it doesn't overflow.
|
||||
if (rgui->selection_ptr >= rgui->selection_buf->size && rgui->selection_buf->size)
|
||||
|
|
|
@ -48,6 +48,8 @@ void rgui_list_set_alt_at_offset(rgui_list_t *list, size_t index,
|
|||
void rgui_list_get_alt_at_offset(const rgui_list_t *list, size_t index,
|
||||
const char **alt);
|
||||
|
||||
void rgui_list_sort_on_alt(rgui_list_t *list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue