mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Handle article decoding errors for Aard dictionaries
This commit is contained in:
parent
869b044966
commit
06a8129fac
47
aard.cc
47
aard.cc
|
@ -450,6 +450,11 @@ void AardDictionary::loadArticle( uint32_t address,
|
||||||
|
|
||||||
articleText.clear();
|
articleText.clear();
|
||||||
|
|
||||||
|
|
||||||
|
while( 1 )
|
||||||
|
{
|
||||||
|
articleText = "Article loading error";
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Mutex::Lock _( aardMutex );
|
Mutex::Lock _( aardMutex );
|
||||||
df.seek( articleOffset );
|
df.seek( articleOffset );
|
||||||
|
@ -458,9 +463,15 @@ void AardDictionary::loadArticle( uint32_t address,
|
||||||
articleBody.resize( articleSize );
|
articleBody.resize( articleSize );
|
||||||
df.read( &articleBody.front(), articleSize );
|
df.read( &articleBody.front(), articleSize );
|
||||||
}
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if ( articleBody.empty() )
|
if ( articleBody.empty() )
|
||||||
throw exCantReadFile( getDictionaryFilenames()[ 0 ] );
|
break;
|
||||||
|
|
||||||
|
articleText.clear();
|
||||||
|
|
||||||
string text = decompressBzip2( articleBody.data(), articleSize );
|
string text = decompressBzip2( articleBody.data(), articleSize );
|
||||||
if( text.empty() )
|
if( text.empty() )
|
||||||
|
@ -468,26 +479,23 @@ void AardDictionary::loadArticle( uint32_t address,
|
||||||
if( text.empty() )
|
if( text.empty() )
|
||||||
text = string( articleBody.data(), articleSize );
|
text = string( articleBody.data(), articleSize );
|
||||||
|
|
||||||
string::size_type n = 0;
|
if( text.empty() || text[ 0 ] != '[' )
|
||||||
while( n < text.size() && text[n] != '\"' )
|
break;
|
||||||
n++;
|
|
||||||
|
|
||||||
if( n >= text.size() )
|
string::size_type n = text.find( '\"' );
|
||||||
return;
|
if( n == string::npos )
|
||||||
|
break;
|
||||||
|
|
||||||
readJSONValue( text, articleText, n );
|
readJSONValue( text, articleText, n );
|
||||||
|
|
||||||
if( articleText.empty() )
|
if( articleText.empty() )
|
||||||
{
|
{
|
||||||
n = text.find( "\"r\"" );
|
n = text.find( "\"r\"" );
|
||||||
if( n != string::npos )
|
if( n != string::npos && n + 3 < text.size() )
|
||||||
{
|
{
|
||||||
n += 3;
|
n = text.find( '\"', n + 3 );
|
||||||
while( n < text.size() && text[n] != '\"' )
|
if( n == string::npos )
|
||||||
n++;
|
break;
|
||||||
|
|
||||||
if( n >= text.size() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
string link;
|
string link;
|
||||||
readJSONValue( text, link, n );
|
readJSONValue( text, link, n );
|
||||||
|
@ -496,10 +504,15 @@ void AardDictionary::loadArticle( uint32_t address,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if( !articleText.empty() )
|
if( !articleText.empty() )
|
||||||
articleText = convert( articleText );
|
articleText = convert( articleText );
|
||||||
|
else
|
||||||
|
articleText = "Article decoding error";
|
||||||
|
|
||||||
articleText = "<div class=\"sdict\">" + articleText + "</div>";
|
articleText = "<div class=\"aard\">" + articleText + "</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString const& AardDictionary::getDescription()
|
QString const& AardDictionary::getDescription()
|
||||||
|
@ -660,7 +673,13 @@ void AardArticleRequest::run()
|
||||||
string headword, articleText;
|
string headword, articleText;
|
||||||
|
|
||||||
headword = chain[ x ].word;
|
headword = chain[ x ].word;
|
||||||
|
try
|
||||||
|
{
|
||||||
dict.loadArticle( chain[ x ].articleOffset, articleText );
|
dict.loadArticle( chain[ x ].articleOffset, articleText );
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// Ok. Now, does it go to main articles, or to alternate ones? We list
|
// Ok. Now, does it go to main articles, or to alternate ones? We list
|
||||||
// main ones first, and alternates after.
|
// main ones first, and alternates after.
|
||||||
|
|
Loading…
Reference in a new issue