Populate crc32 and db_name fields when adding history/favourites playlist entries

playlist.c: Fix silly range check error
This commit is contained in:
jdgleaver 2019-03-09 13:48:06 +00:00
parent f4e6aaa4d8
commit dc8ef72323
8 changed files with 154 additions and 29 deletions

View file

@ -2395,7 +2395,7 @@ TODO: Add a setting for these tweaks */
if (str_list)
{
if (str_list->size >= 4)
if (str_list->size >= 6)
{
/* Write playlist entry */
command_playlist_push_write(
@ -2403,7 +2403,9 @@ TODO: Add a setting for these tweaks */
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[3].data, /* core_name */
str_list->elems[4].data, /* crc32 */
str_list->elems[5].data /* db_name */
);
runloop_msg_queue_push(msg_hash_to_str(MSG_ADDED_TO_FAVORITES), 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
}

View file

@ -2122,7 +2122,9 @@ static int action_ok_audio_add_to_mixer_and_collection(const char *path,
combined_path,
NULL,
"builtin",
"musicplayer");
"musicplayer",
NULL,
NULL);
if (filestream_exists(combined_path))
task_push_audio_mixer_load(combined_path,
@ -2152,7 +2154,9 @@ static int action_ok_audio_add_to_mixer_and_collection_and_play(const char *path
combined_path,
NULL,
"builtin",
"musicplayer");
"musicplayer",
NULL,
NULL);
if (filestream_exists(combined_path))
task_push_audio_mixer_load_and_play(combined_path,
@ -3824,7 +3828,10 @@ static int action_ok_add_to_favorites(const char *path,
{
global_t *global = global_get_ptr();
struct retro_system_info *system = runloop_get_libretro_system_info();
menu_handle_t *menu = NULL;
struct string_list *str_list = NULL;
const char *crc32 = NULL;
const char *db_name = NULL;
union string_list_elem_attr attr;
char content_label[PATH_MAX_LENGTH];
@ -3882,15 +3889,31 @@ static int action_ok_add_to_favorites(const char *path,
strlcpy(core_name, file_path_str(FILE_PATH_DETECT), sizeof(core_name));
}
/* > crc32 + db_name */
if (menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu))
{
playlist_t *playlist_curr = playlist_get_cached();
if (playlist_index_is_valid(playlist_curr, menu->rpl_entry_selection_ptr, content_path, core_path))
{
playlist_get_crc32(playlist_curr, menu->rpl_entry_selection_ptr, &crc32);
playlist_get_db_name(playlist_curr, menu->rpl_entry_selection_ptr, &db_name);
}
}
/* Copy playlist parameters into string list
* [0]: content_path
* [1]: content_label
* [2]: core_path
* [3]: core_name */
* [3]: core_name
* [4]: crc32
* [5]: db_name */
string_list_append(str_list, content_path, attr);
string_list_append(str_list, content_label, attr);
string_list_append(str_list, core_path, attr);
string_list_append(str_list, core_name, attr);
string_list_append(str_list, !string_is_empty(crc32) ? crc32 : "", attr);
string_list_append(str_list, !string_is_empty(db_name) ? db_name : "", attr);
/* Trigger 'ADD_TO_FAVORITES' event */
if (!command_event(CMD_EVENT_ADD_TO_FAVORITES, (void*)str_list))
@ -3913,19 +3936,21 @@ static int action_ok_add_to_favorites_playlist(const char *path,
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 *tmp_playlist = playlist_get_cached();
playlist_t *playlist_curr = playlist_get_cached();
int ret = 0;
if (!tmp_playlist)
if (!playlist_curr)
return 0;
if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu))
return menu_cbs_exit();
/* Read current playlist parameters */
playlist_get_index(tmp_playlist, menu->rpl_entry_selection_ptr,
playlist_get_index(playlist_curr, menu->rpl_entry_selection_ptr,
&content_path, &content_label, &core_path, &core_name,
NULL, NULL);
&crc32, NULL);
/* Error checking
* > If content path is empty, cannot do anything... */
@ -3947,7 +3972,9 @@ static int action_ok_add_to_favorites_playlist(const char *path,
* [0]: content_path
* [1]: content_label
* [2]: core_path
* [3]: core_name */
* [3]: core_name
* [4]: crc32
* [5]: db_name */
/* > content_path */
string_list_append(str_list, content_path, attr);
@ -3994,6 +4021,13 @@ static int action_ok_add_to_favorites_playlist(const char *path,
string_list_append(str_list, file_path_str(FILE_PATH_DETECT), attr);
}
/* crc32 */
string_list_append(str_list, !string_is_empty(crc32) ? 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);
/* Trigger 'ADD_TO_FAVORITES' event */
if (!command_event(CMD_EVENT_ADD_TO_FAVORITES, (void*)str_list))
ret = menu_cbs_exit();

View file

@ -1756,7 +1756,7 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu,
playlist_get_index(playlist, j,
NULL, NULL, NULL, NULL,
NULL, &crc32);
&crc32, NULL);
if (crc32)
tmp_str_list = string_split(crc32, "|");

View file

@ -32,6 +32,7 @@
#include "playlist.h"
#include "verbosity.h"
#include "configuration.h"
#include "file_path_special.h"
#ifndef PLAYLIST_ENTRIES
#define PLAYLIST_ENTRIES 6
@ -1651,7 +1652,9 @@ void command_playlist_push_write(
const char *path,
const char *label,
const char *core_path,
const char *core_name)
const char *core_name,
const char *crc32,
const char *db_name)
{
if (!playlist)
return;
@ -1662,8 +1665,8 @@ void command_playlist_push_write(
label,
core_path,
core_name,
NULL,
NULL
crc32,
db_name
))
playlist_write_file(playlist);
}
@ -1695,3 +1698,53 @@ void command_playlist_update_write(
playlist_write_file(playlist);
}
bool playlist_index_is_valid(playlist_t *playlist, size_t idx,
const char *path, const char *core_path)
{
if (!playlist)
return false;
if (idx >= playlist->size)
return false;
return string_is_equal(playlist->entries[idx].path, path) &&
string_is_equal(path_basename(playlist->entries[idx].core_path), path_basename(core_path));
}
void playlist_get_crc32(playlist_t *playlist, size_t idx,
const char **crc32)
{
if (!playlist)
return;
if (crc32)
*crc32 = playlist->entries[idx].crc32;
}
void playlist_get_db_name(playlist_t *playlist, size_t idx,
const char **db_name)
{
if (!playlist)
return;
if (db_name)
{
if (!string_is_empty(playlist->entries[idx].db_name))
*db_name = playlist->entries[idx].db_name;
else
{
const char *conf_path_basename = path_basename(playlist->conf_path);
/* Only use file basename if this is a 'collection' playlist
* (i.e. ignore history/favourites) */
if (!string_is_empty(conf_path_basename) &&
!string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_FAVORITES)) &&
!string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_HISTORY)) &&
!string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_IMAGE_HISTORY)) &&
!string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_MUSIC_HISTORY)) &&
!string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_VIDEO_HISTORY)))
*db_name = conf_path_basename;
}
}
}

View file

@ -76,8 +76,8 @@ 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 **db_name,
const char **crc32);
const char **crc32,
const char **db_name);
void playlist_get_runtime_index(playlist_t *playlist,
size_t idx,
@ -139,8 +139,8 @@ void playlist_get_index_by_path(playlist_t *playlist,
const char *search_path,
char **path, char **label,
char **core_path, char **core_name,
char **db_name,
char **crc32);
char **crc32,
char **db_name);
bool playlist_entry_exists(playlist_t *playlist,
const char *path,
@ -167,7 +167,9 @@ void command_playlist_push_write(
const char *path,
const char *label,
const char *core_path,
const char *core_name);
const char *core_name,
const char *crc32,
const char *db_name);
void command_playlist_update_write(
playlist_t *playlist,
@ -179,6 +181,18 @@ void command_playlist_update_write(
const char *crc32,
const char *db_name);
/* Returns true if specified playlist index matches
* specified content/core paths */
bool playlist_index_is_valid(playlist_t *playlist, size_t idx,
const char *path, const char *core_path);
void playlist_get_crc32(playlist_t *playlist, size_t idx,
const char **crc32);
/* If db_name is empty, 'returns' playlist file basename */
void playlist_get_db_name(playlist_t *playlist, size_t idx,
const char **db_name);
RETRO_END_DECLS
#endif

View file

@ -1016,32 +1016,37 @@ static bool task_load_content(content_ctx_info_t *content_info,
const char *core_path = NULL;
const char *core_name = NULL;
const char *label = NULL;
playlist_t *playlist_tmp = g_defaults.content_history;
const char *crc32 = NULL;
const char *db_name = NULL;
playlist_t *playlist_hist = g_defaults.content_history;
global_t *global = global_get_ptr();
switch (path_is_media_type(tmp))
{
case RARCH_CONTENT_MOVIE:
#ifdef HAVE_FFMPEG
playlist_tmp = g_defaults.video_history;
playlist_hist = g_defaults.video_history;
core_name = "movieplayer";
core_path = "builtin";
#endif
break;
case RARCH_CONTENT_MUSIC:
playlist_tmp = g_defaults.music_history;
playlist_hist = g_defaults.music_history;
core_name = "musicplayer";
core_path = "builtin";
break;
case RARCH_CONTENT_IMAGE:
#ifdef HAVE_IMAGEVIEWER
playlist_tmp = g_defaults.image_history;
playlist_hist = g_defaults.image_history;
core_name = "imageviewer";
core_path = "builtin";
#endif
break;
default:
{
#ifdef HAVE_MENU
menu_handle_t *menu = NULL;
#endif
core_info_t *core_info = NULL;
/* Set core path */
@ -1057,6 +1062,19 @@ static bool task_load_content(content_ctx_info_t *content_info,
if (string_is_empty(core_name))
core_name = info->library_name;
#ifdef HAVE_MENU
/* Set database name + checksum */
if (menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu))
{
playlist_t *playlist_curr = playlist_get_cached();
if (playlist_index_is_valid(playlist_curr, menu->rpl_entry_selection_ptr, tmp, core_path))
{
playlist_get_crc32(playlist_curr, menu->rpl_entry_selection_ptr, &crc32);
playlist_get_db_name(playlist_curr, menu->rpl_entry_selection_ptr, &db_name);
}
}
#endif
break;
}
}
@ -1072,13 +1090,15 @@ static bool task_load_content(content_ctx_info_t *content_info,
if (
content_ctx->history_list_enable
&& playlist_tmp)
&& playlist_hist)
command_playlist_push_write(
playlist_tmp,
playlist_hist,
tmp,
label,
core_path,
core_name);
core_name,
crc32,
db_name);
}
free(tmp);

View file

@ -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, NULL, &playlist_crc32);
playlist_get_index(playlist, j, &playlist_path, NULL, NULL, NULL, &playlist_crc32, 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, NULL, &playlist_crc32);
playlist_get_index(playlist, k, &playlist_path, NULL, NULL, NULL, &playlist_crc32, NULL);
get_entry(entry, sizeof(entry), playlist_path);
if(!string_is_empty(entry) &&

View file

@ -166,7 +166,9 @@ static void task_screenshot_handler(retro_task_t *task)
state->filename,
NULL,
"builtin",
"imageviewer");
"imageviewer",
NULL,
NULL);
#endif
task_set_progress(task, 100);