diff options
Diffstat (limited to 'apps/tree.c')
-rw-r--r-- | apps/tree.c | 110 |
1 files changed, 62 insertions, 48 deletions
diff --git a/apps/tree.c b/apps/tree.c index f0f1f0e94e..7563c1ef6e 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -577,9 +577,10 @@ static void set_current_file_ex(const char *path, const char *filename) | |||
577 | /* separate directory from filename */ | 577 | /* separate directory from filename */ |
578 | /* gets the directory's name and put it into tc.currdir */ | 578 | /* gets the directory's name and put it into tc.currdir */ |
579 | filename = strrchr(path+1,'/'); | 579 | filename = strrchr(path+1,'/'); |
580 | if (filename) | 580 | size_t endpos = filename - path; |
581 | if (endpos < MAX_PATH - 1) | ||
581 | { | 582 | { |
582 | strmemccpy(tc.currdir, path, filename - path + 1); | 583 | strmemccpy(tc.currdir, path, endpos + 1); |
583 | filename++; | 584 | filename++; |
584 | } | 585 | } |
585 | else | 586 | else |
@@ -588,9 +589,18 @@ static void set_current_file_ex(const char *path, const char *filename) | |||
588 | filename = path+1; | 589 | filename = path+1; |
589 | } | 590 | } |
590 | } | 591 | } |
591 | else /* path and filename came in separate */ | 592 | else /* path and filename came in separate ensure an ending '/' */ |
592 | { | 593 | { |
593 | strmemccpy(tc.currdir, path, MAX_PATH); | 594 | char *end_p = strmemccpy(tc.currdir, path, MAX_PATH); |
595 | size_t endpos = end_p - tc.currdir; | ||
596 | if (endpos < MAX_PATH) | ||
597 | { | ||
598 | if (tc.currdir[endpos - 2] != '/') | ||
599 | { | ||
600 | tc.currdir[endpos - 1] = '/'; | ||
601 | tc.currdir[endpos] = '\0'; | ||
602 | } | ||
603 | } | ||
594 | } | 604 | } |
595 | strmemccpy(lastfile, filename, MAX_PATH); | 605 | strmemccpy(lastfile, filename, MAX_PATH); |
596 | 606 | ||
@@ -615,13 +625,12 @@ static void set_current_file_ex(const char *path, const char *filename) | |||
615 | if (ft_load(&tc, NULL) >= 0) | 625 | if (ft_load(&tc, NULL) >= 0) |
616 | { | 626 | { |
617 | tc.selected_item = tree_get_file_position(lastfile); | 627 | tc.selected_item = tree_get_file_position(lastfile); |
618 | } | 628 | if (!tc.is_browsing && tc.out_of_tree == 0) |
619 | 629 | { | |
620 | if (!tc.is_browsing && tc.out_of_tree == 0) | 630 | /* the browser is closed */ |
621 | { | 631 | /* don't allow the previous items to overwrite what we just loaded */ |
622 | /* the browser is closed */ | 632 | tc.out_of_tree = tc.selected_item + 1; |
623 | /* don't allow the previous items to overwrite what we just loaded */ | 633 | } |
624 | tc.out_of_tree = tc.selected_item + 1; | ||
625 | } | 634 | } |
626 | } | 635 | } |
627 | 636 | ||
@@ -998,13 +1007,6 @@ int rockbox_browse(struct browse_context *browse) | |||
998 | int ret_val = 0; | 1007 | int ret_val = 0; |
999 | int dirfilter = browse->dirfilter; | 1008 | int dirfilter = browse->dirfilter; |
1000 | 1009 | ||
1001 | if (tc.out_of_tree > 0) | ||
1002 | { | ||
1003 | tc.selected_item = tc.out_of_tree - 1; | ||
1004 | tc.out_of_tree = 0; | ||
1005 | return ft_enter(&tc); | ||
1006 | } | ||
1007 | |||
1008 | if (backup_count >= NUM_TC_BACKUP) | 1010 | if (backup_count >= NUM_TC_BACKUP) |
1009 | return GO_TO_PREVIOUS; | 1011 | return GO_TO_PREVIOUS; |
1010 | if (backup_count >= 0) | 1012 | if (backup_count >= 0) |
@@ -1015,43 +1017,55 @@ int rockbox_browse(struct browse_context *browse) | |||
1015 | tc.sort_dir = global_settings.sort_dir; | 1017 | tc.sort_dir = global_settings.sort_dir; |
1016 | 1018 | ||
1017 | reload_dir = true; | 1019 | reload_dir = true; |
1018 | if (*tc.dirfilter >= NUM_FILTER_MODES) | 1020 | |
1021 | if (tc.out_of_tree > 0) | ||
1022 | { | ||
1023 | /* an item has already been loaded out_of_tree holds the selected index | ||
1024 | * what happens with the item is dependent on the browse context */ | ||
1025 | tc.selected_item = tc.out_of_tree - 1; | ||
1026 | tc.out_of_tree = 0; | ||
1027 | ret_val = ft_enter(&tc); | ||
1028 | } | ||
1029 | else | ||
1019 | { | 1030 | { |
1020 | int last_context; | 1031 | if (*tc.dirfilter >= NUM_FILTER_MODES) |
1021 | /* don't reset if its the same browse already loaded */ | ||
1022 | if (tc.browse != browse || | ||
1023 | !(tc.currdir[1] && strcmp(tc.currdir, browse->root) == 0)) | ||
1024 | { | 1032 | { |
1025 | tc.browse = browse; | 1033 | int last_context; |
1026 | tc.selected_item = 0; | 1034 | /* don't reset if its the same browse already loaded */ |
1027 | tc.dirlevel = 0; | 1035 | if (tc.browse != browse || |
1036 | !(tc.currdir[1] && strcmp(tc.currdir, browse->root) == 0)) | ||
1037 | { | ||
1038 | tc.browse = browse; | ||
1039 | tc.selected_item = 0; | ||
1040 | tc.dirlevel = 0; | ||
1028 | 1041 | ||
1029 | strmemccpy(tc.currdir, browse->root, sizeof(tc.currdir)); | 1042 | strmemccpy(tc.currdir, browse->root, sizeof(tc.currdir)); |
1030 | } | 1043 | } |
1031 | 1044 | ||
1032 | start_wps = false; | 1045 | start_wps = false; |
1033 | last_context = curr_context; | 1046 | last_context = curr_context; |
1034 | 1047 | ||
1035 | if (browse->selected) | 1048 | if (browse->selected) |
1036 | { | 1049 | { |
1037 | set_current_file_ex(browse->root, browse->selected); | 1050 | set_current_file_ex(browse->root, browse->selected); |
1038 | /* set_current_file changes dirlevel, change it back */ | 1051 | /* set_current_file changes dirlevel, change it back */ |
1039 | tc.dirlevel = 0; | 1052 | tc.dirlevel = 0; |
1040 | } | 1053 | } |
1041 | 1054 | ||
1042 | ret_val = dirbrowse(); | ||
1043 | curr_context = last_context; | ||
1044 | } | ||
1045 | else | ||
1046 | { | ||
1047 | if (dirfilter != SHOW_ID3DB && (browse->flags & BROWSE_DIRFILTER) == 0) | ||
1048 | tc.dirfilter = &global_settings.dirfilter; | ||
1049 | tc.browse = browse; | ||
1050 | set_current_file(browse->root); | ||
1051 | if (browse->flags&BROWSE_RUNFILE) | ||
1052 | ret_val = ft_enter(&tc); | ||
1053 | else | ||
1054 | ret_val = dirbrowse(); | 1055 | ret_val = dirbrowse(); |
1056 | curr_context = last_context; | ||
1057 | } | ||
1058 | else | ||
1059 | { | ||
1060 | if (dirfilter != SHOW_ID3DB && (browse->flags & BROWSE_DIRFILTER) == 0) | ||
1061 | tc.dirfilter = &global_settings.dirfilter; | ||
1062 | tc.browse = browse; | ||
1063 | set_current_file(browse->root); | ||
1064 | if (browse->flags&BROWSE_RUNFILE) | ||
1065 | ret_val = ft_enter(&tc); | ||
1066 | else | ||
1067 | ret_val = dirbrowse(); | ||
1068 | } | ||
1055 | } | 1069 | } |
1056 | backup_count--; | 1070 | backup_count--; |
1057 | if (backup_count >= 0) | 1071 | if (backup_count >= 0) |