diff options
-rw-r--r-- | apps/dbtree.c | 11 | ||||
-rw-r--r-- | apps/dbtree.h | 1 | ||||
-rw-r--r-- | apps/tree.c | 14 |
3 files changed, 23 insertions, 3 deletions
diff --git a/apps/dbtree.c b/apps/dbtree.c index 480564d39f..5b0d325213 100644 --- a/apps/dbtree.c +++ b/apps/dbtree.c @@ -64,14 +64,14 @@ #define ID3DB_VERSION 2 -static int fd; +static int fd = -1; static int songstart, albumstart, artiststart, filestart, songcount, albumcount, artistcount, filecount, songlen, songarraylen, genrelen, filelen, albumlen, albumarraylen, - artistlen, rundbdirty,initialized = 0; + artistlen, rundbdirty, initialized = 0; static int db_play_folder(struct tree_context* c); static int db_search(struct tree_context* c, char* string); @@ -137,6 +137,13 @@ int db_init(void) return 0; } +void db_shutdown(void) +{ + if (fd >= 0) + close(fd); + initialized = 0; +} + int db_load(struct tree_context* c) { int i, offset, rc; diff --git a/apps/dbtree.h b/apps/dbtree.h index 2c51b34a32..94453c59af 100644 --- a/apps/dbtree.h +++ b/apps/dbtree.h @@ -26,6 +26,7 @@ enum table { invalid, root, allsongs, allalbums, allartists, search, searchartists, searchalbums, searchsongs }; int db_init(void); +void db_shutdown(void); int db_enter(struct tree_context* c); void db_exit(struct tree_context* c); int db_load(struct tree_context* c); diff --git a/apps/tree.c b/apps/tree.c index bd4fe37180..bcb96a8995 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -625,6 +625,12 @@ static bool check_changed_id3mode(bool currmode) return currmode; } +static void tree_prepare_usb(void *parameter) +{ + (void) parameter; + db_shutdown(); +} + static bool dirbrowse(void) { int numentries=0; @@ -1121,8 +1127,10 @@ static bool dirbrowse(void) #endif default: - if(default_event_handler(button) == SYS_USB_CONNECTED) + if (default_event_handler_ex(button, tree_prepare_usb, NULL) + == SYS_USB_CONNECTED) { + db_init(); /* re-init database */ if(*tc.dirfilter > NUM_FILTER_MODES) /* leave sub-browsers after usb, doing otherwise might be confusing to the user */ @@ -1160,6 +1168,10 @@ static bool dirbrowse(void) if ( reload_root ) { strcpy(currdir, "/"); tc.dirlevel = 0; + tc.currtable = 0; + tc.currextra = 0; + lasttable = -1; + lastextra = -1; reload_root = false; } if (! reload_dir ) |