From b6ac9a9f395b486baf5de455cf2505351b32d8ec Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Wed, 22 Nov 2023 13:43:53 -0500 Subject: Revert "tree.c cleanup update_dir()" This reverts commit 1d2dfb3a7681ab462bb5ca31d3362dbf2d0fcfcb. Reason for revert: crash on ipod Classic boot Change-Id: Ie0fe569515f73bb7853796e5e7df13fde42e8642 --- apps/tree.c | 146 ++++++++++++++++++++++++++++-------------------------------- 1 file changed, 68 insertions(+), 78 deletions(-) diff --git a/apps/tree.c b/apps/tree.c index f0f1f0e94e..ba4da816d1 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -352,20 +352,9 @@ static int tree_get_file_position(char * filename) */ static int update_dir(void) { - struct gui_synclist * const list = &tree_lists; - int show_path_in_browser = global_settings.show_path_in_browser; bool changed = false; - - const char* title = NULL;/* Must clear the title as the list is reused */ - int icon = NOICON; - #ifdef HAVE_TAGCACHE bool id3db = *tc.dirfilter == SHOW_ID3DB; -#else - const bool id3db = false; -#endif - -#ifdef HAVE_TAGCACHE /* Checks for changes */ if (id3db) { if (tc.currtable != lasttable || @@ -396,7 +385,9 @@ static int update_dir(void) /* if selected item is undefined */ if (tc.selected_item == -1) { +#ifdef HAVE_TAGCACHE if (!id3db) +#endif /* use lastfile to determine the selected item */ tc.selected_item = tree_get_file_position(lastfile); @@ -407,22 +398,31 @@ static int update_dir(void) } if (changed) { - if( !id3db && tc.dirfull ) + if( +#ifdef HAVE_TAGCACHE + !id3db && +#endif + tc.dirfull ) { splash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL)); } } - gui_synclist_init(list, &tree_get_filename, &tc, false, 1, NULL); + gui_synclist_init(&tree_lists, &tree_get_filename, &tc, false, 1, NULL); #ifdef HAVE_TAGCACHE if (id3db) { - if (show_path_in_browser == SHOW_PATH_FULL - || show_path_in_browser == SHOW_PATH_CURRENT) + if (global_settings.show_path_in_browser == SHOW_PATH_FULL + || global_settings.show_path_in_browser == SHOW_PATH_CURRENT) + { + gui_synclist_set_title(&tree_lists, tagtree_get_title(&tc), + filetype_get_icon(ATTR_DIRECTORY)); + } + else { - title = tagtree_get_title(&tc); - icon = filetype_get_icon(ATTR_DIRECTORY); + /* Must clear the title as the list is reused */ + gui_synclist_set_title(&tree_lists, NULL, NOICON); } } else @@ -430,52 +430,49 @@ static int update_dir(void) { if (tc.browse && tc.browse->title) { - title = tc.browse->title; - icon = tc.browse->icon; + int icon = tc.browse->icon; if (icon == NOICON) icon = filetype_get_icon(ATTR_DIRECTORY); + gui_synclist_set_title(&tree_lists, tc.browse->title, icon); } - else + else if (global_settings.show_path_in_browser == SHOW_PATH_FULL) { - if (show_path_in_browser == SHOW_PATH_FULL) + gui_synclist_set_title(&tree_lists, tc.currdir, + filetype_get_icon(ATTR_DIRECTORY)); + } + else if (global_settings.show_path_in_browser == SHOW_PATH_CURRENT) + { + char *title = strrchr(tc.currdir, '/') + 1; + if (*title == '\0') { - title = tc.currdir; - icon = filetype_get_icon(ATTR_DIRECTORY); + /* Display "Files" for the root dir */ + gui_synclist_set_title(&tree_lists, str(LANG_DIR_BROWSER), + filetype_get_icon(ATTR_DIRECTORY)); } - else if (show_path_in_browser == SHOW_PATH_CURRENT) - { - title = strrchr(tc.currdir, '/'); - if (title != NULL) - { - title++; /* step past the separator */ - if (*title == '\0') - { - /* Display "Files" for the root dir */ - title = str(LANG_DIR_BROWSER); - } - icon = filetype_get_icon(ATTR_DIRECTORY); - } - } + else + gui_synclist_set_title(&tree_lists, title, + filetype_get_icon(ATTR_DIRECTORY)); + } + else + { + /* Must clear the title as the list is reused */ + gui_synclist_set_title(&tree_lists, NULL, NOICON); } } - /* set title and icon, if nothing is set, clear the title - * with NULL and icon as NOICON as the list is reused */ - gui_synclist_set_title(list, title, icon); - - gui_synclist_set_nb_items(list, tc.filesindir); - gui_synclist_set_icon_callback(list, - global_settings.show_icons?tree_get_fileicon:NULL); - gui_synclist_set_voice_callback(list, &tree_voice_cb); + gui_synclist_set_nb_items(&tree_lists, tc.filesindir); + gui_synclist_set_icon_callback(&tree_lists, + global_settings.show_icons?tree_get_fileicon:NULL); + gui_synclist_set_voice_callback(&tree_lists, tree_voice_cb); #ifdef HAVE_LCD_COLOR - gui_synclist_set_color_callback(list, &tree_get_filecolor); + gui_synclist_set_color_callback(&tree_lists, &tree_get_filecolor); #endif if( tc.selected_item >= tc.filesindir) tc.selected_item=tc.filesindir-1; - gui_synclist_select_item(list, tc.selected_item); - gui_synclist_draw(list); - gui_synclist_speak_item(list); + gui_synclist_select_item(&tree_lists, tc.selected_item); + gui_synclist_draw(&tree_lists); + gui_synclist_speak_item(&tree_lists); return tc.filesindir; } @@ -486,13 +483,13 @@ void resume_directory(const char *dir) int ret; #ifdef HAVE_TAGCACHE bool id3db = *tc.dirfilter == SHOW_ID3DB; -#else - const bool id3db = false; #endif /* make sure the dirfilter is sane. The only time it should be possible * thats its not is when resume playlist is called from a plugin */ +#ifdef HAVE_TAGCACHE if (!id3db) +#endif *tc.dirfilter = global_settings.dirfilter; ret = ft_load(&tc, dir); *tc.dirfilter = dirfilter; @@ -560,9 +557,10 @@ void set_dirfilter(int l_dirfilter) *tc.dirfilter = l_dirfilter; } -/* Selects a path + file and update tree context properly */ -static void set_current_file_ex(const char *path, const char *filename) +/* Selects a file and update tree context properly */ +void set_current_file(const char *path) { + const char *name; int i; #ifdef HAVE_TAGCACHE @@ -572,27 +570,21 @@ static void set_current_file_ex(const char *path, const char *filename) return; #endif - if (!filename) /* path and filename supplied combined */ + /* separate directory from filename */ + /* gets the directory's name and put it into tc.currdir */ + name = strrchr(path+1,'/'); + if (name) { - /* separate directory from filename */ - /* gets the directory's name and put it into tc.currdir */ - filename = strrchr(path+1,'/'); - if (filename) - { - strmemccpy(tc.currdir, path, filename - path + 1); - filename++; - } - else - { - strcpy(tc.currdir, "/"); - filename = path+1; - } + strmemccpy(tc.currdir, path, name - path + 1); + name++; } - else /* path and filename came in separate */ + else { - strmemccpy(tc.currdir, path, MAX_PATH); + strcpy(tc.currdir, "/"); + name = path+1; } - strmemccpy(lastfile, filename, MAX_PATH); + + strmemccpy(lastfile, name, MAX_PATH); /* If we changed dir we must recalculate the dirlevel @@ -625,12 +617,6 @@ static void set_current_file_ex(const char *path, const char *filename) } } -/* Selects a file and update tree context properly */ -void set_current_file(const char *path) -{ - set_current_file_ex(path, NULL); -} - /* main loop, handles key events */ static int dirbrowse(void) @@ -995,6 +981,7 @@ static int backup_count = -1; int rockbox_browse(struct browse_context *browse) { tc.is_browsing = (browse != NULL); + static char current[MAX_PATH]; int ret_val = 0; int dirfilter = browse->dirfilter; @@ -1034,7 +1021,9 @@ int rockbox_browse(struct browse_context *browse) if (browse->selected) { - set_current_file_ex(browse->root, browse->selected); + snprintf(current, sizeof(current), "%s/%s", + browse->root, browse->selected); + set_current_file(current); /* set_current_file changes dirlevel, change it back */ tc.dirlevel = 0; } @@ -1047,7 +1036,8 @@ int rockbox_browse(struct browse_context *browse) if (dirfilter != SHOW_ID3DB && (browse->flags & BROWSE_DIRFILTER) == 0) tc.dirfilter = &global_settings.dirfilter; tc.browse = browse; - set_current_file(browse->root); + strmemccpy(current, browse->root, MAX_PATH); + set_current_file(current); if (browse->flags&BROWSE_RUNFILE) ret_val = ft_enter(&tc); else -- cgit v1.2.3