Make it possible to override the config dir from the command line

This commit is contained in:
Aurélien Gâteau 2014-07-28 18:11:24 +02:00
parent cb53cc41cb
commit 289704ab90
3 changed files with 29 additions and 4 deletions

View File

@ -20,10 +20,12 @@
#include "CalamaresApplication.h"
#include "kdsingleapplicationguard/kdsingleapplicationguard.h"
#include "utils/CalamaresUtils.h"
#include "utils/Logger.h"
#include <QCommandLineParser>
#include <QDebug>
#include <QDir>
int
main( int argc, char *argv[] )
@ -38,10 +40,17 @@ main( int argc, char *argv[] )
"Verbose output for debugging purposes." );
parser.addOption( debugOption );
QCommandLineOption configOption( QStringList() << "c" << "config",
"Configuration dir to use, for testing purposes.", "config" );
parser.addOption( configOption );
parser.process( a );
a.setDebug( parser.isSet( debugOption ) );
if ( parser.isSet( configOption ) )
CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) );
KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances );
int returnCode = 0;

View File

@ -34,14 +34,26 @@
namespace CalamaresUtils
{
static QDir s_appDataDir;
void
setAppDataDir( const QDir& dir )
{
s_appDataDir = dir;
}
QDir
appDataDir()
{
QDir path( CMAKE_INSTALL_FULL_DATADIR );
if ( !path.exists() || !path.isReadable() )
path.mkpath( path.absolutePath() );
if ( s_appDataDir.path().isEmpty() )
{
s_appDataDir = QDir( CMAKE_INSTALL_FULL_DATADIR );
if ( !s_appDataDir.exists() || !s_appDataDir.isReadable() )
s_appDataDir.mkpath( s_appDataDir.absolutePath() );
}
return path;
return s_appDataDir;
}

View File

@ -36,6 +36,10 @@ namespace CalamaresUtils
DLLEXPORT QDir systemLibDir();
DLLEXPORT void installTranslator( QObject* parent );
/**
* Override app data dir. Only for testing purposes.
*/
DLLEXPORT void setAppDataDir( const QDir& dir );
}
#endif // CALAMARESUTILS_H