summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Holmgren <magnushol@gmail.com>2007-11-15 20:22:03 +0000
committerMagnus Holmgren <magnushol@gmail.com>2007-11-15 20:22:03 +0000
commit7aa4ae6e4507bcf8f9956e852940e41422a57a8f (patch)
tree32c1345dd2fd7590d6d1e56f2fa89e1174eb7a78
parentf801714572e4c2c6731682ed450f98242d26a767 (diff)
downloadrockbox-7aa4ae6e4507bcf8f9956e852940e41422a57a8f.tar.gz
rockbox-7aa4ae6e4507bcf8f9956e852940e41422a57a8f.zip
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
-rw-r--r--apps/recorder/albumart.c92
1 files changed, 58 insertions, 34 deletions
diff --git a/apps/recorder/albumart.c b/apps/recorder/albumart.c
index ef89b06002..d99280ce85 100644
--- a/apps/recorder/albumart.c
+++ b/apps/recorder/albumart.c
@@ -109,6 +109,30 @@ static bool file_exists(const char *file)
109 return true; 109 return true;
110} 110}
111 111
112/* Make sure part of path only contain chars valid for a FAT32 long name.
113 * Double quotes are replaced with single quotes, other unsupported chars
114 * are replaced with an underscore.
115 *
116 * path - path to modify.
117 * offset - where in path to start checking.
118 * count - number of chars to check.
119 */
120static void fix_path_part(char* path, int offset, int count)
121{
122 static const char invalid_chars[] = "*/:<>?\\|";
123 int i;
124
125 path += offset;
126
127 for (i = 0; i <= count; i++, path++)
128 {
129 if (*path == '"')
130 *path = '\'';
131 else if (strchr(invalid_chars, *path))
132 *path = '_';
133 }
134}
135
112/* Look for the first matching album art bitmap in the following list: 136/* Look for the first matching album art bitmap in the following list:
113 * ./<trackname><size>.bmp 137 * ./<trackname><size>.bmp
114 * ./<albumname><size>.bmp 138 * ./<albumname><size>.bmp
@@ -127,37 +151,37 @@ static bool search_files(const struct mp3entry *id3, const char *size_string,
127 char dir[MAX_PATH + 1]; 151 char dir[MAX_PATH + 1];
128 bool found = false; 152 bool found = false;
129 const char *trackname; 153 const char *trackname;
154 int dirlen;
155 int albumlen;
130 156
131 if (!id3 || !buf) 157 if (!id3 || !buf)
132 return false; 158 return false;
133 159
134 trackname = id3->path; 160 trackname = id3->path;
135 strip_filename(dir, sizeof(dir), trackname); 161 strip_filename(dir, sizeof(dir), trackname);
162 dirlen = strlen(dir);
163 albumlen = id3->album ? strlen(id3->album) : 0;
136 164
137 /* the first file we look for is one specific to the track playing */ 165 /* the first file we look for is one specific to the track playing */
138 strip_extension(path, sizeof(path) - strlen(size_string) - 4, trackname); 166 strip_extension(path, sizeof(path) - strlen(size_string) - 4, trackname);
139 strcat(path, size_string); 167 strcat(path, size_string);
140 strcat(path, ".bmp"); 168 strcat(path, ".bmp");
141 found = file_exists(path); 169 found = file_exists(path);
142 if (!found && id3->album && strlen(id3->album) > 0) 170 if (!found && albumlen > 0)
143 { 171 {
144 /* if it doesn't exist, 172 /* if it doesn't exist,
145 * we look for a file specific to the track's album name */ 173 * we look for a file specific to the track's album name */
146 snprintf(path, sizeof(path) - 1, 174 snprintf(path, sizeof(path),
147 "%s%s%s.bmp", 175 "%s%s%s.bmp", dir, id3->album, size_string);
148 (strlen(dir) >= 1) ? dir : "", 176 fix_path_part(path, dirlen, albumlen);
149 id3->album, size_string);
150 path[sizeof(path) - 1] = 0;
151 found = file_exists(path); 177 found = file_exists(path);
152 } 178 }
153 179
154 if (!found) 180 if (!found)
155 { 181 {
156 /* if it still doesn't exist, we look for a generic file */ 182 /* if it still doesn't exist, we look for a generic file */
157 snprintf(path, sizeof(path)-1, 183 snprintf(path, sizeof(path),
158 "%scover%s.bmp", 184 "%scover%s.bmp", dir, size_string);
159 (strlen(dir) >= 1) ? dir : "", size_string);
160 path[sizeof(path)-1] = 0;
161 found = file_exists(path); 185 found = file_exists(path);
162 } 186 }
163 187
@@ -165,33 +189,33 @@ static bool search_files(const struct mp3entry *id3, const char *size_string,
165 { 189 {
166 /* if it still doesn't exist, 190 /* if it still doesn't exist,
167 * we continue to search in the parent directory */ 191 * we continue to search in the parent directory */
168 char temp[MAX_PATH + 1]; 192 strcpy(path, dir);
169 strncpy(temp, dir, strlen(dir) - 1); 193 path[dirlen - 1] = 0;
170 temp[strlen(dir) - 1] = 0; 194 strip_filename(dir, sizeof(dir), path);
171 195 dirlen = strlen(dir);
172 strip_filename(dir, sizeof(dir), temp);
173 } 196 }
174 197
175 if (!found && id3->album && strlen(id3->album) > 0) 198 /* only try parent if there is one */
199 if (dirlen > 0)
176 { 200 {
177 /* we look in the parent directory 201 if (!found && albumlen > 0)
178 * for a file specific to the track's album name */ 202 {
179 snprintf(path, sizeof(path)-1, 203 /* we look in the parent directory
180 "%s%s%s.bmp", 204 * for a file specific to the track's album name */
181 (strlen(dir) >= 1) ? dir : "", 205 snprintf(path, sizeof(path),
182 id3->album, size_string); 206 "%s%s%s.bmp", dir, id3->album, size_string);
183 found = file_exists(path); 207 fix_path_part(path, dirlen, albumlen);
184 } 208 found = file_exists(path);
185 209 }
186 if (!found) 210
187 { 211 if (!found)
188 /* if it still doesn't exist, we look in the parent directory 212 {
189 * for a generic file */ 213 /* if it still doesn't exist, we look in the parent directory
190 snprintf(path, sizeof(path)-1, 214 * for a generic file */
191 "%scover%s.bmp", 215 snprintf(path, sizeof(path),
192 (strlen(dir) >= 1) ? dir : "", size_string); 216 "%scover%s.bmp", dir, size_string);
193 path[sizeof(path)-1] = 0; 217 found = file_exists(path);
194 found = file_exists(path); 218 }
195 } 219 }
196 220
197 if (!found) 221 if (!found)