summaryrefslogtreecommitdiff
path: root/apps/filetree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/filetree.c')
-rw-r--r--apps/filetree.c85
1 files changed, 62 insertions, 23 deletions
diff --git a/apps/filetree.c b/apps/filetree.c
index eb429c83e3..4f59804686 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -46,6 +46,10 @@
46#include "strnatcmp.h" 46#include "strnatcmp.h"
47#include "keyboard.h" 47#include "keyboard.h"
48 48
49#ifdef HAVE_MULTIVOLUME
50#include "mv.h"
51#endif
52
49#if CONFIG_TUNER 53#if CONFIG_TUNER
50#include "radio.h" 54#include "radio.h"
51#endif 55#endif
@@ -471,6 +475,45 @@ static void ft_apply_skin_file(char *buf, char *file, const int maxlen)
471 settings_apply_skins(); 475 settings_apply_skins();
472} 476}
473 477
478int ft_assemble_path(char *buf, size_t bufsz, const char* currdir, const char* filename)
479{
480 int len;
481 if (!filename)
482 filename = "";
483#ifdef HAVE_MULTIVOLUME
484 if (currdir && currdir[0] && currdir[1]) /* Not in / */
485 {
486 if (currdir[1] != VOL_START_TOK)
487 {
488 len = snprintf(buf, bufsz, "%s%s/%s", root_realpath(), currdir, filename);
489 }
490 else
491 len = snprintf(buf, bufsz, "%s/%s", currdir, filename);
492 }
493 else /* In / */
494 {
495 if (filename[0] != VOL_START_TOK)
496 {
497 len = snprintf(buf, bufsz, "%s/%s",root_realpath(), filename);
498 }
499 else
500 len = snprintf(buf, bufsz, "/%s", filename);
501 }
502#else
503 if (currdir && currdir[0] && currdir[1]) /* Not in / */
504 {
505 len = snprintf(buf, bufsz, "%s%s/%s", root_realpath(), currdir, filename);
506 }
507 else /* In / */
508 {
509 len = snprintf(buf, bufsz, "%s/%s",root_realpath(), filename);
510 }
511#endif
512 if ((unsigned) len > bufsz)
513 splash(HZ, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
514 return len;
515}
516
474int ft_enter(struct tree_context* c) 517int ft_enter(struct tree_context* c)
475{ 518{
476 int rc = GO_TO_PREVIOUS; 519 int rc = GO_TO_PREVIOUS;
@@ -484,16 +527,7 @@ int ft_enter(struct tree_context* c)
484 } 527 }
485 528
486 int file_attr = file->attr; 529 int file_attr = file->attr;
487 int len; 530 ft_assemble_path(buf, sizeof(buf), c->currdir, file->name);
488
489 if (c->currdir[1])
490 {
491 len = snprintf(buf,sizeof(buf),"%s/%s",c->currdir, file->name);
492 if ((unsigned) len > sizeof(buf))
493 splash(HZ, ID2P(LANG_PLAYLIST_ACCESS_ERROR));
494 }
495 else
496 snprintf(buf,sizeof(buf),"/%s",file->name);
497 531
498 if (file_attr & ATTR_DIRECTORY) { 532 if (file_attr & ATTR_DIRECTORY) {
499 memcpy(c->currdir, buf, sizeof(c->currdir)); 533 memcpy(c->currdir, buf, sizeof(c->currdir));
@@ -537,22 +571,27 @@ int ft_enter(struct tree_context* c)
537 PLAYLIST_INSERT_LAST, true, true); 571 PLAYLIST_INSERT_LAST, true, true);
538 splash(HZ, ID2P(LANG_QUEUE_LAST)); 572 splash(HZ, ID2P(LANG_QUEUE_LAST));
539 } 573 }
540 else if (playlist_create(c->currdir, NULL) != -1) 574 else
541 { 575 {
542 start_index = ft_build_playlist(c, c->selected_item); 576 /* use the assembled path sans filename */
543 if (global_settings.playlist_shuffle) 577 char * fp = strrchr(buf, PATH_SEPCH);
578 if (fp)
579 *fp = '\0';
580 if (playlist_create(buf, NULL) != -1)
544 { 581 {
545 start_index = playlist_shuffle(seed, start_index); 582 start_index = ft_build_playlist(c, c->selected_item);
546 583 if (global_settings.playlist_shuffle)
547 /* when shuffling dir.: play all files 584 {
548 even if the file selected by user is 585 start_index = playlist_shuffle(seed, start_index);
549 not the first one */ 586 /* when shuffling dir.: play all files
550 if (!global_settings.play_selected) 587 even if the file selected by user is
551 start_index = 0; 588 not the first one */
589 if (!global_settings.play_selected)
590 start_index = 0;
591 }
592 playlist_start(start_index, 0, 0);
593 play = true;
552 } 594 }
553
554 playlist_start(start_index, 0, 0);
555 play = true;
556 } 595 }
557 break; 596 break;
558 } 597 }