summaryrefslogtreecommitdiff
path: root/apps/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tree.c')
-rw-r--r--apps/tree.c93
1 files changed, 2 insertions, 91 deletions
diff --git a/apps/tree.c b/apps/tree.c
index a5741dfc31..97f152ff74 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -69,6 +69,7 @@
69#include "gwps-common.h" 69#include "gwps-common.h"
70#include "eeprom_settings.h" 70#include "eeprom_settings.h"
71#include "scrobbler.h" 71#include "scrobbler.h"
72#include "playlist_catalog.h"
72 73
73/* gui api */ 74/* gui api */
74#include "list.h" 75#include "list.h"
@@ -883,107 +884,17 @@ static int dirbrowse()
883 return true; 884 return true;
884} 885}
885 886
886static int plsize = 0;
887static long pltick;
888static bool add_dir(char* dirname, int len, int fd)
889{
890 bool abort = false;
891 DIR* dir;
892
893 /* check for user abort */
894 if (action_userabort(TIMEOUT_NOBLOCK))
895 return true;
896
897 dir = opendir(dirname);
898 if(!dir)
899 return true;
900
901 while (true) {
902 struct dirent *entry;
903
904 entry = readdir(dir);
905 if (!entry)
906 break;
907 if (entry->attribute & ATTR_DIRECTORY) {
908 int dirlen = strlen(dirname);
909 bool result;
910
911 if (!strcmp((char *)entry->d_name, ".") ||
912 !strcmp((char *)entry->d_name, ".."))
913 continue;
914
915 if (dirname[1])
916 snprintf(dirname+dirlen, len-dirlen, "/%s", entry->d_name);
917 else
918 snprintf(dirname, len, "/%s", entry->d_name);
919
920 result = add_dir(dirname, len, fd);
921 dirname[dirlen] = '\0';
922 if (result) {
923 abort = true;
924 break;
925 }
926 }
927 else {
928 int x = strlen((char *)entry->d_name);
929 int i;
930 char *cp = strrchr((char *)entry->d_name,'.');
931
932 if (cp) {
933 cp++;
934
935 /* add all supported audio files to playlists */
936 for (i=0; i < filetypes_count; i++) {
937 if (filetypes[i].tree_attr == FILE_ATTR_AUDIO) {
938 if (!strcasecmp(cp, filetypes[i].extension)) {
939 write(fd, dirname, strlen(dirname));
940 write(fd, "/", 1);
941 write(fd, entry->d_name, x);
942 write(fd, "\n", 1);
943
944 plsize++;
945 if(TIME_AFTER(current_tick, pltick+HZ/4)) {
946 pltick = current_tick;
947 gui_syncsplash(0, "%d %s",
948 plsize, str(LANG_DIR_BROWSER));
949 }
950 break;
951 }
952 }
953 }
954 }
955 }
956 }
957 closedir(dir);
958
959 return abort;
960}
961
962bool create_playlist(void) 887bool create_playlist(void)
963{ 888{
964 int fd;
965 char filename[MAX_PATH]; 889 char filename[MAX_PATH];
966 890
967 pltick = current_tick;
968
969 snprintf(filename, sizeof filename, "%s.m3u8", 891 snprintf(filename, sizeof filename, "%s.m3u8",
970 tc.currdir[1] ? tc.currdir : "/root"); 892 tc.currdir[1] ? tc.currdir : "/root");
971 gui_syncsplash(0, "%s %s", str(LANG_CREATING), filename); 893 gui_syncsplash(0, "%s %s", str(LANG_CREATING), filename);
972
973 fd = creat(filename);
974 if (fd < 0)
975 return false;
976 894
977 trigger_cpu_boost(); 895 trigger_cpu_boost();
978 896 catalog_add_to_a_playlist(tc.currdir, ATTR_DIRECTORY, true, filename);
979 snprintf(filename, sizeof(filename), "%s",
980 tc.currdir[1] ? tc.currdir : "/");
981 plsize = 0;
982 add_dir(filename, sizeof(filename), fd);
983 close(fd);
984
985 cancel_cpu_boost(); 897 cancel_cpu_boost();
986 sleep(HZ);
987 898
988 return true; 899 return true;
989} 900}