-rw-r--r-- | library/config.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/library/config.cpp b/library/config.cpp index b47c620..b28c771 100644 --- a/library/config.cpp +++ b/library/config.cpp @@ -462,11 +462,11 @@ void Config::write( const QString &fn ) qWarning( "could not open for writing `%s'", strNewFile.latin1() ); git = groups.end(); return; } - + QString str; - QCString cstr; + QCString cstr; QMap< QString, ConfigGroup >::Iterator g_it = groups.begin(); for ( ; g_it != groups.end(); ++g_it ) { str += "[" + g_it.key() + "]\n"; @@ -474,9 +474,9 @@ void Config::write( const QString &fn ) for ( ; e_it != ( *g_it ).end(); ++e_it ) str += e_it.key() + " = " + *e_it + "\n"; } cstr = str.utf8(); - + int total_length; total_length = f.writeBlock( cstr.data(), cstr.length() ); if ( total_length != int(cstr.length()) ) { QMessageBox::critical( 0, QObject::tr("Out of Space"), @@ -484,16 +484,16 @@ void Config::write( const QString &fn ) f.close(); QFile::remove( strNewFile ); return; } - + f.close(); // now rename the file... if ( rename( strNewFile, filename ) < 0 ) { - qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), + qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), filename.latin1() ); QFile::remove( strNewFile ); - } + } } /*! Returns whether the Config is in a valid state. @@ -520,8 +520,18 @@ void Config::read() git = groups.end(); return; } + + // hack to avoid problems if big files are passed to test + // if they are valid configs ( like passing a mp3 ... ) + // I just hope that there are no conf files > 100000 byte + // not the best solution, find something else later + if ( f.size() > 100000 ) { + return; + } + + QTextStream s( &f ); #if QT_VERSION <= 230 && defined(QT_NO_CODECS) // The below should work, but doesn't in Qt 2.3.0 s.setCodec( QTextCodec::codecForMib( 106 ) ); @@ -545,12 +555,12 @@ void Config::read() */ bool Config::parse( const QString &l ) { QString line = l.stripWhiteSpace(); - + if ( line [0] == QChar ( '#' )) return true; // ignore comments - + if ( line[ 0 ] == QChar( '[' ) ) { QString gname = line; gname = gname.remove( 0, 1 ); if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) |