Read .m3u playlist files using the default code page (unless they start with a BOM) rather than UTF-8. Change default playlist suffix to .m3u8 (playlists are always saved using UTF-8).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11626 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Magnus Holmgren 2006-11-29 19:22:44 +00:00
parent 6ae46065b4
commit a515b10d47
3 changed files with 45 additions and 4 deletions

View File

@ -68,6 +68,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "playlist.h"
#include "file.h"
#include "action.h"
@ -97,6 +98,7 @@
#include "lang.h"
#include "talk.h"
#include "splash.h"
#include "rbunicode.h"
#define PLAYLIST_CONTROL_FILE ROCKBOX_DIR "/.playlist_control"
#define PLAYLIST_CONTROL_FILE_VERSION 2
@ -202,6 +204,7 @@ static const char playlist_thread_name[] = "playlist cachectrl";
static void empty_playlist(struct playlist_info* playlist, bool resume)
{
playlist->filename[0] = '\0';
playlist->utf8 = true;
if(playlist->fd >= 0)
/* If there is an already open playlist, close it. */
@ -437,6 +440,10 @@ static void update_playlist_filename(struct playlist_info* playlist,
{
char *sep="";
int dirlen = strlen(dir);
int filelen = strlen(file);
/* Default to utf8 unless explicitly told otherwise. */
playlist->utf8 = !(filelen > 4 && strcasecmp(&file[filelen - 4], ".m3u") == 0);
/* If the dir does not end in trailing slash, we use a separator.
Otherwise we don't. */
@ -509,6 +516,7 @@ static int add_indices_to_playlist(struct playlist_info* playlist,
nread -= 3;
p += 3;
i += 3;
playlist->utf8 = true; /* Override any earlier indication. */
}
for(count=0; count < nread; count++,p++) {
@ -1267,7 +1275,38 @@ static int get_filename(struct playlist_info* playlist, int index, int seek,
if (lseek(fd, seek, SEEK_SET) != seek)
max = -1;
else
max = read(fd, tmp_buf, buf_length);
{
max = read(fd, tmp_buf, MIN((size_t) buf_length, sizeof(tmp_buf)));
if ((max > 0) && !playlist->utf8)
{
char* end;
int i = 0;
/* Locate EOL. */
while ((tmp_buf[i] != '\n') && (tmp_buf[i] != '\r')
&& (i < max))
{
i++;
}
/* Now work back killing white space. */
while ((i > 0) && isspace(tmp_buf[i - 1]))
{
i--;
}
/* Borrow dir_buf a little... */
/* TODO: iso_decode can overflow dir_buf; it really
* should take a dest size argument.
*/
end = iso_decode(tmp_buf, dir_buf, -1, i);
*end = 0;
strncpy(tmp_buf, dir_buf, sizeof(tmp_buf));
tmp_buf[sizeof(tmp_buf) - 1] = 0;
max = strlen(tmp_buf);
}
}
}
mutex_unlock(&playlist->control_mutex);
@ -2697,6 +2736,7 @@ int playlist_set_current(struct playlist_info* playlist)
strncpy(current_playlist.filename, playlist->filename,
sizeof(current_playlist.filename));
current_playlist.utf8 = playlist->utf8;
current_playlist.fd = playlist->fd;
close(playlist->control_fd);

View File

@ -30,7 +30,7 @@
#define PLAYLIST_ATTR_SKIPPED 0x04
#define PLAYLIST_MAX_CACHE 16
#define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u"
#define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u8"
enum playlist_command {
PLAYLIST_COMMAND_PLAYLIST,
@ -69,6 +69,7 @@ struct playlist_info
bool current; /* current playing playlist */
char filename[MAX_PATH]; /* path name of m3u playlist on disk */
char control_filename[MAX_PATH]; /* full path of control file */
bool utf8; /* playlist is in .m3u8 format */
int fd; /* descriptor of the open playlist file */
int control_fd; /* descriptor of the open control file */
bool control_created; /* has control file been created? */

View File

@ -85,8 +85,8 @@ int save_playlist_screen(struct playlist_info* playlist)
filename = playlist_get_name(playlist, temp, sizeof(temp));
if (!filename || (len=strlen(filename)) <= 4 ||
strcasecmp(&filename[len-4], ".m3u"))
if (!filename || (len=strlen(filename)) <= 5 ||
strcasecmp(&filename[len-5], ".m3u8"))
strcpy(filename, DEFAULT_DYNAMIC_PLAYLIST_NAME);
if (!kbd_input(filename, sizeof(temp)))