]> git.sesse.net Git - vlc/commitdiff
skins2: check missing files first thing ...
authorErwan Tulou <erwan10@videolan.org>
Thu, 22 Jul 2010 12:29:39 +0000 (14:29 +0200)
committerErwan Tulou <erwan10@videolan.org>
Thu, 22 Jul 2010 12:52:57 +0000 (14:52 +0200)
... and make user experience with skins2 less frightening !

missing files in skins should never occur, but reality is quite different
(see vlc skins website). Yet, if a check is done before any other processing,
we can avoid the unfriendly error dialog boxes issued by vlc core, and those
skins often end up quite usable (missing files are either no longer used or
for ancillary functionalities, that go unnoticed)

modules/gui/skins2/parser/builder.cpp

index 7be91dcadbb617ba0fa3b7b94b9c242aea7c1a52..6981757b4cc322cf02aa83a78c995819f58b8f9a 100644 (file)
@@ -57,6 +57,7 @@
 #include "../utils/var_text.hpp"
 
 #include <vlc_image.h>
+#include <fstream>
 
 
 Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData,
@@ -181,16 +182,24 @@ void Builder::addTheme( const BuilderData::Theme &rData )
 void Builder::addIniFile( const BuilderData::IniFile &rData )
 {
     // Parse the INI file
-    IniFile iniFile( getIntf(), rData.m_id, getFilePath( rData.m_file ) );
+    string full_path = getFilePath( rData.m_file );
+    if( !full_path.size() )
+        return;
+
+    IniFile iniFile( getIntf(), rData.m_id, full_path );
     iniFile.parseFile();
 }
 
 
 void Builder::addBitmap( const BuilderData::Bitmap &rData )
 {
+    string full_path = getFilePath( rData.m_fileName );
+    if( !full_path.size() )
+        return;
+
     GenericBitmap *pBmp =
         new FileBitmap( getIntf(), m_pImageHandler,
-                        getFilePath( rData.m_fileName ), rData.m_alphaColor,
+                        full_path, rData.m_alphaColor,
                         rData.m_nbFrames, rData.m_fps, rData.m_nbLoops );
     if( !pBmp->getData() )
     {
@@ -239,9 +248,12 @@ void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
         return;
     }
 
+    string full_path = getFilePath( rData.m_file );
+    if( !full_path.size() )
+        return;
+
     GenericBitmap *pBmp =
-        new FileBitmap( getIntf(), m_pImageHandler,
-                        getFilePath( rData.m_file ), 0 );
+        new FileBitmap( getIntf(), m_pImageHandler, full_path, 0 );
     if( !pBmp->getData() )
     {
         // Invalid bitmap
@@ -265,10 +277,12 @@ void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
 
 void Builder::addFont( const BuilderData::Font &rData )
 {
+    string full_path = getFilePath( rData.m_fontFile );
+    if( !full_path.size() )
+        return;
+
     // Try to load the font from the theme directory
-    GenericFont *pFont = new FT2Font( getIntf(),
-                                      getFilePath( rData.m_fontFile ),
-                                      rData.m_size );
+    GenericFont *pFont = new FT2Font( getIntf(), full_path, rData.m_size );
     if( pFont->init() )
     {
         m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
@@ -1177,7 +1191,16 @@ string Builder::getFilePath( const string &rFileName ) const
        file.replace( pos, 1, sep );
 #endif
 
-    return m_path + sep + sFromLocale( file );
+    string full_path = m_path + sep + sFromLocale( file );
+
+    // check that the file exists and can be read
+    if( ifstream( full_path.c_str() ).fail() )
+    {
+        msg_Err( getIntf(), "missing file: %s", file.c_str() );
+        full_path = "";
+    }
+
+    return full_path;
 }