]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/theme_loader.cpp
Qt: cache "no-art" pixmap as well
[vlc] / modules / gui / skins2 / src / theme_loader.cpp
index 51e36f809adc7fbdb76b72afb1eaa9cf4dc54c84..0d9cfd5b9ee7fede21f097417049b9b057588139 100644 (file)
@@ -50,7 +50,7 @@
 #if defined( HAVE_ZLIB_H )
 #   include <zlib.h>
 #   include <errno.h>
-int gzopen_frontend ( char *pathname, int oflags, int mode );
+int gzopen_frontend ( const char *pathname, int oflags, int mode );
 int gzclose_frontend( int );
 int gzread_frontend ( int, void *, size_t );
 int gzwrite_frontend( int, const void *, size_t );
@@ -73,11 +73,18 @@ int makedir( const char *newdir );
 
 bool ThemeLoader::load( const string &fileName )
 {
+    string path = getFilePath( fileName );
+
+    //Before all, let's see if the file is present
+    struct stat p_stat;
+    if( vlc_stat( path.c_str(), &p_stat ) )
+        return false;
+
     // First, we try to un-targz the file, and if it fails we hope it's a XML
     // file...
-    string path = getFilePath( fileName );
+
 #if defined( HAVE_ZLIB_H )
-    if( ! extract( fileName ) && ! parse( path, fileName ) )
+    if( ! extract( sToLocale( fileName ) ) && ! parse( path, fileName ) )
         return false;
 #else
     if( ! parse( path, fileName ) )
@@ -105,10 +112,7 @@ bool ThemeLoader::load( const string &fileName )
         // Show the windows
         pNewTheme->getWindowManager().showAll( true );
     }
-    if( skin_last ) free( skin_last );
-
-    // The new theme cannot embed a video output yet
-    VlcProc::instance( getIntf() )->dropVout();
+    free( skin_last );
 
     return true;
 }
@@ -198,6 +202,8 @@ bool ThemeLoader::extractFileInZip( unzFile file, const string &rootDir )
         return false;
     }
 
+#ifdef WIN32
+
     // Convert the file name to lower case, because some winamp skins
     // use the wrong case...
     for( size_t i=0; i< strlen( filenameInZip ); i++)
@@ -205,13 +211,12 @@ bool ThemeLoader::extractFileInZip( unzFile file, const string &rootDir )
         filenameInZip[i] = tolower( filenameInZip[i] );
     }
 
+#endif
+
     // Allocate the buffer
     void *pBuffer = malloc( ZIP_BUFFER_SIZE );
     if( !pBuffer )
-    {
-        msg_Err( getIntf(), "failed to allocate memory" );
         return false;
-    }
 
     // Get the path of the file
     OSFactory *pOsFactory = OSFactory::instance( getIntf() );
@@ -278,7 +283,7 @@ bool ThemeLoader::extract( const string &fileName )
 {
     bool result = true;
     char *tmpdir = tempnam( NULL, "vlt" );
-    string tempPath = tmpdir;
+    string tempPath = sFromLocale( tmpdir );
     free( tmpdir );
 
     // Extract the file in a temporary directory
@@ -353,10 +358,7 @@ bool ThemeLoader::parse( const string &path, const string &xmlFile )
     // Start the parser
     SkinParser parser( getIntf(), xmlFile, path );
     if( ! parser.parse() )
-    {
-        msg_Err( getIntf(), "failed to parse %s", xmlFile.c_str() );
         return false;
-    }
 
     // Build and store the theme
     Builder builder( getIntf(), parser.getData(), path );
@@ -410,10 +412,10 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
     const string &sep = OSFactory::instance( getIntf() )->getDirSeparator();
 
     DIR *pCurrDir;
-    struct dirent *pDirContent;
+    char *pszDirContent;
 
     // Open the dir
-    pCurrDir = opendir( rootDir.c_str() );
+    pCurrDir = vlc_opendir( rootDir.c_str() );
 
     if( pCurrDir == NULL )
     {
@@ -422,22 +424,20 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
         return false;
     }
 
-    // Get the first directory entry
-    pDirContent = (dirent*)readdir( pCurrDir );
-
     // While we still have entries in the directory
-    while( pDirContent != NULL )
+    while( ( pszDirContent = vlc_readdir( pCurrDir ) ) != NULL )
     {
-        string newURI = rootDir + sep + pDirContent->d_name;
+        string newURI = rootDir + sep + pszDirContent;
 
         // Skip . and ..
-        if( string( pDirContent->d_name ) != "." &&
-            string( pDirContent->d_name ) != ".." )
+        if( string( pszDirContent ) != "." &&
+            string( pszDirContent ) != ".." )
         {
 #if defined( S_ISDIR )
             struct stat stat_data;
-            stat( newURI.c_str(), &stat_data );
-            if( S_ISDIR(stat_data.st_mode) )
+
+            if( ( vlc_stat( newURI.c_str(), &stat_data ) == 0 )
+             && S_ISDIR(stat_data.st_mode) )
 #elif defined( DT_DIR )
             if( pDirContent->d_type & DT_DIR )
 #else
@@ -447,6 +447,7 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
                 // Can we find the file in this subdirectory?
                 if( findFile( newURI, rFileName, themeFilePath ) )
                 {
+                    free( pszDirContent );
                     closedir( pCurrDir );
                     return true;
                 }
@@ -454,16 +455,17 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
             else
             {
                 // Found the theme file?
-                if( rFileName == string( pDirContent->d_name ) )
+                if( rFileName == string( pszDirContent ) )
                 {
                     themeFilePath = newURI;
+                    free( pszDirContent );
                     closedir( pCurrDir );
                     return true;
                 }
             }
         }
 
-        pDirContent = (dirent*)readdir( pCurrDir );
+        free( pszDirContent );
     }
 
     closedir( pCurrDir );
@@ -575,34 +577,33 @@ int tar_extract_all( TAR *t, char *prefix )
 
             switch( buffer.header.typeflag )
             {
-                case DIRTYPE:
-                    makedir( fname );
-                    break;
-                case REGTYPE:
-                case AREGTYPE:
-                    remaining = getoct( buffer.header.size, 12 );
-                    if( remaining )
+            case DIRTYPE:
+                makedir( fname );
+                break;
+            case REGTYPE:
+            case AREGTYPE:
+                remaining = getoct( buffer.header.size, 12 );
+                if( !remaining ) outfile = NULL; else
+                {
+                    outfile = fopen( fname, "wb" );
+                    if( outfile == NULL )
                     {
-                        outfile = fopen( fname, "wb" );
-                        if( outfile == NULL )
+                        /* try creating directory */
+                        char *p = strrchr( fname, '/' );
+                        if( p != NULL )
                         {
-                            /* try creating directory */
-                            char *p = strrchr( fname, '/' );
-                            if( p != NULL )
+                            *p = '\0';
+                            makedir( fname );
+                            *p = '/';
+                            outfile = fopen( fname, "wb" );
+                            if( !outfile )
                             {
-                                *p = '\0';
-                                makedir( fname );
-                                *p = '/';
-                                outfile = fopen( fname, "wb" );
-                                if( !outfile )
-                                {
-                                    fprintf( stderr, "tar couldn't create %s\n",
-                                             fname );
-                                }
+                                fprintf( stderr, "tar couldn't create %s\n",
+                                         fname );
                             }
                         }
                     }
-                    else outfile = NULL;
+                }
 
                 /*
                  * could have no contents
@@ -623,6 +624,7 @@ int tar_extract_all( TAR *t, char *prefix )
                 {
                     fprintf( stderr, "error writing %s skipping...\n", fname );
                     fclose( outfile );
+                    outfile = NULL;
                     unlink( fname );
                 }
             }
@@ -729,23 +731,23 @@ int makedir( const char *newdir )
 static int currentGzFd = -1;
 static void * currentGzVp = NULL;
 
-int gzopen_frontend( char *pathname, int oflags, int mode )
+int gzopen_frontend( const char *pathname, int oflags, int mode )
 {
-    char *gzflags;
+    const char *gzflags;
     gzFile gzf;
 
     switch( oflags )
     {
-        case O_WRONLY:
-            gzflags = "wb";
-            break;
-        case O_RDONLY:
-            gzflags = "rb";
-            break;
-        case O_RDWR:
-        default:
-            errno = EINVAL;
-            return -1;
+    case O_WRONLY:
+        gzflags = "wb";
+        break;
+    case O_RDONLY:
+        gzflags = "rb";
+        break;
+    case O_RDWR:
+    default:
+        errno = EINVAL;
+        return -1;
     }
 
     gzf = gzopen( pathname, gzflags );