From 230c64ba4b1e3dee151c531bc476f02c10da2f70 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Thu, 11 Apr 2019 00:09:13 -0400 Subject: [PATCH 1/6] add subsystem support for playlists, only missing the content load portion --- command.c | 3 +- discord/discord.c | 2 +- menu/cbs/menu_cbs_ok.c | 30 ++--- menu/cbs/menu_cbs_sublabel.c | 2 +- menu/drivers/ozone/ozone.c | 2 +- menu/drivers/stripes.c | 2 +- menu/menu_displaylist.c | 6 +- menu/menu_thumbnail_path.c | 2 +- playlist.c | 182 ++++++++++++++++++++++++++++-- playlist.h | 17 ++- tasks/task_content.c | 4 +- tasks/task_database.c | 10 +- tasks/task_netplay_find_content.c | 4 +- tasks/task_screenshot.c | 4 +- ui/drivers/qt/qt_playlist.cpp | 4 +- 15 files changed, 227 insertions(+), 47 deletions(-) diff --git a/command.c b/command.c index 31879c9adb..a00ef3e435 100755 --- a/command.c +++ b/command.c @@ -2415,7 +2415,8 @@ TODO: Add a setting for these tweaks */ str_list->elems[2].data, /* core_path */ str_list->elems[3].data, /* core_name */ str_list->elems[4].data, /* crc32 */ - str_list->elems[5].data /* db_name */ + str_list->elems[5].data, /* db_name */ + NULL, NULL ); runloop_msg_queue_push(msg_hash_to_str(MSG_ADDED_TO_FAVORITES), 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } diff --git a/discord/discord.c b/discord/discord.c index 8e8f339709..f6c2108d76 100644 --- a/discord/discord.c +++ b/discord/discord.c @@ -349,7 +349,7 @@ void discord_update(enum discord_presence presence) if (current_playlist) playlist_get_index_by_path( - current_playlist, path_get(RARCH_PATH_CONTENT), NULL, &label, NULL, NULL, NULL, NULL); + current_playlist, path_get(RARCH_PATH_CONTENT), NULL, &label, NULL, NULL, NULL, NULL, NULL, NULL); if (!label) label = (char *)path_basename(path_get(RARCH_PATH_BASENAME)); diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 9908a2aabe..730aeaa375 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -967,7 +967,7 @@ static bool menu_content_playlist_load(playlist_t *playlist, size_t idx) const char *path = NULL; playlist_get_index(playlist, - idx, &path, NULL, NULL, NULL, NULL, NULL); + idx, &path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (!string_is_empty(path)) { @@ -1735,7 +1735,7 @@ static int action_ok_playlist_entry_collection(const char *path, selection_ptr = entry_idx; playlist_get_index(playlist, selection_ptr, - &entry_path, &entry_label, &core_path, &core_name, NULL, NULL); + &entry_path, &entry_label, &core_path, &core_name, NULL, NULL, NULL, NULL); /* Is the core path / name of the playlist entry not yet filled in? */ if ( string_is_equal(core_path, file_path_str(FILE_PATH_DETECT)) @@ -1794,7 +1794,7 @@ static int action_ok_playlist_entry_collection(const char *path, } playlist_get_index(playlist, - selection_ptr, &path, NULL, NULL, NULL, NULL, NULL); + selection_ptr, &path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); return default_action_ok_load_content_from_playlist_from_menu( new_core_path, path, entry_label); @@ -1820,7 +1820,7 @@ static int action_ok_playlist_entry(const char *path, selection_ptr = entry_idx; playlist_get_index(playlist, selection_ptr, - &entry_path, &entry_label, &core_path, &core_name, NULL, NULL); + &entry_path, &entry_label, &core_path, &core_name, NULL, NULL, NULL, NULL); if ( string_is_equal(core_path, file_path_str(FILE_PATH_DETECT)) && string_is_equal(core_name, file_path_str(FILE_PATH_DETECT))) @@ -1869,7 +1869,7 @@ static int action_ok_playlist_entry(const char *path, playlist_get_index(playlist, selection_ptr, &path, NULL, NULL, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); return default_action_ok_load_content_from_playlist_from_menu( new_core_path, path, entry_label); @@ -1893,7 +1893,7 @@ static int action_ok_playlist_entry_start_content(const char *path, selection_ptr = menu->scratchpad.unsigned_var; playlist_get_index(playlist, selection_ptr, - &entry_path, &entry_label, &core_path, &core_name, NULL, NULL); + &entry_path, &entry_label, &core_path, &core_name, NULL, NULL, NULL, NULL); if ( string_is_equal(core_path, file_path_str(FILE_PATH_DETECT)) && string_is_equal(core_name, file_path_str(FILE_PATH_DETECT))) @@ -1943,7 +1943,7 @@ static int action_ok_playlist_entry_start_content(const char *path, } playlist_get_index(playlist, - selection_ptr, &path, NULL, NULL, NULL, NULL, NULL); + selection_ptr, &path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); return default_action_ok_load_content_from_playlist_from_menu(core_path, path, entry_label); @@ -2067,7 +2067,7 @@ static int action_ok_audio_add_to_mixer(const char *path, return -1; playlist_get_index(tmp_playlist, entry_idx, - &entry_path, NULL, NULL, NULL, NULL, NULL); + &entry_path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (filestream_exists(entry_path)) task_push_audio_mixer_load(entry_path, @@ -2089,7 +2089,7 @@ static int action_ok_audio_add_to_mixer_and_play(const char *path, return -1; playlist_get_index(tmp_playlist, entry_idx, - &entry_path, NULL, NULL, NULL, NULL, NULL); + &entry_path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (filestream_exists(entry_path)) task_push_audio_mixer_load_and_play(entry_path, @@ -2120,8 +2120,8 @@ static int action_ok_audio_add_to_mixer_and_collection(const char *path, NULL, "builtin", "musicplayer", - NULL, - NULL); + NULL, NULL, + NULL, NULL); if (filestream_exists(combined_path)) task_push_audio_mixer_load(combined_path, @@ -2152,8 +2152,8 @@ static int action_ok_audio_add_to_mixer_and_collection_and_play(const char *path NULL, "builtin", "musicplayer", - NULL, - NULL); + NULL, NULL, + NULL, NULL); if (filestream_exists(combined_path)) task_push_audio_mixer_load_and_play(combined_path, @@ -3803,7 +3803,7 @@ static int action_ok_reset_core_association(const char *path, playlist_get_index(tmp_playlist, menu->rpl_entry_selection_ptr, - &tmp_path, NULL, NULL, NULL, NULL, NULL); + &tmp_path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (!command_event(CMD_EVENT_RESET_CORE_ASSOCIATION, (void *)&menu->rpl_entry_selection_ptr)) @@ -3947,7 +3947,7 @@ static int action_ok_add_to_favorites_playlist(const char *path, /* Read current playlist parameters */ playlist_get_index(playlist_curr, menu->rpl_entry_selection_ptr, &content_path, &content_label, &core_path, &core_name, - &crc32, NULL); + &crc32, NULL, NULL, NULL); /* Error checking * > If content path is empty, cannot do anything... */ diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index f2cb33e60b..acf1f2bb45 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -859,7 +859,7 @@ static int action_bind_sublabel_playlist_entry( return 0; /* Read playlist entry */ - playlist_get_index(playlist, i, NULL, NULL, NULL, &core_name, NULL, NULL); + playlist_get_index(playlist, i, NULL, NULL, NULL, &core_name, NULL, NULL, NULL, NULL); /* Only add sublabel if a core is currently assigned */ if (string_is_empty(core_name) || string_is_equal(core_name, file_path_str(FILE_PATH_DETECT))) diff --git a/menu/drivers/ozone/ozone.c b/menu/drivers/ozone/ozone.c index e1b68f5a18..54ad392ef8 100644 --- a/menu/drivers/ozone/ozone.c +++ b/menu/drivers/ozone/ozone.c @@ -1141,7 +1141,7 @@ void ozone_update_content_metadata(ozone_handle_t *ozone) { const char *core_label = NULL; playlist_get_index(playlist, selection, - NULL, NULL, NULL, &core_name, NULL, NULL); + NULL, NULL, NULL, &core_name, NULL, NULL, NULL, NULL); /* Fill core name */ if (!core_name || string_is_equal(core_name, "DETECT")) diff --git a/menu/drivers/stripes.c b/menu/drivers/stripes.c index 7d6338c9f2..d77f4295a1 100644 --- a/menu/drivers/stripes.c +++ b/menu/drivers/stripes.c @@ -905,7 +905,7 @@ static void stripes_update_thumbnail_path(void *data, unsigned i, char pos) { const char *core_name = NULL; playlist_get_index(playlist, i, - NULL, NULL, NULL, &core_name, NULL, NULL); + NULL, NULL, NULL, &core_name, NULL, NULL, NULL, NULL); if (string_is_equal(core_name, "imageviewer")) { diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 0aa0b97034..9e1799089e 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1354,7 +1354,7 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, /* Read playlist entry */ playlist_get_index(playlist, i, - &path, &label, &core_path, &core_name, NULL, NULL); + &path, &label, &core_path, &core_name, NULL, NULL, NULL, NULL); /* Extract any available runtime values, if required */ if (get_runtime) @@ -1741,7 +1741,7 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu, playlist_get_index(playlist, j, NULL, NULL, NULL, NULL, - &crc32, NULL); + &crc32, NULL, NULL, NULL); if (crc32) tmp_str_list = string_split(crc32, "|"); @@ -2890,7 +2890,7 @@ static int menu_displaylist_parse_horizontal_content_actions( if (playlist) playlist_get_index(playlist, idx, - &entry_path, &label, &core_path, &core_name, NULL, &db_name); + &entry_path, &label, &core_path, &core_name, NULL, &db_name, NULL, NULL); content_loaded = !rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL) && string_is_equal(menu->deferred_path, fullpath); diff --git a/menu/menu_thumbnail_path.c b/menu/menu_thumbnail_path.c index 9bf097d9c3..7a085d5f74 100644 --- a/menu/menu_thumbnail_path.c +++ b/menu/menu_thumbnail_path.c @@ -340,7 +340,7 @@ bool menu_thumbnail_set_content_playlist(menu_thumbnail_path_data_t *path_data, /* Read playlist values */ playlist_get_index(playlist, idx, - &content_path, &content_label, NULL, &core_name, NULL, &db_name); + &content_path, &content_label, NULL, &core_name, NULL, &db_name, NULL, NULL); /* Content without a path is invalid by definition */ if (string_is_empty(content_path)) diff --git a/playlist.c b/playlist.c index 459f27586f..db281914ce 100644 --- a/playlist.c +++ b/playlist.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "playlist.h" @@ -46,6 +47,8 @@ struct playlist_entry char *core_name; char *db_name; char *crc32; + char *subsystem_ident; + struct string_list *subsystem_roms; unsigned runtime_hours; unsigned runtime_minutes; unsigned runtime_seconds; @@ -82,8 +85,11 @@ typedef struct char **current_entry_val; int *current_entry_int_val; unsigned *current_entry_uint_val; + struct string_list **current_entry_string_list_val; char *current_meta_string; + char *current_items_string; bool in_items; + bool in_subsystem_roms; } JSONContext; static playlist_t *playlist_cached = NULL; @@ -121,7 +127,9 @@ void playlist_get_index(playlist_t *playlist, const char **path, const char **label, const char **core_path, const char **core_name, const char **crc32, - const char **db_name) + const char **db_name, + const char **subsystem_ident, + const struct string_list **subsystem_roms) { if (!playlist) return; @@ -138,6 +146,10 @@ void playlist_get_index(playlist_t *playlist, *db_name = playlist->entries[idx].db_name; if (crc32) *crc32 = playlist->entries[idx].crc32; + if (subsystem_ident) + *subsystem_ident = playlist->entries[idx].subsystem_ident; + if (subsystem_roms) + *subsystem_roms = playlist->entries[idx].subsystem_roms; } void playlist_get_runtime_index(playlist_t *playlist, @@ -200,7 +212,9 @@ void playlist_get_index_by_path(playlist_t *playlist, char **path, char **label, char **core_path, char **core_name, char **crc32, - char **db_name) + char **db_name, + char **subsystem_ident, + struct string_list **subsystem_roms) { size_t i; if (!playlist) @@ -223,6 +237,10 @@ void playlist_get_index_by_path(playlist_t *playlist, *db_name = playlist->entries[i].db_name; if (crc32) *crc32 = playlist->entries[i].crc32; + if (subsystem_ident) + *subsystem_ident = playlist->entries[i].subsystem_ident; + if (subsystem_roms) + *subsystem_roms = playlist->entries[i].subsystem_roms; break; } } @@ -265,6 +283,10 @@ static void playlist_free_entry(struct playlist_entry *entry) free(entry->db_name); if (entry->crc32 != NULL) free(entry->crc32); + if (entry->subsystem_ident != NULL) + free(entry->subsystem_ident); + if (entry->subsystem_roms != NULL) + string_list_free(entry->subsystem_roms); entry->path = NULL; entry->label = NULL; @@ -272,6 +294,8 @@ static void playlist_free_entry(struct playlist_entry *entry) entry->core_name = NULL; entry->db_name = NULL; entry->crc32 = NULL; + entry->subsystem_ident = NULL; + entry->subsystem_roms = NULL; entry->runtime_hours = 0; entry->runtime_minutes = 0; entry->runtime_seconds = 0; @@ -544,7 +568,9 @@ bool playlist_push(playlist_t *playlist, const char *path, const char *label, const char *core_path, const char *core_name, const char *crc32, - const char *db_name) + const char *db_name, + const char *subsystem_ident, + const struct string_list *subsystem_roms) { size_t i; bool core_path_empty = string_is_empty(core_path); @@ -595,6 +621,37 @@ bool playlist_push(playlist_t *playlist, if (!string_is_equal(playlist->entries[i].core_path, core_path)) continue; + if (!string_is_empty(subsystem_ident) && !string_is_empty(playlist->entries[i].subsystem_ident) && !string_is_equal(playlist->entries[i].subsystem_ident, subsystem_ident)) + continue; + + if (string_is_empty(subsystem_ident) && !string_is_empty(playlist->entries[i].subsystem_ident)) + continue; + + if (!string_is_empty(subsystem_ident) && string_is_empty(playlist->entries[i].subsystem_ident)) + continue; + + if (subsystem_roms) + { + int j; + const struct string_list *roms = playlist->entries[i].subsystem_roms; + bool unequal = false; + + if (subsystem_roms->size != roms->size) + continue; + + for (j = 0; j < subsystem_roms->size; j++) + { + if (!string_is_equal(subsystem_roms->elems[j].data, roms->elems[j].data)) + { + unequal = true; + break; + } + } + + if (unequal) + continue; + } + /* If top entry, we don't want to push a new entry since * the top and the entry to be pushed are the same. */ if (i == 0) @@ -629,6 +686,8 @@ bool playlist_push(playlist_t *playlist, playlist->entries[0].core_name = NULL; playlist->entries[0].db_name = NULL; playlist->entries[0].crc32 = NULL; + playlist->entries[0].subsystem_ident = NULL; + playlist->entries[0].subsystem_roms = NULL; playlist->entries[0].runtime_hours = 0; playlist->entries[0].runtime_minutes = 0; playlist->entries[0].runtime_seconds = 0; @@ -650,6 +709,19 @@ bool playlist_push(playlist_t *playlist, playlist->entries[0].db_name = strdup(db_name); if (!string_is_empty(crc32)) playlist->entries[0].crc32 = strdup(crc32); + if (!string_is_empty(subsystem_ident)) + playlist->entries[0].subsystem_ident = strdup(subsystem_ident); + if (subsystem_roms) + { + union string_list_elem_attr attributes = {0}; + + playlist->entries[0].subsystem_roms = string_list_new(); + + for (i = 0; i < subsystem_roms->size; i++) + { + string_list_append(playlist->entries[0].subsystem_roms, subsystem_roms->elems[i].data, attributes); + } + } } playlist->size++; @@ -1001,6 +1073,49 @@ void playlist_write_file(playlist_t *playlist) JSON_Writer_WriteColon(context.writer); JSON_Writer_WriteSpace(context.writer, 1); JSON_Writer_WriteString(context.writer, playlist->entries[i].db_name ? playlist->entries[i].db_name : "", playlist->entries[i].db_name ? strlen(playlist->entries[i].db_name) : 0, JSON_UTF8); + + if (!string_is_empty(playlist->entries[i].subsystem_ident)) + { + JSON_Writer_WriteComma(context.writer); + JSON_Writer_WriteNewLine(context.writer); + JSON_Writer_WriteSpace(context.writer, 6); + JSON_Writer_WriteString(context.writer, "subsystem_ident", strlen("subsystem_ident"), JSON_UTF8); + JSON_Writer_WriteColon(context.writer); + JSON_Writer_WriteSpace(context.writer, 1); + JSON_Writer_WriteString(context.writer, playlist->entries[i].subsystem_ident ? playlist->entries[i].subsystem_ident : "", playlist->entries[i].subsystem_ident ? strlen(playlist->entries[i].subsystem_ident) : 0, JSON_UTF8); + } + + if (playlist->entries[i].subsystem_roms && playlist->entries[i].subsystem_roms->size > 0) + { + int j; + + JSON_Writer_WriteComma(context.writer); + JSON_Writer_WriteNewLine(context.writer); + JSON_Writer_WriteSpace(context.writer, 6); + JSON_Writer_WriteString(context.writer, "subsystem_roms", strlen("subsystem_roms"), JSON_UTF8); + JSON_Writer_WriteColon(context.writer); + JSON_Writer_WriteSpace(context.writer, 1); + JSON_Writer_WriteStartArray(context.writer); + JSON_Writer_WriteNewLine(context.writer); + + for (j = 0; j < playlist->entries[i].subsystem_roms->size; j++) + { + const struct string_list *roms = playlist->entries[i].subsystem_roms; + JSON_Writer_WriteSpace(context.writer, 8); + JSON_Writer_WriteString(context.writer, !string_is_empty(roms->elems[j].data) ? roms->elems[j].data : "", !string_is_empty(roms->elems[j].data) ? strlen(roms->elems[j].data) : 0, JSON_UTF8); + + if (j < playlist->entries[i].subsystem_roms->size - 1) + { + JSON_Writer_WriteComma(context.writer); + JSON_Writer_WriteNewLine(context.writer); + } + } + + JSON_Writer_WriteNewLine(context.writer); + JSON_Writer_WriteSpace(context.writer, 6); + JSON_Writer_WriteEndArray(context.writer); + } + JSON_Writer_WriteNewLine(context.writer); JSON_Writer_WriteSpace(context.writer, 4); @@ -1106,6 +1221,12 @@ static JSON_Parser_HandlerResult JSONStartArrayHandler(JSON_Parser parser) if (string_is_equal(pCtx->current_meta_string, "items") && pCtx->array_depth == 1) pCtx->in_items = true; } + else if (pCtx->object_depth == 2) + { + if (pCtx->array_depth == 2) + if (string_is_equal(pCtx->current_items_string, "subsystem_roms")) + pCtx->in_subsystem_roms = true; + } return JSON_Parser_Continue; } @@ -1125,6 +1246,19 @@ static JSON_Parser_HandlerResult JSONEndArrayHandler(JSON_Parser parser) free(pCtx->current_meta_string); pCtx->current_meta_string = NULL; pCtx->in_items = false; + + if (pCtx->current_items_string) + { + free(pCtx->current_items_string); + pCtx->current_items_string = NULL; + } + } + } + else if (pCtx->object_depth == 2) + { + if (pCtx->in_subsystem_roms && string_is_equal(pCtx->current_items_string, "subsystem_roms") && pCtx->array_depth == 1) + { + pCtx->in_subsystem_roms = false; } } @@ -1174,7 +1308,19 @@ static JSON_Parser_HandlerResult JSONStringHandler(JSON_Parser parser, char *pVa JSONContext *pCtx = (JSONContext*)JSON_Parser_GetUserData(parser); (void)attributes; /* unused */ - if (pCtx->in_items && pCtx->object_depth == 2) + if (pCtx->in_items && pCtx->in_subsystem_roms && pCtx->object_depth == 2 && pCtx->array_depth == 2) + { + if (pCtx->current_entry_string_list_val && length && !string_is_empty(pValue)) + { + union string_list_elem_attr attr = {0}; + + if (!*pCtx->current_entry_string_list_val) + *pCtx->current_entry_string_list_val = string_list_new(); + + string_list_append(*pCtx->current_entry_string_list_val, pValue, attr); + } + } + else if (pCtx->in_items && pCtx->object_depth == 2) { if (pCtx->array_depth == 1) { @@ -1269,6 +1415,13 @@ static JSON_Parser_HandlerResult JSONObjectMemberHandler(JSON_Parser parser, cha if (length) { + if (!string_is_empty(pValue)) + { + if (!string_is_empty(pCtx->current_items_string)) + free(pCtx->current_items_string); + pCtx->current_items_string = strdup(pValue); + } + if (string_is_equal(pValue, "path")) pCtx->current_entry_val = &pCtx->current_entry->path; else if (string_is_equal(pValue, "label")) @@ -1281,6 +1434,10 @@ static JSON_Parser_HandlerResult JSONObjectMemberHandler(JSON_Parser parser, cha pCtx->current_entry_val = &pCtx->current_entry->crc32; else if (string_is_equal(pValue, "db_name")) pCtx->current_entry_val = &pCtx->current_entry->db_name; + else if (string_is_equal(pValue, "subsystem_ident")) + pCtx->current_entry_val = &pCtx->current_entry->subsystem_ident; + else if (string_is_equal(pValue, "subsystem_roms")) + pCtx->current_entry_string_list_val = &pCtx->current_entry->subsystem_roms; else if (string_is_equal(pValue, "runtime_hours")) pCtx->current_entry_uint_val = &pCtx->current_entry->runtime_hours; else if (string_is_equal(pValue, "runtime_minutes")) @@ -1441,6 +1598,9 @@ static bool playlist_read_file( if (context.current_meta_string) free(context.current_meta_string); + + if (context.current_items_string) + free(context.current_items_string); } else { @@ -1464,9 +1624,9 @@ static bool playlist_read_file( /* Read playlist entry and terminate string with NUL character * regardless of Windows or Unix line endings */ - if((last = strrchr(buf[i], '\r'))) + if ((last = strrchr(buf[i], '\r'))) *last = '\0'; - else if((last = strrchr(buf[i], '\n'))) + else if ((last = strrchr(buf[i], '\n'))) *last = '\0'; } @@ -1577,6 +1737,7 @@ static int playlist_qsort_func(const struct playlist_entry *a, goto end; a_fallback_label = (char*)calloc(PATH_MAX_LENGTH, sizeof(char)); + if (!a_fallback_label) goto end; @@ -1594,6 +1755,7 @@ static int playlist_qsort_func(const struct playlist_entry *a, goto end; b_fallback_label = (char*)calloc(PATH_MAX_LENGTH, sizeof(char)); + if (!b_fallback_label) goto end; @@ -1641,7 +1803,9 @@ void command_playlist_push_write( const char *core_path, const char *core_name, const char *crc32, - const char *db_name) + const char *db_name, + const char *subsystem_ident, + const struct string_list *subsystem_roms) { if (!playlist) return; @@ -1653,7 +1817,9 @@ void command_playlist_push_write( core_path, core_name, crc32, - db_name + db_name, + subsystem_ident, + subsystem_roms )) playlist_write_file(playlist); } diff --git a/playlist.h b/playlist.h index 9de8b2a19a..7265ebfb8e 100644 --- a/playlist.h +++ b/playlist.h @@ -21,6 +21,7 @@ #include #include +#include RETRO_BEGIN_DECLS @@ -77,7 +78,9 @@ void playlist_get_index(playlist_t *playlist, const char **path, const char **label, const char **core_path, const char **core_name, const char **crc32, - const char **db_name); + const char **db_name, + const char **subsystem_ident, + const struct string_list **subsystem_roms); void playlist_get_runtime_index(playlist_t *playlist, size_t idx, @@ -109,7 +112,9 @@ bool playlist_push(playlist_t *playlist, const char *path, const char *label, const char *core_path, const char *core_name, const char *crc32, - const char *db_name); + const char *db_name, + const char *subsystem_ident, + const struct string_list *subsystem_roms); bool playlist_push_runtime(playlist_t *playlist, const char *path, const char *core_path, @@ -140,7 +145,9 @@ void playlist_get_index_by_path(playlist_t *playlist, char **path, char **label, char **core_path, char **core_name, char **crc32, - char **db_name); + char **db_name, + char **subsystem_ident, + struct string_list **subsystem_roms); bool playlist_entry_exists(playlist_t *playlist, const char *path, @@ -169,7 +176,9 @@ void command_playlist_push_write( const char *core_path, const char *core_name, const char *crc32, - const char *db_name); + const char *db_name, + const char *subsystem_ident, + const struct string_list *subsystem_roms); void command_playlist_update_write( playlist_t *playlist, diff --git a/tasks/task_content.c b/tasks/task_content.c index d1c9c03fd0..348cf524e2 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -1094,7 +1094,9 @@ static bool task_load_content(content_ctx_info_t *content_info, core_path, core_name, crc32, - db_name); + db_name, + path_get(RARCH_PATH_SUBSYSTEM), + path_get_subsystem_list()); } free(tmp); diff --git a/tasks/task_database.c b/tasks/task_database.c index 4d701c0bee..29700f1413 100644 --- a/tasks/task_database.c +++ b/tasks/task_database.c @@ -843,13 +843,14 @@ static int database_info_list_iterate_found_match( fprintf(stderr, "entry path str: %s\n", entry_path_str); #endif - if(!playlist_entry_exists(playlist, entry_path_str, db_crc)) + if (!playlist_entry_exists(playlist, entry_path_str, db_crc)) { playlist_push(playlist, entry_path_str, db_info_entry->name, file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_DETECT), - db_crc, db_playlist_base_str); + db_crc, db_playlist_base_str, + NULL, NULL); } playlist_write_file(playlist); @@ -1010,7 +1011,7 @@ static int task_database_iterate_playlist_lutro( free(db_playlist_path); - if(!playlist_entry_exists(playlist, + if (!playlist_entry_exists(playlist, path, file_path_str(FILE_PATH_DETECT))) { char *game_title = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); @@ -1025,7 +1026,8 @@ static int task_database_iterate_playlist_lutro( file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_DETECT), - file_path_str(FILE_PATH_LUTRO_PLAYLIST)); + file_path_str(FILE_PATH_LUTRO_PLAYLIST), + NULL, NULL); free(game_title); } diff --git a/tasks/task_netplay_find_content.c b/tasks/task_netplay_find_content.c index 8cce2eb286..205606d2bb 100644 --- a/tasks/task_netplay_find_content.c +++ b/tasks/task_netplay_find_content.c @@ -277,7 +277,7 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) const char *playlist_crc32 = NULL; const char *playlist_path = NULL; - playlist_get_index(playlist, j, &playlist_path, NULL, NULL, NULL, &playlist_crc32, NULL); + playlist_get_index(playlist, j, &playlist_path, NULL, NULL, NULL, &playlist_crc32, NULL, NULL, NULL); if(have_crc && string_is_equal(playlist_crc32, state->content_crc)) { @@ -345,7 +345,7 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) const char *playlist_crc32 = NULL; const char *playlist_path = NULL; - playlist_get_index(playlist, k, &playlist_path, NULL, NULL, NULL, &playlist_crc32, NULL); + playlist_get_index(playlist, k, &playlist_path, NULL, NULL, NULL, &playlist_crc32, NULL, NULL, NULL); get_entry(entry, sizeof(entry), playlist_path); if(!string_is_empty(entry) && diff --git a/tasks/task_screenshot.c b/tasks/task_screenshot.c index e2a229db23..eb1f8beedb 100644 --- a/tasks/task_screenshot.c +++ b/tasks/task_screenshot.c @@ -176,8 +176,8 @@ static void task_screenshot_handler(retro_task_t *task) NULL, "builtin", "imageviewer", - NULL, - NULL); + NULL, NULL, + NULL, NULL); #endif task_set_progress(task, 100); diff --git a/ui/drivers/qt/qt_playlist.cpp b/ui/drivers/qt/qt_playlist.cpp index 2ebcc684a0..8e2aab5325 100644 --- a/ui/drivers/qt/qt_playlist.cpp +++ b/ui/drivers/qt/qt_playlist.cpp @@ -602,7 +602,7 @@ void MainWindow::addFilesToPlaylist(QStringList files) } playlist_push(playlist, pathData, fileNameNoExten, - corePathData, coreNameData, "00000000|crc", databaseData); + corePathData, coreNameData, "00000000|crc", databaseData, NULL, NULL); } playlist_write_file(playlist); @@ -1368,7 +1368,7 @@ void PlaylistModel::getPlaylistItems(QString path) playlist_get_index(playlist, i, &path, &label, &core_path, - &core_name, &crc32, &db_name); + &core_name, &crc32, &db_name, NULL, NULL); if (string_is_empty(path)) continue; From 71bfd98012983e5bdc09088bde368a0673a8ec93 Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 11 Apr 2019 18:18:37 -0500 Subject: [PATCH 2/6] [subsystem] allow loading from history --- menu/cbs/menu_cbs_ok.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 730aeaa375..7ae36ebea9 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1715,9 +1715,17 @@ static int action_ok_playlist_entry_collection(const char *path, playlist_t *tmp_playlist = NULL; menu_handle_t *menu = NULL; + const char *subsystem_ident = NULL; + const struct string_list + *subsystem_rom_list = NULL; + unsigned i = 0; + + if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) return menu_cbs_exit(); + + new_core_path[0] = '\0'; tmp_playlist = playlist_get_cached(); @@ -1735,7 +1743,32 @@ static int action_ok_playlist_entry_collection(const char *path, selection_ptr = entry_idx; playlist_get_index(playlist, selection_ptr, - &entry_path, &entry_label, &core_path, &core_name, NULL, NULL, NULL, NULL); + &entry_path, &entry_label, &core_path, &core_name, NULL, NULL, &subsystem_ident, &subsystem_rom_list); + + + /* Subsystem codepath */ + if (!string_is_empty(subsystem_ident) && subsystem_rom_list) + { + content_ctx_info_t content_info = {0}; + task_push_load_new_core(core_path, NULL, + &content_info, CORE_TYPE_PLAIN, NULL, NULL); + content_clear_subsystem(); + if (!content_set_subsystem_by_name(subsystem_ident)) + { + RARCH_LOG("[playlist] subsystem not found in implementation\n"); + /* TODO: Add OSD message telling users that content can't be loaded */ + return 0; + } + + for (i = 0; i < subsystem_rom_list->size; i++) + content_add_subsystem(subsystem_rom_list->elems[i].data); + task_push_load_subsystem_with_core_from_menu( + NULL, &content_info, + CORE_TYPE_PLAIN, NULL, NULL); + /* TODO: update playlist entry? move to first position I guess? */ + return 1; + } + /* Is the core path / name of the playlist entry not yet filled in? */ if ( string_is_equal(core_path, file_path_str(FILE_PATH_DETECT)) From 729f13cad4af202d8498a11ed21f3852ead3ac8a Mon Sep 17 00:00:00 2001 From: bparker06 Date: Thu, 11 Apr 2019 19:45:28 -0400 Subject: [PATCH 3/6] Update menu_cbs_ok.c --- menu/cbs/menu_cbs_ok.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 7ae36ebea9..8999fe2c30 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1720,12 +1720,9 @@ static int action_ok_playlist_entry_collection(const char *path, *subsystem_rom_list = NULL; unsigned i = 0; - if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) return menu_cbs_exit(); - - new_core_path[0] = '\0'; tmp_playlist = playlist_get_cached(); @@ -1736,6 +1733,7 @@ static int action_ok_playlist_entry_collection(const char *path, if (!tmp_playlist) return menu_cbs_exit(); + playlist_initialized = true; } @@ -1745,14 +1743,16 @@ static int action_ok_playlist_entry_collection(const char *path, playlist_get_index(playlist, selection_ptr, &entry_path, &entry_label, &core_path, &core_name, NULL, NULL, &subsystem_ident, &subsystem_rom_list); - /* Subsystem codepath */ - if (!string_is_empty(subsystem_ident) && subsystem_rom_list) + if (!string_is_empty(subsystem_ident)) { - content_ctx_info_t content_info = {0}; + content_ctx_info_t content_info = {0}; + task_push_load_new_core(core_path, NULL, &content_info, CORE_TYPE_PLAIN, NULL, NULL); + content_clear_subsystem(); + if (!content_set_subsystem_by_name(subsystem_ident)) { RARCH_LOG("[playlist] subsystem not found in implementation\n"); @@ -1762,6 +1762,7 @@ static int action_ok_playlist_entry_collection(const char *path, for (i = 0; i < subsystem_rom_list->size; i++) content_add_subsystem(subsystem_rom_list->elems[i].data); + task_push_load_subsystem_with_core_from_menu( NULL, &content_info, CORE_TYPE_PLAIN, NULL, NULL); @@ -1769,7 +1770,6 @@ static int action_ok_playlist_entry_collection(const char *path, return 1; } - /* Is the core path / name of the playlist entry not yet filled in? */ if ( string_is_equal(core_path, file_path_str(FILE_PATH_DETECT)) && string_is_equal(core_name, file_path_str(FILE_PATH_DETECT))) From d08779adf039d16f94a1e80aa08207c23af827b8 Mon Sep 17 00:00:00 2001 From: radius Date: Thu, 11 Apr 2019 18:51:27 -0500 Subject: [PATCH 4/6] [subsystem] add a function to get the friendly name --- content.h | 3 +++ tasks/task_content.c | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/content.h b/content.h index 20ff9cd9aa..fb44c05e21 100644 --- a/content.h +++ b/content.h @@ -112,6 +112,9 @@ char* content_get_subsystem_rom(unsigned index); /* Sets the subsystem by name */ bool content_set_subsystem_by_name(const char* subsystem_name); +/* Get the current subsystem "friendly name" */ +void content_get_subsystem_friendly_name(const char* subsystem_name, char* subsystem_friendly_name, size_t len); + RETRO_END_DECLS #endif diff --git a/tasks/task_content.c b/tasks/task_content.c index 348cf524e2..ccbdb42a3d 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -1982,6 +1982,28 @@ bool content_set_subsystem_by_name(const char* subsystem_name) return false; } +void content_get_subsystem_friendly_name(const char* subsystem_name, char* subsystem_friendly_name, size_t len) +{ + rarch_system_info_t *system = runloop_get_system_info(); + const struct retro_subsystem_info *subsystem; + unsigned i = 0; + + /* Core fully loaded, use the subsystem data */ + if (system->subsystem.data) + subsystem = system->subsystem.data; + /* Core not loaded completely, use the data we peeked on load core */ + else + subsystem = subsystem_data; + + for (i = 0; i < subsystem_current_count; i++, subsystem++) + { + if (string_is_equal(subsystem_name, subsystem->ident)) + strlcpy(subsystem_friendly_name, subsystem->desc, len); + } + + return; +} + /* Add a rom to the subsystem rom buffer */ void content_add_subsystem(const char* path) { From f7b0c0947c261727f4b31673fecc111f6b864d06 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Fri, 12 Apr 2019 12:50:27 -0400 Subject: [PATCH 5/6] add subsystem_name (friendly name) to history playlist, make playlist_entry struct public to simplify function parameters --- command.c | 29 ++-- discord/discord.c | 10 +- menu/cbs/menu_cbs_ok.c | 257 ++++++++++++++---------------- menu/cbs/menu_cbs_sublabel.c | 7 +- menu/drivers/ozone/ozone.c | 7 +- menu/drivers/stripes.c | 7 +- menu/menu_displaylist.c | 58 +++---- menu/menu_thumbnail_path.c | 13 +- playlist.c | 237 ++++++++++----------------- playlist.h | 73 ++++----- tasks/task_content.c | 33 ++-- tasks/task_database.c | 34 ++-- tasks/task_netplay_find_content.c | 54 ++++--- tasks/task_screenshot.c | 18 ++- ui/drivers/qt/qt_playlist.cpp | 72 +++++---- 15 files changed, 438 insertions(+), 471 deletions(-) diff --git a/command.c b/command.c index a00ef3e435..85a07db7e9 100755 --- a/command.c +++ b/command.c @@ -2407,16 +2407,19 @@ TODO: Add a setting for these tweaks */ { if (str_list->size >= 6) { + struct playlist_entry entry = {0}; + + entry.path = str_list->elems[0].data; /* content_path */ + entry.label = str_list->elems[1].data; /* content_label */ + entry.core_path = str_list->elems[2].data; /* core_path */ + entry.core_name = str_list->elems[3].data; /* core_name */ + entry.crc32 = str_list->elems[4].data; /* crc32 */ + entry.db_name = str_list->elems[5].data; /* db_name */ + /* Write playlist entry */ command_playlist_push_write( g_defaults.content_favorites, - str_list->elems[0].data, /* content_path */ - str_list->elems[1].data, /* content_label */ - str_list->elems[2].data, /* core_path */ - str_list->elems[3].data, /* core_name */ - str_list->elems[4].data, /* crc32 */ - str_list->elems[5].data, /* db_name */ - NULL, NULL + &entry ); runloop_msg_queue_push(msg_hash_to_str(MSG_ADDED_TO_FAVORITES), 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } @@ -2429,16 +2432,16 @@ TODO: Add a setting for these tweaks */ const char *core_name = "DETECT"; const char *core_path = "DETECT"; size_t *playlist_index = (size_t*)data; + struct playlist_entry entry = {0}; + + /* the update function reads our entry as const, so these casts are safe */ + entry.core_path = (char*)core_path; + entry.core_name = (char*)core_name; command_playlist_update_write( NULL, *playlist_index, - NULL, - NULL, - core_path, - core_name, - NULL, - NULL); + &entry); runloop_msg_queue_push(msg_hash_to_str(MSG_RESET_CORE_ASSOCIATION), 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); break; diff --git a/discord/discord.c b/discord/discord.c index f6c2108d76..ba7c3fdc95 100644 --- a/discord/discord.c +++ b/discord/discord.c @@ -344,15 +344,19 @@ void discord_update(enum discord_presence presence) { const char *system_id = core_info->system_id ? core_info->system_id : "core"; - char *label = NULL; + const char *label = NULL; + const struct playlist_entry *entry = NULL; playlist_t *current_playlist = playlist_get_cached(); if (current_playlist) + { playlist_get_index_by_path( - current_playlist, path_get(RARCH_PATH_CONTENT), NULL, &label, NULL, NULL, NULL, NULL, NULL, NULL); + current_playlist, path_get(RARCH_PATH_CONTENT), &entry); + label = entry->label; + } if (!label) - label = (char *)path_basename(path_get(RARCH_PATH_BASENAME)); + label = path_basename(path_get(RARCH_PATH_BASENAME)); #if 0 RARCH_LOG("[discord] current core: %s\n", system_id); RARCH_LOG("[discord] current content: %s\n", label); diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 8999fe2c30..98e6d14335 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -965,9 +965,11 @@ end: static bool menu_content_playlist_load(playlist_t *playlist, size_t idx) { const char *path = NULL; + const struct playlist_entry *entry = NULL; - playlist_get_index(playlist, - idx, &path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + playlist_get_index(playlist, idx, &entry); + + path = entry->path; if (!string_is_empty(path)) { @@ -1708,16 +1710,9 @@ static int action_ok_playlist_entry_collection(const char *path, size_t selection_ptr = 0; bool playlist_initialized = false; playlist_t *playlist = NULL; - const char *entry_path = NULL; - const char *entry_label = NULL; - const char *core_path = NULL; - const char *core_name = NULL; playlist_t *tmp_playlist = NULL; menu_handle_t *menu = NULL; - - const char *subsystem_ident = NULL; - const struct string_list - *subsystem_rom_list = NULL; + const struct playlist_entry *entry = NULL; unsigned i = 0; if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) @@ -1740,28 +1735,27 @@ static int action_ok_playlist_entry_collection(const char *path, playlist = tmp_playlist; selection_ptr = entry_idx; - playlist_get_index(playlist, selection_ptr, - &entry_path, &entry_label, &core_path, &core_name, NULL, NULL, &subsystem_ident, &subsystem_rom_list); + playlist_get_index(playlist, selection_ptr, &entry); /* Subsystem codepath */ - if (!string_is_empty(subsystem_ident)) + if (!string_is_empty(entry->subsystem_ident)) { content_ctx_info_t content_info = {0}; - task_push_load_new_core(core_path, NULL, + task_push_load_new_core(entry->core_path, NULL, &content_info, CORE_TYPE_PLAIN, NULL, NULL); content_clear_subsystem(); - if (!content_set_subsystem_by_name(subsystem_ident)) + if (!content_set_subsystem_by_name(entry->subsystem_ident)) { RARCH_LOG("[playlist] subsystem not found in implementation\n"); /* TODO: Add OSD message telling users that content can't be loaded */ return 0; } - for (i = 0; i < subsystem_rom_list->size; i++) - content_add_subsystem(subsystem_rom_list->elems[i].data); + for (i = 0; i < entry->subsystem_roms->size; i++) + content_add_subsystem(entry->subsystem_roms->elems[i].data); task_push_load_subsystem_with_core_from_menu( NULL, &content_info, @@ -1771,8 +1765,8 @@ static int action_ok_playlist_entry_collection(const char *path, } /* Is the core path / name of the playlist entry not yet filled in? */ - if ( string_is_equal(core_path, file_path_str(FILE_PATH_DETECT)) - && string_is_equal(core_name, file_path_str(FILE_PATH_DETECT))) + if ( string_is_equal(entry->core_path, file_path_str(FILE_PATH_DETECT)) + && string_is_equal(entry->core_name, file_path_str(FILE_PATH_DETECT))) { core_info_ctx_find_t core_info; const char *entry_path = NULL; @@ -1802,18 +1796,20 @@ static int action_ok_playlist_entry_collection(const char *path, tmp_playlist = playlist_get_cached(); if (tmp_playlist) + { + struct playlist_entry entry = {0}; + + entry.core_path = new_core_path; + entry.core_name = core_info.inf->display_name; + command_playlist_update_write( tmp_playlist, selection_ptr, - NULL, - NULL, - new_core_path, - core_info.inf->display_name, - NULL, - NULL); + &entry); + } } else - strlcpy(new_core_path, core_path, sizeof(new_core_path)); + strlcpy(new_core_path, entry->core_path, sizeof(new_core_path)); if (!playlist || !menu_content_playlist_load(playlist, selection_ptr)) { @@ -1826,11 +1822,10 @@ static int action_ok_playlist_entry_collection(const char *path, return menu_cbs_exit(); } - playlist_get_index(playlist, - selection_ptr, &path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + playlist_get_index(playlist, selection_ptr, &entry); return default_action_ok_load_content_from_playlist_from_menu( - new_core_path, path, entry_label); + new_core_path, entry->path, entry->label); } static int action_ok_playlist_entry(const char *path, @@ -1839,11 +1834,9 @@ static int action_ok_playlist_entry(const char *path, char new_core_path[PATH_MAX_LENGTH]; size_t selection_ptr = 0; playlist_t *playlist = g_defaults.content_history; - const char *entry_path = NULL; - const char *entry_label = NULL; - const char *core_path = NULL; - const char *core_name = NULL; menu_handle_t *menu = NULL; + const struct playlist_entry *entry = NULL; + const char *entry_label = NULL; new_core_path[0] = '\0'; @@ -1852,11 +1845,12 @@ static int action_ok_playlist_entry(const char *path, selection_ptr = entry_idx; - playlist_get_index(playlist, selection_ptr, - &entry_path, &entry_label, &core_path, &core_name, NULL, NULL, NULL, NULL); + playlist_get_index(playlist, selection_ptr, &entry); - if ( string_is_equal(core_path, file_path_str(FILE_PATH_DETECT)) - && string_is_equal(core_name, file_path_str(FILE_PATH_DETECT))) + entry_label = entry->label; + + if ( string_is_equal(entry->core_path, file_path_str(FILE_PATH_DETECT)) + && string_is_equal(entry->core_name, file_path_str(FILE_PATH_DETECT))) { core_info_ctx_find_t core_info; const char *entry_path = NULL; @@ -1875,21 +1869,23 @@ static int action_ok_playlist_entry(const char *path, if (!found_associated_core) /* TODO: figure out if this should refer to the inner or outer entry_path */ /* TODO: make sure there's only one entry_path in this function */ - return action_ok_file_load_with_detect_core(entry_path, + return action_ok_file_load_with_detect_core(entry->path, label, type, selection_ptr, entry_idx); - command_playlist_update_write(NULL, - selection_ptr, - NULL, - NULL, - new_core_path, - core_info.inf->display_name, - NULL, - NULL); + { + struct playlist_entry entry = {0}; + + entry.core_path = new_core_path; + entry.core_name = core_info.inf->display_name; + + command_playlist_update_write(NULL, + selection_ptr, + &entry); + } } - else if (!string_is_empty(core_path)) - strlcpy(new_core_path, core_path, sizeof(new_core_path)); + else if (!string_is_empty(entry->core_path)) + strlcpy(new_core_path, entry->core_path, sizeof(new_core_path)); if (!playlist || !menu_content_playlist_load(playlist, selection_ptr)) { @@ -1901,23 +1897,19 @@ static int action_ok_playlist_entry(const char *path, } playlist_get_index(playlist, - selection_ptr, &path, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + selection_ptr, &entry); return default_action_ok_load_content_from_playlist_from_menu( - new_core_path, path, entry_label); + new_core_path, entry->path, entry_label); } static int action_ok_playlist_entry_start_content(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { size_t selection_ptr = 0; - const char *entry_path = NULL; - const char *entry_label = NULL; - const char *core_path = NULL; - const char *core_name = NULL; menu_handle_t *menu = NULL; playlist_t *playlist = playlist_get_cached(); + const struct playlist_entry *entry = NULL; if ( !playlist || !menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) @@ -1925,11 +1917,10 @@ static int action_ok_playlist_entry_start_content(const char *path, selection_ptr = menu->scratchpad.unsigned_var; - playlist_get_index(playlist, selection_ptr, - &entry_path, &entry_label, &core_path, &core_name, NULL, NULL, NULL, NULL); + playlist_get_index(playlist, selection_ptr, &entry); - if ( string_is_equal(core_path, file_path_str(FILE_PATH_DETECT)) - && string_is_equal(core_name, file_path_str(FILE_PATH_DETECT))) + if ( string_is_equal(entry->core_path, file_path_str(FILE_PATH_DETECT)) + && string_is_equal(entry->core_name, file_path_str(FILE_PATH_DETECT))) { core_info_ctx_find_t core_info; char new_core_path[PATH_MAX_LENGTH]; @@ -1958,15 +1949,17 @@ static int action_ok_playlist_entry_start_content(const char *path, return action_ok_file_load_with_detect_core(entry_path, label, type, selection_ptr, entry_idx); - command_playlist_update_write( - playlist, - selection_ptr, - NULL, - NULL, - new_core_path, - core_info.inf->display_name, - NULL, - NULL); + { + struct playlist_entry entry = {0}; + + entry.core_path = new_core_path; + entry.core_name = core_info.inf->display_name; + + command_playlist_update_write( + playlist, + selection_ptr, + &entry); + } } if (!menu_content_playlist_load(playlist, selection_ptr)) @@ -1975,10 +1968,9 @@ static int action_ok_playlist_entry_start_content(const char *path, goto error; } - playlist_get_index(playlist, - selection_ptr, &path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + playlist_get_index(playlist, selection_ptr, &entry); - return default_action_ok_load_content_from_playlist_from_menu(core_path, path, entry_label); + return default_action_ok_load_content_from_playlist_from_menu(entry->core_path, entry->path, entry->label); error: return menu_cbs_exit(); @@ -2095,15 +2087,15 @@ static int action_ok_audio_add_to_mixer(const char *path, { const char *entry_path = NULL; playlist_t *tmp_playlist = playlist_get_cached(); + const struct playlist_entry *entry = NULL; if (!tmp_playlist) return -1; - playlist_get_index(tmp_playlist, entry_idx, - &entry_path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + playlist_get_index(tmp_playlist, entry_idx, &entry); - if (filestream_exists(entry_path)) - task_push_audio_mixer_load(entry_path, + if (filestream_exists(entry->path)) + task_push_audio_mixer_load(entry->path, NULL, NULL, false, AUDIO_MIXER_SLOT_SELECTION_AUTOMATIC, 0 @@ -2117,15 +2109,15 @@ static int action_ok_audio_add_to_mixer_and_play(const char *path, { const char *entry_path = NULL; playlist_t *tmp_playlist = playlist_get_cached(); + const struct playlist_entry *entry = NULL; if (!tmp_playlist) return -1; - playlist_get_index(tmp_playlist, entry_idx, - &entry_path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + playlist_get_index(tmp_playlist, entry_idx, &entry); - if (filestream_exists(entry_path)) - task_push_audio_mixer_load_and_play(entry_path, + if (filestream_exists(entry->path)) + task_push_audio_mixer_load_and_play(entry->path, NULL, NULL, false, AUDIO_MIXER_SLOT_SELECTION_AUTOMATIC, 0); @@ -2138,6 +2130,7 @@ static int action_ok_audio_add_to_mixer_and_collection(const char *path, { char combined_path[PATH_MAX_LENGTH]; menu_handle_t *menu = NULL; + struct playlist_entry entry = {0}; combined_path[0] = '\0'; @@ -2147,14 +2140,12 @@ static int action_ok_audio_add_to_mixer_and_collection(const char *path, fill_pathname_join(combined_path, menu->scratch2_buf, menu->scratch_buf, sizeof(combined_path)); - command_playlist_push_write( - g_defaults.music_history, - combined_path, - NULL, - "builtin", - "musicplayer", - NULL, NULL, - NULL, NULL); + /* the push function reads our entry as const, so these casts are safe */ + entry.path = combined_path; + entry.core_path = (char*)"builtin"; + entry.core_name = (char*)"musicplayer"; + + command_playlist_push_write(g_defaults.music_history, &entry); if (filestream_exists(combined_path)) task_push_audio_mixer_load(combined_path, @@ -2170,6 +2161,7 @@ static int action_ok_audio_add_to_mixer_and_collection_and_play(const char *path { char combined_path[PATH_MAX_LENGTH]; menu_handle_t *menu = NULL; + struct playlist_entry entry = {0}; combined_path[0] = '\0'; @@ -2179,14 +2171,12 @@ static int action_ok_audio_add_to_mixer_and_collection_and_play(const char *path fill_pathname_join(combined_path, menu->scratch2_buf, menu->scratch_buf, sizeof(combined_path)); - command_playlist_push_write( - g_defaults.music_history, - combined_path, - NULL, - "builtin", - "musicplayer", - NULL, NULL, - NULL, NULL); + /* the push function reads our entry as const, so these casts are safe */ + entry.path = combined_path; + entry.core_path = (char*)"builtin"; + entry.core_name = (char*)"musicplayer"; + + command_playlist_push_write(g_defaults.music_history, &entry); if (filestream_exists(combined_path)) task_push_audio_mixer_load_and_play(combined_path, @@ -2250,14 +2240,16 @@ static void menu_input_st_string_cb_rename_entry(void *userdata, const char *label = menu_input_dialog_get_buffer(); if (!string_is_empty(label)) + { + struct playlist_entry entry = {0}; + + /* the update function reads our entry as const, so these casts are safe */ + entry.label = (char*)label; + command_playlist_update_write(NULL, menu_input_dialog_get_kb_idx(), - NULL, - label, - NULL, - NULL, - NULL, - NULL); + &entry); + } } menu_input_dialog_end(); @@ -2708,15 +2700,20 @@ static int action_ok_core_deferred_set(const char *new_core_path, ext_name, settings->bools.show_hidden_files, true); - command_playlist_update_write( - NULL, - menu->scratchpad.unsigned_var, - NULL, - content_label, - new_core_path, - core_display_name, - NULL, - NULL); + + { + struct playlist_entry entry = {0}; + + /* the update function reads our entry as const, so these casts are safe */ + entry.label = (char*)content_label; + entry.core_path = (char*)new_core_path; + entry.core_name = core_display_name; + + command_playlist_update_write( + NULL, + menu->scratchpad.unsigned_var, + &entry); + } menu_entries_pop_stack(&selection, 0, 1); menu_navigation_set_selection(selection); @@ -3834,10 +3831,6 @@ static int action_ok_reset_core_association(const char *path, if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) return menu_cbs_exit(); - playlist_get_index(tmp_playlist, - menu->rpl_entry_selection_ptr, - &tmp_path, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - if (!command_event(CMD_EVENT_RESET_CORE_ASSOCIATION, (void *)&menu->rpl_entry_selection_ptr)) return menu_cbs_exit(); @@ -3962,14 +3955,9 @@ static int action_ok_add_to_favorites(const char *path, static int action_ok_add_to_favorites_playlist(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { - const char *content_path = NULL; - const char *content_label = NULL; - const char *core_path = NULL; - const char *core_name = NULL; - const char *crc32 = NULL; - const char *db_name = NULL; menu_handle_t *menu = NULL; playlist_t *playlist_curr = playlist_get_cached(); + const struct playlist_entry *entry = NULL; int ret = 0; if (!playlist_curr) @@ -3978,13 +3966,11 @@ static int action_ok_add_to_favorites_playlist(const char *path, return menu_cbs_exit(); /* Read current playlist parameters */ - playlist_get_index(playlist_curr, menu->rpl_entry_selection_ptr, - &content_path, &content_label, &core_path, &core_name, - &crc32, NULL, NULL, NULL); + playlist_get_index(playlist_curr, menu->rpl_entry_selection_ptr, &entry); /* Error checking * > If content path is empty, cannot do anything... */ - if (!string_is_empty(content_path)) + if (!string_is_empty(entry->path)) { struct string_list *str_list = NULL; union string_list_elem_attr attr; @@ -4007,43 +3993,43 @@ static int action_ok_add_to_favorites_playlist(const char *path, * [5]: db_name */ /* > content_path */ - string_list_append(str_list, content_path, attr); + string_list_append(str_list, entry->path, attr); /* > content_label */ - if (!string_is_empty(content_label)) + if (!string_is_empty(entry->label)) { - string_list_append(str_list, content_label, attr); + string_list_append(str_list, entry->label, attr); } else { /* Label is empty - use file name instead */ char fallback_content_label[PATH_MAX_LENGTH]; fallback_content_label[0] = '\0'; - fill_short_pathname_representation(fallback_content_label, content_path, sizeof(fallback_content_label)); + fill_short_pathname_representation(fallback_content_label, entry->path, sizeof(fallback_content_label)); string_list_append(str_list, fallback_content_label, attr); } /* > core_path + core_name */ - if (!string_is_empty(core_path) && !string_is_empty(core_name)) + if (!string_is_empty(entry->core_path) && !string_is_empty(entry->core_name)) { core_info_ctx_find_t core_info; /* >> core_path */ - string_list_append(str_list, core_path, attr); + string_list_append(str_list, entry->core_path, attr); /* >> core_name * (always use display name, if available) */ core_info.inf = NULL; - core_info.path = core_path; + core_info.path = entry->core_path; - if (core_info_find(&core_info, core_path)) + if (core_info_find(&core_info, entry->core_path)) if (!string_is_empty(core_info.inf->display_name)) strlcpy(core_display_name, core_info.inf->display_name, sizeof(core_display_name)); if (!string_is_empty(core_display_name)) string_list_append(str_list, core_display_name, attr); else - string_list_append(str_list, core_name, attr); + string_list_append(str_list, entry->core_name, attr); } else { @@ -4052,11 +4038,10 @@ static int action_ok_add_to_favorites_playlist(const char *path, } /* crc32 */ - string_list_append(str_list, !string_is_empty(crc32) ? crc32 : "", attr); + string_list_append(str_list, !string_is_empty(entry->crc32) ? entry->crc32 : "", attr); /* db_name */ - playlist_get_db_name(playlist_curr, menu->rpl_entry_selection_ptr, &db_name); - string_list_append(str_list, !string_is_empty(db_name) ? db_name : "", attr); + string_list_append(str_list, !string_is_empty(entry->db_name) ? entry->db_name : "", attr); /* Trigger 'ADD_TO_FAVORITES' event */ if (!command_event(CMD_EVENT_ADD_TO_FAVORITES, (void*)str_list)) diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index acf1f2bb45..854f01a5fc 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -837,6 +837,7 @@ static int action_bind_sublabel_playlist_entry( { settings_t *settings = config_get_ptr(); playlist_t *playlist = NULL; + const struct playlist_entry *entry = NULL; const char *core_name = NULL; unsigned runtime_hours = 0; unsigned runtime_minutes = 0; @@ -853,13 +854,17 @@ static int action_bind_sublabel_playlist_entry( /* Get current playlist */ playlist = playlist_get_cached(); + if (!playlist) return 0; + if (i >= playlist_get_size(playlist)) return 0; /* Read playlist entry */ - playlist_get_index(playlist, i, NULL, NULL, NULL, &core_name, NULL, NULL, NULL, NULL); + playlist_get_index(playlist, i, &entry); + + core_name = entry->core_name; /* Only add sublabel if a core is currently assigned */ if (string_is_empty(core_name) || string_is_equal(core_name, file_path_str(FILE_PATH_DETECT))) diff --git a/menu/drivers/ozone/ozone.c b/menu/drivers/ozone/ozone.c index 54ad392ef8..c08b616d41 100644 --- a/menu/drivers/ozone/ozone.c +++ b/menu/drivers/ozone/ozone.c @@ -1132,6 +1132,7 @@ void ozone_update_content_metadata(ozone_handle_t *ozone) { size_t selection = menu_navigation_get_selection(); playlist_t *playlist = playlist_get_cached(); + const struct playlist_entry *entry = NULL; const char *core_name = NULL; settings_t *settings = config_get_ptr(); @@ -1140,8 +1141,9 @@ void ozone_update_content_metadata(ozone_handle_t *ozone) if (ozone->is_playlist && playlist) { const char *core_label = NULL; - playlist_get_index(playlist, selection, - NULL, NULL, NULL, &core_name, NULL, NULL, NULL, NULL); + playlist_get_index(playlist, selection, &entry); + + core_name = entry->core_name; /* Fill core name */ if (!core_name || string_is_equal(core_name, "DETECT")) @@ -1207,7 +1209,6 @@ void ozone_update_content_metadata(ozone_handle_t *ozone) msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISABLED)); } } - } static void ozone_set_thumbnail_content(void *data, const char *s) diff --git a/menu/drivers/stripes.c b/menu/drivers/stripes.c index d77f4295a1..9515008558 100644 --- a/menu/drivers/stripes.c +++ b/menu/drivers/stripes.c @@ -903,11 +903,10 @@ static void stripes_update_thumbnail_path(void *data, unsigned i, char pos) if (playlist) { - const char *core_name = NULL; - playlist_get_index(playlist, i, - NULL, NULL, NULL, &core_name, NULL, NULL, NULL, NULL); + const struct playlist_entry *entry = NULL; + playlist_get_index(playlist, i, &entry); - if (string_is_equal(core_name, "imageviewer")) + if (string_is_equal(entry->core_name, "imageviewer")) { if (pos == 'R' || (pos == 'L' && string_is_equal(stripes_thumbnails_ident('R'), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF)))) diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 9e1799089e..68571c7f52 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1345,22 +1345,18 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, for (i = 0; i < list_size; i++) { char menu_entry_label[PATH_MAX_LENGTH]; - const char *path = NULL; - const char *label = NULL; - const char *core_path = NULL; - const char *core_name = NULL; + const struct playlist_entry *entry = NULL; menu_entry_label[0] = '\0'; /* Read playlist entry */ - playlist_get_index(playlist, i, - &path, &label, &core_path, &core_name, NULL, NULL, NULL, NULL); + playlist_get_index(playlist, i, &entry); /* Extract any available runtime values, if required */ if (get_runtime) { runtime_log_t *runtime_log = NULL; - runtime_log = runtime_log_init(path, core_path, + runtime_log = runtime_log_init(entry->path, entry->core_path, settings->uints.playlist_sublabel_runtime_type == PLAYLIST_RUNTIME_PER_CORE); if (runtime_log) @@ -1400,7 +1396,7 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, } } - if (!string_is_empty(path)) + if (!string_is_empty(entry->path)) { /* Standard playlist entry * > Base menu entry label is always playlist label @@ -1408,27 +1404,27 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info, * > If required, add currently associated core (if any), otherwise * no further action is necessary */ - if (string_is_empty(label)) - fill_short_pathname_representation(menu_entry_label, path, sizeof(menu_entry_label)); + if (string_is_empty(entry->label)) + fill_short_pathname_representation(menu_entry_label, entry->path, sizeof(menu_entry_label)); else - strlcpy(menu_entry_label, label, sizeof(menu_entry_label)); + strlcpy(menu_entry_label, entry->label, sizeof(menu_entry_label)); if (show_inline_core_name) { - if (!string_is_empty(core_name) && !string_is_equal(core_name, file_path_str(FILE_PATH_DETECT))) + if (!string_is_empty(entry->core_name) && !string_is_equal(entry->core_name, file_path_str(FILE_PATH_DETECT))) { strlcat(menu_entry_label, label_spacer, sizeof(menu_entry_label)); - strlcat(menu_entry_label, core_name, sizeof(menu_entry_label)); + strlcat(menu_entry_label, entry->core_name, sizeof(menu_entry_label)); } } - menu_entries_append_enum(info->list, menu_entry_label, path, + menu_entries_append_enum(info->list, menu_entry_label, entry->path, MENU_ENUM_LABEL_PLAYLIST_ENTRY, FILE_TYPE_RPL_ENTRY, 0, i); } else { - if (core_name) - strlcpy(menu_entry_label, core_name, sizeof(menu_entry_label)); + if (entry->core_name) + strlcpy(menu_entry_label, entry->core_name, sizeof(menu_entry_label)); menu_entries_append_enum(info->list, menu_entry_label, path_playlist, MENU_ENUM_LABEL_PLAYLIST_ENTRY, FILE_TYPE_PLAYLIST_ENTRY, 0, i); @@ -1735,16 +1731,14 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu, { for (j = 0; j < playlist_size(playlist); j++) { - const char *crc32 = NULL; + const struct playlist_entry *entry = NULL; bool match_found = false; struct string_list *tmp_str_list = NULL; - playlist_get_index(playlist, j, - NULL, NULL, NULL, NULL, - &crc32, NULL, NULL, NULL); + playlist_get_index(playlist, j, &entry); - if (crc32) - tmp_str_list = string_split(crc32, "|"); + if (entry->crc32) + tmp_str_list = string_split(entry->crc32, "|"); if (!tmp_str_list) continue; @@ -2878,19 +2872,14 @@ static int menu_displaylist_parse_horizontal_content_actions( menu_displaylist_info_t *info) { bool content_loaded = false; - const char *label = NULL; - const char *entry_path = NULL; - const char *core_path = NULL; - const char *core_name = NULL; - const char *db_name = NULL; playlist_t *playlist = playlist_get_cached(); settings_t *settings = config_get_ptr(); const char *fullpath = path_get(RARCH_PATH_CONTENT); unsigned idx = menu->rpl_entry_selection_ptr; + const struct playlist_entry *entry = NULL; if (playlist) - playlist_get_index(playlist, idx, - &entry_path, &label, &core_path, &core_name, NULL, &db_name, NULL, NULL); + playlist_get_index(playlist, idx, &entry); content_loaded = !rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL) && string_is_equal(menu->deferred_path, fullpath); @@ -2901,8 +2890,8 @@ static int menu_displaylist_parse_horizontal_content_actions( { const char *ext = NULL; - if (!string_is_empty(entry_path)) - ext = path_get_extension(entry_path); + if (!string_is_empty(entry->path)) + ext = path_get_extension(entry->path); if (!string_is_empty(ext) && audio_driver_mixer_extension_supported(ext)) @@ -2956,10 +2945,9 @@ static int menu_displaylist_parse_horizontal_content_actions( msg_hash_to_str(MENU_ENUM_LABEL_RESET_CORE_ASSOCIATION), MENU_ENUM_LABEL_RESET_CORE_ASSOCIATION, FILE_TYPE_PLAYLIST_ENTRY, 0, 0); } - } - if (!string_is_empty(db_name) && (!content_loaded || + if (!string_is_empty(entry->db_name) && (!content_loaded || (content_loaded && settings->bools.quick_menu_show_information))) { char *db_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); @@ -2968,7 +2956,7 @@ static int menu_displaylist_parse_horizontal_content_actions( fill_pathname_join_noext(db_path, settings->paths.path_content_database, - db_name, + entry->db_name, PATH_MAX_LENGTH * sizeof(char)); strlcat(db_path, file_path_str(FILE_PATH_RDB_EXTENSION), @@ -2977,7 +2965,7 @@ static int menu_displaylist_parse_horizontal_content_actions( if (filestream_exists(db_path)) menu_entries_append_enum( info->list, - label, + entry->label, db_path, MENU_ENUM_LABEL_INFORMATION, FILE_TYPE_RDB_ENTRY, 0, idx); diff --git a/menu/menu_thumbnail_path.c b/menu/menu_thumbnail_path.c index 7a085d5f74..f5eb0a141c 100644 --- a/menu/menu_thumbnail_path.c +++ b/menu/menu_thumbnail_path.c @@ -316,7 +316,8 @@ bool menu_thumbnail_set_content_playlist(menu_thumbnail_path_data_t *path_data, const char *content_label = NULL; const char *core_name = NULL; const char *db_name = NULL; - + const struct playlist_entry *entry = NULL; + if (!path_data) return false; @@ -339,9 +340,13 @@ bool menu_thumbnail_set_content_playlist(menu_thumbnail_path_data_t *path_data, return false; /* Read playlist values */ - playlist_get_index(playlist, idx, - &content_path, &content_label, NULL, &core_name, NULL, &db_name, NULL, NULL); - + playlist_get_index(playlist, idx, &entry); + + content_path = entry->path; + content_label = entry->label; + core_name = entry->core_name; + db_name = entry->db_name; + /* Content without a path is invalid by definition */ if (string_is_empty(content_path)) return false; diff --git a/playlist.c b/playlist.c index db281914ce..24a3e305d7 100644 --- a/playlist.c +++ b/playlist.c @@ -1,7 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2017 - Daniel De Matteis - * Copyright (C) 2018-2019 - Brad Parker + * Copyright (C) 2016-2019 - Brad Parker * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- @@ -39,30 +39,6 @@ #define PLAYLIST_ENTRIES 6 #endif -struct playlist_entry -{ - char *path; - char *label; - char *core_path; - char *core_name; - char *db_name; - char *crc32; - char *subsystem_ident; - struct string_list *subsystem_roms; - unsigned runtime_hours; - unsigned runtime_minutes; - unsigned runtime_seconds; - /* Note: due to platform dependence, have to record - * timestamp as either a string or independent integer - * values. The latter is more verbose, but more efficient. */ - unsigned last_played_year; - unsigned last_played_month; - unsigned last_played_day; - unsigned last_played_hour; - unsigned last_played_minute; - unsigned last_played_second; -}; - struct content_playlist { bool modified; @@ -124,32 +100,12 @@ char *playlist_get_conf_path(playlist_t *playlist) **/ void playlist_get_index(playlist_t *playlist, size_t idx, - const char **path, const char **label, - const char **core_path, const char **core_name, - const char **crc32, - const char **db_name, - const char **subsystem_ident, - const struct string_list **subsystem_roms) + const struct playlist_entry **entry) { - if (!playlist) + if (!playlist || !entry) return; - if (path) - *path = playlist->entries[idx].path; - if (label) - *label = playlist->entries[idx].label; - if (core_path) - *core_path = playlist->entries[idx].core_path; - if (core_name) - *core_name = playlist->entries[idx].core_name; - if (db_name) - *db_name = playlist->entries[idx].db_name; - if (crc32) - *crc32 = playlist->entries[idx].crc32; - if (subsystem_ident) - *subsystem_ident = playlist->entries[idx].subsystem_ident; - if (subsystem_roms) - *subsystem_roms = playlist->entries[idx].subsystem_roms; + *entry = &playlist->entries[idx]; } void playlist_get_runtime_index(playlist_t *playlist, @@ -209,15 +165,11 @@ void playlist_delete_index(playlist_t *playlist, void playlist_get_index_by_path(playlist_t *playlist, const char *search_path, - char **path, char **label, - char **core_path, char **core_name, - char **crc32, - char **db_name, - char **subsystem_ident, - struct string_list **subsystem_roms) + const struct playlist_entry **entry) { size_t i; - if (!playlist) + + if (!playlist || !entry) return; for (i = 0; i < playlist->size; i++) @@ -225,22 +177,8 @@ void playlist_get_index_by_path(playlist_t *playlist, if (!string_is_equal(playlist->entries[i].path, search_path)) continue; - if (path) - *path = playlist->entries[i].path; - if (label) - *label = playlist->entries[i].label; - if (core_path) - *core_path = playlist->entries[i].core_path; - if (core_name) - *core_name = playlist->entries[i].core_name; - if (db_name) - *db_name = playlist->entries[i].db_name; - if (crc32) - *crc32 = playlist->entries[i].crc32; - if (subsystem_ident) - *subsystem_ident = playlist->entries[i].subsystem_ident; - if (subsystem_roms) - *subsystem_roms = playlist->entries[i].subsystem_roms; + *entry = &playlist->entries[i]; + break; } } @@ -285,6 +223,8 @@ static void playlist_free_entry(struct playlist_entry *entry) free(entry->crc32); if (entry->subsystem_ident != NULL) free(entry->subsystem_ident); + if (entry->subsystem_name != NULL) + free(entry->subsystem_name); if (entry->subsystem_roms != NULL) string_list_free(entry->subsystem_roms); @@ -295,6 +235,7 @@ static void playlist_free_entry(struct playlist_entry *entry) entry->db_name = NULL; entry->crc32 = NULL; entry->subsystem_ident = NULL; + entry->subsystem_name = NULL; entry->subsystem_roms = NULL; entry->runtime_hours = 0; entry->runtime_minutes = 0; @@ -308,10 +249,7 @@ static void playlist_free_entry(struct playlist_entry *entry) } void playlist_update(playlist_t *playlist, size_t idx, - const char *path, const char *label, - const char *core_path, const char *core_name, - const char *crc32, - const char *db_name) + const struct playlist_entry *update_entry) { struct playlist_entry *entry = NULL; @@ -320,52 +258,52 @@ void playlist_update(playlist_t *playlist, size_t idx, entry = &playlist->entries[idx]; - if (path && (path != entry->path)) + if (update_entry->path && (update_entry->path != entry->path)) { if (entry->path != NULL) free(entry->path); - entry->path = strdup(path); + entry->path = strdup(update_entry->path); playlist->modified = true; } - if (label && (label != entry->label)) + if (update_entry->label && (update_entry->label != entry->label)) { if (entry->label != NULL) free(entry->label); - entry->label = strdup(label); + entry->label = strdup(update_entry->label); playlist->modified = true; } - if (core_path && (core_path != entry->core_path)) + if (update_entry->core_path && (update_entry->core_path != entry->core_path)) { if (entry->core_path != NULL) free(entry->core_path); entry->core_path = NULL; - entry->core_path = strdup(core_path); + entry->core_path = strdup(update_entry->core_path); playlist->modified = true; } - if (core_name && (core_name != entry->core_name)) + if (update_entry->core_name && (update_entry->core_name != entry->core_name)) { if (entry->core_name != NULL) free(entry->core_name); - entry->core_name = strdup(core_name); + entry->core_name = strdup(update_entry->core_name); playlist->modified = true; } - if (db_name && (db_name != entry->db_name)) + if (update_entry->db_name && (update_entry->db_name != entry->db_name)) { if (entry->db_name != NULL) free(entry->db_name); - entry->db_name = strdup(db_name); + entry->db_name = strdup(update_entry->db_name); playlist->modified = true; } - if (crc32 && (crc32 != entry->crc32)) + if (update_entry->crc32 && (update_entry->crc32 != entry->crc32)) { if (entry->crc32 != NULL) free(entry->crc32); - entry->crc32 = strdup(crc32); + entry->crc32 = strdup(update_entry->crc32); playlist->modified = true; } } @@ -558,30 +496,24 @@ success: /** * playlist_push: * @playlist : Playlist handle. - * @path : Path of new playlist entry. - * @core_path : Core path of new playlist entry. - * @core_name : Core name of new playlist entry. * * Push entry to top of playlist. **/ bool playlist_push(playlist_t *playlist, - const char *path, const char *label, - const char *core_path, const char *core_name, - const char *crc32, - const char *db_name, - const char *subsystem_ident, - const struct string_list *subsystem_roms) + const struct playlist_entry *entry) { size_t i; - bool core_path_empty = string_is_empty(core_path); - bool core_name_empty = string_is_empty(core_name); + bool core_path_empty = string_is_empty(entry->core_path); + bool core_name_empty = string_is_empty(entry->core_name); + const char *core_name = entry->core_name; + const char *path = entry->path; if (core_path_empty || core_name_empty) { if (core_name_empty && !core_path_empty) { static char base_path[255] = {0}; - fill_pathname_base_noext(base_path, core_path, sizeof(base_path)); + fill_pathname_base_noext(base_path, entry->core_path, sizeof(base_path)); core_name = base_path; } @@ -607,9 +539,9 @@ bool playlist_push(playlist_t *playlist, (path && playlist->entries[i].path && #ifdef _WIN32 /*prevent duplicates on case-insensitive operating systems*/ - string_is_equal_noncase(path,playlist->entries[i].path) + string_is_equal_noncase(path, playlist->entries[i].path) #else - string_is_equal(path,playlist->entries[i].path) + string_is_equal(path, playlist->entries[i].path) #endif ); @@ -618,30 +550,39 @@ bool playlist_push(playlist_t *playlist, if (!equal_path) continue; - if (!string_is_equal(playlist->entries[i].core_path, core_path)) + if (!string_is_equal(playlist->entries[i].core_path, entry->core_path)) continue; - if (!string_is_empty(subsystem_ident) && !string_is_empty(playlist->entries[i].subsystem_ident) && !string_is_equal(playlist->entries[i].subsystem_ident, subsystem_ident)) + if (!string_is_empty(entry->subsystem_ident) && !string_is_empty(playlist->entries[i].subsystem_ident) && !string_is_equal(playlist->entries[i].subsystem_ident, entry->subsystem_ident)) continue; - if (string_is_empty(subsystem_ident) && !string_is_empty(playlist->entries[i].subsystem_ident)) + if (string_is_empty(entry->subsystem_ident) && !string_is_empty(playlist->entries[i].subsystem_ident)) continue; - if (!string_is_empty(subsystem_ident) && string_is_empty(playlist->entries[i].subsystem_ident)) + if (!string_is_empty(entry->subsystem_ident) && string_is_empty(playlist->entries[i].subsystem_ident)) continue; - if (subsystem_roms) + if (!string_is_empty(entry->subsystem_name) && !string_is_empty(playlist->entries[i].subsystem_name) && !string_is_equal(playlist->entries[i].subsystem_name, entry->subsystem_name)) + continue; + + if (string_is_empty(entry->subsystem_name) && !string_is_empty(playlist->entries[i].subsystem_name)) + continue; + + if (!string_is_empty(entry->subsystem_name) && string_is_empty(playlist->entries[i].subsystem_name)) + continue; + + if (entry->subsystem_roms) { int j; const struct string_list *roms = playlist->entries[i].subsystem_roms; bool unequal = false; - if (subsystem_roms->size != roms->size) + if (entry->subsystem_roms->size != roms->size) continue; - for (j = 0; j < subsystem_roms->size; j++) + for (j = 0; j < entry->subsystem_roms->size; j++) { - if (!string_is_equal(subsystem_roms->elems[j].data, roms->elems[j].data)) + if (!string_is_equal(entry->subsystem_roms->elems[j].data, roms->elems[j].data)) { unequal = true; break; @@ -687,6 +628,7 @@ bool playlist_push(playlist_t *playlist, playlist->entries[0].db_name = NULL; playlist->entries[0].crc32 = NULL; playlist->entries[0].subsystem_ident = NULL; + playlist->entries[0].subsystem_name = NULL; playlist->entries[0].subsystem_roms = NULL; playlist->entries[0].runtime_hours = 0; playlist->entries[0].runtime_minutes = 0; @@ -697,29 +639,31 @@ bool playlist_push(playlist_t *playlist, playlist->entries[0].last_played_hour = 0; playlist->entries[0].last_played_minute = 0; playlist->entries[0].last_played_second = 0; - if (!string_is_empty(path)) - playlist->entries[0].path = strdup(path); - if (!string_is_empty(label)) - playlist->entries[0].label = strdup(label); - if (!string_is_empty(core_path)) - playlist->entries[0].core_path = strdup(core_path); + if (!string_is_empty(entry->path)) + playlist->entries[0].path = strdup(entry->path); + if (!string_is_empty(entry->label)) + playlist->entries[0].label = strdup(entry->label); + if (!string_is_empty(entry->core_path)) + playlist->entries[0].core_path = strdup(entry->core_path); if (!string_is_empty(core_name)) playlist->entries[0].core_name = strdup(core_name); - if (!string_is_empty(db_name)) - playlist->entries[0].db_name = strdup(db_name); - if (!string_is_empty(crc32)) - playlist->entries[0].crc32 = strdup(crc32); - if (!string_is_empty(subsystem_ident)) - playlist->entries[0].subsystem_ident = strdup(subsystem_ident); - if (subsystem_roms) + if (!string_is_empty(entry->db_name)) + playlist->entries[0].db_name = strdup(entry->db_name); + if (!string_is_empty(entry->crc32)) + playlist->entries[0].crc32 = strdup(entry->crc32); + if (!string_is_empty(entry->subsystem_ident)) + playlist->entries[0].subsystem_ident = strdup(entry->subsystem_ident); + if (!string_is_empty(entry->subsystem_name)) + playlist->entries[0].subsystem_name = strdup(entry->subsystem_name); + if (entry->subsystem_roms) { union string_list_elem_attr attributes = {0}; playlist->entries[0].subsystem_roms = string_list_new(); - for (i = 0; i < subsystem_roms->size; i++) + for (i = 0; i < entry->subsystem_roms->size; i++) { - string_list_append(playlist->entries[0].subsystem_roms, subsystem_roms->elems[i].data, attributes); + string_list_append(playlist->entries[0].subsystem_roms, entry->subsystem_roms->elems[i].data, attributes); } } } @@ -1085,6 +1029,17 @@ void playlist_write_file(playlist_t *playlist) JSON_Writer_WriteString(context.writer, playlist->entries[i].subsystem_ident ? playlist->entries[i].subsystem_ident : "", playlist->entries[i].subsystem_ident ? strlen(playlist->entries[i].subsystem_ident) : 0, JSON_UTF8); } + if (!string_is_empty(playlist->entries[i].subsystem_name)) + { + JSON_Writer_WriteComma(context.writer); + JSON_Writer_WriteNewLine(context.writer); + JSON_Writer_WriteSpace(context.writer, 6); + JSON_Writer_WriteString(context.writer, "subsystem_name", strlen("subsystem_name"), JSON_UTF8); + JSON_Writer_WriteColon(context.writer); + JSON_Writer_WriteSpace(context.writer, 1); + JSON_Writer_WriteString(context.writer, playlist->entries[i].subsystem_name ? playlist->entries[i].subsystem_name : "", playlist->entries[i].subsystem_name ? strlen(playlist->entries[i].subsystem_name) : 0, JSON_UTF8); + } + if (playlist->entries[i].subsystem_roms && playlist->entries[i].subsystem_roms->size > 0) { int j; @@ -1436,6 +1391,8 @@ static JSON_Parser_HandlerResult JSONObjectMemberHandler(JSON_Parser parser, cha pCtx->current_entry_val = &pCtx->current_entry->db_name; else if (string_is_equal(pValue, "subsystem_ident")) pCtx->current_entry_val = &pCtx->current_entry->subsystem_ident; + else if (string_is_equal(pValue, "subsystem_name")) + pCtx->current_entry_val = &pCtx->current_entry->subsystem_name; else if (string_is_equal(pValue, "subsystem_roms")) pCtx->current_entry_string_list_val = &pCtx->current_entry->subsystem_roms; else if (string_is_equal(pValue, "runtime_hours")) @@ -1798,28 +1755,14 @@ void playlist_qsort(playlist_t *playlist) void command_playlist_push_write( playlist_t *playlist, - const char *path, - const char *label, - const char *core_path, - const char *core_name, - const char *crc32, - const char *db_name, - const char *subsystem_ident, - const struct string_list *subsystem_roms) + const struct playlist_entry *entry) { if (!playlist) return; if (playlist_push( playlist, - path, - label, - core_path, - core_name, - crc32, - db_name, - subsystem_ident, - subsystem_roms + entry )) playlist_write_file(playlist); } @@ -1827,12 +1770,7 @@ void command_playlist_push_write( void command_playlist_update_write( playlist_t *plist, size_t idx, - const char *path, - const char *label, - const char *core_path, - const char *core_display_name, - const char *crc32, - const char *db_name) + const struct playlist_entry *entry) { playlist_t *playlist = plist ? plist : playlist_get_cached(); @@ -1842,12 +1780,7 @@ void command_playlist_update_write( playlist_update( playlist, idx, - path, - label, - core_path, - core_display_name, - crc32, - db_name); + entry); playlist_write_file(playlist); } diff --git a/playlist.h b/playlist.h index 7265ebfb8e..5532d1e40d 100644 --- a/playlist.h +++ b/playlist.h @@ -1,6 +1,7 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen * Copyright (C) 2011-2017 - Daniel De Matteis + * Copyright (C) 2016-2019 - Brad Parker * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- @@ -25,7 +26,32 @@ RETRO_BEGIN_DECLS -typedef struct content_playlist playlist_t; +typedef struct content_playlist playlist_t; + +struct playlist_entry +{ + char *path; + char *label; + char *core_path; + char *core_name; + char *db_name; + char *crc32; + char *subsystem_ident; + char *subsystem_name; + struct string_list *subsystem_roms; + unsigned runtime_hours; + unsigned runtime_minutes; + unsigned runtime_seconds; + /* Note: due to platform dependence, have to record + * timestamp as either a string or independent integer + * values. The latter is more verbose, but more efficient. */ + unsigned last_played_year; + unsigned last_played_month; + unsigned last_played_day; + unsigned last_played_hour; + unsigned last_played_minute; + unsigned last_played_second; +}; /** * playlist_init: @@ -67,20 +93,12 @@ size_t playlist_size(playlist_t *playlist); * playlist_get_index: * @playlist : Playlist handle. * @idx : Index of playlist entry. - * @path : Path of playlist entry. - * @core_path : Core path of playlist entry. - * @core_name : Core name of playlist entry. * * Gets values of playlist index: **/ void playlist_get_index(playlist_t *playlist, size_t idx, - const char **path, const char **label, - const char **core_path, const char **core_name, - const char **crc32, - const char **db_name, - const char **subsystem_ident, - const struct string_list **subsystem_roms); + const struct playlist_entry **entry); void playlist_get_runtime_index(playlist_t *playlist, size_t idx, @@ -109,12 +127,7 @@ void playlist_delete_index(playlist_t *playlist, * Push entry to top of playlist. **/ bool playlist_push(playlist_t *playlist, - const char *path, const char *label, - const char *core_path, const char *core_name, - const char *crc32, - const char *db_name, - const char *subsystem_ident, - const struct string_list *subsystem_roms); + const struct playlist_entry *entry); bool playlist_push_runtime(playlist_t *playlist, const char *path, const char *core_path, @@ -123,10 +136,7 @@ bool playlist_push_runtime(playlist_t *playlist, unsigned last_played_hour, unsigned last_played_minute, unsigned last_played_second); void playlist_update(playlist_t *playlist, size_t idx, - const char *path, const char *label, - const char *core_path, const char *core_name, - const char *crc32, - const char *db_name); + const struct playlist_entry *update_entry); /* Note: register_update determines whether the internal * 'playlist->modified' flag is set when updating runtime @@ -142,12 +152,7 @@ void playlist_update_runtime(playlist_t *playlist, size_t idx, void playlist_get_index_by_path(playlist_t *playlist, const char *search_path, - char **path, char **label, - char **core_path, char **core_name, - char **crc32, - char **db_name, - char **subsystem_ident, - struct string_list **subsystem_roms); + const struct playlist_entry **entry); bool playlist_entry_exists(playlist_t *playlist, const char *path, @@ -171,24 +176,12 @@ bool playlist_init_cached(const char *path, size_t size); void command_playlist_push_write( playlist_t *playlist, - const char *path, - const char *label, - const char *core_path, - const char *core_name, - const char *crc32, - const char *db_name, - const char *subsystem_ident, - const struct string_list *subsystem_roms); + const struct playlist_entry *entry); void command_playlist_update_write( playlist_t *playlist, size_t idx, - const char *path, - const char *label, - const char *core_path, - const char *core_display_name, - const char *crc32, - const char *db_name); + const struct playlist_entry *entry); /* Returns true if specified playlist index matches * specified content/core paths */ diff --git a/tasks/task_content.c b/tasks/task_content.c index ccbdb42a3d..aecf58c0f9 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -439,7 +439,7 @@ static bool load_content_from_compressed_archive( string_list_append(additional_path_allocs, new_path, attributes); info[i].path = - additional_path_allocs->elems[additional_path_allocs->size -1 ].data; + additional_path_allocs->elems[additional_path_allocs->size - 1].data; if (!string_list_append(content_ctx->temporary_content, new_path, attributes)) @@ -1052,6 +1052,7 @@ static bool task_load_content(content_ctx_info_t *content_info, * (As far as I can tell, core_info_get_current_core() * should always provide a valid pointer here...) */ core_info_get_current_core(&core_info); + if (core_info) core_name = core_info->display_name; @@ -1087,16 +1088,28 @@ static bool task_load_content(content_ctx_info_t *content_info, if ( content_ctx->history_list_enable && playlist_hist) + { + char subsystem_name[PATH_MAX_LENGTH]; + struct playlist_entry entry = {0}; + + subsystem_name[0] = '\0'; + + content_get_subsystem_friendly_name(path_get(RARCH_PATH_SUBSYSTEM), subsystem_name, sizeof(subsystem_name)); + + /* the push function reads our entry as const, so these casts are safe */ + entry.path = (char*)tmp; + entry.label = (char*)label; + entry.core_path = (char*)core_path; + entry.core_name = (char*)core_name; + entry.crc32 = (char*)crc32; + entry.db_name = (char*)db_name; + entry.subsystem_ident = (char*)path_get(RARCH_PATH_SUBSYSTEM), + entry.subsystem_name = (char*)subsystem_name; + entry.subsystem_roms = (struct string_list*)path_get_subsystem_list(); + command_playlist_push_write( - playlist_hist, - tmp, - label, - core_path, - core_name, - crc32, - db_name, - path_get(RARCH_PATH_SUBSYSTEM), - path_get_subsystem_list()); + playlist_hist, &entry); + } } free(tmp); diff --git a/tasks/task_database.c b/tasks/task_database.c index 29700f1413..e68f3306bb 100644 --- a/tasks/task_database.c +++ b/tasks/task_database.c @@ -845,12 +845,17 @@ static int database_info_list_iterate_found_match( if (!playlist_entry_exists(playlist, entry_path_str, db_crc)) { - playlist_push(playlist, entry_path_str, - db_info_entry->name, - file_path_str(FILE_PATH_DETECT), - file_path_str(FILE_PATH_DETECT), - db_crc, db_playlist_base_str, - NULL, NULL); + struct playlist_entry entry = {0}; + + /* the push function reads our entry as const, so these casts are safe */ + entry.path = entry_path_str; + entry.label = db_info_entry->name; + entry.core_path = (char*)file_path_str(FILE_PATH_DETECT); + entry.core_name = (char*)file_path_str(FILE_PATH_DETECT); + entry.crc32 = db_crc; + entry.db_name = db_playlist_base_str; + + playlist_push(playlist, &entry); } playlist_write_file(playlist); @@ -1015,19 +1020,22 @@ static int task_database_iterate_playlist_lutro( path, file_path_str(FILE_PATH_DETECT))) { char *game_title = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); + struct playlist_entry entry = {0}; game_title[0] = '\0'; fill_short_pathname_representation_noext(game_title, path, PATH_MAX_LENGTH * sizeof(char)); - playlist_push(playlist, path, - game_title, - file_path_str(FILE_PATH_DETECT), - file_path_str(FILE_PATH_DETECT), - file_path_str(FILE_PATH_DETECT), - file_path_str(FILE_PATH_LUTRO_PLAYLIST), - NULL, NULL); + /* the push function reads our entry as const, so these casts are safe */ + entry.path = (char*)path; + entry.label = game_title; + entry.core_path = (char*)file_path_str(FILE_PATH_DETECT); + entry.core_name = (char*)file_path_str(FILE_PATH_DETECT); + entry.crc32 = (char*)file_path_str(FILE_PATH_DETECT); + entry.db_name = (char*)file_path_str(FILE_PATH_LUTRO_PLAYLIST); + + playlist_push(playlist, &entry); free(game_title); } diff --git a/tasks/task_netplay_find_content.c b/tasks/task_netplay_find_content.c index 205606d2bb..842629b588 100644 --- a/tasks/task_netplay_find_content.c +++ b/tasks/task_netplay_find_content.c @@ -205,7 +205,8 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) /* start by checking cases that don't require a search */ /* the core doesn't have any content to match, so fast-succeed */ - if(!core_requires_content(state)) { + if (!core_requires_content(state)) + { state->found = true; state->contentless = true; task_set_data(task, state); @@ -222,7 +223,8 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) } /* We opened the playlist directory, but there's nothing there. Nothing to do. */ - if(state->lpl_list->size == 0 && core_requires_content(state)) { + if (state->lpl_list->size == 0 && core_requires_content(state)) + { string_list_free(state->lpl_list); finish_task(task, "There are no playlists available; cannot execute search"); command_event(CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED, state->hostname); @@ -233,7 +235,7 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) have_crc = !string_is_equal(state->content_crc, "00000000|crc"); /* if content is already loaded and the lobby gave us a CRC, check the loaded content first */ - if(have_crc && content_get_crc() > 0) + if (have_crc && content_get_crc() > 0) { char current[PATH_MAX_LENGTH]; @@ -258,7 +260,7 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) /* now let's do the search */ if (string_is_empty(state->subsystem_name) || string_is_equal(state->subsystem_name, "N/A")) { - for(i = 0; i < state->lpl_list->size; i++) + for (i = 0; i < state->lpl_list->size; i++) { playlist_t *playlist = NULL; unsigned playlist_size = 0; @@ -272,14 +274,18 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) playlist = playlist_init(lpl_path, 99999); playlist_size = playlist_get_size(playlist); - for(j = 0; j < playlist_size; j++) + for (j = 0; j < playlist_size; j++) { - const char *playlist_crc32 = NULL; const char *playlist_path = NULL; + const char *playlist_crc32 = NULL; + const struct playlist_entry *playlist_entry = NULL; - playlist_get_index(playlist, j, &playlist_path, NULL, NULL, NULL, &playlist_crc32, NULL, NULL, NULL); + playlist_get_index(playlist, j, &playlist_entry); - if(have_crc && string_is_equal(playlist_crc32, state->content_crc)) + playlist_path = playlist_entry->path; + playlist_crc32 = playlist_entry->crc32; + + if (have_crc && string_is_equal(playlist_crc32, state->content_crc)) { RARCH_LOG("[lobby] CRC match %s\n", playlist_crc32); strlcpy(state->content_path, playlist_path, sizeof(state->content_path)); @@ -298,7 +304,7 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) * Otherwise, on match we complete the task and mark it as successful immediately. */ - if(!string_is_empty(entry) && + if (!string_is_empty(entry) && string_is_equal(entry, state->content_path) && strstr(state->core_extensions, path_get_extension(playlist_path))) { @@ -312,8 +318,10 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) playlist_free(playlist); return; } + task_set_progress(task, (int)(j / playlist_size * 100.0)); } + playlist_free(playlist); } } @@ -326,7 +334,7 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) { found[i] = false; - for(j = 0; j < state->lpl_list->size && !found[i]; j++) + for (j = 0; j < state->lpl_list->size && !found[i]; j++) { playlist_t *playlist = NULL; unsigned playlist_size = 0; @@ -340,34 +348,37 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) playlist = playlist_init(lpl_path, 99999); playlist_size = playlist_get_size(playlist); - for(k = 0; k < playlist_size && !found[i]; k++) + for (k = 0; k < playlist_size && !found[i]; k++) { - const char *playlist_crc32 = NULL; - const char *playlist_path = NULL; + const struct playlist_entry *playlist_entry = NULL; - playlist_get_index(playlist, k, &playlist_path, NULL, NULL, NULL, &playlist_crc32, NULL, NULL, NULL); - get_entry(entry, sizeof(entry), playlist_path); + playlist_get_index(playlist, k, &playlist_entry); - if(!string_is_empty(entry) && + get_entry(entry, sizeof(entry), playlist_entry->path); + + if (!string_is_empty(entry) && strstr(game_list->elems[i].data, entry) && - strstr(state->core_extensions, path_get_extension(playlist_path))) + strstr(state->core_extensions, path_get_extension(playlist_entry->path))) { - RARCH_LOG("[lobby] filename match %s\n", playlist_path); + RARCH_LOG("[lobby] filename match %s\n", playlist_entry->path); if (i == 0) { state->content_path[0] = '\0'; - strlcpy(state->content_path, playlist_path, sizeof(state->content_path)); + strlcpy(state->content_path, playlist_entry->path, sizeof(state->content_path)); } else { strlcat(state->content_path, "|", sizeof(state->content_path)); - strlcat(state->content_path, playlist_path, sizeof(state->content_path)); + strlcat(state->content_path, playlist_entry->path, sizeof(state->content_path)); } + found[i] = true; } + task_set_progress(task, (int)(j / playlist_size * 100.0)); } + playlist_free(playlist); } } @@ -388,6 +399,7 @@ static void task_netplay_crc_scan_handler(retro_task_t *task) task_set_data(task, state); finish_task(task, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_COMPAT_CONTENT_FOUND)); } + string_list_free(state->lpl_list); string_list_free(game_list); return; @@ -457,7 +469,7 @@ bool task_push_netplay_crc_scan(uint32_t crc, char* name, #if 0 printf("Info: %s State: %s", info->list[i].core_name, state->core_name); #endif - if(string_is_equal(info->list[i].core_name, state->core_name)) + if (string_is_equal(info->list[i].core_name, state->core_name)) { strlcpy(state->core_path, info->list[i].path, sizeof(state->core_path)); diff --git a/tasks/task_screenshot.c b/tasks/task_screenshot.c index eb1f8beedb..c00ff8ebc4 100644 --- a/tasks/task_screenshot.c +++ b/tasks/task_screenshot.c @@ -170,14 +170,16 @@ static void task_screenshot_handler(retro_task_t *task) !state->silence && state->history_list_enable ) - command_playlist_push_write( - g_defaults.image_history, - state->filename, - NULL, - "builtin", - "imageviewer", - NULL, NULL, - NULL, NULL); + { + struct playlist_entry entry = {0}; + + /* the push function reads our entry as const, so these casts are safe */ + entry.path = state->filename; + entry.core_path = (char*)"builtin"; + entry.core_name = (char*)"imageviewer"; + + command_playlist_push_write(g_defaults.image_history, &entry); + } #endif task_set_progress(task, 100); diff --git a/ui/drivers/qt/qt_playlist.cpp b/ui/drivers/qt/qt_playlist.cpp index 8e2aab5325..ea8166d772 100644 --- a/ui/drivers/qt/qt_playlist.cpp +++ b/ui/drivers/qt/qt_playlist.cpp @@ -601,8 +601,19 @@ void MainWindow::addFilesToPlaylist(QStringList files) } } - playlist_push(playlist, pathData, fileNameNoExten, - corePathData, coreNameData, "00000000|crc", databaseData, NULL, NULL); + { + struct playlist_entry entry = {0}; + + /* the push function reads our entry as const, so these casts are safe */ + entry.path = const_cast(pathData); + entry.label = const_cast(fileNameNoExten); + entry.core_path = const_cast(corePathData); + entry.core_name = const_cast(coreNameData); + entry.crc32 = const_cast("00000000|crc"); + entry.db_name = const_cast(databaseData); + + playlist_push(playlist, &entry); + } } playlist_write_file(playlist); @@ -703,8 +714,20 @@ bool MainWindow::updateCurrentPlaylistEntry(const QHash &conte playlist = playlist_init(playlistPathData, COLLECTION_SIZE); - playlist_update(playlist, index, pathData, labelData, - corePathData, coreNameData, crc32Data, dbNameData); + { + struct playlist_entry entry = {0}; + + /* the update function reads our entry as const, so these casts are safe */ + entry.path = const_cast(pathData); + entry.label = const_cast(labelData); + entry.core_path = const_cast(corePathData); + entry.core_name = const_cast(coreNameData); + entry.crc32 = const_cast(crc32Data); + entry.db_name = const_cast(dbNameData); + + playlist_update(playlist, index, &entry); + } + playlist_write_file(playlist); playlist_free(playlist); @@ -1358,48 +1381,41 @@ void PlaylistModel::getPlaylistItems(QString path) for (i = 0; i < playlistSize; i++) { - const char *path = NULL; - const char *label = NULL; - const char *core_path = NULL; - const char *core_name = NULL; - const char *crc32 = NULL; - const char *db_name = NULL; + const struct playlist_entry *entry = NULL; QHash hash; - playlist_get_index(playlist, i, - &path, &label, &core_path, - &core_name, &crc32, &db_name, NULL, NULL); + playlist_get_index(playlist, i, &entry); - if (string_is_empty(path)) + if (string_is_empty(entry->path)) continue; else - hash["path"] = path; + hash["path"] = entry->path; hash["index"] = QString::number(i); - if (string_is_empty(label)) + if (string_is_empty(entry->label)) { - hash["label"] = path; - hash["label_noext"] = path; + hash["label"] = entry->path; + hash["label_noext"] = entry->path; } else { - hash["label"] = label; - hash["label_noext"] = label; + hash["label"] = entry->label; + hash["label_noext"] = entry->label; } - if (!string_is_empty(core_path)) - hash["core_path"] = core_path; + if (!string_is_empty(entry->core_path)) + hash["core_path"] = entry->core_path; - if (!string_is_empty(core_name)) - hash["core_name"] = core_name; + if (!string_is_empty(entry->core_name)) + hash["core_name"] = entry->core_name; - if (!string_is_empty(crc32)) - hash["crc32"] = crc32; + if (!string_is_empty(entry->crc32)) + hash["crc32"] = entry->crc32; - if (!string_is_empty(db_name)) + if (!string_is_empty(entry->db_name)) { - hash["db_name"] = db_name; + hash["db_name"] = entry->db_name; hash["db_name"].remove(file_path_str(FILE_PATH_LPL_EXTENSION)); } From 15c0191f08b09990ee0f6d192ed8220d47cfa1c1 Mon Sep 17 00:00:00 2001 From: bparker06 Date: Fri, 12 Apr 2019 13:04:59 -0400 Subject: [PATCH 6/6] Update task_content.c --- tasks/task_content.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasks/task_content.c b/tasks/task_content.c index aecf58c0f9..8c02546939 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -2011,7 +2011,10 @@ void content_get_subsystem_friendly_name(const char* subsystem_name, char* subsy for (i = 0; i < subsystem_current_count; i++, subsystem++) { if (string_is_equal(subsystem_name, subsystem->ident)) + { strlcpy(subsystem_friendly_name, subsystem->desc, len); + break; + } } return;