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
This commit is contained in:
William Wilgus 2019-08-17 23:40:45 -05:00
parent 5a4cdb96b9
commit 8b7ae89b43
3 changed files with 42 additions and 26 deletions

View file

@ -42,25 +42,30 @@ int save_playlist_screen(struct playlist_info* playlist)
{
char temp[MAX_PATH+1], *dot;
int len;
playlist_get_name(playlist, temp, sizeof(temp)-1);
len = strlen(temp);
dot = strrchr(temp, '.');
if (!dot && len <= 1)
{
snprintf(temp, sizeof(temp), "%s%s",
catalog_get_directory(), DEFAULT_DYNAMIC_PLAYLIST_NAME);
}
dot = strrchr(temp, '.');
if (!dot)
{
/* folder of some type */
if (len > 1)
strcpy(&temp[len-1], ".m3u8");
else
snprintf(temp, sizeof(temp), "%s%s",
catalog_get_directory(), DEFAULT_DYNAMIC_PLAYLIST_NAME);
}
else if (len > 4 && !strcasecmp(dot, ".m3u"))
strcat(temp, "8");
if (dot) /* remove extension */
*dot = '\0';
if (!kbd_input(temp, sizeof(temp)))
{
len = strlen(temp);
if(len > 4 && !strcasecmp(&temp[len-4], ".m3u"))
strlcat(temp, "8", sizeof(temp));
else if(len <= 5 || strcasecmp(&temp[len-5], ".m3u8"))
strlcat(temp, ".m3u8", sizeof(temp));
playlist_save(playlist, temp, NULL, 0);
/* reload in case playlist was saved to cwd */

View file

@ -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);
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
{

View file

@ -941,9 +941,11 @@ static int dirbrowse(void)
int create_playlist(void)
{
bool ret;
#if 0 /* handled in catalog_add_to_a_playlist() */
char filename[MAX_PATH + 16]; /* add enough space for extension */
const char *playlist_dir = catalog_get_directory();
if (strcmp(tc.currdir, playlist_dir) != 0)
if (tc.currdir[1] && strcmp(tc.currdir, playlist_dir) != 0)
snprintf(filename, sizeof filename, "%s.m3u8", tc.currdir);
else
snprintf(filename, sizeof filename, "%s/all.m3u8", playlist_dir);
@ -951,12 +953,13 @@ int create_playlist(void)
if (kbd_input(filename, MAX_PATH))
return 0;
splashf(0, "%s %s", str(LANG_CREATING), filename);
#endif
trigger_cpu_boost();
catalog_add_to_a_playlist(tc.currdir, ATTR_DIRECTORY, true, filename);
ret = catalog_add_to_a_playlist(tc.currdir, ATTR_DIRECTORY, true, NULL);
cancel_cpu_boost();
return 1;
return (ret) ? 1 : 0;
}
void browse_context_init(struct browse_context *browse,