diff --git a/core_info.c b/core_info.c index 24bf4a438b..10ce0c5b9e 100644 --- a/core_info.c +++ b/core_info.c @@ -558,6 +558,18 @@ core_info_t *core_info_find(core_info_list_t *list, return NULL; } +core_info_t *core_info_get(core_info_list_t *list, size_t i) +{ + core_info_t *info = (core_info_t*)&list->list[i]; +printf("%zu\n", i); + if (!info) + return NULL; + if (!info->path) + return NULL; + + return info; +} + static int core_info_firmware_cmp(const void *a_, const void *b_) { const core_info_firmware_t *a = (const core_info_firmware_t*)a_; diff --git a/core_info.h b/core_info.h index 86337fa307..d369501a2f 100644 --- a/core_info.h +++ b/core_info.h @@ -111,6 +111,8 @@ bool core_info_get_display_name(const char *path, char *s, size_t len); void core_info_get_name(const char *path, char *s, size_t len); +core_info_t *core_info_get(core_info_list_t *list, size_t i); + #ifdef __cplusplus } #endif diff --git a/menu/cbs/menu_cbs_left.c b/menu/cbs/menu_cbs_left.c index 33937d1445..764bbacd66 100644 --- a/menu/cbs/menu_cbs_left.c +++ b/menu/cbs/menu_cbs_left.c @@ -302,11 +302,48 @@ static int action_left_video_resolution(unsigned type, const char *label, static int playlist_association_left(unsigned type, const char *label, bool wraparound) { - unsigned idx = type - MENU_SETTINGS_PLAYLIST_ASSOCIATION_START; - rarch_system_info_t *system = rarch_system_info_get_ptr(); + int i, next, found, current = 0; + char core_path[PATH_MAX_LENGTH] = {0}; + global_t *global = global_get_ptr(); + settings_t *settings = config_get_ptr(); + const char *path = path_basename(label); + char new_playlist_cores[PATH_MAX_LENGTH] = {0}; - (void)idx; - (void)system; + core_info_list_t *list = (global->core_info.list) ? global->core_info.list : NULL; + if (!list) + return NULL; + + struct string_list *stnames = string_split(settings->playlist_names, ";"); + struct string_list *stcores = string_split(settings->playlist_cores, ";"); + + if (!menu_playlist_find_associated_core(path, core_path, sizeof(core_path))) + strlcpy(core_path, "DETECT", sizeof(core_path)); + + for (i = 0; i < list->count; i++) + { + core_info_t *info = core_info_get(list, i); + if (!strcmp(info->path, core_path)) + current = i; + } + + next = current - 1; + if (next < 0) + { + if (wraparound) + next = list->count; + else + next = 0; + } + + core_info_t *info = core_info_get(list, next); + + found = string_list_find_elem(stnames, path); + if (found) + string_list_set(stcores, found-1, info->path); + + string_list_join_concat(new_playlist_cores, sizeof(new_playlist_cores), stcores, ";"); + + strlcpy(settings->playlist_cores, new_playlist_cores, sizeof(settings->playlist_cores)); return 0; } diff --git a/menu/cbs/menu_cbs_right.c b/menu/cbs/menu_cbs_right.c index df46bf703b..fa3bb82769 100644 --- a/menu/cbs/menu_cbs_right.c +++ b/menu/cbs/menu_cbs_right.c @@ -327,11 +327,48 @@ static int action_right_video_resolution(unsigned type, const char *label, static int playlist_association_right(unsigned type, const char *label, bool wraparound) { - unsigned idx = type - MENU_SETTINGS_PLAYLIST_ASSOCIATION_START; - rarch_system_info_t *system = rarch_system_info_get_ptr(); + int i, next, found, current = 0; + char core_path[PATH_MAX_LENGTH] = {0}; + global_t *global = global_get_ptr(); + settings_t *settings = config_get_ptr(); + const char *path = path_basename(label); + char new_playlist_cores[PATH_MAX_LENGTH] = {0}; - (void)system; - (void)idx; + core_info_list_t *list = (global->core_info.list) ? global->core_info.list : NULL; + if (!list) + return NULL; + + struct string_list *stnames = string_split(settings->playlist_names, ";"); + struct string_list *stcores = string_split(settings->playlist_cores, ";"); + + if (!menu_playlist_find_associated_core(path, core_path, sizeof(core_path))) + strlcpy(core_path, "DETECT", sizeof(core_path)); + + for (i = 0; i < list->count; i++) + { + core_info_t *info = core_info_get(list, i); + if (!strcmp(info->path, core_path)) + current = i; + } + + next = current + 1; + if (next >= list->count) + { + if (wraparound) + next = list->count-1; + else + next = 0; + } + + core_info_t *info = core_info_get(list, next); + + found = string_list_find_elem(stnames, path); + if (found) + string_list_set(stcores, found-1, info->path); + + string_list_join_concat(new_playlist_cores, sizeof(new_playlist_cores), stcores, ";"); + + strlcpy(settings->playlist_cores, new_playlist_cores, sizeof(settings->playlist_cores)); return 0; }