Handle article decoding errors for Aard dictionaries

This commit is contained in:
Abs62 2013-03-04 16:57:12 +04:00
parent 869b044966
commit 06a8129fac

47
aard.cc
View file

@ -450,6 +450,11 @@ void AardDictionary::loadArticle( uint32_t address,
articleText.clear();
while( 1 )
{
articleText = "Article loading error";
try
{
Mutex::Lock _( aardMutex );
df.seek( articleOffset );
@ -458,9 +463,15 @@ void AardDictionary::loadArticle( uint32_t address,
articleBody.resize( articleSize );
df.read( &articleBody.front(), articleSize );
}
catch(...)
{
break;
}
if ( articleBody.empty() )
throw exCantReadFile( getDictionaryFilenames()[ 0 ] );
break;
articleText.clear();
string text = decompressBzip2( articleBody.data(), articleSize );
if( text.empty() )
@ -468,26 +479,23 @@ void AardDictionary::loadArticle( uint32_t address,
if( text.empty() )
text = string( articleBody.data(), articleSize );
string::size_type n = 0;
while( n < text.size() && text[n] != '\"' )
n++;
if( text.empty() || text[ 0 ] != '[' )
break;
if( n >= text.size() )
return;
string::size_type n = text.find( '\"' );
if( n == string::npos )
break;
readJSONValue( text, articleText, n );
if( articleText.empty() )
{
n = text.find( "\"r\"" );
if( n != string::npos )
if( n != string::npos && n + 3 < text.size() )
{
n += 3;
while( n < text.size() && text[n] != '\"' )
n++;
if( n >= text.size() )
return;
n = text.find( '\"', n + 3 );
if( n == string::npos )
break;
string link;
readJSONValue( text, link, n );
@ -496,10 +504,15 @@ void AardDictionary::loadArticle( uint32_t address,
}
}
break;
}
if( !articleText.empty() )
articleText = convert( articleText );
else
articleText = "Article decoding error";
articleText = "<div class=\"sdict\">" + articleText + "</div>";
articleText = "<div class=\"aard\">" + articleText + "</div>";
}
QString const& AardDictionary::getDescription()
@ -660,7 +673,13 @@ void AardArticleRequest::run()
string headword, articleText;
headword = chain[ x ].word;
try
{
dict.loadArticle( chain[ x ].articleOffset, articleText );
}
catch(...)
{
}
// Ok. Now, does it go to main articles, or to alternate ones? We list
// main ones first, and alternates after.