diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/tree.c | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/apps/tree.c b/apps/tree.c index f6b5176051..de630df4cc 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -47,7 +47,7 @@ | |||
47 | #define MAX_DIR_LEVELS 10 | 47 | #define MAX_DIR_LEVELS 10 |
48 | 48 | ||
49 | struct entry { | 49 | struct entry { |
50 | bool file; /* true if file, false if dir */ | 50 | char attr; /* FAT attributes */ |
51 | char name[TREE_MAX_FILENAMELEN]; | 51 | char name[TREE_MAX_FILENAMELEN]; |
52 | }; | 52 | }; |
53 | 53 | ||
@@ -105,6 +105,8 @@ extern unsigned char bitmap_icons_6x8[LastIcon][6]; | |||
105 | #define TREE_MENU BUTTON_MENU | 105 | #define TREE_MENU BUTTON_MENU |
106 | #endif /* HAVE_RECORDER_KEYPAD */ | 106 | #endif /* HAVE_RECORDER_KEYPAD */ |
107 | 107 | ||
108 | #define TREE_ATTR_M3U 0x80 /* unused by FAT attributes */ | ||
109 | |||
108 | static int compare(const void* e1, const void* e2) | 110 | static int compare(const void* e1, const void* e2) |
109 | { | 111 | { |
110 | return strncmp((*(struct entry**)e1)->name, (*(struct entry**)e2)->name, | 112 | return strncmp((*(struct entry**)e1)->name, (*(struct entry**)e2)->name, |
@@ -129,22 +131,40 @@ static int showdir(char *path, int start) | |||
129 | struct dirent *entry = readdir(dir); | 131 | struct dirent *entry = readdir(dir); |
130 | if (!entry) | 132 | if (!entry) |
131 | break; | 133 | break; |
132 | if(entry->d_name[0] == '.') { | 134 | |
133 | /* skip names starting with a dot */ | 135 | /* skip directories . and .. */ |
136 | if (!strncmp(entry->d_name, ".", 1) || | ||
137 | !strncmp(entry->d_name, "..", 2)) { | ||
134 | i--; | 138 | i--; |
135 | continue; | 139 | continue; |
136 | } | 140 | } |
137 | dircache[i].file = !(entry->attribute & ATTR_DIRECTORY); | 141 | dircache[i].attr = entry->attribute; |
138 | 142 | ||
139 | /* show only dir/m3u/mp3 ? */ | ||
140 | len = strlen(entry->d_name); | 143 | len = strlen(entry->d_name); |
141 | if ( global_settings.mp3filter && | 144 | if ( global_settings.mp3filter ) { |
142 | dircache[i].file && | 145 | |
143 | (len > 4) && | 146 | /* filter hidden files and directories */ |
144 | (strcasecmp(&entry->d_name[len-4], ".m3u") && | 147 | if ( dircache[i].attr & ATTR_HIDDEN ) { |
145 | strcasecmp(&entry->d_name[len-4], ".mp3"))) { | 148 | i--; |
146 | i--; | 149 | continue; |
147 | continue; | 150 | } |
151 | |||
152 | if ( !(dircache[i].attr & ATTR_DIRECTORY) ) { | ||
153 | /* if not an mp3 or m3u, skip this file */ | ||
154 | if ( (len > 4) && | ||
155 | (strcasecmp(&entry->d_name[len-4], ".m3u") && | ||
156 | strcasecmp(&entry->d_name[len-4], ".mp3"))) { | ||
157 | i--; | ||
158 | continue; | ||
159 | } | ||
160 | else if ( len > 4 ) { | ||
161 | /* mark m3u files as playlists */ | ||
162 | if ( !strcasecmp(&entry->d_name[len-4], ".m3u") ) | ||
163 | dircache[i].attr |= TREE_ATTR_M3U; | ||
164 | /* cut off .mp3 and .m3u extensions */ | ||
165 | entry->d_name[len-4] = 0; | ||
166 | } | ||
167 | } | ||
148 | } | 168 | } |
149 | 169 | ||
150 | strncpy(dircache[i].name,entry->d_name,TREE_MAX_FILENAMELEN); | 170 | strncpy(dircache[i].name,entry->d_name,TREE_MAX_FILENAMELEN); |
@@ -177,11 +197,12 @@ static int showdir(char *path, int start) | |||
177 | len = strlen(dircacheptr[i]->name); | 197 | len = strlen(dircacheptr[i]->name); |
178 | 198 | ||
179 | #ifdef HAVE_LCD_BITMAP | 199 | #ifdef HAVE_LCD_BITMAP |
180 | if ( dircacheptr[i]->file ) { | 200 | if ( !(dircacheptr[i]->attr & ATTR_DIRECTORY) ) { |
181 | if(!strcasecmp(&dircacheptr[i]->name[len-4], ".m3u")) | 201 | if ( (dircacheptr[i]->attr & TREE_ATTR_M3U) || |
202 | !strcasecmp(&dircacheptr[i]->name[len-4], ".m3u")) | ||
182 | icon_type = Playlist; | 203 | icon_type = Playlist; |
183 | else | 204 | else |
184 | icon_type=File; | 205 | icon_type = File; |
185 | } else | 206 | } else |
186 | icon_type=Folder; | 207 | icon_type=Folder; |
187 | lcd_bitmap(bitmap_icons_6x8[icon_type], | 208 | lcd_bitmap(bitmap_icons_6x8[icon_type], |
@@ -219,7 +240,7 @@ char* peek_next_track(int steps) | |||
219 | dircursor++; | 240 | dircursor++; |
220 | else | 241 | else |
221 | start++; | 242 | start++; |
222 | if ( dircacheptr[dircursor+start]->file && | 243 | if ( !(dircacheptr[dircursor+start]->attr & ATTR_DIRECTORY) && |
223 | dircacheptr[dircursor+start]->name[strlen(dircacheptr[dircursor+start]->name)-1] == '3') { | 244 | dircacheptr[dircursor+start]->name[strlen(dircacheptr[dircursor+start]->name)-1] == '3') { |
224 | snprintf(buf,sizeof buf,"%s/%s", | 245 | snprintf(buf,sizeof buf,"%s/%s", |
225 | currdir, dircacheptr[dircursor+start]->name ); | 246 | currdir, dircacheptr[dircursor+start]->name ); |
@@ -233,7 +254,7 @@ char* peek_next_track(int steps) | |||
233 | dircursor--; | 254 | dircursor--; |
234 | else | 255 | else |
235 | start--; | 256 | start--; |
236 | if ( dircacheptr[dircursor+start]->file && | 257 | if ( !(dircacheptr[dircursor+start]->attr & ATTR_DIRECTORY) && |
237 | dircacheptr[dircursor+start]->name[strlen(dircacheptr[dircursor+start]->name)-1] == '3') { | 258 | dircacheptr[dircursor+start]->name[strlen(dircacheptr[dircursor+start]->name)-1] == '3') { |
238 | snprintf(buf, sizeof(buf), "%s/%s", | 259 | snprintf(buf, sizeof(buf), "%s/%s", |
239 | currdir, dircacheptr[dircursor+start]->name); | 260 | currdir, dircacheptr[dircursor+start]->name); |
@@ -316,7 +337,7 @@ bool dirbrowse(char *root) | |||
316 | dircacheptr[dircursor+start]->name); | 337 | dircacheptr[dircursor+start]->name); |
317 | } | 338 | } |
318 | 339 | ||
319 | if (!dircacheptr[dircursor+start]->file) { | 340 | if (dircacheptr[dircursor+start]->attr & ATTR_DIRECTORY) { |
320 | if ( play_mode == 1 ) | 341 | if ( play_mode == 1 ) |
321 | play_mode = 0; | 342 | play_mode = 0; |
322 | memcpy(currdir,buf,sizeof(currdir)); | 343 | memcpy(currdir,buf,sizeof(currdir)); |