From 9cf3dceb9d26d92665e5f10beeae86b5c37aa977 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 12 May 2015 15:56:49 +0200 Subject: [PATCH] Create DISPLAYLIST_CORES_UPDATER --- menu/menu_displaylist.c | 51 +++++++++++++++++++++++ menu/menu_displaylist.h | 1 + menu/menu_entries_cbs_deferred_push.c | 58 +++++---------------------- 3 files changed, 61 insertions(+), 49 deletions(-) diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 2614a72a4d..72ae4a6e40 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -28,6 +28,52 @@ #include "../performance.h" #include "../settings.h" +#ifdef HAVE_NETWORKING +extern char *core_buf; +extern size_t core_len; + +static void print_buf_lines(file_list_t *list, char *buf, int buf_size, + unsigned type) +{ + int i; + char c, *line_start = buf; + + for (i = 0; i < buf_size; i++) + { + size_t ln; + + /* The end of the buffer, print the last bit */ + if (*(buf + i) == '\0') + break; + + if (*(buf + i) != '\n') + continue; + + /* Found a line ending, print the line and compute new line_start */ + + /* Save the next char */ + c = *(buf + i + 1); + /* replace with \0 */ + *(buf + i + 1) = '\0'; + + /* We need to strip the newline. */ + ln = strlen(line_start) - 1; + if (line_start[ln] == '\n') + line_start[ln] = '\0'; + + menu_list_push(list, line_start, "", + type, 0); + + /* Restore the saved char */ + *(buf + i + 1) = c; + line_start = buf + i + 1; + } + /* If the buffer was completely full, and didn't end with a newline, just + * ignore the partial last line. + */ +} +#endif + static void menu_displaylist_push_perfcounter( menu_displaylist_info_t *info, const struct retro_perf_counter **counters, @@ -606,6 +652,11 @@ int menu_displaylist_push_list(menu_displaylist_info_t *info, unsigned type) menu_driver_populate_entries( info->path, info->label, info->type); break; + case DISPLAYLIST_CORES_UPDATER: + menu_list_clear(info->list); + print_buf_lines(info->list, core_buf, core_len, MENU_FILE_DOWNLOAD_CORE); + menu_list_populate_generic(info->list, info->path, info->label, info->type); + break; } return ret; diff --git a/menu/menu_displaylist.h b/menu/menu_displaylist.h index fef71b7d47..d0bf3ac4c6 100644 --- a/menu/menu_displaylist.h +++ b/menu/menu_displaylist.h @@ -36,6 +36,7 @@ enum DISPLAYLIST_DEFAULT, DISPLAYLIST_CORES, DISPLAYLIST_CORES_ALL, + DISPLAYLIST_CORES_UPDATER, DISPLAYLIST_CORES_DETECTED, DISPLAYLIST_PERFCOUNTER_SELECTION, DISPLAYLIST_PERFCOUNTERS_CORE, diff --git a/menu/menu_entries_cbs_deferred_push.c b/menu/menu_entries_cbs_deferred_push.c index ab5dc61960..accdb0d184 100644 --- a/menu/menu_entries_cbs_deferred_push.c +++ b/menu/menu_entries_cbs_deferred_push.c @@ -1711,52 +1711,11 @@ static int deferred_push_disk_options(void *data, void *userdata, } #ifdef HAVE_NETWORKING -static void print_buf_lines(file_list_t *list, char *buf, int buf_size, - unsigned type) -{ - int i; - char c, *line_start = buf; - - for (i = 0; i < buf_size; i++) - { - size_t ln; - - /* The end of the buffer, print the last bit */ - if (*(buf + i) == '\0') - break; - - if (*(buf + i) != '\n') - continue; - - /* Found a line ending, print the line and compute new line_start */ - - /* Save the next char */ - c = *(buf + i + 1); - /* replace with \0 */ - *(buf + i + 1) = '\0'; - - /* We need to strip the newline. */ - ln = strlen(line_start) - 1; - if (line_start[ln] == '\n') - line_start[ln] = '\0'; - - menu_list_push(list, line_start, "", - type, 0); - - /* Restore the saved char */ - *(buf + i + 1) = c; - line_start = buf + i + 1; - } - /* If the buffer was completely full, and didn't end with a newline, just - * ignore the partial last line. - */ -} - /* HACK - we have to find some way to pass state inbetween * function pointer callback functions that don't necessarily * call each other. */ -static char *core_buf; -static size_t core_len; +char *core_buf; +size_t core_len; int cb_core_updater_list(void *data_, size_t len) { @@ -1787,14 +1746,15 @@ int cb_core_updater_list(void *data_, size_t len) static int deferred_push_core_updater_list(void *data, void *userdata, const char *path, const char *label, unsigned type) { - file_list_t *list = (file_list_t*)data; - menu_list_clear(list); + menu_displaylist_info_t info = {0}; - print_buf_lines(list, core_buf, core_len, MENU_FILE_DOWNLOAD_CORE); + info.list = (file_list_t*)data; + info.menu_list = (file_list_t*)userdata; + info.type = type; + strlcpy(info.path, path, sizeof(info.path)); + strlcpy(info.label, label, sizeof(info.label)); - menu_list_populate_generic(list, path, label, type); - - return 0; + return menu_displaylist_push_list(&info, DISPLAYLIST_CORES_UPDATER); } #endif