From 28e52ddb9b8a1ae76eba086114ecf0bca90383ee Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Sun, 20 Dec 2009 15:05:02 +0100 Subject: [PATCH] Add --data-path option. Access the src share directory now works from build tree. --- bin/vlc.c | 4 +- include/vlc_configuration.h | 3 +- modules/control/http/http.c | 3 +- modules/gui/hildon/maemo.c | 5 ++- modules/gui/skins2/win32/win32_factory.cpp | 14 +++---- modules/gui/skins2/x11/x11_factory.cpp | 4 +- modules/misc/lua/intf.c | 6 +-- modules/misc/lua/libs/misc.c | 7 +++- modules/misc/lua/libs/net.c | 2 +- modules/misc/lua/vlc.c | 13 +++--- modules/misc/lua/vlc.h | 2 +- modules/misc/notify/growl.m | 3 +- modules/misc/notify/notify.c | 4 +- src/Makefile.am | 1 + src/config/configuration.h | 2 + src/config/dirs.c | 46 ++++++++++++++++++++++ src/config/dirs_macos.c | 2 +- src/config/dirs_win.c | 2 +- src/config/dirs_xdg.c | 2 +- src/libvlc-module.c | 7 ++++ src/libvlccore.sym | 2 +- 21 files changed, 99 insertions(+), 35 deletions(-) create mode 100644 src/config/dirs.c diff --git a/bin/vlc.c b/bin/vlc.c index bad420bacc..246ea149d5 100644 --- a/bin/vlc.c +++ b/bin/vlc.c @@ -133,9 +133,7 @@ int main( int i_argc, const char *ppsz_argv[] ) argv[argc++] = FromLocale ("--plugin-path="TOP_BUILDDIR"/modules"); #endif #ifdef TOP_SRCDIR -# ifdef ENABLE_HTTPD - argv[argc++] = FromLocale ("--http-src="TOP_SRCDIR"/share/http"); -# endif + argv[argc++] = FromLocale ("--data-path="TOP_SRCDIR"/share"); #endif int i = 1; diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h index c208509efc..2c7345e963 100644 --- a/include/vlc_configuration.h +++ b/include/vlc_configuration.h @@ -214,7 +214,8 @@ VLC_EXPORT( int, __config_SaveConfigFile, ( vlc_object_t *, const char * ) ); VLC_EXPORT( void, __config_ResetAll, ( vlc_object_t * ) ); VLC_EXPORT( module_config_t *, config_FindConfig,( vlc_object_t *, const char * ) LIBVLC_USED ); -VLC_EXPORT(const char *, config_GetDataDir, ( void ) LIBVLC_USED); +VLC_EXPORT(char *, __config_GetDataDir, ( vlc_object_t * ) LIBVLC_USED); +#define config_GetDataDir(a) __config_GetDataDir(VLC_OBJECT(a)) VLC_EXPORT(const char *, config_GetConfDir, ( void ) LIBVLC_USED); typedef enum vlc_userdir diff --git a/modules/control/http/http.c b/modules/control/http/http.c index fe043e9808..ec762d0bbe 100644 --- a/modules/control/http/http.c +++ b/modules/control/http/http.c @@ -232,9 +232,10 @@ static int Open( vlc_object_t *p_this ) psz_src = config_GetPsz( p_intf, "http-src" ); if( ( psz_src == NULL ) || ( *psz_src == '\0' ) ) { - const char *data_path = config_GetDataDir (); + char *data_path = config_GetDataDir( p_intf ); if( asprintf( &psz_src, "%s" DIR_SEP "http", data_path ) == -1 ) psz_src = NULL; + free( data_path ); } if( !psz_src || *psz_src == '\0' ) diff --git a/modules/gui/hildon/maemo.c b/modules/gui/hildon/maemo.c index 476dacf530..f6d74655ee 100644 --- a/modules/gui/hildon/maemo.c +++ b/modules/gui/hildon/maemo.c @@ -158,12 +158,13 @@ static void Run( intf_thread_t *p_intf ) // A little theming char *psz_rc_file = NULL; - if( asprintf( &psz_rc_file, "%s/maemo/vlc_intf.rc", - config_GetDataDir() ) != -1 ) + char *psz_data = config_GetDataDir( p_intf ); + if( asprintf( &psz_rc_file, "%s/maemo/vlc_intf.rc", psz_data ) != -1 ) { gtk_rc_parse( psz_rc_file ); free( psz_rc_file ); } + free( psz_data ); // We create the main vertical box main_vbox = gtk_vbox_new( FALSE, 0 ); diff --git a/modules/gui/skins2/win32/win32_factory.cpp b/modules/gui/skins2/win32/win32_factory.cpp index 07b6325f48..e7bbf66952 100644 --- a/modules/gui/skins2/win32/win32_factory.cpp +++ b/modules/gui/skins2/win32/win32_factory.cpp @@ -229,14 +229,12 @@ bool Win32Factory::init() char *datadir = config_GetUserDir( VLC_DATA_DIR ); m_resourcePath.push_back( (string)datadir + "\\skins" ); free( datadir ); - m_resourcePath.push_back( (string)config_GetDataDir() + - "\\skins" ); - m_resourcePath.push_back( (string)config_GetDataDir() + - "\\skins2" ); - m_resourcePath.push_back( (string)config_GetDataDir() + - "\\share\\skins" ); - m_resourcePath.push_back( (string)config_GetDataDir() + - "\\share\\skins2" ); + datadir = config_GetDataDir( getIntf() ); + m_resourcePath.push_back( (string)datadir + "\\skins" ); + m_resourcePath.push_back( (string)datadir + "\\skins2" ); + m_resourcePath.push_back( (string)datadir + "\\share\\skins" ); + m_resourcePath.push_back( (string)datadir + "\\share\\skins2" ); + free( datadir ); // All went well return true; diff --git a/modules/gui/skins2/x11/x11_factory.cpp b/modules/gui/skins2/x11/x11_factory.cpp index a6b0df6f4b..f203de836b 100644 --- a/modules/gui/skins2/x11/x11_factory.cpp +++ b/modules/gui/skins2/x11/x11_factory.cpp @@ -80,7 +80,9 @@ bool X11Factory::init() m_resourcePath.push_back( (string)datadir + "/skins2" ); free( datadir ); m_resourcePath.push_back( (string)"share/skins2" ); - m_resourcePath.push_back( (string)config_GetDataDir () + "/skins2" ); + datadir = config_GetDataDir( getIntf() ); + m_resourcePath.push_back( (string)datadir + "/skins2" ); + free( datadir ); return true; } diff --git a/modules/misc/lua/intf.c b/modules/misc/lua/intf.c index d7430bcab9..424a32d7bf 100644 --- a/modules/misc/lua/intf.c +++ b/modules/misc/lua/intf.c @@ -57,11 +57,11 @@ static const char * const ppsz_intf_options[] = { "intf", "config", NULL }; /***************************************************************************** * *****************************************************************************/ -static char *FindFile( const char *psz_name ) +static char *FindFile( vlc_object_t *p_this, const char *psz_name ) { char *ppsz_dir_list[] = { NULL, NULL, NULL, NULL }; char **ppsz_dir; - vlclua_dir_list( "intf", ppsz_dir_list ); + vlclua_dir_list( p_this, "intf", ppsz_dir_list ); for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ ) { char *psz_filename; @@ -162,7 +162,7 @@ int Open_LuaIntf( vlc_object_t *p_this ) return VLC_ENOMEM; } p_sys = p_intf->p_sys; - p_sys->psz_filename = FindFile( psz_name ); + p_sys->psz_filename = FindFile( p_this, psz_name ); if( !p_sys->psz_filename ) { msg_Err( p_intf, "Couldn't find lua interface script \"%s\".", diff --git a/modules/misc/lua/libs/misc.c b/modules/misc/lua/libs/misc.c index 37fdb72c95..e5a1f02aa1 100644 --- a/modules/misc/lua/libs/misc.c +++ b/modules/misc/lua/libs/misc.c @@ -114,7 +114,9 @@ static int vlclua_quit( lua_State *L ) *****************************************************************************/ static int vlclua_datadir( lua_State *L ) { - lua_pushstring( L, config_GetDataDir() ); + char *psz_data = config_GetDataDir( vlclua_get_this( L ) ); + lua_pushstring( L, psz_data ); + free( psz_data ); return 1; } @@ -157,7 +159,8 @@ static int vlclua_datadir_list( lua_State *L ) char **ppsz_dir = ppsz_dir_list; int i = 1; - if( vlclua_dir_list( psz_dirname, ppsz_dir_list ) != VLC_SUCCESS ) + if( vlclua_dir_list( vlclua_get_this( L ), psz_dirname, ppsz_dir_list ) + != VLC_SUCCESS ) return 0; lua_newtable( L ); for( ; *ppsz_dir; ppsz_dir++ ) diff --git a/modules/misc/lua/libs/net.c b/modules/misc/lua/libs/net.c index 4e4b5787dd..6d2c30a16a 100644 --- a/modules/misc/lua/libs/net.c +++ b/modules/misc/lua/libs/net.c @@ -132,7 +132,7 @@ static int vlclua_net_accept( lua_State *L ) int i_fd = -1; unsigned int i_count = 1; - while( pi_fd[0][i_count] != -1 ) + while( pi_fd[i_count] != -1 ) i_count++; struct pollfd ufd[i_count+1]; diff --git a/modules/misc/lua/vlc.c b/modules/misc/lua/vlc.c index 2fa37dc027..f26638eb65 100644 --- a/modules/misc/lua/vlc.c +++ b/modules/misc/lua/vlc.c @@ -105,7 +105,7 @@ static int file_compare( const char **a, const char **b ) return strcmp( *a, *b ); } -int vlclua_dir_list( const char *luadirname, char **ppsz_dir_list ) +int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname, char **ppsz_dir_list ) { int i = 0; char *datadir = config_GetUserDir( VLC_DATA_DIR ); @@ -121,25 +121,26 @@ int vlclua_dir_list( const char *luadirname, char **ppsz_dir_list ) free( datadir ); i++; + char *psz_datapath = config_GetDataDir( p_this ); # if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32) { - const char *psz_vlcpath = config_GetDataDir(); if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s", - psz_vlcpath, luadirname ) < 0 ) + psz_datapath, luadirname ) < 0 ) return VLC_ENOMEM; i++; if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "share" DIR_SEP "lua" DIR_SEP "%s", - psz_vlcpath, luadirname ) < 0 ) + psz_datapath, luadirname ) < 0 ) return VLC_ENOMEM; i++; } # else if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s", - config_GetDataDir (), luadirname ) < 0 ) + psz_datapath, luadirname ) < 0 ) return VLC_ENOMEM; i++; # endif + free( psz_datapath ); return VLC_SUCCESS; } @@ -169,7 +170,7 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this, char *ppsz_dir_list[] = { NULL, NULL, NULL, NULL }; char **ppsz_dir; - i_ret = vlclua_dir_list( luadirname, ppsz_dir_list ); + i_ret = vlclua_dir_list( p_this, luadirname, ppsz_dir_list ); if( i_ret != VLC_SUCCESS ) return i_ret; i_ret = VLC_EGENERIC; diff --git a/modules/misc/lua/vlc.h b/modules/misc/lua/vlc.h index 94d69f6357..f455f4e0dc 100644 --- a/modules/misc/lua/vlc.h +++ b/modules/misc/lua/vlc.h @@ -105,7 +105,7 @@ int vlclua_push_ret( lua_State *, int i_error ); int vlclua_scripts_batch_execute( vlc_object_t *p_this, const char * luadirname, int (*func)(vlc_object_t *, const char *, lua_State *, void *), lua_State * L, void * user_data ); -int vlclua_dir_list( const char *luadirname, char **ppsz_dir_list ); +int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname, char **ppsz_dir_list ); void vlclua_dir_list_free( char **ppsz_dir_list ); /***************************************************************************** diff --git a/modules/misc/notify/growl.m b/modules/misc/notify/growl.m index 68e27541b2..575739f248 100644 --- a/modules/misc/notify/growl.m +++ b/modules/misc/notify/growl.m @@ -115,9 +115,10 @@ static int Open( vlc_object_t *p_this ) p_sys->app_name = CFSTR( "VLC media player" ); p_sys->notification_type = CFSTR( "New input playing" ); - const char *data_path = config_GetDataDir (); + char *data_path = config_GetDataDir ( p_this ); char buf[strlen (data_path) + sizeof ("/vlc48x48.png")]; snprintf (buf, sizeof (buf), "%s/vlc48x48.png", data_path); + free( data_path ); p_sys->default_icon = (CFDataRef) readFile( buf ); playlist_t *p_playlist = pl_Hold( p_intf ); diff --git a/modules/misc/notify/notify.c b/modules/misc/notify/notify.c index 1bbcc2073e..9945386927 100644 --- a/modules/misc/notify/notify.c +++ b/modules/misc/notify/notify.c @@ -224,11 +224,13 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var, { GError *p_error = NULL; char *psz_pixbuf; - if( asprintf( &psz_pixbuf, "%s/vlc48x48.png", config_GetDataDir() ) >= 0 ) + char *psz_data = config_GetDataDir( p_this ); + if( asprintf( &psz_pixbuf, "%s/vlc48x48.png", psz_data ) >= 0 ) { pix = gdk_pixbuf_new_from_file( psz_pixbuf, &p_error ); free( psz_pixbuf ); } + free( psz_data ); } free( psz_arturl ); diff --git a/src/Makefile.am b/src/Makefile.am index 4da4a1068a..2f81f6f9ee 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -428,6 +428,7 @@ SOURCES_libvlc_common = \ config/intf.c \ config/keys.c \ config/cmdline.c \ + config/dirs.c \ misc/events.c \ misc/image.c \ misc/messages.c \ diff --git a/src/config/configuration.h b/src/config/configuration.h index 79e041e047..2e88f9981c 100644 --- a/src/config/configuration.h +++ b/src/config/configuration.h @@ -45,6 +45,8 @@ void config_UnsetCallbacks( module_config_t *, size_t ); int __config_LoadCmdLine ( vlc_object_t *, int *, const char *[], bool ); int __config_LoadConfigFile( vlc_object_t *, const char * ); +const char *config_GetDataDirDefault( void ); + int IsConfigStringType( int type ); int IsConfigIntegerType (int type); static inline int IsConfigFloatType (int type) diff --git a/src/config/dirs.c b/src/config/dirs.c new file mode 100644 index 0000000000..d490975f5a --- /dev/null +++ b/src/config/dirs.c @@ -0,0 +1,46 @@ +/***************************************************************************** + * dirs.c: crossplatform directories configuration + ***************************************************************************** + * Copyright (C) 2009 the VideoLAN team + * + * Authors: Antoine Cellerier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "../libvlc.h" + +#include "configuration.h" + +/** + * Determines the shared data directory + * + * @return a string (always succeeds). Needs to be freed. + */ +char *__config_GetDataDir( vlc_object_t *p_obj ) +{ + char *psz_path = config_GetPsz( p_obj, "data-path" ); + if( psz_path && *psz_path ) + return psz_path; + free( psz_path ); + return strdup( config_GetDataDirDefault() ); +} + diff --git a/src/config/dirs_macos.c b/src/config/dirs_macos.c index a7d5e5ff20..a411fc67de 100644 --- a/src/config/dirs_macos.c +++ b/src/config/dirs_macos.c @@ -49,7 +49,7 @@ const char *config_GetConfDir( void ) return configdir; } -const char *config_GetDataDir (void) +const char *config_GetDataDirDefault (void) { pthread_once(&once, init_dirs); return datadir; diff --git a/src/config/dirs_win.c b/src/config/dirs_win.c index 65d7aefa88..ea7410ebae 100644 --- a/src/config/dirs_win.c +++ b/src/config/dirs_win.c @@ -43,7 +43,7 @@ #include #include -const char *config_GetDataDir( void ) +const char *config_GetDataDirDefault( void ) { static char path[PATH_MAX] = ""; #warning FIXME: thread-safety! diff --git a/src/config/dirs_xdg.c b/src/config/dirs_xdg.c index 6f6c0046bc..7398cf0ddb 100644 --- a/src/config/dirs_xdg.c +++ b/src/config/dirs_xdg.c @@ -40,7 +40,7 @@ * * @return a string (always succeeds). */ -const char *config_GetDataDir( void ) +const char *config_GetDataDirDefault( void ) { return DATA_PATH; } diff --git a/src/libvlc-module.c b/src/libvlc-module.c index a8a83baa73..c8b95f2b45 100644 --- a/src/libvlc-module.c +++ b/src/libvlc-module.c @@ -1120,6 +1120,10 @@ static const char *const ppsz_clock_descriptions[] = "Additional path for VLC to look for its modules. You can add " \ "several paths by concatenating them using \" PATH_SEP \" as separator") +#define DATA_PATH_TEXT N_("Data search path") +#define DATA_PATH_LONGTEXT N_( \ + "Override the default data/share search path.") + #define VLM_CONF_TEXT N_("VLM configuration file") #define VLM_CONF_LONGTEXT N_( \ "Read a VLM configuration file as soon as VLM is started." ) @@ -2033,6 +2037,9 @@ vlc_module_begin () add_directory( "plugin-path", NULL, NULL, PLUGIN_PATH_TEXT, PLUGIN_PATH_LONGTEXT, true ) change_need_restart () + add_directory( "data-path", NULL, NULL, DATA_PATH_TEXT, + DATA_PATH_LONGTEXT, true ) + change_need_restart () set_section( N_("Performance options"), NULL ) add_obsolete_bool( "minimize-threads" ) diff --git a/src/libvlccore.sym b/src/libvlccore.sym index 5b895e41d3..080f31e846 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -52,7 +52,7 @@ __config_ChainParse __config_ExistIntf config_FindConfig config_GetConfDir -config_GetDataDir +__config_GetDataDir __config_GetFloat config_GetUserDir __config_GetInt -- 2.39.2