diff --git a/core_info.c b/core_info.c index 0034949b95..50f47791b9 100644 --- a/core_info.c +++ b/core_info.c @@ -100,6 +100,71 @@ static void core_info_list_resolve_all_firmware( } } +void core_info_get_name(const char *path, char *s, size_t len) +{ + size_t i; + core_info_t *core_info = NULL; + core_info_list_t *core_info_list = NULL; + settings_t *settings = config_get_ptr(); + struct string_list *contents = dir_list_new_special(NULL, DIR_LIST_CORES); + + if (!contents) + return NULL; + + core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list)); + if (!core_info_list) + goto error; + + core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info)); + if (!core_info) + goto error; + + core_info_list->list = core_info; + core_info_list->count = contents->size; + + for (i = 0; i < contents->size; i++) + { + char info_path_base[PATH_MAX_LENGTH], info_path[PATH_MAX_LENGTH]; + core_info[i].path = strdup(contents->elems[i].data); + + if (!core_info[i].path) + break; + + if (strcmp(core_info[i].path, path) != 0) + continue; + + fill_pathname_base(info_path_base, contents->elems[i].data, + sizeof(info_path_base)); + path_remove_extension(info_path_base); + +#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP)) + char *substr = strrchr(info_path_base, '_'); + if (substr) + *substr = '\0'; +#endif + + strlcat(info_path_base, ".info", sizeof(info_path_base)); + + fill_pathname_join(info_path, (*settings->libretro_info_path) ? + settings->libretro_info_path : settings->libretro_directory, + info_path_base, sizeof(info_path)); + + core_info[i].data = config_file_new(info_path); + + if (core_info[i].data) + config_get_string(core_info[i].data, "corename", + &core_info[i].core_name); + + strlcpy(s, core_info[i].core_name, len); + } + +error: + if (contents) + dir_list_free(contents); + contents = NULL; + core_info_list_free(core_info_list); +} + core_info_list_t *core_info_list_new(void) { size_t i; diff --git a/core_info.h b/core_info.h index 953f37cc41..96366bacc2 100644 --- a/core_info.h +++ b/core_info.h @@ -104,6 +104,8 @@ const char *core_info_list_get_all_extensions(core_info_list_t *list); bool core_info_list_get_display_name(core_info_list_t *list, const char *path, char *buf, size_t size); +void core_info_get_name(const char *path, char *s, size_t len); + #ifdef __cplusplus } #endif diff --git a/menu/menu_entries_cbs_deferred_push.c b/menu/menu_entries_cbs_deferred_push.c index 2a1fd70c72..3ae8220d37 100644 --- a/menu/menu_entries_cbs_deferred_push.c +++ b/menu/menu_entries_cbs_deferred_push.c @@ -505,7 +505,8 @@ void menu_entries_cbs_init_bind_deferred_push(menu_file_list_cbs_t *cbs, cbs->action_deferred_push = deferred_push_category; else if (type == MENU_FILE_PLAYLIST_COLLECTION) cbs->action_deferred_push = deferred_push_rdb_collection; - else if (!strcmp(label, "deferred_core_list")) + else if (!strcmp(label, "deferred_core_list") || + !strcmp(label, "deferred_core_list_set")) cbs->action_deferred_push = deferred_push_core_list_deferred; else if (!strcmp(label, "deferred_video_filter")) cbs->action_deferred_push = deferred_push_video_filter; diff --git a/menu/menu_entries_cbs_ok.c b/menu/menu_entries_cbs_ok.c index 86123cbb68..14045cfc18 100644 --- a/menu/menu_entries_cbs_ok.c +++ b/menu/menu_entries_cbs_ok.c @@ -73,7 +73,10 @@ static int action_ok_file_load_with_detect_core(const char *path, info.type = 0; info.directory_ptr = idx; strlcpy(info.path, settings->libretro_directory, sizeof(info.path)); - strlcpy(info.label, "deferred_core_list", sizeof(info.label)); + if (!strcmp(label, "collection")) + strlcpy(info.label, "deferred_core_list_set", sizeof(info.label)); + else + strlcpy(info.label, "deferred_core_list", sizeof(info.label)); ret = menu_displaylist_push_list(&info, DISPLAYLIST_GENERIC); } @@ -785,6 +788,31 @@ static int action_ok_path_use_directory(const char *path, return 0; } +static int action_ok_core_deferred_set(const char *path, + const char *label, unsigned type, size_t idx) +{ + char core_display_name[PATH_MAX_LENGTH]; + menu_handle_t *menu = menu_driver_get_ptr(); + content_playlist_t *playlist = menu ? menu->playlist : NULL; + if (!menu) + return -1; + + core_info_get_name(path, core_display_name, sizeof(core_display_name)); + + content_playlist_update(playlist, idx, + NULL, NULL, + path , core_display_name, + NULL); + + content_playlist_write_file(playlist); + content_playlist_free(playlist); + menu->playlist = NULL; + + menu_list_flush_stack(menu->menu_list, NULL, MENU_SETTINGS); + + return -1; +} + static int action_ok_core_load_deferred(const char *path, const char *label, unsigned type, size_t idx) { @@ -1560,6 +1588,8 @@ void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs, case MENU_FILE_CORE: if (!strcmp(menu_label, "deferred_core_list")) cbs->action_ok = action_ok_core_load_deferred; + else if (!strcmp(menu_label, "deferred_core_list_set")) + cbs->action_ok = action_ok_core_deferred_set; else if (!strcmp(menu_label, "core_list")) cbs->action_ok = action_ok_core_load; else if (!strcmp(menu_label, "core_updater_list")) diff --git a/playlist.c b/playlist.c index ebfc8db398..81857f2b6e 100644 --- a/playlist.c +++ b/playlist.c @@ -119,6 +119,33 @@ static void content_playlist_free_entry(content_playlist_entry_t *entry) memset(entry, 0, sizeof(*entry)); } +void content_playlist_update(content_playlist_t *playlist, size_t idx, + const char *path, const char *label, + const char *core_path, const char *core_name, + const char *crc32) +{ + if (!playlist) + return; + idx = idx - 1; + if (idx > playlist->size) + return; + + if (path != NULL) + playlist->entries[idx].path = strdup(path); + if (label != NULL) + playlist->entries[idx].label = strdup(label); + if (core_path != NULL) + { + playlist->entries[idx].core_path = strdup(core_path); + } + if (core_name != NULL) + { + playlist->entries[idx].core_name = strdup(core_name); + } + if (crc32 != NULL) + playlist->entries[idx].crc32 = strdup(crc32); +} + /** * content_playlist_push: * @playlist : Playlist handle. diff --git a/playlist.h b/playlist.h index 8819a50154..56dff6cbec 100644 --- a/playlist.h +++ b/playlist.h @@ -108,6 +108,11 @@ void content_playlist_push(content_playlist_t *playlist, const char *core_path, const char *core_name, const char *crc32); +void content_playlist_update(content_playlist_t *playlist, size_t idx, + const char *path, const char *label, + const char *core_path, const char *core_name, + const char *crc32); + void content_playlist_get_index_by_path(content_playlist_t *playlist, const char *search_path, char **path, char **label,