mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Handle article decoding errors for Aard dictionaries
This commit is contained in:
parent
869b044966
commit
06a8129fac
75
aard.cc
75
aard.cc
|
@ -450,56 +450,69 @@ 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 );
|
||||||
df.read( &size, sizeof(size) );
|
df.read( &size, sizeof(size) );
|
||||||
articleSize = size;
|
articleSize = size;
|
||||||
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;
|
||||||
|
|
||||||
string text = decompressBzip2( articleBody.data(), articleSize );
|
articleText.clear();
|
||||||
if( text.empty() )
|
|
||||||
|
string text = decompressBzip2( articleBody.data(), articleSize );
|
||||||
|
if( text.empty() )
|
||||||
text = decompressZlib( articleBody.data(), articleSize );
|
text = decompressZlib( articleBody.data(), articleSize );
|
||||||
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() )
|
string link;
|
||||||
return;
|
readJSONValue( text, link, n );
|
||||||
|
if( !link.empty() )
|
||||||
string link;
|
articleText = "<a href=\"" + link + "\">" + link + "</a>";
|
||||||
readJSONValue( text, link, n );
|
|
||||||
if( !link.empty() )
|
|
||||||
articleText = "<a href=\"" + link + "\">" + link + "</a>";
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
dict.loadArticle( chain[ x ].articleOffset, articleText );
|
try
|
||||||
|
{
|
||||||
|
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