[vlc-commits] commit: skins2: check missing files first thing ... (Erwan Tulou )

git at videolan.org git at videolan.org
Thu Jul 22 15:10:11 CEST 2010


vlc/vlc-1.1 | branch: master | Erwan Tulou <erwan10 at videolan.org> | Thu Jul 22 14:29:39 2010 +0200| [fffbdafe99c64ab5e8a9ecc0c8ce8b42cfe933d4] | committer: Erwan Tulou 

skins2: check missing files first thing ...

... 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)
(cherry picked from commit 3b35ca6d42b294a614a790032c24987a44a8c3c1)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=fffbdafe99c64ab5e8a9ecc0c8ce8b42cfe933d4
---

 modules/gui/skins2/parser/builder.cpp |   39 ++++++++++++++++++++++++++------
 1 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/modules/gui/skins2/parser/builder.cpp b/modules/gui/skins2/parser/builder.cpp
index 74c0a62..d9c7583 100644
--- a/modules/gui/skins2/parser/builder.cpp
+++ b/modules/gui/skins2/parser/builder.cpp
@@ -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 );
@@ -1174,7 +1188,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;
 }
 
 



More information about the vlc-commits mailing list