From: Erwan Tulou Date: Thu, 22 Jul 2010 12:29:39 +0000 (+0200) Subject: skins2: check missing files first thing ... X-Git-Tag: 1.2.0-pre1~5715 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=3b35ca6d42b294a614a790032c24987a44a8c3c1;p=vlc 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) --- diff --git a/modules/gui/skins2/parser/builder.cpp b/modules/gui/skins2/parser/builder.cpp index 7be91dcadb..6981757b4c 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 +#include 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; }