From 8b7ae89b43ef4c96b55671759869397676ee9e05 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 17 Aug 2019 23:40:45 -0500 Subject: Playlist rework consolidate some of the playlist create functions remove extensions from playlist naming (you can still add it if you desire) switch to strlcpy, strlcpy functions Change-Id: Ibd62912da4d1f68ed5366baa887d92d4c6b1f933 --- apps/playlist_catalog.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'apps/playlist_catalog.c') diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c index 2147ea990c..7de907c8d0 100644 --- a/apps/playlist_catalog.c +++ b/apps/playlist_catalog.c @@ -326,7 +326,7 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr, bool new_playlist, char *m3u8name) { int result; - char playlist[MAX_PATH + 6]; + char playlist[MAX_PATH + 7]; /* room for /.m3u8\0*/ if (in_add_to_playlist) return false; @@ -338,24 +338,32 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr, size_t len; if (m3u8name == NULL) { - /*If sel is a folder, we prefill the text field with its name*/ - const char *name = strrchr(sel, '/'); - snprintf(playlist, sizeof(playlist), "%s/%s.m3u8", + const char *name; + /* If sel is empty, root, or playlist directory we use 'all' */ + if (!sel || !strcmp(sel, "/") || !strcmp(sel, playlist_dir)) + { + if (!sel || !strcmp(sel, PLAYLIST_CATALOG_DEFAULT_DIR)) + sel = "/"; + name = "/all"; + } + else /*If sel is a folder, we prefill the text field with its name*/ + name = strrchr(sel, '/'); + + snprintf(playlist, MAX_PATH + 1, "%s/%s", playlist_dir, (name!=NULL && (sel_attr & ATTR_DIRECTORY))?name+1:""); } else - strcpy(playlist, m3u8name); + strlcpy(playlist, m3u8name, MAX_PATH); - len = strlen(playlist); + if (kbd_input(playlist, MAX_PATH)) + return false; + len = strlen(playlist); if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u")) - strcat(playlist, "8"); + strlcat(playlist, "8", sizeof(playlist)); else if(len <= 5 || strcasecmp(&playlist[len-5], ".m3u8")) - strcat(playlist, ".m3u8"); - - if (kbd_input(playlist, sizeof(playlist))) - return false; + strlcat(playlist, ".m3u8", sizeof(playlist)); } else { -- cgit v1.2.3