diff options
Diffstat (limited to 'apps/tree.c')
-rw-r--r-- | apps/tree.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/apps/tree.c b/apps/tree.c index 387878c96e..a72c98281c 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -51,21 +51,25 @@ | |||
51 | #include "screens.h" | 51 | #include "screens.h" |
52 | #include "keyboard.h" | 52 | #include "keyboard.h" |
53 | #include "onplay.h" | 53 | #include "onplay.h" |
54 | #include "buffer.h" | ||
54 | 55 | ||
55 | #ifdef HAVE_LCD_BITMAP | 56 | #ifdef HAVE_LCD_BITMAP |
56 | #include "widgets.h" | 57 | #include "widgets.h" |
57 | #endif | 58 | #endif |
58 | 59 | ||
59 | #define NAME_BUFFER_SIZE (AVERAGE_FILENAME_LENGTH * MAX_FILES_IN_DIR) | 60 | /* Mirror of global_settings.max_files_in_dir */ |
61 | int max_files_in_dir; | ||
60 | 62 | ||
61 | static char name_buffer[NAME_BUFFER_SIZE]; | 63 | static char *name_buffer; |
62 | static int name_buffer_length; | 64 | static int name_buffer_size; /* Size of allocated buffer */ |
65 | static int name_buffer_length; /* Currently used amount */ | ||
63 | struct entry { | 66 | struct entry { |
64 | short attr; /* FAT attributes + file type flags */ | 67 | short attr; /* FAT attributes + file type flags */ |
65 | char *name; | 68 | char *name; |
66 | }; | 69 | }; |
67 | 70 | ||
68 | static struct entry dircache[MAX_FILES_IN_DIR]; | 71 | static struct entry *dircache; |
72 | |||
69 | static int dircursor; | 73 | static int dircursor; |
70 | static int dirstart; | 74 | static int dirstart; |
71 | static int dirlevel; | 75 | static int dirlevel; |
@@ -249,7 +253,7 @@ static int showdir(char *path, int start) | |||
249 | name_buffer_length = 0; | 253 | name_buffer_length = 0; |
250 | dir_buffer_full = false; | 254 | dir_buffer_full = false; |
251 | 255 | ||
252 | for ( i=0; i<MAX_FILES_IN_DIR; i++ ) { | 256 | for ( i=0; i < max_files_in_dir; i++ ) { |
253 | int len; | 257 | int len; |
254 | struct dirent *entry = readdir(dir); | 258 | struct dirent *entry = readdir(dir); |
255 | struct entry* dptr = &dircache[i]; | 259 | struct entry* dptr = &dircache[i]; |
@@ -333,7 +337,7 @@ static int showdir(char *path, int start) | |||
333 | continue; | 337 | continue; |
334 | } | 338 | } |
335 | 339 | ||
336 | if (len > NAME_BUFFER_SIZE - name_buffer_length - 1) { | 340 | if (len > name_buffer_size - name_buffer_length - 1) { |
337 | /* Tell the world that we ran out of buffer space */ | 341 | /* Tell the world that we ran out of buffer space */ |
338 | dir_buffer_full = true; | 342 | dir_buffer_full = true; |
339 | break; | 343 | break; |
@@ -348,7 +352,7 @@ static int showdir(char *path, int start) | |||
348 | lastdir[sizeof(lastdir)-1] = 0; | 352 | lastdir[sizeof(lastdir)-1] = 0; |
349 | qsort(dircache,filesindir,sizeof(struct entry),compare); | 353 | qsort(dircache,filesindir,sizeof(struct entry),compare); |
350 | 354 | ||
351 | if ( dir_buffer_full || filesindir == MAX_FILES_IN_DIR ) { | 355 | if ( dir_buffer_full || filesindir == max_files_in_dir ) { |
352 | #ifdef HAVE_LCD_CHARCELLS | 356 | #ifdef HAVE_LCD_CHARCELLS |
353 | lcd_double_height(false); | 357 | lcd_double_height(false); |
354 | #endif | 358 | #endif |
@@ -1317,3 +1321,14 @@ bool create_playlist(void) | |||
1317 | 1321 | ||
1318 | return true; | 1322 | return true; |
1319 | } | 1323 | } |
1324 | |||
1325 | void tree_init(void) | ||
1326 | { | ||
1327 | /* We copy the settings value in case it is changed by the user. We can't | ||
1328 | use the next reboot. */ | ||
1329 | max_files_in_dir = global_settings.max_files_in_dir; | ||
1330 | name_buffer_size = AVERAGE_FILENAME_LENGTH * max_files_in_dir; | ||
1331 | |||
1332 | name_buffer = buffer_alloc(name_buffer_size); | ||
1333 | dircache = buffer_alloc(max_files_in_dir * sizeof(struct entry)); | ||
1334 | } | ||