summaryrefslogtreecommitdiff
path: root/apps/playlist_catalog.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/playlist_catalog.c')
-rw-r--r--apps/playlist_catalog.c30
1 files changed, 19 insertions, 11 deletions
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,
326 bool new_playlist, char *m3u8name) 326 bool new_playlist, char *m3u8name)
327{ 327{
328 int result; 328 int result;
329 char playlist[MAX_PATH + 6]; 329 char playlist[MAX_PATH + 7]; /* room for /.m3u8\0*/
330 if (in_add_to_playlist) 330 if (in_add_to_playlist)
331 return false; 331 return false;
332 332
@@ -338,24 +338,32 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
338 size_t len; 338 size_t len;
339 if (m3u8name == NULL) 339 if (m3u8name == NULL)
340 { 340 {
341 /*If sel is a folder, we prefill the text field with its name*/ 341 const char *name;
342 const char *name = strrchr(sel, '/'); 342 /* If sel is empty, root, or playlist directory we use 'all' */
343 snprintf(playlist, sizeof(playlist), "%s/%s.m3u8", 343 if (!sel || !strcmp(sel, "/") || !strcmp(sel, playlist_dir))
344 {
345 if (!sel || !strcmp(sel, PLAYLIST_CATALOG_DEFAULT_DIR))
346 sel = "/";
347 name = "/all";
348 }
349 else /*If sel is a folder, we prefill the text field with its name*/
350 name = strrchr(sel, '/');
351
352 snprintf(playlist, MAX_PATH + 1, "%s/%s",
344 playlist_dir, 353 playlist_dir,
345 (name!=NULL && (sel_attr & ATTR_DIRECTORY))?name+1:""); 354 (name!=NULL && (sel_attr & ATTR_DIRECTORY))?name+1:"");
346 } 355 }
347 else 356 else
348 strcpy(playlist, m3u8name); 357 strlcpy(playlist, m3u8name, MAX_PATH);
349 358
350 len = strlen(playlist); 359 if (kbd_input(playlist, MAX_PATH))
360 return false;
351 361
362 len = strlen(playlist);
352 if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u")) 363 if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u"))
353 strcat(playlist, "8"); 364 strlcat(playlist, "8", sizeof(playlist));
354 else if(len <= 5 || strcasecmp(&playlist[len-5], ".m3u8")) 365 else if(len <= 5 || strcasecmp(&playlist[len-5], ".m3u8"))
355 strcat(playlist, ".m3u8"); 366 strlcat(playlist, ".m3u8", sizeof(playlist));
356
357 if (kbd_input(playlist, sizeof(playlist)))
358 return false;
359 } 367 }
360 else 368 else
361 { 369 {