mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
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
This commit is contained in:
parent
f7ba156b27
commit
35fa12d85f
1 changed files with 23 additions and 25 deletions
|
@ -124,20 +124,20 @@ static int create_playlist_list(char** playlists, int num_items,
|
||||||
|
|
||||||
/* use the tree browser dircache to load only playlists */
|
/* use the tree browser dircache to load only playlists */
|
||||||
*(tc->dirfilter) = SHOW_PLAYLIST;
|
*(tc->dirfilter) = SHOW_PLAYLIST;
|
||||||
|
|
||||||
if (ft_load(tc, playlist_dir) < 0)
|
if (ft_load(tc, playlist_dir) < 0)
|
||||||
{
|
{
|
||||||
splashf(HZ*2, ID2P(LANG_CATALOG_NO_DIRECTORY), playlist_dir);
|
splashf(HZ*2, ID2P(LANG_CATALOG_NO_DIRECTORY), playlist_dir);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
files = (struct entry*) tc->dircache;
|
files = (struct entry*) tc->dircache;
|
||||||
num_files = tc->filesindir;
|
num_files = tc->filesindir;
|
||||||
|
|
||||||
/* we've overwritten the dircache so tree browser will need to be
|
/* we've overwritten the dircache so tree browser will need to be
|
||||||
reloaded */
|
reloaded */
|
||||||
reload_directory();
|
reload_directory();
|
||||||
|
|
||||||
/* if it exists, most recent playlist will always be index 0 */
|
/* if it exists, most recent playlist will always be index 0 */
|
||||||
if (most_recent_playlist[0] != '\0')
|
if (most_recent_playlist[0] != '\0')
|
||||||
{
|
{
|
||||||
|
@ -224,7 +224,7 @@ static int display_playlists(char* playlist, bool view)
|
||||||
char* playlists[MAX_PLAYLISTS];
|
char* playlists[MAX_PLAYLISTS];
|
||||||
struct gui_synclist playlist_lists;
|
struct gui_synclist playlist_lists;
|
||||||
|
|
||||||
if (create_playlist_list(playlists, sizeof(playlists),
|
if (create_playlist_list(playlists, MAX_PLAYLISTS,
|
||||||
&num_playlists) != 0)
|
&num_playlists) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -345,14 +345,12 @@ static int add_to_playlist(const char* playlist, bool new_playlist,
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
int flags = O_CREAT|O_WRONLY;
|
|
||||||
|
|
||||||
if (new_playlist)
|
if (new_playlist)
|
||||||
flags |= O_TRUNC;
|
fd = open_utf8(playlist, O_CREAT|O_WRONLY|O_TRUNC);
|
||||||
else
|
else
|
||||||
flags |= O_APPEND;
|
fd = open(playlist, O_CREAT|O_WRONLY|O_APPEND);
|
||||||
|
|
||||||
fd = open(playlist, flags);
|
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
@ -370,33 +368,33 @@ static int add_to_playlist(const char* playlist, bool new_playlist,
|
||||||
/* append playlist */
|
/* append playlist */
|
||||||
int f, fs, i;
|
int f, fs, i;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
if(strcasecmp(playlist, sel) == 0)
|
if(strcasecmp(playlist, sel) == 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
f = open(sel, O_RDONLY);
|
f = open_utf8(sel, O_RDONLY);
|
||||||
if (f < 0)
|
if (f < 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
fs = filesize(f);
|
fs = filesize(f);
|
||||||
|
|
||||||
for (i=0; i<fs;)
|
for (i=0; i<fs;)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
n = read(f, buf, sizeof(buf));
|
n = read(f, buf, sizeof(buf));
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (write(fd, buf, n) < 0)
|
if (write(fd, buf, n) < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
i += n;
|
i += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= fs)
|
if (i >= fs)
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
close(f);
|
close(f);
|
||||||
}
|
}
|
||||||
else if (sel_attr & ATTR_DIRECTORY)
|
else if (sel_attr & ATTR_DIRECTORY)
|
||||||
|
@ -415,7 +413,7 @@ static int add_to_playlist(const char* playlist, bool new_playlist,
|
||||||
/* Ask if user wants to recurse directory */
|
/* Ask if user wants to recurse directory */
|
||||||
recurse = (gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES);
|
recurse = (gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.fd = fd;
|
context.fd = fd;
|
||||||
context.count = 0;
|
context.count = 0;
|
||||||
|
|
||||||
|
@ -437,7 +435,7 @@ bool catalog_view_playlists(void)
|
||||||
bool retval = true;
|
bool retval = true;
|
||||||
if (in_cat_viewer)
|
if (in_cat_viewer)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (initialize_catalog() == -1)
|
if (initialize_catalog() == -1)
|
||||||
return false;
|
return false;
|
||||||
in_cat_viewer = true;
|
in_cat_viewer = true;
|
||||||
|
@ -450,7 +448,7 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
|
||||||
bool new_playlist, char *m3u8name)
|
bool new_playlist, char *m3u8name)
|
||||||
{
|
{
|
||||||
char playlist[MAX_PATH];
|
char playlist[MAX_PATH];
|
||||||
|
|
||||||
if (initialize_catalog() == -1)
|
if (initialize_catalog() == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -465,7 +463,7 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strcpy(playlist, m3u8name);
|
strcpy(playlist, m3u8name);
|
||||||
|
|
||||||
len = strlen(playlist);
|
len = strlen(playlist);
|
||||||
|
|
||||||
if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u"))
|
if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue