mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-28 03:44:07 +00:00
mdx normal index check logic
This commit is contained in:
parent
5a8de1ea1d
commit
4ab26f687c
|
@ -579,14 +579,63 @@ bool needToRebuildIndex( vector< string > const & dictionaryFiles,
|
||||||
|
|
||||||
return fileInfo.lastModified().toSecsSinceEpoch() < lastModified;
|
return fileInfo.lastModified().toSecsSinceEpoch() < lastModified;
|
||||||
#else
|
#else
|
||||||
QDir d(FsEncoding::decode( indexFile.c_str() ));
|
QFileInfo fileInfo( FsEncoding::decode( indexFile.c_str() ) );
|
||||||
if(!d.exists()){
|
|
||||||
|
if ( fileInfo.exists()&&fileInfo.isFile() )
|
||||||
|
{
|
||||||
|
QFile::remove(FsEncoding::decode( indexFile.c_str() ));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool needToRebuildBTreeIndex( vector< string > const & dictionaryFiles,
|
||||||
|
string const & indexFile ) noexcept
|
||||||
|
{
|
||||||
|
unsigned long lastModified = 0;
|
||||||
|
|
||||||
|
for( std::vector< string >::const_iterator i = dictionaryFiles.begin();
|
||||||
|
i != dictionaryFiles.end(); ++i )
|
||||||
|
{
|
||||||
|
QString name = FsEncoding::decode( i->c_str() );
|
||||||
|
QFileInfo fileInfo( name );
|
||||||
|
unsigned long ts;
|
||||||
|
|
||||||
|
if( fileInfo.isDir() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( name.toLower().endsWith( ".zip" ) )
|
||||||
|
{
|
||||||
|
ZipFile::SplitZipFile zf( name );
|
||||||
|
if( !zf.exists() )
|
||||||
|
return true;
|
||||||
|
ts = zf.lastModified().toSecsSinceEpoch();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( !fileInfo.exists() )
|
||||||
|
return true;
|
||||||
|
ts = fileInfo.lastModified().toSecsSinceEpoch();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ts > lastModified )
|
||||||
|
lastModified = ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir d(FsEncoding::decode( indexFile.c_str() ));
|
||||||
|
if(d.exists()){
|
||||||
|
d.removeRecursively();
|
||||||
|
}
|
||||||
|
QFileInfo fileInfo( FsEncoding::decode( indexFile.c_str() ) );
|
||||||
|
|
||||||
|
if ( !fileInfo.exists() )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return fileInfo.lastModified().toSecsSinceEpoch() < lastModified;
|
||||||
|
}
|
||||||
|
|
||||||
QString generateRandomDictionaryId()
|
QString generateRandomDictionaryId()
|
||||||
{
|
{
|
||||||
return QString(
|
return QString(
|
||||||
|
|
|
@ -483,6 +483,9 @@ string makeDictionaryId( vector< string > const & dictionaryFiles ) noexcept;
|
||||||
bool needToRebuildIndex( vector< string > const & dictionaryFiles,
|
bool needToRebuildIndex( vector< string > const & dictionaryFiles,
|
||||||
string const & indexFile ) noexcept;
|
string const & indexFile ) noexcept;
|
||||||
|
|
||||||
|
bool needToRebuildBTreeIndex( vector< string > const & dictionaryFiles,
|
||||||
|
string const & indexFile ) noexcept;
|
||||||
|
|
||||||
/// Returns a random dictionary id useful for interactively created
|
/// Returns a random dictionary id useful for interactively created
|
||||||
/// dictionaries.
|
/// dictionaries.
|
||||||
QString generateRandomDictionaryId();
|
QString generateRandomDictionaryId();
|
||||||
|
|
2
mdx.cc
2
mdx.cc
|
@ -1401,7 +1401,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
string dictId = Dictionary::makeDictionaryId( dictFiles );
|
string dictId = Dictionary::makeDictionaryId( dictFiles );
|
||||||
string indexFile = indicesDir + dictId;
|
string indexFile = indicesDir + dictId;
|
||||||
|
|
||||||
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) ||
|
if ( Dictionary::needToRebuildBTreeIndex( dictFiles, indexFile ) ||
|
||||||
indexIsOldOrBad( dictFiles, indexFile ) )
|
indexIsOldOrBad( dictFiles, indexFile ) )
|
||||||
{
|
{
|
||||||
// Building the index
|
// Building the index
|
||||||
|
|
Loading…
Reference in a new issue