diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index 989b5a928..d80c43d5d 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -20,10 +20,12 @@ #include "CalamaresApplication.h" #include "kdsingleapplicationguard/kdsingleapplicationguard.h" +#include "utils/CalamaresUtils.h" #include "utils/Logger.h" #include #include +#include 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; diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index cdf903c75..cfb374273 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -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; } diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index fdb0d053c..f7713be18 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -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