mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
*! getProgramDataDir() fixed for builds with no dir specified (Windows).
+ Ability to use a template config file added.
This commit is contained in:
parent
be068dc044
commit
e5613471ee
|
@ -123,6 +123,8 @@ Class load() throw( exError )
|
||||||
{
|
{
|
||||||
QString configName = getConfigFileName();
|
QString configName = getConfigFileName();
|
||||||
|
|
||||||
|
bool loadFromTemplate = false;
|
||||||
|
|
||||||
if ( !QFile::exists( configName ) )
|
if ( !QFile::exists( configName ) )
|
||||||
{
|
{
|
||||||
// Make the default config, save it and return it
|
// Make the default config, save it and return it
|
||||||
|
@ -164,9 +166,17 @@ Class load() throw( exError )
|
||||||
|
|
||||||
c.mediawikis = makeDefaultMediaWikis( true );
|
c.mediawikis = makeDefaultMediaWikis( true );
|
||||||
|
|
||||||
save( c );
|
// Check if we have a template config file. If we do, load it instead
|
||||||
|
|
||||||
return c;
|
configName = getProgramDataDir() + "/content/defconfig";
|
||||||
|
loadFromTemplate = QFile( configName ).exists();
|
||||||
|
|
||||||
|
if ( !loadFromTemplate )
|
||||||
|
{
|
||||||
|
save( c );
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile configFile( configName );
|
QFile configFile( configName );
|
||||||
|
@ -179,10 +189,29 @@ Class load() throw( exError )
|
||||||
QString errorStr;
|
QString errorStr;
|
||||||
int errorLine, errorColumn;
|
int errorLine, errorColumn;
|
||||||
|
|
||||||
if ( !dd.setContent( &configFile, false, &errorStr, &errorLine, &errorColumn ) )
|
if ( !loadFromTemplate )
|
||||||
{
|
{
|
||||||
printf( "Error: %s at %d,%d\n", errorStr.toLocal8Bit().constData(), errorLine, errorColumn );
|
// Load the config as usual
|
||||||
throw exMalformedConfigFile();
|
if ( !dd.setContent( &configFile, false, &errorStr, &errorLine, &errorColumn ) )
|
||||||
|
{
|
||||||
|
printf( "Error: %s at %d,%d\n", errorStr.toLocal8Bit().constData(), errorLine, errorColumn );
|
||||||
|
throw exMalformedConfigFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We need to replace all %PROGRAMDIR% with the program data dir
|
||||||
|
QByteArray data = configFile.readAll();
|
||||||
|
|
||||||
|
data.replace( "%PROGRAMDIR%", getProgramDataDir().toUtf8() );
|
||||||
|
|
||||||
|
QBuffer bufferedData( &data );
|
||||||
|
|
||||||
|
if ( !dd.setContent( &bufferedData, false, &errorStr, &errorLine, &errorColumn ) )
|
||||||
|
{
|
||||||
|
printf( "Error: %s at %d,%d\n", errorStr.toLocal8Bit().constData(), errorLine, errorColumn );
|
||||||
|
throw exMalformedConfigFile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configFile.close();
|
configFile.close();
|
||||||
|
@ -696,7 +725,7 @@ QString getProgramDataDir() throw()
|
||||||
#ifdef PROGRAM_DATA_DIR
|
#ifdef PROGRAM_DATA_DIR
|
||||||
return PROGRAM_DATA_DIR;
|
return PROGRAM_DATA_DIR;
|
||||||
#else
|
#else
|
||||||
return "foo"; // Fixme
|
return QCoreApplication::applicationDirPath();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue