]> git.sesse.net Git - vlc/commitdiff
Use config_GetUserDataDir() internally
authorRémi Denis-Courmont <rem@videolan.org>
Tue, 6 May 2008 20:07:59 +0000 (23:07 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Tue, 6 May 2008 20:15:51 +0000 (23:15 +0300)
src/control/media_library.c
src/libvlc-common.c
src/libvlc.h
src/playlist/loadsave.c
src/video_output/vout_intf.c

index 518ae6d5ad49d6e443a55a8b19667b614fc784df..a85c1b92e333063f1c5d48f61124cb75732b8249 100644 (file)
@@ -89,8 +89,7 @@ void
 libvlc_media_library_load( libvlc_media_library_t * p_mlib,
                            libvlc_exception_t * p_e )
 {
-    const char *psz_datadir =
-        libvlc_priv (p_mlib->p_libvlc_instance->p_libvlc_int)->psz_datadir;
+    char *psz_datadir = config_GetUserDataDir();
     char * psz_uri;
 
     if( !psz_datadir ) /* XXX: i doubt that this can ever happen */
@@ -102,9 +101,11 @@ libvlc_media_library_load( libvlc_media_library_t * p_mlib,
     if( asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xsp",
                   psz_datadir ) == -1 )
     {
+        free( psz_datadir );
         libvlc_exception_raise( p_e, "Can't get create the path" );
         return;
     }
+    free( psz_datadir );
     if( p_mlib->p_mlist )
         libvlc_media_list_release( p_mlib->p_mlist );
 
index 5f4f25cb44b9c87cb5232c15e1887e5a18073f79..006396da2ee8f227c91b99476b8f08956ea41ee9 100644 (file)
@@ -296,7 +296,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
 
     /* Set the config file stuff */
     p_libvlc->psz_homedir    = config_GetHomeDir();
-    priv->psz_datadir    = config_GetUserDataDir();
     priv->psz_configfile = config_GetCustomConfigFile( p_libvlc );
 
     /* Check for plugins cache options */
@@ -1060,7 +1059,6 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, bool b_release )
     module_EndBank( p_libvlc );
 
     FREENULL( p_libvlc->psz_homedir );
-    free( priv->psz_datadir );
     FREENULL( priv->psz_configfile );
     var_DelCallback( p_libvlc, "key-pressed", vlc_key_to_action,
                      p_libvlc->p_hotkeys );
index e4710ab16368ce279de8552a768b468d8f14fdc6..c6c2917a31fb6497b252b7bdb3e4d52abaf2ef66 100644 (file)
@@ -211,7 +211,6 @@ typedef struct libvlc_priv_t
     /* Configuration */
     vlc_mutex_t        config_lock; ///< config file lock
     char *             psz_configfile;   ///< location of config file
-    char              *psz_datadir;      ///< user data directory
 
     /* There is no real reason to keep a list of items, but not to break
      * everything, let's keep it */
index e685d3b53199ee9c7bf1446157aee25e96bffb18..181717e95fa97394e6a85b8d56be7c6ea380eaa3 100644 (file)
@@ -108,7 +108,7 @@ static void input_item_subitem_added( const vlc_event_t * p_event,
 
 int playlist_MLLoad( playlist_t *p_playlist )
 {
-    const char *psz_datadir = libvlc_priv (p_playlist->p_libvlc)->psz_datadir;
+    char *psz_datadir = config_GetUserDataDir();
     char *psz_uri = NULL;
     input_item_t *p_input;
 
@@ -127,18 +127,18 @@ int playlist_MLLoad( playlist_t *p_playlist )
     struct stat p_stat;
     /* checks if media library file is present */
     if( utf8_stat( psz_uri , &p_stat ) )
-    {
-        free( psz_uri );
-        return VLC_EGENERIC;
-    }
+        goto error;
     free( psz_uri );
 
+    /* FIXME: WTF? stat() should never be used right before open()! */
     if( asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xspf",
                   psz_datadir ) == -1 )
     {
         psz_uri = NULL;
         goto error;
     }
+    free( psz_datadir );
+    psz_datadir = NULL;
 
     const char *const psz_option = "meta-file";
     /* that option has to be cleaned in input_item_subitem_added() */
@@ -183,12 +183,13 @@ int playlist_MLLoad( playlist_t *p_playlist )
 
 error:
     free( psz_uri );
+    free( psz_datadir );
     return VLC_ENOMEM;
 }
 
 int playlist_MLDump( playlist_t *p_playlist )
 {
-    char *psz_datadir = libvlc_priv (p_playlist->p_libvlc)->psz_datadir;
+    char *psz_datadir = config_GetUserDataDir();
     if( !config_GetInt( p_playlist, "media-library") ) return VLC_SUCCESS;
     if( !psz_datadir ) /* XXX: This should never happen */
     {
@@ -198,6 +199,7 @@ int playlist_MLDump( playlist_t *p_playlist )
 
     char psz_dirname[ strlen( psz_datadir ) + sizeof( DIR_SEP "ml.xspf")];
     strcpy( psz_dirname, psz_datadir );
+    free( psz_datadir );
     if( config_CreateDir( (vlc_object_t *)p_playlist, psz_dirname ) )
     {
         return VLC_EGENERIC;
index f5211331aceade75dd10f7b27060d9c7a9ef7385..6218844119e4da1620e7b8167e4fc54adf861812 100644 (file)
@@ -637,12 +637,13 @@ int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
 #else
     /* XXX: This saves in the data directory. Shouldn't we try saving
      *      to psz_homedir/Desktop or something nicer ? */
-    if( !val.psz_string && libvlc_priv (p_vout->p_libvlc)->psz_datadir )
+    char *psz_datadir = config_GetUserDataDir();
+    if( !val.psz_string && psz_datadir )
     {
-        if( asprintf( &val.psz_string, "%s",
-                      libvlc_priv (p_vout->p_libvlc)->psz_datadir ) == -1 )
+        if( asprintf( &val.psz_string, "%s", psz_datadir ) == -1 )
             val.psz_string = NULL;
     }
+    free( psz_datadir );
 #endif
 
     if( !val.psz_string )