]> git.sesse.net Git - vlc/commitdiff
album art: use filename_sanitize function
authorRémi Duraffort <ivoire@videolan.org>
Tue, 31 Mar 2009 19:04:40 +0000 (21:04 +0200)
committerRémi Duraffort <ivoire@videolan.org>
Tue, 31 Mar 2009 19:08:38 +0000 (21:08 +0200)
and change this function to replace spaces by '_' on windows.
(should fix #2143)

include/vlc_strings.h
src/playlist/art.c
src/text/strings.c

index eab608e09063b3cd8d14842f4861abb50008cbc6..4173ac48fe1805c990d32f5d4e763f57d5f872f6 100644 (file)
@@ -50,7 +50,7 @@ VLC_EXPORT( char *, __str_format_meta, ( vlc_object_t *, const char * ) );
 #define str_format( a, b ) __str_format( VLC_OBJECT( a ), b )
 VLC_EXPORT( char *, __str_format, ( vlc_object_t *, const char * ) );
 
-VLC_EXPORT( void, filename_sanitize, ( char * ) );
+VLC_EXPORT( char *, filename_sanitize, ( const char * ) );
 VLC_EXPORT( void, path_sanitize, ( char * ) );
 
 /**
index 7a82360ee5c3df72765b1869f0bf570bc0bd1334..002ec6ed332fbfe8b540638880bae22833e523c9 100644 (file)
@@ -61,29 +61,6 @@ static void ArtCacheCreateDir( const char *psz_dir )
     utf8_mkdir( psz_dir, 0700 );
 }
 
-static char *ArtCacheGetSanitizedFileName( const char *psz )
-{
-    char *dup = strdup(psz);
-    int i;
-
-    filename_sanitize( dup );
-
-    /* Doesn't create a filename with invalid characters
-     * TODO: several filesystems forbid several characters: list them all
-     */
-    for( i = 0; dup[i] != '\0'; i++ )
-    {
-        if( dup[i] == DIR_SEP_CHAR )
-            dup[i] = ' ';
-        // "<>:\"/?*" are forbidden for win filenames
-#if defined( WIN32 ) || defined( UNDER_CE )
-        else if( strchr( "<>:\"/?*", dup[i] ) )
-            dup[i] = '_';
-#endif
-    }
-    return dup;
-}
-
 static void ArtCacheGetDirPath( char *psz_dir,
                                 const char *psz_title,
                                 const char *psz_artist, const char *psz_album )
@@ -92,8 +69,8 @@ static void ArtCacheGetDirPath( char *psz_dir,
 
     if( !EMPTY_STR(psz_artist) && !EMPTY_STR(psz_album) )
     {
-        char * psz_album_sanitized = ArtCacheGetSanitizedFileName( psz_album );
-        char * psz_artist_sanitized = ArtCacheGetSanitizedFileName( psz_artist );
+        char *psz_album_sanitized = filename_sanitize( psz_album );
+        char *psz_artist_sanitized = filename_sanitize( psz_artist );
         snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
                   "art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s",
                   psz_cachedir, psz_artist_sanitized, psz_album_sanitized );
@@ -102,7 +79,7 @@ static void ArtCacheGetDirPath( char *psz_dir,
     }
     else
     {
-        char * psz_title_sanitized = ArtCacheGetSanitizedFileName( psz_title );
+        char * psz_title_sanitized = filename_sanitize( psz_title );
         snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
                   "art" DIR_SEP "title" DIR_SEP "%s",
                   psz_cachedir, psz_title_sanitized );
@@ -153,9 +130,7 @@ static char *ArtCacheName( input_item_t *p_item, const char *psz_type )
 
     ArtCacheCreateDir( psz_path );
 
-    char *psz_ext = strdup( psz_type ? psz_type : "" );
-    filename_sanitize( psz_ext );
-
+    char *psz_ext = filename_sanitize( psz_type ? psz_type : "" );
     char *psz_filename;
     if( asprintf( &psz_filename, "file://%s" DIR_SEP "art%s", psz_path, psz_ext ) < 0 )
         psz_filename = NULL;
index ee0085e7e73cfe3b02b20cbef40543fe3ec2bf1a..33818407723af74fb087be2159ee50b46fdfadb4 100644 (file)
@@ -1020,8 +1020,10 @@ char *__str_format( vlc_object_t *p_this, const char *psz_src )
 /**
  * Remove forbidden characters from filenames (including slashes)
  */
-void filename_sanitize( char *str )
+char* filename_sanitize( const char *str_origin )
 {
+    char *str = strdup( str_origin );
+    char *str_base = str;
     if( *str == '.' && (str[1] == '\0' || (str[1] == '.' && str[2] == '\0' ) ) )
     {
         while( *str )
@@ -1029,7 +1031,7 @@ void filename_sanitize( char *str )
             *str = '_';
             str++;
         }
-        return;
+        return str_base;
     }
 
     while( *str )
@@ -1048,11 +1050,13 @@ void filename_sanitize( char *str )
             case '|':
             case '<':
             case '>':
+            case ' ':
 #endif
                 *str = '_';
         }
         str++;
     }
+    return str_base;
 }
 
 /**