fix: epwing case sensitive (#1093)

* fix: epwing folder name is casesensitive in Linux

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
xiaoyifang 2023-08-27 18:30:55 +08:00 committed by GitHub
parent 98af55557e
commit ccd04e0b51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 8 deletions

View file

@ -1187,13 +1187,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
QFileInfo info( fontSubName ); QFileInfo info( fontSubName );
if ( info.exists() && info.isFile() ) if ( info.exists() && info.isFile() )
dictFiles.push_back( fontSubName.toStdString() ); dictFiles.push_back( fontSubName.toStdString() );
else {
//to make the subbook in different index.
auto virtual_file = QString::fromStdString( mainDirectory ) + QDir::separator() + QString::number( sb );
dictFiles.push_back( virtual_file.toStdString() );
}
// Check if we need to rebuid the index // Check if we need to rebuild the index
string dictId = Dictionary::makeDictionaryId( dictFiles ); string dictId = Dictionary::makeDictionaryId( dictFiles );
@ -1208,7 +1203,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
File::Class idx( indexFile, "wb" ); File::Class idx( indexFile, "wb" );
IdxHeader idxHeader; IdxHeader idxHeader{};
memset( &idxHeader, 0, sizeof( idxHeader ) ); memset( &idxHeader, 0, sizeof( idxHeader ) );

View file

@ -596,7 +596,36 @@ QString EpwingBook::getCurrentSubBookDirectory()
throw exEbLibrary( error_string.toUtf8().data() ); throw exEbLibrary( error_string.toUtf8().data() );
} }
return QString::fromLocal8Bit( buffer ); QString subDir = QString::fromLocal8Bit( buffer );
return repairSubBookDirectory( subDir );
}
QString EpwingBook::repairSubBookDirectory( QString subBookDir )
{
char path[ EB_MAX_PATH_LENGTH + 1 ];
EB_Error_Code error_code = eb_path( &book, path );
if ( error_code != EB_SUCCESS )
return subBookDir;
const QString & mainDirectory = QString::fromLocal8Bit( path );
QDir mainDir( mainDirectory );
QStringList allIdxFiles = mainDir.entryList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks );
if ( allIdxFiles.contains( subBookDir ) ) {
return subBookDir;
}
qDebug() << "Epwing: can not found subbook directory,try to fix automatically, dir=>" << subBookDir;
for ( const auto & file : allIdxFiles ) {
if ( file.compare( subBookDir, Qt::CaseInsensitive ) == 0 ) {
qDebug() << "Epwing: found " << file;
return file;
}
}
//return original subbook directory
return subBookDir;
} }
QString EpwingBook::makeFName( QString const & ext, int page, int offset ) const QString EpwingBook::makeFName( QString const & ext, int page, int offset ) const

View file

@ -239,6 +239,7 @@ public:
bool getMatches( QString word, QVector< QString > & matches ); bool getMatches( QString word, QVector< QString > & matches );
bool getArticlePos( QString word, QVector< int > & pages, QVector< int > & offsets ); bool getArticlePos( QString word, QVector< int > & pages, QVector< int > & offsets );
QString repairSubBookDirectory( QString subBookDir );
}; };
struct EContainer struct EContainer