Commit a661eda5 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Fix playlist item insertion when local charset is not UTF-8

parent 26a0d71e
...@@ -136,10 +136,10 @@ static int Open( vlc_object_t *p_this ) ...@@ -136,10 +136,10 @@ static int Open( vlc_object_t *p_this )
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
struct stat stat_info; struct stat stat_info;
char *psz_path = ToLocale( p_access->psz_path );
if( ( stat( p_access->psz_path, &stat_info ) == -1 ) || if( ( stat( psz_path, &stat_info ) == -1 ) ||
!S_ISDIR( stat_info.st_mode ) ) !S_ISDIR( stat_info.st_mode ) )
#elif defined(WIN32) #elif defined(WIN32)
int i_ret; int i_ret;
...@@ -159,9 +159,11 @@ static int Open( vlc_object_t *p_this ) ...@@ -159,9 +159,11 @@ static int Open( vlc_object_t *p_this )
strcmp( p_access->psz_access, "directory") ) strcmp( p_access->psz_access, "directory") )
#endif #endif
{ {
LocaleFree( psz_path );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
LocaleFree( psz_path );
p_access->pf_read = Read; p_access->pf_read = Read;
p_access->pf_block = NULL; p_access->pf_block = NULL;
p_access->pf_seek = NULL; p_access->pf_seek = NULL;
...@@ -211,16 +213,29 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len) ...@@ -211,16 +213,29 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len)
msg_Err( p_access, "can't find playlist" ); msg_Err( p_access, "can't find playlist" );
goto end; goto end;
} }
else
{
char *ptr;
/* Remove the ending '/' char */ psz_name = ToLocale( p_access->psz_path );
psz_name = strdup( p_access->psz_path ); ptr = strdup( psz_name );
if( psz_name == NULL ) LocaleFree( psz_name );
goto end; if( ptr == NULL )
goto end;
if( (psz_name[strlen(psz_name)-1] == '/') || psz_name = ptr;
(psz_name[strlen(psz_name)-1] == '\\') )
{ /* Remove the ending '/' char */
psz_name[strlen(psz_name)-1] = '\0'; ptr += strlen( ptr );
if( ( ptr > psz_name ) )
{
switch( *--ptr )
{
case '/':
case '\\':
*ptr = '\0';
}
}
} }
/* Initialize structure */ /* Initialize structure */
...@@ -243,7 +258,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len) ...@@ -243,7 +258,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len)
/* The playlist position we will use for the add */ /* The playlist position we will use for the add */
i_pos = p_playlist->i_index + 1; i_pos = p_playlist->i_index + 1;
msg_Dbg( p_access, "opening directory `%s'", psz_name ); msg_Dbg( p_access, "opening directory `%s'", p_access->psz_path );
if( &p_playlist->status.p_item->input == if( &p_playlist->status.p_item->input ==
((input_thread_t *)p_access->p_parent)->input.p_item ) ((input_thread_t *)p_access->p_parent)->input.p_item )
...@@ -435,8 +450,9 @@ static int ReadDir( playlist_t *p_playlist, ...@@ -435,8 +450,9 @@ static int ReadDir( playlist_t *p_playlist,
{ {
#if defined( S_ISDIR ) #if defined( S_ISDIR )
struct stat stat_data; struct stat stat_data;
stat( psz_uri, &stat_data );
if( S_ISDIR(stat_data.st_mode) && i_mode != MODE_COLLAPSE ) if( !stat( psz_uri, &stat_data )
&& S_ISDIR(stat_data.st_mode) && i_mode != MODE_COLLAPSE )
#elif defined( DT_DIR ) #elif defined( DT_DIR )
if( ( p_dir_content->d_type & DT_DIR ) && i_mode != MODE_COLLAPSE ) if( ( p_dir_content->d_type & DT_DIR ) && i_mode != MODE_COLLAPSE )
#else #else
...@@ -451,22 +467,14 @@ static int ReadDir( playlist_t *p_playlist, ...@@ -451,22 +467,14 @@ static int ReadDir( playlist_t *p_playlist,
} }
else if( i_mode == MODE_EXPAND ) else if( i_mode == MODE_EXPAND )
{ {
char *psz_newname; char *psz_newname, *psz_tmp;
msg_Dbg(p_playlist, "Reading subdirectory %s", psz_uri ); msg_Dbg(p_playlist, "Reading subdirectory %s", psz_uri );
if( !strncmp( psz_uri, psz_name, strlen( psz_name ) ) ) psz_tmp = FromLocale( p_dir_content->d_name );
{ psz_newname = vlc_fix_readdir_charset(
char *psz_subdir = psz_uri; p_playlist, psz_tmp );
/* Skip the parent path + the separator */ LocaleFree( psz_tmp );
psz_subdir += strlen( psz_name ) + 1;
psz_newname = vlc_fix_readdir_charset(
p_playlist, psz_subdir );
}
else
{
psz_newname = vlc_fix_readdir_charset(
p_playlist, psz_name );
}
p_node = playlist_NodeCreate( p_playlist, p_node = playlist_NodeCreate( p_playlist,
p_parent->pp_parents[0]->i_view, p_parent->pp_parents[0]->i_view,
psz_newname, p_parent ); psz_newname, p_parent );
...@@ -481,13 +489,14 @@ static int ReadDir( playlist_t *p_playlist, ...@@ -481,13 +489,14 @@ static int ReadDir( playlist_t *p_playlist,
return VLC_EGENERIC; return VLC_EGENERIC;
} }
/* an strdup() just because of Mac OS X */
free( psz_newname ); free( psz_newname );
} }
} }
else else
{ {
playlist_item_t *p_item; playlist_item_t *p_item;
char *psz_tmp1, *psz_tmp2; char *psz_tmp1, *psz_tmp2, *psz_loc;
#ifdef HAVE_STRSEP #ifdef HAVE_STRSEP
if( i_extensions > 0 ) if( i_extensions > 0 )
...@@ -511,10 +520,16 @@ static int ReadDir( playlist_t *p_playlist, ...@@ -511,10 +520,16 @@ static int ReadDir( playlist_t *p_playlist,
} }
#endif /* HAVE_STRSEP */ #endif /* HAVE_STRSEP */
psz_loc = FromLocale( psz_uri );
psz_tmp1 = vlc_fix_readdir_charset( VLC_OBJECT(p_playlist), psz_tmp1 = vlc_fix_readdir_charset( VLC_OBJECT(p_playlist),
psz_uri ); psz_loc );
LocaleFree( psz_loc );
psz_loc = FromLocale( p_dir_content->d_name );
psz_tmp2 = vlc_fix_readdir_charset( VLC_OBJECT(p_playlist), psz_tmp2 = vlc_fix_readdir_charset( VLC_OBJECT(p_playlist),
p_dir_content->d_name ); psz_loc );
msg_Err( p_playlist, "adding file %s from %s", psz_loc, p_dir_content->d_name );
LocaleFree( psz_loc );
p_item = playlist_ItemNewWithType( VLC_OBJECT(p_playlist), p_item = playlist_ItemNewWithType( VLC_OBJECT(p_playlist),
psz_tmp1, psz_tmp2, ITEM_TYPE_VFILE ); psz_tmp1, psz_tmp2, ITEM_TYPE_VFILE );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment