]> git.sesse.net Git - vlc/commitdiff
Skins2 theme loader:
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 25 Nov 2006 14:10:59 +0000 (14:10 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 25 Nov 2006 14:10:59 +0000 (14:10 +0000)
 - use utf8_(read|open)dir
 - do not assume that stat() succeeds (tiny race condition)

modules/gui/skins2/src/theme_loader.cpp

index 73655004e66b51c3667be8ec4d8249091081c527..6aef3021e78eb9dc8ca9e63e7f8edf38d5d182d1 100644 (file)
@@ -278,7 +278,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
@@ -311,7 +311,7 @@ bool ThemeLoader::extract( const string &fileName )
             list<string>::const_iterator it;
             for( it = resPath.begin(); it != resPath.end(); it++ )
             {
-                if( findFile( sToLocale( *it ), WINAMP2_XML_FILE, xmlFile ) )
+                if( findFile( *it, WINAMP2_XML_FILE, xmlFile ) )
                     break;
             }
         }
@@ -410,10 +410,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 = utf8_opendir( rootDir.c_str() );
 
     if( pCurrDir == NULL )
     {
@@ -422,22 +422,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 = utf8_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( ( utf8_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 +445,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 +453,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 = sFromLocale( newURI );
+                    themeFilePath = newURI;
+                    free( pszDirContent );
                     closedir( pCurrDir );
                     return true;
                 }
             }
         }
 
-        pDirContent = (dirent*)readdir( pCurrDir );
+        free( pszDirContent );
     }
 
     closedir( pCurrDir );