mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
clean: delete useless fopen style mode char* API from File::Index
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
This commit is contained in:
parent
8f42e2e073
commit
fa9ad2fdf7
|
@ -103,7 +103,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -287,10 +287,10 @@ private:
|
||||||
|
|
||||||
AardDictionary::AardDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
AardDictionary::AardDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() ),
|
idxHeader( idx.read< IdxHeader >() ),
|
||||||
chunks( idx, idxHeader.chunksOffset ),
|
chunks( idx, idxHeader.chunksOffset ),
|
||||||
df( dictionaryFiles[ 0 ], "rb" )
|
df( dictionaryFiles[ 0 ], QIODevice::ReadOnly )
|
||||||
{
|
{
|
||||||
// Read dictionary name
|
// Read dictionary name
|
||||||
|
|
||||||
|
@ -802,7 +802,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File::Index df( fileName, "rb" );
|
File::Index df( fileName, QIODevice::ReadOnly );
|
||||||
|
|
||||||
AAR_header dictHeader;
|
AAR_header dictHeader;
|
||||||
|
|
||||||
|
@ -871,7 +871,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
|
|
||||||
initializing.indexingDictionary( dictName );
|
initializing.indexingDictionary( dictName );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ private:
|
||||||
|
|
||||||
BglDictionary::BglDictionary( string const & id, string const & indexFile, string const & dictionaryFile ):
|
BglDictionary::BglDictionary( string const & id, string const & indexFile, string const & dictionaryFile ):
|
||||||
BtreeDictionary( id, vector< string >( 1, dictionaryFile ) ),
|
BtreeDictionary( id, vector< string >( 1, dictionaryFile ) ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() ),
|
idxHeader( idx.read< IdxHeader >() ),
|
||||||
chunks( idx, idxHeader.chunksOffset )
|
chunks( idx, idxHeader.chunksOffset )
|
||||||
{
|
{
|
||||||
|
@ -1083,7 +1083,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
|
|
||||||
initializing.indexingDictionary( b.title() );
|
initializing.indexingDictionary( b.title() );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
|
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -155,8 +155,8 @@ DictdDictionary::DictdDictionary( string const & id,
|
||||||
string const & indexFile,
|
string const & indexFile,
|
||||||
vector< string > const & dictionaryFiles ):
|
vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
indexFile( dictionaryFiles[ 0 ], "rb" ),
|
indexFile( dictionaryFiles[ 0 ], QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() )
|
idxHeader( idx.read< IdxHeader >() )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -606,7 +606,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
|
|
||||||
initializing.indexingDictionary( dictionaryName );
|
initializing.indexingDictionary( dictionaryName );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
|
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
|
|
||||||
|
@ -619,7 +619,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
|
|
||||||
IndexedWords indexedWords;
|
IndexedWords indexedWords;
|
||||||
|
|
||||||
File::Index indexFile( dictFiles[ 0 ], "rb" );
|
File::Index indexFile( dictFiles[ 0 ], QIODevice::ReadOnly );
|
||||||
|
|
||||||
// Read words from index until none's left.
|
// Read words from index until none's left.
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ struct InsidedCard
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile, bool hasZipFile )
|
bool indexIsOldOrBad( string const & indexFile, bool hasZipFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ private:
|
||||||
|
|
||||||
DslDictionary::DslDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
DslDictionary::DslDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() ),
|
idxHeader( idx.read< IdxHeader >() ),
|
||||||
dz( 0 ),
|
dz( 0 ),
|
||||||
deferredInitRunnableStarted( false ),
|
deferredInitRunnableStarted( false ),
|
||||||
|
@ -1807,7 +1807,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
gdDebug( "Dsl: Building the index for dictionary: %s\n",
|
gdDebug( "Dsl: Building the index for dictionary: %s\n",
|
||||||
QString::fromStdU32String( scanner.getDictionaryName() ).toUtf8().data() );
|
QString::fromStdU32String( scanner.getDictionaryName() ).toUtf8().data() );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
|
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ EpwingDictionary::EpwingDictionary( string const & id,
|
||||||
vector< string > const & dictionaryFiles,
|
vector< string > const & dictionaryFiles,
|
||||||
int subBook ):
|
int subBook ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() ),
|
idxHeader( idx.read< IdxHeader >() ),
|
||||||
chunks( idx, idxHeader.chunksOffset )
|
chunks( idx, idxHeader.chunksOffset )
|
||||||
{
|
{
|
||||||
|
@ -1197,7 +1197,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
QByteArray nameData = str.toUtf8();
|
QByteArray nameData = str.toUtf8();
|
||||||
initializing.indexingDictionary( nameData.data() );
|
initializing.indexingDictionary( nameData.data() );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
|
|
||||||
IdxHeader idxHeader{};
|
IdxHeader idxHeader{};
|
||||||
|
|
||||||
|
|
|
@ -335,7 +335,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile, bool hasZipFile )
|
bool indexIsOldOrBad( string const & indexFile, bool hasZipFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ private:
|
||||||
|
|
||||||
GlsDictionary::GlsDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
GlsDictionary::GlsDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() ),
|
idxHeader( idx.read< IdxHeader >() ),
|
||||||
dz( 0 ),
|
dz( 0 ),
|
||||||
chunks( idx, idxHeader.chunksOffset )
|
chunks( idx, idxHeader.chunksOffset )
|
||||||
|
@ -1270,7 +1270,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
gdDebug( "Gls: Building the index for dictionary: %s\n",
|
gdDebug( "Gls: Building the index for dictionary: %s\n",
|
||||||
QString::fromStdU32String( scanner.getDictionaryName() ).toUtf8().data() );
|
QString::fromStdU32String( scanner.getDictionaryName() ).toUtf8().data() );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
|
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ string LsaDictionary::getName() noexcept
|
||||||
|
|
||||||
LsaDictionary::LsaDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
LsaDictionary::LsaDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() )
|
idxHeader( idx.read< IdxHeader >() )
|
||||||
{
|
{
|
||||||
// Initialize the index
|
// Initialize the index
|
||||||
|
@ -405,7 +405,7 @@ sptr< Dictionary::DataRequest > LsaDictionary::getResource( string const & name
|
||||||
return std::make_shared< Dictionary::DataRequestInstant >( false ); // No such resource
|
return std::make_shared< Dictionary::DataRequestInstant >( false ); // No such resource
|
||||||
}
|
}
|
||||||
|
|
||||||
File::Index f( getDictionaryFilenames()[ 0 ], "rb" );
|
File::Index f( getDictionaryFilenames()[ 0 ], QIODevice::ReadOnly );
|
||||||
|
|
||||||
f.seek( chain[ 0 ].articleOffset );
|
f.seek( chain[ 0 ].articleOffset );
|
||||||
Entry e( f );
|
Entry e( f );
|
||||||
|
@ -522,7 +522,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File::Index f( *i, "rb" );
|
File::Index f( *i, QIODevice::ReadOnly );
|
||||||
|
|
||||||
/// Check the signature
|
/// Check the signature
|
||||||
|
|
||||||
|
@ -547,7 +547,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
|
|
||||||
initializing.indexingDictionary( Utils::Fs::basename( *i ) );
|
initializing.indexingDictionary( Utils::Fs::basename( *i ) );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
|
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
|
|
||||||
|
|
|
@ -302,7 +302,7 @@ private:
|
||||||
|
|
||||||
MdxDictionary::MdxDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
MdxDictionary::MdxDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxFileName( indexFile ),
|
idxFileName( indexFile ),
|
||||||
idxHeader( idx.read< IdxHeader >() ),
|
idxHeader( idx.read< IdxHeader >() ),
|
||||||
chunks( idx, idxHeader.chunksOffset ),
|
chunks( idx, idxHeader.chunksOffset ),
|
||||||
|
@ -1307,7 +1307,7 @@ private:
|
||||||
|
|
||||||
static bool indexIsOldOrBad( vector< string > const & dictFiles, string const & indexFile )
|
static bool indexIsOldOrBad( vector< string > const & dictFiles, string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
return idx.readRecords( &header, sizeof( header ), 1 ) != 1 || header.signature != kSignature
|
return idx.readRecords( &header, sizeof( header ), 1 ) != 1 || header.signature != kSignature
|
||||||
|
@ -1385,7 +1385,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
||||||
// We write a dummy header first. At the end of the process the header
|
// We write a dummy header first. At the end of the process the header
|
||||||
|
|
|
@ -97,7 +97,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -188,10 +188,10 @@ SdictDictionary::SdictDictionary( string const & id,
|
||||||
string const & indexFile,
|
string const & indexFile,
|
||||||
vector< string > const & dictionaryFiles ):
|
vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() ),
|
idxHeader( idx.read< IdxHeader >() ),
|
||||||
chunks( idx, idxHeader.chunksOffset ),
|
chunks( idx, idxHeader.chunksOffset ),
|
||||||
df( dictionaryFiles[ 0 ], "rb" )
|
df( dictionaryFiles[ 0 ], QIODevice::ReadOnly )
|
||||||
{
|
{
|
||||||
// Read dictionary name
|
// Read dictionary name
|
||||||
|
|
||||||
|
@ -689,7 +689,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
try {
|
try {
|
||||||
gdDebug( "SDict: Building the index for dictionary: %s\n", fileName.c_str() );
|
gdDebug( "SDict: Building the index for dictionary: %s\n", fileName.c_str() );
|
||||||
|
|
||||||
File::Index df( fileName, "rb" );
|
File::Index df( fileName, QIODevice::ReadOnly );
|
||||||
|
|
||||||
DCT_header dictHeader;
|
DCT_header dictHeader;
|
||||||
|
|
||||||
|
@ -722,7 +722,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
|
|
||||||
initializing.indexingDictionary( dictName );
|
initializing.indexingDictionary( dictName );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ struct RefEntry
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -702,7 +702,7 @@ private:
|
||||||
SlobDictionary::SlobDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
SlobDictionary::SlobDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idxFileName( indexFile ),
|
idxFileName( indexFile ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() )
|
idxHeader( idx.read< IdxHeader >() )
|
||||||
{
|
{
|
||||||
// Open data file
|
// Open data file
|
||||||
|
@ -1285,7 +1285,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
|
|
||||||
initializing.indexingDictionary( sf.getDictionaryName().toUtf8().constData() );
|
initializing.indexingDictionary( sf.getDictionaryName().toUtf8().constData() );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ SoundDirDictionary::SoundDirDictionary( string const & id,
|
||||||
QString const & iconFilename_ ):
|
QString const & iconFilename_ ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
name( name_ ),
|
name( name_ ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() ),
|
idxHeader( idx.read< IdxHeader >() ),
|
||||||
chunks( idx, idxHeader.chunksOffset ),
|
chunks( idx, idxHeader.chunksOffset ),
|
||||||
iconFilename( iconFilename_ )
|
iconFilename( iconFilename_ )
|
||||||
|
@ -370,7 +370,7 @@ sptr< Dictionary::DataRequest > SoundDirDictionary::getResource( string const &
|
||||||
// Now try loading that file
|
// Now try loading that file
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File::Index f( fileName.toStdString(), "rb" );
|
File::Index f( fileName.toStdString(), QIODevice::ReadOnly );
|
||||||
|
|
||||||
sptr< Dictionary::DataRequestInstant > dr = std::make_shared< Dictionary::DataRequestInstant >( true );
|
sptr< Dictionary::DataRequestInstant > dr = std::make_shared< Dictionary::DataRequestInstant >( true );
|
||||||
|
|
||||||
|
@ -479,7 +479,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( Config::SoundDirs const &
|
||||||
|
|
||||||
initializing.indexingDictionary( soundDir.name.toUtf8().data() );
|
initializing.indexingDictionary( soundDir.name.toUtf8().data() );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
|
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ StardictDictionary::StardictDictionary( string const & id,
|
||||||
string const & indexFile,
|
string const & indexFile,
|
||||||
vector< string > const & dictionaryFiles ):
|
vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() ),
|
idxHeader( idx.read< IdxHeader >() ),
|
||||||
bookName( loadString( idxHeader.bookNameSize ) ),
|
bookName( loadString( idxHeader.bookNameSize ) ),
|
||||||
sameTypeSequence( loadString( idxHeader.sameTypeSequenceSize ) ),
|
sameTypeSequence( loadString( idxHeader.sameTypeSequenceSize ) ),
|
||||||
|
@ -1918,7 +1918,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
|
|
||||||
initializing.indexingDictionary( ifo.bookname );
|
initializing.indexingDictionary( ifo.bookname );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
|
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
|
|
||||||
|
|
|
@ -37,50 +37,18 @@ bool tryPossibleZipName( std::string const & name, std::string & copyTo )
|
||||||
|
|
||||||
void loadFromFile( std::string const & filename, std::vector< char > & data )
|
void loadFromFile( std::string const & filename, std::vector< char > & data )
|
||||||
{
|
{
|
||||||
File::Index f( filename, "rb" );
|
File::Index f( filename, QIODevice::ReadOnly );
|
||||||
auto size = f.file().size(); // QFile::size() obtains size via statx on Linux
|
auto size = f.file().size(); // QFile::size() obtains size via statx on Linux
|
||||||
data.resize( size );
|
data.resize( size );
|
||||||
f.read( data.data(), size );
|
f.read( data.data(), size );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Index::open( char const * mode )
|
Index::Index( std::string_view filename, QIODevice::OpenMode mode )
|
||||||
{
|
|
||||||
QFile::OpenMode openMode = QIODevice::Text;
|
|
||||||
|
|
||||||
const char * pch = mode;
|
|
||||||
while ( *pch ) {
|
|
||||||
switch ( *pch ) {
|
|
||||||
case 'r':
|
|
||||||
openMode |= QIODevice::ReadOnly;
|
|
||||||
break;
|
|
||||||
case 'w':
|
|
||||||
openMode |= QIODevice::WriteOnly;
|
|
||||||
break;
|
|
||||||
case '+':
|
|
||||||
openMode &= ~( QIODevice::ReadOnly | QIODevice::WriteOnly );
|
|
||||||
openMode |= QIODevice::ReadWrite;
|
|
||||||
break;
|
|
||||||
case 'a':
|
|
||||||
openMode |= QIODevice::Append;
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
openMode &= ~QIODevice::Text;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
++pch;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !f.open( openMode ) ) {
|
|
||||||
throw exCantOpen( f.fileName().toStdString() + ": " + f.errorString().toUtf8().data() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Index::Index( std::string_view filename, char const * mode )
|
|
||||||
{
|
{
|
||||||
f.setFileName( QString::fromUtf8( filename.data(), filename.size() ) );
|
f.setFileName( QString::fromUtf8( filename.data(), filename.size() ) );
|
||||||
open( mode );
|
if ( !f.open( mode ) ) {
|
||||||
|
throw exCantOpen( ( f.fileName() + ": " + f.errorString() ).toStdString() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Index::read( void * buf, qint64 size )
|
void Index::read( void * buf, qint64 size )
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
QMutex lock;
|
QMutex lock;
|
||||||
|
|
||||||
// Create QFile Object and open() it.
|
// Create QFile Object and open() it.
|
||||||
Index( std::string_view filename, char const * mode );
|
Index( std::string_view filename, QIODevice::OpenMode mode );
|
||||||
|
|
||||||
/// QFile::read & QFile::write , but with exception throwing
|
/// QFile::read & QFile::write , but with exception throwing
|
||||||
void read( void * buf, qint64 size );
|
void read( void * buf, qint64 size );
|
||||||
|
@ -113,8 +113,6 @@ public:
|
||||||
~Index() noexcept;
|
~Index() noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// QFile::open but with fopen-like mode settings.
|
|
||||||
void open( char const * mode );
|
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
void readType( T & value )
|
void readType( T & value )
|
||||||
|
|
|
@ -125,7 +125,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ private:
|
||||||
|
|
||||||
XdxfDictionary::XdxfDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
XdxfDictionary::XdxfDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() )
|
idxHeader( idx.read< IdxHeader >() )
|
||||||
{
|
{
|
||||||
// Read the dictionary name
|
// Read the dictionary name
|
||||||
|
@ -1077,7 +1077,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
|
|
||||||
//initializing.indexingDictionary( nameFromFileName( dictFiles[ 0 ] ) );
|
//initializing.indexingDictionary( nameFromFileName( dictFiles[ 0 ] ) );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
|
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
map< string, string > abrv;
|
map< string, string > abrv;
|
||||||
|
|
|
@ -93,7 +93,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
// Some supporting functions
|
// Some supporting functions
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ private:
|
||||||
|
|
||||||
ZimDictionary::ZimDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
ZimDictionary::ZimDictionary( string const & id, string const & indexFile, vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() ),
|
idxHeader( idx.read< IdxHeader >() ),
|
||||||
df( dictionaryFiles[ 0 ] )
|
df( dictionaryFiles[ 0 ] )
|
||||||
{
|
{
|
||||||
|
@ -832,7 +832,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
initializing.indexingDictionary( firstName.mid( n + 1 ).toUtf8().constData() );
|
initializing.indexingDictionary( firstName.mid( n + 1 ).toUtf8().constData() );
|
||||||
}
|
}
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
||||||
idxHeader.namePtr = 0xFFFFFFFF;
|
idxHeader.namePtr = 0xFFFFFFFF;
|
||||||
|
|
|
@ -60,7 +60,7 @@ static_assert( alignof( IdxHeader ) == 1 );
|
||||||
|
|
||||||
bool indexIsOldOrBad( string const & indexFile )
|
bool indexIsOldOrBad( string const & indexFile )
|
||||||
{
|
{
|
||||||
File::Index idx( indexFile, "rb" );
|
File::Index idx( indexFile, QIODevice::ReadOnly );
|
||||||
|
|
||||||
IdxHeader header;
|
IdxHeader header;
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ ZipSoundsDictionary::ZipSoundsDictionary( string const & id,
|
||||||
string const & indexFile,
|
string const & indexFile,
|
||||||
vector< string > const & dictionaryFiles ):
|
vector< string > const & dictionaryFiles ):
|
||||||
BtreeDictionary( id, dictionaryFiles ),
|
BtreeDictionary( id, dictionaryFiles ),
|
||||||
idx( indexFile, "rb" ),
|
idx( indexFile, QIODevice::ReadOnly ),
|
||||||
idxHeader( idx.read< IdxHeader >() )
|
idxHeader( idx.read< IdxHeader >() )
|
||||||
{
|
{
|
||||||
chunks = std::shared_ptr< ChunkedStorage::Reader >( new ChunkedStorage::Reader( idx, idxHeader.chunksOffset ) );
|
chunks = std::shared_ptr< ChunkedStorage::Reader >( new ChunkedStorage::Reader( idx, idxHeader.chunksOffset ) );
|
||||||
|
@ -405,7 +405,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
|
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
|
||||||
gdDebug( "Zips: Building the index for dictionary: %s\n", fileName.c_str() );
|
gdDebug( "Zips: Building the index for dictionary: %s\n", fileName.c_str() );
|
||||||
|
|
||||||
File::Index idx( indexFile, "wb" );
|
File::Index idx( indexFile, QIODevice::WriteOnly );
|
||||||
IdxHeader idxHeader;
|
IdxHeader idxHeader;
|
||||||
|
|
||||||
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
memset( &idxHeader, 0, sizeof( idxHeader ) );
|
||||||
|
|
Loading…
Reference in a new issue