]> git.sesse.net Git - vlc/commitdiff
XDG Base Directory Specification fix. I wasn't using the XDG_CACHE_HOME variable...
authorAntoine Cellerier <dionoea@videolan.org>
Sun, 9 Sep 2007 17:27:07 +0000 (17:27 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Sun, 9 Sep 2007 17:27:07 +0000 (17:27 +0000)
include/main.h
src/input/meta.c
src/libvlc-common.c
src/modules/configuration.c
src/modules/configuration.h
src/modules/modules.c

index df0d190b5d5c1daf03cf4fbca9b9cffc6cd7e0ea..69e290db184f41933835c5e13a9daebdc65495e4 100644 (file)
@@ -41,7 +41,8 @@ struct libvlc_int_t
 
     char *                 psz_homedir;      ///< user's home directory
     char *                 psz_configdir;    ///< user's configuration directory
-    char *                 psz_datadir;      ///< user's data/cache directory
+    char *                 psz_datadir;      ///< user's data directory
+    char *                 psz_cachedir;     ///< user's cache directory
 
     char *                 psz_configfile;   ///< location of config file
 
index 08f5c5069cd0cd30a99ed49985060da2266b6510..ca318207c565a46c0ed6a6ddc951d0a4155faa33 100644 (file)
@@ -236,10 +236,10 @@ static void ArtCacheCreateDir( const char *psz_dir )
     {
         while( *psz && *psz != DIR_SEP_CHAR) psz++;
         if( !*psz ) break;
-        *psz = 0;        
+        *psz = 0;
         if( !EMPTY_STR( psz_newdir ) ) utf8_mkdir( psz_newdir );
         *psz = DIR_SEP_CHAR;
-        psz++;   
+        psz++;
     }
     utf8_mkdir( psz_dir );
 }
@@ -275,7 +275,7 @@ static void __ArtCacheGetDirPath( vlc_object_t *p_obj,
 
         snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP
                   "art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s",
-                      p_obj->p_libvlc->psz_datadir,
+                      p_obj->p_libvlc->psz_cachedir,
                       psz_artist_sanitized, psz_album_sanitized );
         free( psz_album_sanitized );
         free( psz_artist_sanitized );
@@ -285,7 +285,7 @@ static void __ArtCacheGetDirPath( vlc_object_t *p_obj,
         char * psz_title_sanitized = ArtCacheGetSanitizedFileName( psz_title );
         snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP
                   "art" DIR_SEP "title" DIR_SEP "%s",
-                  p_obj->p_libvlc->psz_datadir,
+                  p_obj->p_libvlc->psz_cachedir,
                   psz_title_sanitized );
         free( psz_title_sanitized );
     }
@@ -417,7 +417,7 @@ int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item )
     }
 
     psz_type = strrchr( psz_arturl, '.' );
-    if( strlen( psz_type ) > 5 ) 
+    if( strlen( psz_type ) > 5 )
         psz_type = NULL; /* remove extension if it's > to 4 characters */
 
     /* Warning: psz_title, psz_artist, psz_album may change in ArtCache*() */
index 01be53e76c84a31185884c86e30e0bdb56c35deb..af6982f5546b178e55a0daf5d16dd1c37ede5ebd 100644 (file)
@@ -328,6 +328,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
     p_libvlc->psz_homedir    = config_GetHomeDir();
     p_libvlc->psz_configdir  = config_GetConfigDir( p_libvlc );
     p_libvlc->psz_datadir    = config_GetUserDataDir( p_libvlc );
+    p_libvlc->psz_cachedir   = config_GetCacheDir( p_libvlc );
     p_libvlc->psz_configfile = config_GetCustomConfigFile( p_libvlc );
 
     /* Check for plugins cache options */
@@ -1054,6 +1055,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
     FREENULL( p_libvlc->psz_homedir );
     FREENULL( p_libvlc->psz_configdir );
     FREENULL( p_libvlc->psz_datadir );
+    FREENULL( p_libvlc->psz_cachedir );
     FREENULL( p_libvlc->psz_configfile );
     FREENULL( p_libvlc->p_hotkeys );
 
index e9f583a7b5015cafbfb4e2c3cf0236682bf633bf..4e74b417eedefe50fd2a1657445e927b84c9e05a 100644 (file)
@@ -1914,8 +1914,8 @@ char *config_GetConfigDir( libvlc_int_t *p_libvlc )
 }
 
 /**
- * Get the user's VLC data and cache directory
- * (used for stuff like the modules cache, the album art cache, ...)
+ * Get the user's VLC data directory
+ * (used for stuff like the skins, custom lua modules, ...)
  */
 char *config_GetUserDataDir( libvlc_int_t *p_libvlc )
 {
@@ -1943,6 +1943,36 @@ char *config_GetUserDataDir( libvlc_int_t *p_libvlc )
 #endif
 }
 
+/**
+ * Get the user's VLC cache directory
+ * (used for stuff like the modules cache, the album art cache, ...)
+ */
+char *config_GetCacheDir( libvlc_int_t *p_libvlc )
+{
+    char *psz_dir;
+#if defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS)
+    char *psz_parent = config_GetUserDir();
+    if( !psz_parent ) psz_parent = p_libvlc->psz_homedir;
+    if( asprintf( &psz_dir, "%s" DIR_SEP CONFIG_DIR, psz_parent ) == -1 )
+        return NULL;
+    return psz_dir;
+#else
+    /* XDG Base Directory Specification - Version 0.6 */
+    char *psz_env = getenv( "XDG_CACHE_HOME" );
+    if( psz_env )
+    {
+        if( asprintf( &psz_dir, "%s/vlc", psz_env ) == -1 )
+            return NULL;
+        return psz_dir;
+    }
+    psz_env = getenv( "HOME" );
+    if( !psz_env ) psz_env = p_libvlc->psz_homedir; /* not part of XDG spec but we want a sensible fallback */
+    if( asprintf( &psz_dir, "%s/.cache/vlc", psz_env ) == -1 )
+        return NULL;
+    return psz_dir;
+#endif
+}
+
 /**
  * Get the user's configuration file
  */
index f7213169be9ec11083e5212bce5a5870baa609be..f9d1fc6a9a9e62483750b4cfe390a2cbc4aa1d7d 100644 (file)
@@ -42,6 +42,7 @@ int __config_LoadCmdLine   ( vlc_object_t *, int *, char *[], vlc_bool_t );
 char *config_GetHomeDir    ( void );
 char *config_GetConfigDir  ( libvlc_int_t * );
 char *config_GetUserDataDir( libvlc_int_t * );
+char *config_GetCacheDir   ( libvlc_int_t * );
 char *config_GetConfigFile ( libvlc_int_t * );
 char *config_GetCustomConfigFile( libvlc_int_t * );
 int __config_LoadConfigFile( vlc_object_t *, const char * );
index 9cd1c654eaa9598e074cd2c94f9192d4d36c1930..217ed1cd57d662b7ce59429ea1eeb59db68159d6 100644 (file)
@@ -1665,7 +1665,7 @@ static char * GetWindowsError( void )
  *****************************************************************************/
 static void CacheLoad( vlc_object_t *p_this )
 {
-    char *psz_filename, *psz_datadir;
+    char *psz_filename, *psz_cachedir;
     FILE *file;
     int i, j, i_size, i_read;
     char p_cachestring[sizeof(PLUGINSCACHE_DIR COPYRIGHT_MESSAGE)];
@@ -1675,15 +1675,15 @@ static void CacheLoad( vlc_object_t *p_this )
     int32_t i_file_size, i_marker;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    psz_datadir = p_this->p_libvlc->psz_datadir;
-    if( !psz_datadir ) /* XXX: this should never happen */
+    psz_cachedir = p_this->p_libvlc->psz_cachedir;
+    if( !psz_cachedir ) /* XXX: this should never happen */
     {
         msg_Err( p_this, "Unable to get cache directory" );
         return;
     }
 
     i_size = asprintf( &psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s",
-            psz_datadir, PLUGINSCACHE_DIR, CacheName() );
+            psz_cachedir, PLUGINSCACHE_DIR, CacheName() );
     if( i_size <= 0 )
     {
         msg_Err( p_this, "out of memory" );
@@ -2022,15 +2022,15 @@ static void CacheSave( vlc_object_t *p_this )
         "# For information about cache directory tags, see:\r\n"
         "#   http://www.brynosaurus.com/cachedir/\r\n";
 
-    char *psz_filename, *psz_datadir;
+    char *psz_filename, *psz_cachedir;
     FILE *file;
     int i, j, i_cache;
     module_cache_t **pp_cache;
     int32_t i_file_size = 0;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
 
-    psz_datadir = p_this->p_libvlc->psz_datadir;
-    if( !psz_datadir ) /* XXX: this should never happen */
+    psz_cachedir = p_this->p_libvlc->psz_cachedir;
+    if( !psz_cachedir ) /* XXX: this should never happen */
     {
         msg_Err( p_this, "Unable to get cache directory" );
         return;
@@ -2038,7 +2038,7 @@ static void CacheSave( vlc_object_t *p_this )
 
     psz_filename =
        (char *)malloc( sizeof(DIR_SEP PLUGINSCACHE_DIR DIR_SEP ) +
-                       strlen(psz_datadir) + strlen(CacheName()) );
+                       strlen(psz_cachedir) + strlen(CacheName()) );
 
     if( !psz_filename )
     {
@@ -2046,7 +2046,7 @@ static void CacheSave( vlc_object_t *p_this )
         return;
     }
 
-    sprintf( psz_filename, "%s", psz_datadir );
+    sprintf( psz_filename, "%s", psz_cachedir );
 
     config_CreateDir( p_this, psz_filename );
 
@@ -2063,7 +2063,7 @@ static void CacheSave( vlc_object_t *p_this )
         fclose( file );
     }
 
-    sprintf( psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s", psz_datadir,
+    sprintf( psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s", psz_cachedir,
              PLUGINSCACHE_DIR, CacheName() );
 
     msg_Dbg( p_this, "saving plugins cache file %s", psz_filename );