Commit 4809df7d authored by Olivier Teulière's avatar Olivier Teulière

* skins2: fixed several encoding issues. In particular, it should now be

   possible to load a skin on Windows when logged with an account containing
   non-english characters.
parent 93ca90e6
...@@ -1061,7 +1061,7 @@ GenericFont *Builder::getFont( const string &fontId ) ...@@ -1061,7 +1061,7 @@ GenericFont *Builder::getFont( const string &fontId )
string Builder::getFilePath( const string &rFileName ) const string Builder::getFilePath( const string &rFileName ) const
{ {
OSFactory *pFactory = OSFactory::instance( getIntf() ); OSFactory *pFactory = OSFactory::instance( getIntf() );
return m_path + pFactory->getDirSeparator() + rFileName; return m_path + pFactory->getDirSeparator() + sFromLocale( rFileName );
} }
......
...@@ -66,6 +66,26 @@ class ThemeRepository; ...@@ -66,6 +66,26 @@ class ThemeRepository;
} }
/// Wrapper around FromLocale, to avoid the need to call LocaleFree()
static inline string sFromLocale( const string &rLocale )
{
char *s = FromLocale( rLocale.c_str() );
string res = s;
LocaleFree( s );
return res;
}
/// Wrapper around ToLocale, to avoid the need to call LocaleFree()
static inline string sToLocale( const string &rUTF8 )
{
char *s = ToLocale( rUTF8.c_str() );
string res = s;
LocaleFree( s );
return res;
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// intf_sys_t: description and status of skin interface // intf_sys_t: description and status of skin interface
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
......
...@@ -77,7 +77,7 @@ bool ThemeLoader::load( const string &fileName ) ...@@ -77,7 +77,7 @@ bool ThemeLoader::load( const string &fileName )
// file... // file...
string path = getFilePath( fileName ); string path = getFilePath( fileName );
#if defined( HAVE_ZLIB_H ) #if defined( HAVE_ZLIB_H )
if( ! extract( fileName ) && ! parse( path, fileName ) ) if( ! extract( sToLocale( fileName ) ) && ! parse( path, fileName ) )
return false; return false;
#else #else
if( ! parse( path, fileName ) ) if( ! parse( path, fileName ) )
...@@ -311,7 +311,7 @@ bool ThemeLoader::extract( const string &fileName ) ...@@ -311,7 +311,7 @@ bool ThemeLoader::extract( const string &fileName )
list<string>::const_iterator it; list<string>::const_iterator it;
for( it = resPath.begin(); it != resPath.end(); it++ ) for( it = resPath.begin(); it != resPath.end(); it++ )
{ {
if( findFile( *it, WINAMP2_XML_FILE, xmlFile ) ) if( findFile( sToLocale( *it ), WINAMP2_XML_FILE, xmlFile ) )
break; break;
} }
} }
...@@ -456,7 +456,7 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName, ...@@ -456,7 +456,7 @@ bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
// Found the theme file? // Found the theme file?
if( rFileName == string( pDirContent->d_name ) ) if( rFileName == string( pDirContent->d_name ) )
{ {
themeFilePath = newURI; themeFilePath = sFromLocale( newURI );
closedir( pCurrDir ); closedir( pCurrDir );
return true; return true;
} }
......
...@@ -37,33 +37,59 @@ class ThemeLoader: public SkinObject ...@@ -37,33 +37,59 @@ class ThemeLoader: public SkinObject
ThemeLoader( intf_thread_t *pIntf ): SkinObject( pIntf ) {} ThemeLoader( intf_thread_t *pIntf ): SkinObject( pIntf ) {}
virtual ~ThemeLoader() {} virtual ~ThemeLoader() {}
/**
* The expected fileName must be an UTF-8 string (usually the result of
* a call to FromLocale())
*/
bool load( const string &fileName ); bool load( const string &fileName );
private: private:
#if defined( HAVE_ZLIB_H ) #if defined( HAVE_ZLIB_H )
/// Extract files from an archive (handles tar.gz and zip) /// Extract files from an archive (handles tar.gz and zip)
/**
* Expects a string from the current locale.
*/
bool extract( const string &fileName ); bool extract( const string &fileName );
/// Extract files from a tar.gz archive /// Extract files from a tar.gz archive
/**
* Expects strings from the current locale.
*/
bool extractTarGz( const string &tarFile, const string &rootDir ); bool extractTarGz( const string &tarFile, const string &rootDir );
/// Extract files from a .zip archive /// Extract files from a .zip archive
/**
* Expects strings from the current locale.
*/
bool extractZip( const string &zipFile, const string &rootDir ); bool extractZip( const string &zipFile, const string &rootDir );
/// Extract the current file from a .zip archive /// Extract the current file from a .zip archive
/**
* Expects a string from the current locale.
*/
bool extractFileInZip( unzFile file, const string &rootDir ); bool extractFileInZip( unzFile file, const string &rootDir );
/// Clean up the temporary files created by the extraction /// Clean up the temporary files created by the extraction
/**
* Expects a string from the current locale.
*/
void deleteTempFiles( const string &path ); void deleteTempFiles( const string &path );
#endif #endif
/// Parse the XML file given as a parameter and build the skin /// Parse the XML file given as a parameter and build the skin
/**
* Expects UTF8 strings
*/
bool parse( const string &path, const string &xmlFile ); bool parse( const string &path, const string &xmlFile );
/// Recursively look for the XML file from rootDir. /// Recursively look for the XML file from rootDir.
/// The first corresponding file found will be chosen and themeFilePath /**
/// will be updated accordingly. * The first corresponding file found will be chosen and themeFilePath
/// The method returns true if a theme file was found, false otherwise * will be updated accordingly.
* The method returns true if a theme file was found, false otherwise.
* rootDir and rFilename must both be strings in the current locale,
* whereas themeFilePath will be in UTF8.
*/
bool findFile( const string &rootDir, const string &rFileName, bool findFile( const string &rootDir, const string &rFileName,
string &themeFilePath ); string &themeFilePath );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment