summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2010-02-17 14:14:24 +0000
committerTeruaki Kawashima <teru@rockbox.org>2010-02-17 14:14:24 +0000
commit35fa12d85f8552336c76c9ce39afa22b057c4ca5 (patch)
tree3979cbc1c190a65f6a6b0bbb162cf67c0dd1b46e
parentf7ba156b27e661bf4f6cdba9d961640e6a3e5c1d (diff)
downloadrockbox-35fa12d85f8552336c76c9ce39afa22b057c4ca5.tar.gz
rockbox-35fa12d85f8552336c76c9ce39afa22b057c4ca5.zip
playlist catalog: improve UTF-8 BOM handling. correct length of array passed to create_playlist_list.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24718 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/playlist_catalog.c48
1 files changed, 23 insertions, 25 deletions
diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c
index 01899f737f..c5d4df0684 100644
--- a/apps/playlist_catalog.c
+++ b/apps/playlist_catalog.c
@@ -124,20 +124,20 @@ static int create_playlist_list(char** playlists, int num_items,
124 124
125 /* use the tree browser dircache to load only playlists */ 125 /* use the tree browser dircache to load only playlists */
126 *(tc->dirfilter) = SHOW_PLAYLIST; 126 *(tc->dirfilter) = SHOW_PLAYLIST;
127 127
128 if (ft_load(tc, playlist_dir) < 0) 128 if (ft_load(tc, playlist_dir) < 0)
129 { 129 {
130 splashf(HZ*2, ID2P(LANG_CATALOG_NO_DIRECTORY), playlist_dir); 130 splashf(HZ*2, ID2P(LANG_CATALOG_NO_DIRECTORY), playlist_dir);
131 goto exit; 131 goto exit;
132 } 132 }
133 133
134 files = (struct entry*) tc->dircache; 134 files = (struct entry*) tc->dircache;
135 num_files = tc->filesindir; 135 num_files = tc->filesindir;
136 136
137 /* we've overwritten the dircache so tree browser will need to be 137 /* we've overwritten the dircache so tree browser will need to be
138 reloaded */ 138 reloaded */
139 reload_directory(); 139 reload_directory();
140 140
141 /* if it exists, most recent playlist will always be index 0 */ 141 /* if it exists, most recent playlist will always be index 0 */
142 if (most_recent_playlist[0] != '\0') 142 if (most_recent_playlist[0] != '\0')
143 { 143 {
@@ -224,7 +224,7 @@ static int display_playlists(char* playlist, bool view)
224 char* playlists[MAX_PLAYLISTS]; 224 char* playlists[MAX_PLAYLISTS];
225 struct gui_synclist playlist_lists; 225 struct gui_synclist playlist_lists;
226 226
227 if (create_playlist_list(playlists, sizeof(playlists), 227 if (create_playlist_list(playlists, MAX_PLAYLISTS,
228 &num_playlists) != 0) 228 &num_playlists) != 0)
229 return -1; 229 return -1;
230 230
@@ -345,14 +345,12 @@ static int add_to_playlist(const char* playlist, bool new_playlist,
345{ 345{
346 int fd; 346 int fd;
347 int result = -1; 347 int result = -1;
348 int flags = O_CREAT|O_WRONLY; 348
349
350 if (new_playlist) 349 if (new_playlist)
351 flags |= O_TRUNC; 350 fd = open_utf8(playlist, O_CREAT|O_WRONLY|O_TRUNC);
352 else 351 else
353 flags |= O_APPEND; 352 fd = open(playlist, O_CREAT|O_WRONLY|O_APPEND);
354 353
355 fd = open(playlist, flags);
356 if(fd < 0) 354 if(fd < 0)
357 return result; 355 return result;
358 356
@@ -370,33 +368,33 @@ static int add_to_playlist(const char* playlist, bool new_playlist,
370 /* append playlist */ 368 /* append playlist */
371 int f, fs, i; 369 int f, fs, i;
372 char buf[1024]; 370 char buf[1024];
373 371
374 if(strcasecmp(playlist, sel) == 0) 372 if(strcasecmp(playlist, sel) == 0)
375 goto exit; 373 goto exit;
376 374
377 f = open(sel, O_RDONLY); 375 f = open_utf8(sel, O_RDONLY);
378 if (f < 0) 376 if (f < 0)
379 goto exit; 377 goto exit;
380 378
381 fs = filesize(f); 379 fs = filesize(f);
382 380
383 for (i=0; i<fs;) 381 for (i=0; i<fs;)
384 { 382 {
385 int n; 383 int n;
386 384
387 n = read(f, buf, sizeof(buf)); 385 n = read(f, buf, sizeof(buf));
388 if (n < 0) 386 if (n < 0)
389 break; 387 break;
390 388
391 if (write(fd, buf, n) < 0) 389 if (write(fd, buf, n) < 0)
392 break; 390 break;
393 391
394 i += n; 392 i += n;
395 } 393 }
396 394
397 if (i >= fs) 395 if (i >= fs)
398 result = 0; 396 result = 0;
399 397
400 close(f); 398 close(f);
401 } 399 }
402 else if (sel_attr & ATTR_DIRECTORY) 400 else if (sel_attr & ATTR_DIRECTORY)
@@ -415,7 +413,7 @@ static int add_to_playlist(const char* playlist, bool new_playlist,
415 /* Ask if user wants to recurse directory */ 413 /* Ask if user wants to recurse directory */
416 recurse = (gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES); 414 recurse = (gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES);
417 } 415 }
418 416
419 context.fd = fd; 417 context.fd = fd;
420 context.count = 0; 418 context.count = 0;
421 419
@@ -437,7 +435,7 @@ bool catalog_view_playlists(void)
437 bool retval = true; 435 bool retval = true;
438 if (in_cat_viewer) 436 if (in_cat_viewer)
439 return false; 437 return false;
440 438
441 if (initialize_catalog() == -1) 439 if (initialize_catalog() == -1)
442 return false; 440 return false;
443 in_cat_viewer = true; 441 in_cat_viewer = true;
@@ -450,7 +448,7 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
450 bool new_playlist, char *m3u8name) 448 bool new_playlist, char *m3u8name)
451{ 449{
452 char playlist[MAX_PATH]; 450 char playlist[MAX_PATH];
453 451
454 if (initialize_catalog() == -1) 452 if (initialize_catalog() == -1)
455 return false; 453 return false;
456 454
@@ -465,7 +463,7 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
465 } 463 }
466 else 464 else
467 strcpy(playlist, m3u8name); 465 strcpy(playlist, m3u8name);
468 466
469 len = strlen(playlist); 467 len = strlen(playlist);
470 468
471 if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u")) 469 if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u"))