1
0
Fork 0
forked from len0rd/rockbox

Improved use of album name when locating the album art file: replace chars that are invalid in file names; double quotes to single quotes, other invalid chars to underscore (now only very long album names could cause a problem). Also removed some unecessary code and reduced stack usage a bit.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15630 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Magnus Holmgren 2007-11-15 20:22:03 +00:00
parent f801714572
commit 7aa4ae6e45

View file

@ -109,6 +109,30 @@ static bool file_exists(const char *file)
return true; return true;
} }
/* Make sure part of path only contain chars valid for a FAT32 long name.
* Double quotes are replaced with single quotes, other unsupported chars
* are replaced with an underscore.
*
* path - path to modify.
* offset - where in path to start checking.
* count - number of chars to check.
*/
static void fix_path_part(char* path, int offset, int count)
{
static const char invalid_chars[] = "*/:<>?\\|";
int i;
path += offset;
for (i = 0; i <= count; i++, path++)
{
if (*path == '"')
*path = '\'';
else if (strchr(invalid_chars, *path))
*path = '_';
}
}
/* Look for the first matching album art bitmap in the following list: /* Look for the first matching album art bitmap in the following list:
* ./<trackname><size>.bmp * ./<trackname><size>.bmp
* ./<albumname><size>.bmp * ./<albumname><size>.bmp
@ -127,37 +151,37 @@ static bool search_files(const struct mp3entry *id3, const char *size_string,
char dir[MAX_PATH + 1]; char dir[MAX_PATH + 1];
bool found = false; bool found = false;
const char *trackname; const char *trackname;
int dirlen;
int albumlen;
if (!id3 || !buf) if (!id3 || !buf)
return false; return false;
trackname = id3->path; trackname = id3->path;
strip_filename(dir, sizeof(dir), trackname); strip_filename(dir, sizeof(dir), trackname);
dirlen = strlen(dir);
albumlen = id3->album ? strlen(id3->album) : 0;
/* the first file we look for is one specific to the track playing */ /* the first file we look for is one specific to the track playing */
strip_extension(path, sizeof(path) - strlen(size_string) - 4, trackname); strip_extension(path, sizeof(path) - strlen(size_string) - 4, trackname);
strcat(path, size_string); strcat(path, size_string);
strcat(path, ".bmp"); strcat(path, ".bmp");
found = file_exists(path); found = file_exists(path);
if (!found && id3->album && strlen(id3->album) > 0) if (!found && albumlen > 0)
{ {
/* if it doesn't exist, /* if it doesn't exist,
* we look for a file specific to the track's album name */ * we look for a file specific to the track's album name */
snprintf(path, sizeof(path) - 1, snprintf(path, sizeof(path),
"%s%s%s.bmp", "%s%s%s.bmp", dir, id3->album, size_string);
(strlen(dir) >= 1) ? dir : "", fix_path_part(path, dirlen, albumlen);
id3->album, size_string);
path[sizeof(path) - 1] = 0;
found = file_exists(path); found = file_exists(path);
} }
if (!found) if (!found)
{ {
/* if it still doesn't exist, we look for a generic file */ /* if it still doesn't exist, we look for a generic file */
snprintf(path, sizeof(path)-1, snprintf(path, sizeof(path),
"%scover%s.bmp", "%scover%s.bmp", dir, size_string);
(strlen(dir) >= 1) ? dir : "", size_string);
path[sizeof(path)-1] = 0;
found = file_exists(path); found = file_exists(path);
} }
@ -165,33 +189,33 @@ static bool search_files(const struct mp3entry *id3, const char *size_string,
{ {
/* if it still doesn't exist, /* if it still doesn't exist,
* we continue to search in the parent directory */ * we continue to search in the parent directory */
char temp[MAX_PATH + 1]; strcpy(path, dir);
strncpy(temp, dir, strlen(dir) - 1); path[dirlen - 1] = 0;
temp[strlen(dir) - 1] = 0; strip_filename(dir, sizeof(dir), path);
dirlen = strlen(dir);
strip_filename(dir, sizeof(dir), temp);
} }
if (!found && id3->album && strlen(id3->album) > 0) /* only try parent if there is one */
if (dirlen > 0)
{ {
/* we look in the parent directory if (!found && albumlen > 0)
* for a file specific to the track's album name */ {
snprintf(path, sizeof(path)-1, /* we look in the parent directory
"%s%s%s.bmp", * for a file specific to the track's album name */
(strlen(dir) >= 1) ? dir : "", snprintf(path, sizeof(path),
id3->album, size_string); "%s%s%s.bmp", dir, id3->album, size_string);
found = file_exists(path); fix_path_part(path, dirlen, albumlen);
} found = file_exists(path);
}
if (!found) if (!found)
{ {
/* if it still doesn't exist, we look in the parent directory /* if it still doesn't exist, we look in the parent directory
* for a generic file */ * for a generic file */
snprintf(path, sizeof(path)-1, snprintf(path, sizeof(path),
"%scover%s.bmp", "%scover%s.bmp", dir, size_string);
(strlen(dir) >= 1) ? dir : "", size_string); found = file_exists(path);
path[sizeof(path)-1] = 0; }
found = file_exists(path);
} }
if (!found) if (!found)