Commit 0b139d49 authored by Antoine Cellerier's avatar Antoine Cellerier

* luaplaylist.c: Look for Lua scripts in the user's CONFIG_DIR"/luaplaylist"...

* luaplaylist.c: Look for Lua scripts in the user's CONFIG_DIR"/luaplaylist" directory too. (+ fix probable compilation errors on WIN32, APPLE and BEOS)
parent 79f9e3f4
...@@ -244,48 +244,23 @@ int E_(Import_LuaPlaylist)( vlc_object_t *p_this ) ...@@ -244,48 +244,23 @@ int E_(Import_LuaPlaylist)( vlc_object_t *p_this )
demux_t *p_demux = (demux_t *)p_this; demux_t *p_demux = (demux_t *)p_this;
lua_State *p_state; lua_State *p_state;
int i_ret = VLC_EGENERIC; int i_ret = VLC_EGENERIC;
char *psz_filename = NULL;
DIR *dir = NULL;
char **ppsz_filelist = NULL; char **ppsz_filelist = NULL;
char **ppsz_fileend = NULL; char **ppsz_fileend = NULL;
char **ppsz_file; char **ppsz_file;
DIR *dir;
char *psz_filename = NULL;
int i_files;
char *psz_dir;
# if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32) char *ppsz_dir_list[] = { NULL, NULL, NULL };
{ char **ppsz_dir;
char *psz_vlcpath = p_intf->p_libvlc_global->psz_vlcpath;
psz_dir = malloc( strlen( psz_vlcpath ) + strlen( "/share/luaplaylist" ) + 1 );
if( !psz_src ) return VLC_ENOMEM;
# if defined( WIN32 )
sprintf( psz_src, "%s/luaplaylist", psz_vlcpath );
# else
sprintf( psz_src, "%s/share/luaplaylist", psz_vlcpath );
# endif
}
# else
{
# ifdef HAVE_SYS_STAT_H
struct stat stat_info;
if( ( utf8_stat( "share/luaplaylist", &stat_info ) == -1 )
|| !S_ISDIR( stat_info.st_mode ) )
{
psz_dir = strdup( DATA_PATH "/luaplaylist" );
}
else
# endif
{
psz_dir = strdup( "share/luaplaylist" );
}
}
# endif
p_demux->p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) ); p_demux->p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) );
if( !p_demux->p_sys ) if( !p_demux->p_sys )
{ {
free( psz_dir );
return VLC_ENOMEM; return VLC_ENOMEM;
} }
p_demux->p_sys->psz_filename = NULL; p_demux->p_sys->psz_filename = NULL;
p_demux->pf_control = Control; p_demux->pf_control = Control;
...@@ -296,7 +271,6 @@ int E_(Import_LuaPlaylist)( vlc_object_t *p_this ) ...@@ -296,7 +271,6 @@ int E_(Import_LuaPlaylist)( vlc_object_t *p_this )
if( !p_state ) if( !p_state )
{ {
msg_Err( p_demux, "Could not create new Lua State" ); msg_Err( p_demux, "Could not create new Lua State" );
free( psz_dir );
free( p_demux->p_sys ); free( p_demux->p_sys );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -315,16 +289,69 @@ int E_(Import_LuaPlaylist)( vlc_object_t *p_this ) ...@@ -315,16 +289,69 @@ int E_(Import_LuaPlaylist)( vlc_object_t *p_this )
lua_pop( p_state, 1 ); lua_pop( p_state, 1 );
dir = utf8_opendir( psz_dir ); ppsz_dir_list[0] = malloc( strlen( p_demux->p_libvlc->psz_homedir )
if( !dir ) goto error; + strlen( "/"CONFIG_DIR"/luaplaylist" ) + 1 );
sprintf( ppsz_dir_list[0], "%s/"CONFIG_DIR"/luaplaylist",
p_demux->p_libvlc->psz_homedir );
# if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32)
{
char *psz_vlcpath = p_demux->p_libvlc_global->psz_vlcpath;
ppsz_dir_list[1] = malloc( strlen( psz_vlcpath ) + strlen( "/share/luaplaylist" ) + 1 );
if( !ppsz_dir_list[1] ) return VLC_ENOMEM;
# if defined( WIN32 )
sprintf( ppsz_dir_list[1], "%s/luaplaylist", psz_vlcpath );
# else
sprintf( ppsz_dir_list[1], "%s/share/luaplaylist", psz_vlcpath );
# endif
}
# else
{
# ifdef HAVE_SYS_STAT_H
struct stat stat_info;
if( ( utf8_stat( "share/luaplaylist", &stat_info ) == -1 )
|| !S_ISDIR( stat_info.st_mode ) )
{
ppsz_dir_list[1] = strdup( DATA_PATH "/luaplaylist" );
}
else
# endif
{
ppsz_dir_list[1] = strdup( "share/luaplaylist" );
}
}
# endif
for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
{
int i_files;
if( ppsz_filelist )
{
for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
ppsz_file++ )
free( *ppsz_file );
free( ppsz_filelist );
ppsz_filelist = NULL;
}
if( dir )
{
closedir( dir );
}
msg_Dbg( p_demux, "Trying Lua scripts in %s", *ppsz_dir );
dir = utf8_opendir( *ppsz_dir );
if( !dir ) continue;
i_files = utf8_loaddir( dir, &ppsz_filelist, file_select, file_compare ); i_files = utf8_loaddir( dir, &ppsz_filelist, file_select, file_compare );
if( i_files < 1 ) goto error; if( i_files < 1 ) continue;
ppsz_fileend = ppsz_filelist + i_files; ppsz_fileend = ppsz_filelist + i_files;
for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend; ppsz_file++ ) for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend; ppsz_file++ )
{ {
free( psz_filename ); psz_filename = NULL; free( psz_filename ); psz_filename = NULL;
asprintf( &psz_filename, "%s/%s", psz_dir, *ppsz_file ); asprintf( &psz_filename, "%s/%s", *ppsz_dir, *ppsz_file );
msg_Dbg( p_demux, "Trying Lua playlist script %s", psz_filename ); msg_Dbg( p_demux, "Trying Lua playlist script %s", psz_filename );
p_demux->p_sys->psz_filename = psz_filename; p_demux->p_sys->psz_filename = psz_filename;
...@@ -376,8 +403,9 @@ int E_(Import_LuaPlaylist)( vlc_object_t *p_this ) ...@@ -376,8 +403,9 @@ int E_(Import_LuaPlaylist)( vlc_object_t *p_this )
if( i_ret == VLC_SUCCESS ) break; if( i_ret == VLC_SUCCESS ) break;
} }
} }
if( i_ret == VLC_SUCCESS ) break;
}
error:
if( ppsz_filelist ) if( ppsz_filelist )
{ {
for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend; for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
...@@ -385,9 +413,10 @@ int E_(Import_LuaPlaylist)( vlc_object_t *p_this ) ...@@ -385,9 +413,10 @@ int E_(Import_LuaPlaylist)( vlc_object_t *p_this )
free( *ppsz_file ); free( *ppsz_file );
free( ppsz_filelist ); free( ppsz_filelist );
} }
for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
free( *ppsz_dir );
if( dir ) closedir( dir ); if( dir ) closedir( dir );
free( psz_dir );
if( i_ret != VLC_SUCCESS ) if( i_ret != VLC_SUCCESS )
E_(Close_LuaPlaylist)( p_this ); E_(Close_LuaPlaylist)( p_this );
return i_ret; return i_ret;
......
...@@ -45,7 +45,9 @@ VLC defines a global vlc object with the following members: ...@@ -45,7 +45,9 @@ VLC defines a global vlc object with the following members:
* vlc.msg_err( <string> ): print an error message. * vlc.msg_err( <string> ): print an error message.
* vlc.msg_info( <string> ): print an info message. * vlc.msg_info( <string> ): print an info message.
Lua scripts are tried in alphabetical order in the luaplaylist/ directory. Lua scripts are tried in alphabetical order in the user's VLC config
director luaplaylist/ subdirectory, then in the global VLC luaplaylist/
directory.
Lua documentation is available on http://www.lua.org . Lua documentation is available on http://www.lua.org .
VLC uses Lua 5.1 VLC uses Lua 5.1
......
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