and change this function to replace spaces by '_' on windows.
(should fix #2143)
#define str_format( a, b ) __str_format( VLC_OBJECT( a ), b )
VLC_EXPORT( char *, __str_format, ( 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 * ) );
/**
VLC_EXPORT( void, path_sanitize, ( char * ) );
/**
utf8_mkdir( psz_dir, 0700 );
}
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 )
static void ArtCacheGetDirPath( char *psz_dir,
const char *psz_title,
const char *psz_artist, const char *psz_album )
if( !EMPTY_STR(psz_artist) && !EMPTY_STR(psz_album) )
{
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 );
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 );
- 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 );
snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
"art" DIR_SEP "title" DIR_SEP "%s",
psz_cachedir, psz_title_sanitized );
ArtCacheCreateDir( psz_path );
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;
char *psz_filename;
if( asprintf( &psz_filename, "file://%s" DIR_SEP "art%s", psz_path, psz_ext ) < 0 )
psz_filename = NULL;
/**
* Remove forbidden characters from filenames (including slashes)
*/
/**
* 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 )
if( *str == '.' && (str[1] == '\0' || (str[1] == '.' && str[2] == '\0' ) ) )
{
while( *str )
case '|':
case '<':
case '>':
case '|':
case '<':
case '>':
#endif
*str = '_';
}
str++;
}
#endif
*str = '_';
}
str++;
}