Handle errors during configuration file loading

This commit is contained in:
Abs62 2013-05-08 20:50:06 +04:00
parent a5e71de63a
commit 534509adaf
3 changed files with 31 additions and 5 deletions

View file

@ -48,10 +48,6 @@ namespace
return result;
}
QString getConfigFileName()
{
return getHomeDir().absoluteFilePath( "config" );
}
}
ProxyServer::ProxyServer(): enabled( false ), type( Socks5 ), port( 3128 )
@ -1559,6 +1555,11 @@ void save( Class const & c ) throw( exError )
renameAtomically( configFile.fileName(), getConfigFileName() );
}
QString getConfigFileName()
{
return getHomeDir().absoluteFilePath( "config" );
}
QString getConfigDir() throw( exError )
{
return getHomeDir().path() + QDir::separator();

View file

@ -524,6 +524,9 @@ Class load() throw( exError );
/// Saves the configuration
void save( Class const & ) throw( exError );
/// Returns the configuration file name.
QString getConfigFileName();
/// Returns the main configuration directory.
QString getConfigDir() throw( exError );

24
main.cc
View file

@ -21,8 +21,10 @@
#endif
#include "termination.hh"
#include "atomic_rename.hh"
#include <QWebSecurityOrigin>
#include <QMessageBox>
int main( int argc, char ** argv )
{
@ -119,7 +121,27 @@ int main( int argc, char ** argv )
app.setWindowIcon( QIcon( ":/icons/macicon.png" ) );
#endif
Config::Class cfg( Config::load() );
Config::Class cfg;
for( ; ; )
{
try
{
cfg = Config::Class( Config::load() );
}
catch( Config::exError )
{
QMessageBox mb( QMessageBox::Warning, "GoldenDict", "Error in configuration file. Continue with default settings?",
QMessageBox::Yes | QMessageBox::No );
mb.exec();
if( mb.result() != QMessageBox::Yes )
return -1;
QString configFile = Config::getConfigFileName();
renameAtomically( configFile, configFile + ".bad" );
continue;
}
break;
}
if ( Config::isPortableVersion() )
{