diff options
| author | Michael Hohmuth <sideral@rockbox.org> | 2011-02-11 00:20:03 +0000 |
|---|---|---|
| committer | Michael Hohmuth <sideral@rockbox.org> | 2011-02-11 00:20:03 +0000 |
| commit | a5303765eca19e2c0ecfe7281a7e1cfaafc23a13 (patch) | |
| tree | 24eaddd45e98a48e19d36f3fc336d658244b8429 | |
| parent | bdec638b9ba8c6a65f51ca72755b0e5d62edd7f4 (diff) | |
| download | rockbox-a5303765eca19e2c0ecfe7281a7e1cfaafc23a13.zip rockbox-a5303765eca19e2c0ecfe7281a7e1cfaafc23a13.tar.gz rockbox-a5303765eca19e2c0ecfe7281a7e1cfaafc23a13.tar.bz2 rockbox-a5303765eca19e2c0ecfe7281a7e1cfaafc23a13.tar.xz | |
autoresume: Match full directory path names only in autoresumable()
Removed genre-tag matching (considered too fragile for real-world use).
Removed substring matching for file names. To avoid unintended
matches, the search pattern now must match the file's full dir name
(or a parent directory thereof), anchored in the root directory.
Search strings now must be delimited with ":" rather than ",". The
default list of directories is "/podcast:/podcasts" (case-insensitive).
Made implementation somewhat more efficient (don't use strtok -> no
need to copy the string to private storage (stack) before tokenizing
it).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29280 a1c6a512-1295-4272-9138-f99709370657
| -rw-r--r-- | apps/menus/settings_menu.c | 2 | ||||
| -rw-r--r-- | apps/metadata.c | 60 | ||||
| -rw-r--r-- | apps/settings.h | 2 | ||||
| -rw-r--r-- | apps/settings_list.c | 4 |
4 files changed, 42 insertions, 26 deletions
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 3637928..b3003bf 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -403,7 +403,7 @@ static int autoresume_nexttrack_callback(int action, break; case ACTION_EXIT_MENUITEM: if (global_settings.autoresume_automatic == AUTORESUME_NEXTTRACK_CUSTOM - && kbd_input ((char*) &global_settings.autoresume_strpat, + && kbd_input ((char*) &global_settings.autoresume_paths, MAX_PATHNAME+1) < 0) { global_settings.autoresume_automatic = oldval; diff --git a/apps/metadata.c b/apps/metadata.c index 9403625..12bea28 100644 --- a/apps/metadata.c +++ b/apps/metadata.c @@ -435,39 +435,55 @@ enum { AUTORESUMABLE_UNKNOWN = 0, AUTORESUMABLE_TRUE, AUTORESUMABLE_FALSE }; bool autoresumable(struct mp3entry *id3) { - unsigned char search[MAX_PATHNAME+1]; - char *saveptr, *substr; - bool is_resumable; - + char *endp, *path; + size_t len; + bool is_resumable; + if (id3->autoresumable) /* result cached? */ return id3->autoresumable == AUTORESUMABLE_TRUE; - is_resumable = true; + is_resumable = false; - strcpy(search, global_settings.autoresume_strpat); - - for (substr = strtok_r(search, ",", &saveptr); - substr; - substr = strtok_r(NULL, ",", &saveptr)) + if (id3->path) { - if (id3->path && strcasestr(id3->path, substr)) - goto out; - if (id3->genre_string && strcasestr(id3->genre_string, substr)) - goto out; + for (path = global_settings.autoresume_paths; + *path; /* search terms left? */ + path++) + { + if (*path == ':') /* Skip empty search patterns */ + continue; + + /* FIXME: As soon as strcspn or strchrnul are made available in + the core, the following can be made more efficient. */ + endp = strchr(path, ':'); + if (endp) + len = endp - path; + else + len = strlen(path); + + /* Note: At this point, len is always > 0 */ + + if (strncasecmp(id3->path, path, len) == 0) + { + /* Full directory-name matches only. Trailing '/' in + search path OK. */ + if (id3->path[len] == '/' || id3->path[len - 1] == '/') + { + is_resumable = true; + break; + } + } + path += len - 1; + } } - - is_resumable = false; - out: /* cache result */ id3->autoresumable = is_resumable ? AUTORESUMABLE_TRUE : AUTORESUMABLE_FALSE; - logf("autoresumable: %s with genre %s is%s resumable", - id3->path, - id3->genre_string ? id3->genre_string : "(NULL)", - is_resumable ? "" : " not"); - + logf("autoresumable: %s is%s resumable", + id3->path, is_resumable ? "" : " not"); + return is_resumable; } diff --git a/apps/settings.h b/apps/settings.h index ae32a65..0734cf0 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -583,7 +583,7 @@ struct user_settings bool autoresume_enable; /* enable auto-resume feature? */ int autoresume_automatic; /* resume next track? 0=never, 1=always, 2=custom */ - unsigned char autoresume_strpat[MAX_PATHNAME+1]; /* comma-separated list */ + unsigned char autoresume_paths[MAX_PATHNAME+1]; /* colon-separated list */ bool runtimedb; /* runtime database active? */ #endif /* HAVE_TAGCACHE */ diff --git a/apps/settings_list.c b/apps/settings_list.c index 75e989e..69b543c 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -1268,8 +1268,8 @@ const struct settings_list settings[] = { ID2P(LANG_SET_BOOL_NO), ID2P(LANG_ALWAYS), ID2P(LANG_AUTORESUME_CUSTOM)), - TEXT_SETTING(0, autoresume_strpat, "autoresume next track patterns", - "podcast", NULL, NULL), + TEXT_SETTING(0, autoresume_paths, "autoresume next track paths", + "/podcast:/podcasts", NULL, NULL), #endif OFFON_SETTING(0, runtimedb, LANG_RUNTIMEDB_ACTIVE, false, |