mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Handle errors during configuration file loading
This commit is contained in:
parent
a5e71de63a
commit
534509adaf
|
@ -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();
|
||||
|
|
|
@ -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
24
main.cc
|
@ -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() )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue