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 /apps | |
parent | bdec638b9ba8c6a65f51ca72755b0e5d62edd7f4 (diff) | |
download | rockbox-a5303765eca19e2c0ecfe7281a7e1cfaafc23a13.tar.gz rockbox-a5303765eca19e2c0ecfe7281a7e1cfaafc23a13.zip |
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
Diffstat (limited to 'apps')
-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 363792870d..b3003bf5c2 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c | |||
@@ -403,7 +403,7 @@ static int autoresume_nexttrack_callback(int action, | |||
403 | break; | 403 | break; |
404 | case ACTION_EXIT_MENUITEM: | 404 | case ACTION_EXIT_MENUITEM: |
405 | if (global_settings.autoresume_automatic == AUTORESUME_NEXTTRACK_CUSTOM | 405 | if (global_settings.autoresume_automatic == AUTORESUME_NEXTTRACK_CUSTOM |
406 | && kbd_input ((char*) &global_settings.autoresume_strpat, | 406 | && kbd_input ((char*) &global_settings.autoresume_paths, |
407 | MAX_PATHNAME+1) < 0) | 407 | MAX_PATHNAME+1) < 0) |
408 | { | 408 | { |
409 | global_settings.autoresume_automatic = oldval; | 409 | global_settings.autoresume_automatic = oldval; |
diff --git a/apps/metadata.c b/apps/metadata.c index 9403625eda..12bea286d0 100644 --- a/apps/metadata.c +++ b/apps/metadata.c | |||
@@ -435,39 +435,55 @@ enum { AUTORESUMABLE_UNKNOWN = 0, AUTORESUMABLE_TRUE, AUTORESUMABLE_FALSE }; | |||
435 | 435 | ||
436 | bool autoresumable(struct mp3entry *id3) | 436 | bool autoresumable(struct mp3entry *id3) |
437 | { | 437 | { |
438 | unsigned char search[MAX_PATHNAME+1]; | 438 | char *endp, *path; |
439 | char *saveptr, *substr; | 439 | size_t len; |
440 | bool is_resumable; | 440 | bool is_resumable; |
441 | 441 | ||
442 | if (id3->autoresumable) /* result cached? */ | 442 | if (id3->autoresumable) /* result cached? */ |
443 | return id3->autoresumable == AUTORESUMABLE_TRUE; | 443 | return id3->autoresumable == AUTORESUMABLE_TRUE; |
444 | 444 | ||
445 | is_resumable = true; | 445 | is_resumable = false; |
446 | 446 | ||
447 | strcpy(search, global_settings.autoresume_strpat); | 447 | if (id3->path) |
448 | |||
449 | for (substr = strtok_r(search, ",", &saveptr); | ||
450 | substr; | ||
451 | substr = strtok_r(NULL, ",", &saveptr)) | ||
452 | { | 448 | { |
453 | if (id3->path && strcasestr(id3->path, substr)) | 449 | for (path = global_settings.autoresume_paths; |
454 | goto out; | 450 | *path; /* search terms left? */ |
455 | if (id3->genre_string && strcasestr(id3->genre_string, substr)) | 451 | path++) |
456 | goto out; | 452 | { |
453 | if (*path == ':') /* Skip empty search patterns */ | ||
454 | continue; | ||
455 | |||
456 | /* FIXME: As soon as strcspn or strchrnul are made available in | ||
457 | the core, the following can be made more efficient. */ | ||
458 | endp = strchr(path, ':'); | ||
459 | if (endp) | ||
460 | len = endp - path; | ||
461 | else | ||
462 | len = strlen(path); | ||
463 | |||
464 | /* Note: At this point, len is always > 0 */ | ||
465 | |||
466 | if (strncasecmp(id3->path, path, len) == 0) | ||
467 | { | ||
468 | /* Full directory-name matches only. Trailing '/' in | ||
469 | search path OK. */ | ||
470 | if (id3->path[len] == '/' || id3->path[len - 1] == '/') | ||
471 | { | ||
472 | is_resumable = true; | ||
473 | break; | ||
474 | } | ||
475 | } | ||
476 | path += len - 1; | ||
477 | } | ||
457 | } | 478 | } |
458 | |||
459 | is_resumable = false; | ||
460 | 479 | ||
461 | out: | ||
462 | /* cache result */ | 480 | /* cache result */ |
463 | id3->autoresumable = | 481 | id3->autoresumable = |
464 | is_resumable ? AUTORESUMABLE_TRUE : AUTORESUMABLE_FALSE; | 482 | is_resumable ? AUTORESUMABLE_TRUE : AUTORESUMABLE_FALSE; |
465 | 483 | ||
466 | logf("autoresumable: %s with genre %s is%s resumable", | 484 | logf("autoresumable: %s is%s resumable", |
467 | id3->path, | 485 | id3->path, is_resumable ? "" : " not"); |
468 | id3->genre_string ? id3->genre_string : "(NULL)", | 486 | |
469 | is_resumable ? "" : " not"); | ||
470 | |||
471 | return is_resumable; | 487 | return is_resumable; |
472 | } | 488 | } |
473 | 489 | ||
diff --git a/apps/settings.h b/apps/settings.h index ae32a65bc6..0734cf0668 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -583,7 +583,7 @@ struct user_settings | |||
583 | bool autoresume_enable; /* enable auto-resume feature? */ | 583 | bool autoresume_enable; /* enable auto-resume feature? */ |
584 | int autoresume_automatic; /* resume next track? 0=never, 1=always, | 584 | int autoresume_automatic; /* resume next track? 0=never, 1=always, |
585 | 2=custom */ | 585 | 2=custom */ |
586 | unsigned char autoresume_strpat[MAX_PATHNAME+1]; /* comma-separated list */ | 586 | unsigned char autoresume_paths[MAX_PATHNAME+1]; /* colon-separated list */ |
587 | bool runtimedb; /* runtime database active? */ | 587 | bool runtimedb; /* runtime database active? */ |
588 | #endif /* HAVE_TAGCACHE */ | 588 | #endif /* HAVE_TAGCACHE */ |
589 | 589 | ||
diff --git a/apps/settings_list.c b/apps/settings_list.c index 75e989eb10..69b543c763 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c | |||
@@ -1268,8 +1268,8 @@ const struct settings_list settings[] = { | |||
1268 | ID2P(LANG_SET_BOOL_NO), | 1268 | ID2P(LANG_SET_BOOL_NO), |
1269 | ID2P(LANG_ALWAYS), | 1269 | ID2P(LANG_ALWAYS), |
1270 | ID2P(LANG_AUTORESUME_CUSTOM)), | 1270 | ID2P(LANG_AUTORESUME_CUSTOM)), |
1271 | TEXT_SETTING(0, autoresume_strpat, "autoresume next track patterns", | 1271 | TEXT_SETTING(0, autoresume_paths, "autoresume next track paths", |
1272 | "podcast", NULL, NULL), | 1272 | "/podcast:/podcasts", NULL, NULL), |
1273 | #endif | 1273 | #endif |
1274 | 1274 | ||
1275 | OFFON_SETTING(0, runtimedb, LANG_RUNTIMEDB_ACTIVE, false, | 1275 | OFFON_SETTING(0, runtimedb, LANG_RUNTIMEDB_ACTIVE, false, |