summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-08-03 09:49:25 +0000
committerThomas Martitz <kugel@rockbox.org>2011-08-03 09:49:25 +0000
commit98096970e05108e723b64072f2b34187c92733de (patch)
tree14207a691999847d44f309dd6051bd646f6aea68
parentfa5cf8edeaf57c8ad3874c10998021cc3c240df5 (diff)
downloadrockbox-98096970e05108e723b64072f2b34187c92733de.tar.gz
rockbox-98096970e05108e723b64072f2b34187c92733de.zip
Cleanup tree.c cache handling a bit.
* Rename stuff to not re-use the term dircache * Move cache to own struct * Encapsulate retrieving entries a bit git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30242 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/filetree.c40
-rw-r--r--apps/playlist.c8
-rw-r--r--apps/plugins/imageviewer/imageviewer.c2
-rw-r--r--apps/plugins/mikmod/mikmod.c2
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c2
-rw-r--r--apps/plugins/rockpaint.c2
-rw-r--r--apps/tagtree.c22
-rw-r--r--apps/tree.c47
-rw-r--r--apps/tree.h18
9 files changed, 74 insertions, 69 deletions
diff --git a/apps/filetree.c b/apps/filetree.c
index 654d33d347..a7c989fc5e 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -60,13 +60,13 @@ int ft_build_playlist(struct tree_context* c, int start_index)
60 int i; 60 int i;
61 int start=start_index; 61 int start=start_index;
62 62
63 struct entry *dircache = c->dircache; 63 struct entry *entries = c->cache.entries;
64 64
65 for(i = 0;i < c->filesindir;i++) 65 for(i = 0;i < c->filesindir;i++)
66 { 66 {
67 if((dircache[i].attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO) 67 if((entries[i].attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO)
68 { 68 {
69 if (playlist_add(dircache[i].name) < 0) 69 if (playlist_add(entries[i].name) < 0)
70 break; 70 break;
71 } 71 }
72 else 72 else
@@ -122,12 +122,12 @@ bool ft_play_playlist(char* pathname, char* dirname, char* filename)
122 return false; 122 return false;
123} 123}
124 124
125/* walk a directory and check all dircache entries if a .talk file exists */ 125/* walk a directory and check all entries if a .talk file exists */
126static void check_file_thumbnails(struct tree_context* c) 126static void check_file_thumbnails(struct tree_context* c)
127{ 127{
128 int i; 128 int i;
129 struct dirent *entry; 129 struct dirent *entry;
130 struct entry* dircache = c->dircache; 130 struct entry* entries = c->cache.entries;
131 DIR *dir; 131 DIR *dir;
132 132
133 dir = opendir(c->currdir); 133 dir = opendir(c->currdir);
@@ -136,18 +136,18 @@ static void check_file_thumbnails(struct tree_context* c)
136 /* mark all files as non talking, except the .talk ones */ 136 /* mark all files as non talking, except the .talk ones */
137 for (i=0; i < c->filesindir; i++) 137 for (i=0; i < c->filesindir; i++)
138 { 138 {
139 if (dircache[i].attr & ATTR_DIRECTORY) 139 if (entries[i].attr & ATTR_DIRECTORY)
140 continue; /* we're not touching directories */ 140 continue; /* we're not touching directories */
141 141
142 if (strcasecmp(file_thumbnail_ext, 142 if (strcasecmp(file_thumbnail_ext,
143 &dircache[i].name[strlen(dircache[i].name) 143 &entries[i].name[strlen(entries[i].name)
144 - strlen(file_thumbnail_ext)])) 144 - strlen(file_thumbnail_ext)]))
145 { /* no .talk file */ 145 { /* no .talk file */
146 dircache[i].attr &= ~FILE_ATTR_THUMBNAIL; /* clear */ 146 entries[i].attr &= ~FILE_ATTR_THUMBNAIL; /* clear */
147 } 147 }
148 else 148 else
149 { /* .talk file, we later let them speak themselves */ 149 { /* .talk file, we later let them speak themselves */
150 dircache[i].attr |= FILE_ATTR_THUMBNAIL; /* set */ 150 entries[i].attr |= FILE_ATTR_THUMBNAIL; /* set */
151 } 151 }
152 } 152 }
153 153
@@ -170,9 +170,9 @@ static void check_file_thumbnails(struct tree_context* c)
170 /* search corresponding file in dir cache */ 170 /* search corresponding file in dir cache */
171 for (i=0; i < c->filesindir; i++) 171 for (i=0; i < c->filesindir; i++)
172 { 172 {
173 if (!strcasecmp(dircache[i].name, (char *)entry->d_name)) 173 if (!strcasecmp(entries[i].name, (char *)entry->d_name))
174 { /* match */ 174 { /* match */
175 dircache[i].attr |= FILE_ATTR_THUMBNAIL; /* set the flag */ 175 entries[i].attr |= FILE_ATTR_THUMBNAIL; /* set the flag */
176 break; /* exit search loop, because we found it */ 176 break; /* exit search loop, because we found it */
177 } 177 }
178 } 178 }
@@ -265,7 +265,7 @@ static int compare(const void* p1, const void* p2)
265 return 0; /* never reached */ 265 return 0; /* never reached */
266} 266}
267 267
268/* load and sort directory into dircache. returns NULL on failure. */ 268/* load and sort directory into the tree's cache. returns NULL on failure. */
269int ft_load(struct tree_context* c, const char* tempdir) 269int ft_load(struct tree_context* c, const char* tempdir)
270{ 270{
271 int files_in_dir = 0; 271 int files_in_dir = 0;
@@ -290,8 +290,8 @@ int ft_load(struct tree_context* c, const char* tempdir)
290 while ((entry = readdir(dir))) { 290 while ((entry = readdir(dir))) {
291 int len; 291 int len;
292 struct dirinfo info; 292 struct dirinfo info;
293 struct entry* dptr = 293 struct entry* table = c->cache.entries;
294 (struct entry*)(c->dircache + files_in_dir * sizeof(struct entry)); 294 struct entry* dptr = &table[files_in_dir];
295 if (!entry) 295 if (!entry)
296 break; 296 break;
297 297
@@ -360,8 +360,8 @@ int ft_load(struct tree_context* c, const char* tempdir)
360 continue; 360 continue;
361 } 361 }
362 362
363 if ((len > c->name_buffer_size - name_buffer_used - 1) || 363 if ((len > c->cache.name_buffer_size - name_buffer_used - 1) ||
364 (files_in_dir >= c->dircache_count)) { 364 (files_in_dir >= c->cache.max_entries)) {
365 /* Tell the world that we ran out of buffer space */ 365 /* Tell the world that we ran out of buffer space */
366 c->dirfull = true; 366 c->dirfull = true;
367 break; 367 break;
@@ -369,7 +369,7 @@ int ft_load(struct tree_context* c, const char* tempdir)
369 369
370 ++files_in_dir; 370 ++files_in_dir;
371 371
372 dptr->name = &c->name_buffer[name_buffer_used]; 372 dptr->name = &c->cache.name_buffer[name_buffer_used];
373 dptr->time_write = 373 dptr->time_write =
374 (long)info.wrtdate<<16 | 374 (long)info.wrtdate<<16 |
375 (long)info.wrttime; /* in one # */ 375 (long)info.wrttime; /* in one # */
@@ -384,7 +384,7 @@ int ft_load(struct tree_context* c, const char* tempdir)
384 closedir(dir); 384 closedir(dir);
385 385
386 compare_sort_dir = c->sort_dir; 386 compare_sort_dir = c->sort_dir;
387 qsort(c->dircache, files_in_dir, sizeof(struct entry), compare); 387 qsort(c->cache.entries, files_in_dir, sizeof(struct entry), compare);
388 388
389 /* If thumbnail talking is enabled, make an extra run to mark files with 389 /* If thumbnail talking is enabled, make an extra run to mark files with
390 associated thumbnails, so we don't do unsuccessful spinups later. */ 390 associated thumbnails, so we don't do unsuccessful spinups later. */
@@ -424,8 +424,8 @@ int ft_enter(struct tree_context* c)
424{ 424{
425 int rc = GO_TO_PREVIOUS; 425 int rc = GO_TO_PREVIOUS;
426 char buf[MAX_PATH]; 426 char buf[MAX_PATH];
427 struct entry *dircache = c->dircache; 427 struct entry* table = c->cache.entries;
428 struct entry* file = &dircache[c->selected_item]; 428 struct entry *file = &table[c->selected_item];
429 429
430 if (c->currdir[1]) 430 if (c->currdir[1])
431 snprintf(buf,sizeof(buf),"%s/%s",c->currdir, file->name); 431 snprintf(buf,sizeof(buf),"%s/%s",c->currdir, file->name);
diff --git a/apps/playlist.c b/apps/playlist.c
index 367e935006..564cd03d90 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -1537,7 +1537,7 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion)
1537 break; 1537 break;
1538 } 1538 }
1539 1539
1540 files = (struct entry*) tc->dircache; 1540 files = tc->cache.entries;
1541 num_files = tc->filesindir; 1541 num_files = tc->filesindir;
1542 1542
1543 for (i=0; i<num_files; i++) 1543 for (i=0; i<num_files; i++)
@@ -1615,7 +1615,7 @@ static int check_subdir_for_music(char *dir, const char *subdir, bool recurse)
1615 return -2; 1615 return -2;
1616 } 1616 }
1617 1617
1618 files = (struct entry*) tc->dircache; 1618 files = tc->cache.entries;
1619 num_files = tc->filesindir; 1619 num_files = tc->filesindir;
1620 1620
1621 for (i=0; i<num_files; i++) 1621 for (i=0; i<num_files; i++)
@@ -3568,7 +3568,7 @@ int playlist_directory_tracksearch(const char* dirname, bool recurse,
3568 return -1; 3568 return -1;
3569 } 3569 }
3570 3570
3571 files = (struct entry*) tc->dircache; 3571 files = tc->cache.entries;
3572 num_files = tc->filesindir; 3572 num_files = tc->filesindir;
3573 3573
3574 /* we've overwritten the dircache so tree browser will need to be 3574 /* we've overwritten the dircache so tree browser will need to be
@@ -3603,7 +3603,7 @@ int playlist_directory_tracksearch(const char* dirname, bool recurse,
3603 break; 3603 break;
3604 } 3604 }
3605 3605
3606 files = (struct entry*) tc->dircache; 3606 files = tc->cache.entries;
3607 num_files = tc->filesindir; 3607 num_files = tc->filesindir;
3608 if (!num_files) 3608 if (!num_files)
3609 { 3609 {
diff --git a/apps/plugins/imageviewer/imageviewer.c b/apps/plugins/imageviewer/imageviewer.c
index 6750c6c912..80e1ba41bf 100644
--- a/apps/plugins/imageviewer/imageviewer.c
+++ b/apps/plugins/imageviewer/imageviewer.c
@@ -136,7 +136,7 @@ static enum image_type image_type = IMAGE_UNKNOWN;
136static void get_pic_list(void) 136static void get_pic_list(void)
137{ 137{
138 struct tree_context *tree = rb->tree_get_context(); 138 struct tree_context *tree = rb->tree_get_context();
139 struct entry *dircache = tree->dircache; 139 struct entry *dircache = tree->cache.entries;
140 int i; 140 int i;
141 char *pname; 141 char *pname;
142 142
diff --git a/apps/plugins/mikmod/mikmod.c b/apps/plugins/mikmod/mikmod.c
index c99d11d636..dff0fce685 100644
--- a/apps/plugins/mikmod/mikmod.c
+++ b/apps/plugins/mikmod/mikmod.c
@@ -185,7 +185,7 @@ bool mod_ext(const char ext[])
185void get_mod_list(void) 185void get_mod_list(void)
186{ 186{
187 struct tree_context *tree = rb->tree_get_context(); 187 struct tree_context *tree = rb->tree_get_context();
188 struct entry *dircache = tree->dircache; 188 struct entry *dircache = tree->cache.entries;
189 int i; 189 int i;
190 char *pname; 190 char *pname;
191 191
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index c6e1f4dded..156ec019c1 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -1876,7 +1876,7 @@ static bool is_videofile(const char* file)
1876static bool get_videofile(int direction, char* videofile, size_t bufsize) 1876static bool get_videofile(int direction, char* videofile, size_t bufsize)
1877{ 1877{
1878 struct tree_context *tree = rb->tree_get_context(); 1878 struct tree_context *tree = rb->tree_get_context();
1879 struct entry *dircache = tree->dircache; 1879 struct entry *dircache = tree->cache.entries;
1880 int i, step, end, found = 0; 1880 int i, step, end, found = 0;
1881 char *videoname = rb->strrchr(videofile, '/') + 1; 1881 char *videoname = rb->strrchr(videofile, '/') + 1;
1882 size_t rest = bufsize - (videoname - videofile) - 1; 1882 size_t rest = bufsize - (videoname - videofile) - 1;
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c
index 1fef0e9f5f..add09c7fef 100644
--- a/apps/plugins/rockpaint.c
+++ b/apps/plugins/rockpaint.c
@@ -948,7 +948,7 @@ static bool browse_fonts( char *dst, int dst_size )
948 948
949 tree = rb->tree_get_context(); 949 tree = rb->tree_get_context();
950 backup = *tree; 950 backup = *tree;
951 dc = tree->dircache; 951 dc = tree->cache.entries;
952 a = backup.currdir+rb->strlen(backup.currdir)-1; 952 a = backup.currdir+rb->strlen(backup.currdir)-1;
953 if( *a != '/' ) 953 if( *a != '/' )
954 { 954 {
diff --git a/apps/tagtree.c b/apps/tagtree.c
index 37de9a242d..0b16695ad1 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -1175,7 +1175,7 @@ static int format_str(struct tagcache_search *tcs, struct display_format *fmt,
1175static int retrieve_entries(struct tree_context *c, int offset, bool init) 1175static int retrieve_entries(struct tree_context *c, int offset, bool init)
1176{ 1176{
1177 struct tagcache_search tcs; 1177 struct tagcache_search tcs;
1178 struct tagentry *dptr = (struct tagentry *)c->dircache; 1178 struct tagentry *dptr = c->cache.entries;
1179 struct display_format *fmt; 1179 struct display_format *fmt;
1180 int i; 1180 int i;
1181 int namebufused = 0; 1181 int namebufused = 0;
@@ -1339,13 +1339,13 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
1339 } 1339 }
1340 } 1340 }
1341 1341
1342 dptr->name = &c->name_buffer[namebufused]; 1342 dptr->name = &c->cache.name_buffer[namebufused];
1343 if (fmt) 1343 if (fmt)
1344 namebufused += strlen(buf)+1; 1344 namebufused += strlen(buf)+1;
1345 else 1345 else
1346 namebufused += tcs.result_len; 1346 namebufused += tcs.result_len;
1347 1347
1348 if (namebufused >= c->name_buffer_size) 1348 if (namebufused >= c->cache.name_buffer_size)
1349 { 1349 {
1350 logf("chunk mode #2: %d", current_entry_count); 1350 logf("chunk mode #2: %d", current_entry_count);
1351 c->dirfull = true; 1351 c->dirfull = true;
@@ -1363,7 +1363,7 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
1363 dptr++; 1363 dptr++;
1364 current_entry_count++; 1364 current_entry_count++;
1365 1365
1366 if (current_entry_count >= c->dircache_count) 1366 if (current_entry_count >= c->cache.max_entries)
1367 { 1367 {
1368 logf("chunk mode #3: %d", current_entry_count); 1368 logf("chunk mode #3: %d", current_entry_count);
1369 c->dirfull = true; 1369 c->dirfull = true;
@@ -1382,9 +1382,12 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
1382 } 1382 }
1383 1383
1384 if (sort) 1384 if (sort)
1385 qsort(c->dircache + special_entry_count * c->dentry_size, 1385 {
1386 int entry_size = sizeof(struct tagentry);
1387 qsort(c->cache.entries + special_entry_count * entry_size,
1386 current_entry_count - special_entry_count, 1388 current_entry_count - special_entry_count,
1387 c->dentry_size, compare); 1389 entry_size, compare);
1390 }
1388 1391
1389 if (!init) 1392 if (!init)
1390 { 1393 {
@@ -1416,7 +1419,7 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
1416 1419
1417 if (strip) 1420 if (strip)
1418 { 1421 {
1419 dptr = c->dircache; 1422 dptr = c->cache.entries;
1420 for (i = 0; i < total_count; i++, dptr++) 1423 for (i = 0; i < total_count; i++, dptr++)
1421 { 1424 {
1422 int len = strlen(dptr->name); 1425 int len = strlen(dptr->name);
@@ -1434,7 +1437,7 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
1434 1437
1435static int load_root(struct tree_context *c) 1438static int load_root(struct tree_context *c)
1436{ 1439{
1437 struct tagentry *dptr = (struct tagentry *)c->dircache; 1440 struct tagentry *dptr = c->cache.entries;
1438 int i; 1441 int i;
1439 1442
1440 tc = c; 1443 tc = c;
@@ -1476,7 +1479,6 @@ int tagtree_load(struct tree_context* c)
1476 int count; 1479 int count;
1477 int table = c->currtable; 1480 int table = c->currtable;
1478 1481
1479 c->dentry_size = sizeof(struct tagentry);
1480 c->dirsindir = 0; 1482 c->dirsindir = 0;
1481 1483
1482 if (!table) 1484 if (!table)
@@ -1870,7 +1872,7 @@ static int tagtree_play_folder(struct tree_context* c)
1870 1872
1871struct tagentry* tagtree_get_entry(struct tree_context *c, int id) 1873struct tagentry* tagtree_get_entry(struct tree_context *c, int id)
1872{ 1874{
1873 struct tagentry *entry = (struct tagentry *)c->dircache; 1875 struct tagentry *entry = (struct tagentry *)c->cache.entries;
1874 int realid = id - current_offset; 1876 int realid = id - current_offset;
1875 1877
1876 /* Load the next chunk if necessary. */ 1878 /* Load the next chunk if necessary. */
diff --git a/apps/tree.c b/apps/tree.c
index e802632c00..fc36671217 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -104,6 +104,12 @@ static int ft_play_dirname(char* name);
104static void ft_play_filename(char *dir, char *file); 104static void ft_play_filename(char *dir, char *file);
105static void say_filetype(int attr); 105static void say_filetype(int attr);
106 106
107static struct entry* get_entry_at(struct tree_context *t, int index)
108{
109 struct entry* entries = t->cache.entries;
110 return &entries[index];
111}
112
107static const char* tree_get_filename(int selected_item, void *data, 113static const char* tree_get_filename(int selected_item, void *data,
108 char *buffer, size_t buffer_len) 114 char *buffer, size_t buffer_len)
109{ 115{
@@ -121,8 +127,7 @@ static const char* tree_get_filename(int selected_item, void *data,
121 else 127 else
122#endif 128#endif
123 { 129 {
124 struct entry* dc = local_tc->dircache; 130 struct entry* e = get_entry_at(local_tc, selected_item);
125 struct entry* e = &dc[selected_item];
126 name = e->name; 131 name = e->name;
127 attr = e->attr; 132 attr = e->attr;
128 } 133 }
@@ -164,8 +169,7 @@ static int tree_get_filecolor(int selected_item, void * data)
164 if (*tc.dirfilter == SHOW_ID3DB) 169 if (*tc.dirfilter == SHOW_ID3DB)
165 return -1; 170 return -1;
166 struct tree_context * local_tc=(struct tree_context *)data; 171 struct tree_context * local_tc=(struct tree_context *)data;
167 struct entry* dc = local_tc->dircache; 172 struct entry* e = get_entry_at(local_tc, selected_item);
168 struct entry* e = &dc[selected_item];
169 return filetype_get_color(e->name, e->attr); 173 return filetype_get_color(e->name, e->attr);
170} 174}
171#endif 175#endif
@@ -180,9 +184,8 @@ static enum themable_icons tree_get_fileicon(int selected_item, void * data)
180 } 184 }
181 else 185 else
182#endif 186#endif
183 { 187 {
184 struct entry* dc = local_tc->dircache; 188 struct entry* e = get_entry_at(local_tc, selected_item);
185 struct entry* e = &dc[selected_item];
186 return filetype_get_icon(e->attr); 189 return filetype_get_icon(e->attr);
187 } 190 }
188} 191}
@@ -203,8 +206,7 @@ static int tree_voice_cb(int selected_item, void * data)
203 else 206 else
204#endif 207#endif
205 { 208 {
206 struct entry* dc = local_tc->dircache; 209 struct entry* e = get_entry_at(local_tc, selected_item);
207 struct entry* e = &dc[selected_item];
208 name = e->name; 210 name = e->name;
209 attr = e->attr; 211 attr = e->attr;
210 } 212 }
@@ -322,12 +324,12 @@ struct tree_context* tree_get_context(void)
322static int tree_get_file_position(char * filename) 324static int tree_get_file_position(char * filename)
323{ 325{
324 int i; 326 int i;
327 struct entry* e;
325 328
326 /* use lastfile to determine the selected item (default=0) */ 329 /* use lastfile to determine the selected item (default=0) */
327 for (i=0; i < tc.filesindir; i++) 330 for (i=0; i < tc.filesindir; i++)
328 { 331 {
329 struct entry* dc = tc.dircache; 332 e = get_entry_at(&tc, i);
330 struct entry* e = &dc[i];
331 if (!strcasecmp(e->name, filename)) 333 if (!strcasecmp(e->name, filename))
332 return(i); 334 return(i);
333 } 335 }
@@ -529,8 +531,7 @@ char* get_current_file(char* buffer, size_t buffer_len)
529 return NULL; 531 return NULL;
530#endif 532#endif
531 533
532 struct entry* dc = tc.dircache; 534 struct entry* e = get_entry_at(&tc, tc.selected_item);
533 struct entry* e = &dc[tc.selected_item];
534 if (getcwd(buffer, buffer_len)) 535 if (getcwd(buffer, buffer_len))
535 { 536 {
536 if (tc.dirlength) 537 if (tc.dirlength)
@@ -649,7 +650,7 @@ static int dirbrowse(void)
649 650
650 gui_synclist_draw(&tree_lists); 651 gui_synclist_draw(&tree_lists);
651 while(1) { 652 while(1) {
652 struct entry *dircache = tc.dircache; 653 struct entry *entries = tc.cache.entries;
653 bool restore = false; 654 bool restore = false;
654 if (tc.dirlevel < 0) 655 if (tc.dirlevel < 0)
655 tc.dirlevel = 0; /* shouldnt be needed.. this code needs work! */ 656 tc.dirlevel = 0; /* shouldnt be needed.. this code needs work! */
@@ -666,7 +667,7 @@ static int dirbrowse(void)
666 break; 667 break;
667 668
668 if ((tc.browse->flags & BROWSE_SELECTONLY) && 669 if ((tc.browse->flags & BROWSE_SELECTONLY) &&
669 !(dircache[tc.selected_item].attr & ATTR_DIRECTORY)) 670 !(entries[tc.selected_item].attr & ATTR_DIRECTORY))
670 { 671 {
671 tc.browse->flags |= BROWSE_SELECTED; 672 tc.browse->flags |= BROWSE_SELECTED;
672 get_current_file(tc.browse->buf, tc.browse->bufsize); 673 get_current_file(tc.browse->buf, tc.browse->bufsize);
@@ -791,15 +792,15 @@ static int dirbrowse(void)
791 else 792 else
792#endif 793#endif
793 { 794 {
794 attr = dircache[tc.selected_item].attr; 795 attr = entries[tc.selected_item].attr;
795 796
796 if (currdir[1]) /* Not in / */ 797 if (currdir[1]) /* Not in / */
797 snprintf(buf, sizeof buf, "%s/%s", 798 snprintf(buf, sizeof buf, "%s/%s",
798 currdir, 799 currdir,
799 dircache[tc.selected_item].name); 800 entries[tc.selected_item].name);
800 else /* In / */ 801 else /* In / */
801 snprintf(buf, sizeof buf, "/%s", 802 snprintf(buf, sizeof buf, "/%s",
802 dircache[tc.selected_item].name); 803 entries[tc.selected_item].name);
803 } 804 }
804 onplay_result = onplay(buf, attr, curr_context, hotkey); 805 onplay_result = onplay(buf, attr, curr_context, hotkey);
805 } 806 }
@@ -1001,17 +1002,17 @@ int rockbox_browse(struct browse_context *browse)
1001void tree_mem_init(void) 1002void tree_mem_init(void)
1002{ 1003{
1003 /* initialize tree context struct */ 1004 /* initialize tree context struct */
1005 struct tree_cache* cache = &tc.cache;
1004 memset(&tc, 0, sizeof(tc)); 1006 memset(&tc, 0, sizeof(tc));
1005 tc.dirfilter = &global_settings.dirfilter; 1007 tc.dirfilter = &global_settings.dirfilter;
1006 tc.sort_dir = global_settings.sort_dir; 1008 tc.sort_dir = global_settings.sort_dir;
1007 1009
1008 tc.name_buffer_size = AVERAGE_FILENAME_LENGTH * 1010 cache->name_buffer_size = AVERAGE_FILENAME_LENGTH *
1009 global_settings.max_files_in_dir; 1011 global_settings.max_files_in_dir;
1010 tc.name_buffer = buffer_alloc(tc.name_buffer_size); 1012 cache->name_buffer = buffer_alloc(cache->name_buffer_size);
1011 1013
1012 tc.dircache_count = global_settings.max_files_in_dir; 1014 cache->max_entries = global_settings.max_files_in_dir;
1013 tc.dircache = buffer_alloc(global_settings.max_files_in_dir * 1015 cache->entries = buffer_alloc(cache->max_entries*(sizeof(cache->entries)));
1014 sizeof(struct entry));
1015 tree_get_filetypes(&filetypes, &filetypes_count); 1016 tree_get_filetypes(&filetypes, &filetypes_count);
1016} 1017}
1017 1018
diff --git a/apps/tree.h b/apps/tree.h
index 104d6c480a..c07b92f298 100644
--- a/apps/tree.h
+++ b/apps/tree.h
@@ -38,6 +38,15 @@ struct entry {
38#define BROWSE_SELECTED 0x0100 /* this bit is set if user selected item */ 38#define BROWSE_SELECTED 0x0100 /* this bit is set if user selected item */
39 39
40struct tree_context; 40struct tree_context;
41struct tree_cache {
42 /* A big buffer with plenty of entry structs,
43 * contains all files and dirs in the current
44 * dir (with filters applied) */
45 void* entries;
46 char* name_buffer;
47 int max_entries; /* Max entries in the cache */
48 int name_buffer_size; /* in bytes */
49};
41 50
42struct browse_context { 51struct browse_context {
43 int dirfilter; 52 int dirfilter;
@@ -80,14 +89,7 @@ struct tree_context {
80 int currtable; /* db use */ 89 int currtable; /* db use */
81 int currextra; /* db use */ 90 int currextra; /* db use */
82#endif 91#endif
83 /* A big buffer with plenty of entry structs, 92 struct tree_cache cache;
84 * contains all files and dirs in the current
85 * dir (with filters applied) */
86 void* dircache;
87 int dircache_count; /* Number of entries in dircache */
88 char* name_buffer;
89 int name_buffer_size;
90 int dentry_size;
91 bool dirfull; 93 bool dirfull;
92 int sort_dir; /* directory sort order */ 94 int sort_dir; /* directory sort order */
93 struct browse_context *browse; 95 struct browse_context *browse;