mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 23:34:06 +00:00
fix:remove code smell
This commit is contained in:
parent
6abdaab5d3
commit
da406e1e02
49
mdx.cc
49
mdx.cc
|
@ -1158,19 +1158,20 @@ QString MdxDictionary::getCachedFileName( QString filename )
|
|||
QString fullName = cacheDirName + QDir::separator() + filename;
|
||||
|
||||
info.setFile( fullName );
|
||||
if( !info.exists() )
|
||||
{
|
||||
if( info.exists() )
|
||||
return fullName;
|
||||
QFile f( fullName );
|
||||
if( f.open( QFile::WriteOnly ) )
|
||||
{
|
||||
if( !f.open( QFile::WriteOnly ) ) {
|
||||
gdWarning( R"(Mdx: file "%s" creating error: "%s")", fullName.toUtf8().data(), f.errorString().toUtf8().data() );
|
||||
return QString();
|
||||
}
|
||||
gd::wstring resourceName = FsEncoding::decode( filename.toStdString() );
|
||||
vector< char > data;
|
||||
|
||||
// In order to prevent recursive internal redirection...
|
||||
set< wstring > resourceIncluded;
|
||||
|
||||
for ( ;; )
|
||||
{
|
||||
for( ;; ) {
|
||||
if( !resourceIncluded.insert( resourceName ).second )
|
||||
continue;
|
||||
|
||||
|
@ -1179,23 +1180,16 @@ QString MdxDictionary::getCachedFileName( QString filename )
|
|||
// Check if this file has a redirection
|
||||
// Always encoded in UTF16-LE
|
||||
// L"@@@LINK="
|
||||
static const char pattern[16] =
|
||||
{
|
||||
'@', '\0', '@', '\0', '@', '\0', 'L', '\0', 'I', '\0', 'N', '\0', 'K', '\0', '=', '\0'
|
||||
};
|
||||
|
||||
if ( data.size() > sizeof( pattern ) )
|
||||
{
|
||||
if ( memcmp( &data.front(), pattern, sizeof( pattern ) ) == 0 )
|
||||
{
|
||||
if( static const char pattern[ 16 ] =
|
||||
{ '@', '\0', '@', '\0', '@', '\0', 'L', '\0', 'I', '\0', 'N', '\0', 'K', '\0', '=', '\0' };
|
||||
data.size() > sizeof( pattern ) && memcmp( &data.front(), pattern, sizeof( pattern ) ) == 0 ) {
|
||||
data.push_back( '\0' );
|
||||
data.push_back( '\0' );
|
||||
QString target = MdictParser::toUtf16( "UTF-16LE", &data.front() + sizeof( pattern ),
|
||||
data.size() - sizeof( pattern ) );
|
||||
QString target =
|
||||
MdictParser::toUtf16( "UTF-16LE", &data.front() + sizeof( pattern ), data.size() - sizeof( pattern ) );
|
||||
resourceName = gd::toWString( target.trimmed() );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1205,20 +1199,10 @@ QString MdxDictionary::getCachedFileName( QString filename )
|
|||
|
||||
f.close();
|
||||
|
||||
if( n < (qint64)data.size() )
|
||||
{
|
||||
gdWarning( R"(Mdx: file "%s" writing error: "%s")", fullName.toUtf8().data(),
|
||||
f.errorString().toUtf8().data() );
|
||||
if( n < (qint64) data.size() ) {
|
||||
gdWarning( R"(Mdx: file "%s" writing error: "%s")", fullName.toUtf8().data(), f.errorString().toUtf8().data() );
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gdWarning( R"(Mdx: file "%s" creating error: "%s")", fullName.toUtf8().data(),
|
||||
f.errorString().toUtf8().data() );
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
return fullName;
|
||||
}
|
||||
|
||||
|
@ -1236,9 +1220,8 @@ void MdxDictionary::loadResourceFile( const wstring & resourceName, vector< char
|
|||
newResourceName.insert( 0, 1, '\\' );
|
||||
}
|
||||
// local file takes precedence
|
||||
string fn = FsEncoding::dirname( getDictionaryFilenames()[ 0 ] ) + FsEncoding::separator() + u8ResourceName;
|
||||
|
||||
if( File::exists( fn ) ) {
|
||||
if( string fn = FsEncoding::dirname( getDictionaryFilenames()[ 0 ] ) + FsEncoding::separator() + u8ResourceName;
|
||||
File::exists( fn ) ) {
|
||||
File::loadFromFile( fn, data );
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue