Index: apps/playlist.c =================================================================== --- apps/playlist.c (revision 18740) +++ apps/playlist.c (working copy) @@ -1433,12 +1433,12 @@ if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM) { int fd = open(ROCKBOX_DIR "/folder_advance_list.dat",O_RDONLY); - char buffer[MAX_PATH]; - int folder_count = 0,i; - srand(current_tick); - *(tc->dirfilter) = SHOW_MUSIC; if (fd >= 0) { + char buffer[MAX_PATH]; + int folder_count = 0,i; + srand(current_tick); + *(tc->dirfilter) = SHOW_MUSIC; read(fd,&folder_count,sizeof(int)); if (!folder_count) exit = true; @@ -1459,11 +1459,13 @@ } } /* not random folder advance */ - if (recursion){ + if (recursion) + { /* start with root */ dir[0] = '\0'; } - else{ + else + { /* start with current directory */ strncpy(dir, playlist->filename, playlist->dirlen-1); dir[playlist->dirlen-1] = '\0'; @@ -1474,14 +1476,14 @@ /* sort in another direction if previous dir is requested */ if(!is_forward){ - if ((global_settings.sort_dir == 0) || (global_settings.sort_dir == 3)) - global_settings.sort_dir = 4; - else if (global_settings.sort_dir == 1) - global_settings.sort_dir = 2; - else if (global_settings.sort_dir == 2) - global_settings.sort_dir = 1; - else if (global_settings.sort_dir == 4) - global_settings.sort_dir = 0; + if ((sort_dir == 0) || (sort_dir == 3)) + sort_dir = 4; + else if (sort_dir == 1) + sort_dir = 2; + else if (sort_dir == 2) + sort_dir = 1; + else if (sort_dir == 4) + sort_dir = 0; } while (!exit) @@ -1490,7 +1492,7 @@ int num_files = 0; int i; - if (ft_load(tc, (dir[0]=='\0')?"/":dir) < 0) + if (ft_load(tc, (dir[0]=='\0')?"/":dir, sort_dir) < 0) { splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR)); exit = true; @@ -1544,12 +1546,10 @@ /* restore dirfilter & sort_dir */ *(tc->dirfilter) = dirfilter; - global_settings.sort_dir = sort_dir; /* special case if nothing found: try start searching again from root */ - if (result == -1 && !recursion){ + if (result == -1 && !recursion) result = get_next_dir(dir,is_forward, true); - } return result; } @@ -1571,7 +1571,7 @@ snprintf(dir+dirlen, MAX_PATH-dirlen, "/%s", subdir); - if (ft_load(tc, dir) < 0) + if (ft_load(tc, dir, global_settings.sort_dir) < 0) { splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR)); return -2; @@ -1625,7 +1625,7 @@ } /* we now need to reload our current directory */ - if(ft_load(tc, dir) < 0) + if(ft_load(tc, dir, global_settings.sort_dir) < 0) splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR)); } return result; @@ -3480,7 +3480,7 @@ /* use the tree browser dircache to load files */ *(tc->dirfilter) = SHOW_ALL; - if (ft_load(tc, dirname) < 0) + if (ft_load(tc, dirname, global_settings.sort_dir) < 0) { splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR)); *(tc->dirfilter) = old_dirfilter; @@ -3515,7 +3515,7 @@ break; /* we now need to reload our current directory */ - if(ft_load(tc, dirname) < 0) + if(ft_load(tc, dirname, global_settings.sort_dir) < 0) { result = -1; break; Index: apps/tree.c =================================================================== --- apps/tree.c (revision 18740) +++ apps/tree.c (working copy) @@ -366,7 +366,7 @@ /* if the tc.currdir has been changed, reload it ...*/ if (strncmp(tc.currdir, lastdir, sizeof(lastdir)) || reload_dir) { - if (ft_load(&tc, NULL) < 0) + if (ft_load(&tc, NULL, global_settings.sort_dir) < 0) return -1; strcpy(lastdir, tc.currdir); changed = true; @@ -484,7 +484,7 @@ bool id3db = *tc.dirfilter == SHOW_ID3DB; #endif - if (ft_load(&tc, dir) < 0) + if (ft_load(&tc, dir, global_settings.sort_dir) < 0) return; lastdir[0] = 0; @@ -588,7 +588,7 @@ } } } - if (ft_load(&tc, NULL) >= 0) + if (ft_load(&tc, NULL, global_settings.sort_dir) >= 0) { tc.selected_item = tree_get_file_position(lastfile); } Index: apps/filetree.c =================================================================== --- apps/filetree.c (revision 18740) +++ apps/filetree.c (working copy) @@ -55,6 +55,10 @@ #include "backdrop.h" + +static int compare_sort_dir; + + int ft_build_playlist(struct tree_context* c, int start_index) { int i; @@ -189,7 +193,7 @@ if (e1->attr & ATTR_DIRECTORY && e2->attr & ATTR_DIRECTORY) { /* two directories */ - criteria = global_settings.sort_dir; + criteria = compare_sort_dir; #ifdef HAVE_MULTIVOLUME if (e1->attr & ATTR_VOLUME || e2->attr & ATTR_VOLUME) @@ -247,7 +251,7 @@ } /* load and sort directory into dircache. returns NULL on failure. */ -int ft_load(struct tree_context* c, const char* tempdir) +int ft_load(struct tree_context* c, const char* tempdir, int sort_dir) { int i; int name_buffer_used = 0; @@ -345,6 +349,7 @@ c->dirlength = i; closedir(dir); + compare_sort_dir = sort_dir; qsort(c->dircache,i,sizeof(struct entry),compare); /* If thumbnail talking is enabled, make an extra run to mark files with Index: apps/filetree.h =================================================================== --- apps/filetree.h (revision 18740) +++ apps/filetree.h (working copy) @@ -22,7 +22,7 @@ #define FILETREE_H #include "tree.h" -int ft_load(struct tree_context* c, const char* tempdir); +int ft_load(struct tree_context* c, const char* tempdir, int sort_dir); int ft_enter(struct tree_context* c); int ft_exit(struct tree_context* c); int ft_build_playlist(struct tree_context* c, int start_index); Index: apps/playlist_catalog.c =================================================================== --- apps/playlist_catalog.c (revision 18740) +++ apps/playlist_catalog.c (working copy) @@ -127,7 +127,7 @@ /* use the tree browser dircache to load only playlists */ *(tc->dirfilter) = SHOW_PLAYLIST; - if (ft_load(tc, playlist_dir) < 0) + if (ft_load(tc, playlist_dir, global_settings.sort_dir) < 0) { splashf(HZ*2, ID2P(LANG_CATALOG_NO_DIRECTORY), playlist_dir); goto exit;