2014-06-11 13:37:10 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Settings.h"
|
2014-06-13 16:40:42 +02:00
|
|
|
|
2014-06-12 18:47:50 +02:00
|
|
|
#include "utils/CalamaresUtils.h"
|
|
|
|
#include "utils/Logger.h"
|
2014-07-03 18:00:40 +02:00
|
|
|
#include "utils/YamlUtils.h"
|
2014-06-12 18:47:50 +02:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
2014-06-13 16:40:42 +02:00
|
|
|
|
|
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
|
|
|
|
|
2014-06-12 18:47:50 +02:00
|
|
|
namespace Calamares
|
|
|
|
{
|
|
|
|
|
2014-06-27 15:21:16 +02:00
|
|
|
Settings* Settings::s_instance = nullptr;
|
2014-06-12 18:47:50 +02:00
|
|
|
|
|
|
|
Settings*
|
|
|
|
Settings::instance()
|
|
|
|
{
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
2014-06-11 13:37:10 +02:00
|
|
|
|
2014-07-03 18:00:40 +02:00
|
|
|
Settings::Settings( bool debugMode, QObject* parent )
|
2014-06-11 13:37:10 +02:00
|
|
|
: QObject( parent )
|
2014-07-17 17:44:16 +02:00
|
|
|
, m_debug( debugMode )
|
2014-06-11 13:37:10 +02:00
|
|
|
{
|
2014-08-05 18:18:57 +02:00
|
|
|
QFileInfo settingsFile( "/etc/calamares/settings.conf" );
|
|
|
|
if ( !settingsFile.exists() || !settingsFile.isReadable() )
|
|
|
|
settingsFile = QFileInfo( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) );
|
|
|
|
|
2014-07-03 18:00:40 +02:00
|
|
|
if ( debugMode )
|
2014-06-13 16:40:42 +02:00
|
|
|
{
|
|
|
|
QFileInfo localFile( QDir( QDir::currentPath() ).absoluteFilePath( "settings.conf" ) );
|
|
|
|
if ( localFile.exists() && localFile.isReadable() )
|
|
|
|
settingsFile.setFile( localFile.absoluteFilePath() );
|
|
|
|
}
|
|
|
|
QFile file( settingsFile.absoluteFilePath() );
|
|
|
|
|
|
|
|
if ( file.exists() && file.open( QFile::ReadOnly | QFile::Text ) )
|
2014-06-12 18:47:50 +02:00
|
|
|
{
|
|
|
|
QByteArray ba = file.readAll();
|
2014-06-13 16:40:42 +02:00
|
|
|
cDebug() << ba;
|
|
|
|
|
|
|
|
try
|
2014-06-12 18:47:50 +02:00
|
|
|
{
|
2014-06-13 16:40:42 +02:00
|
|
|
YAML::Node config = YAML::Load( ba.constData() );
|
|
|
|
Q_ASSERT( config.IsMap() );
|
2014-06-12 18:47:50 +02:00
|
|
|
|
2014-06-13 16:40:42 +02:00
|
|
|
QStringList rawPaths;
|
|
|
|
config[ "modules-search" ] >> rawPaths;
|
|
|
|
for ( int i = 0; i < rawPaths.length(); ++i )
|
2014-06-12 18:47:50 +02:00
|
|
|
{
|
2014-06-13 16:40:42 +02:00
|
|
|
if ( rawPaths[ i ] == "local" )
|
2014-06-24 13:35:21 +02:00
|
|
|
{
|
|
|
|
// If we're running in debug mode, we assume we might also be
|
|
|
|
// running from the build dir, so we add a maximum priority
|
|
|
|
// module search path in the build dir.
|
2014-07-03 18:00:40 +02:00
|
|
|
if ( debugMode )
|
2014-06-24 13:35:21 +02:00
|
|
|
{
|
|
|
|
QString buildDirModules = QDir::current().absolutePath() +
|
|
|
|
QDir::separator() + "src" +
|
|
|
|
QDir::separator() + "modules";
|
|
|
|
if ( QDir( buildDirModules ).exists() )
|
|
|
|
m_modulesSearchPaths.append( buildDirModules );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Install path is set in CalamaresAddPlugin.cmake
|
|
|
|
m_modulesSearchPaths.append( CalamaresUtils::systemLibDir().absolutePath() +
|
|
|
|
QDir::separator() + "calamares" +
|
|
|
|
QDir::separator() + "modules" );
|
|
|
|
}
|
2014-06-12 18:47:50 +02:00
|
|
|
else
|
|
|
|
{
|
2014-06-13 16:40:42 +02:00
|
|
|
QDir path( rawPaths[ i ] );
|
2014-06-12 18:47:50 +02:00
|
|
|
if ( path.exists() && path.isReadable() )
|
|
|
|
m_modulesSearchPaths.append( path.absolutePath() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 18:03:59 +02:00
|
|
|
config[ "prepare" ] >> m_modulesPrepareList;
|
|
|
|
config[ "install" ] >> m_modulesInstallList;
|
|
|
|
config[ "postinstall" ] >> m_modulesPostInstallList;
|
2014-06-12 18:47:50 +02:00
|
|
|
}
|
2014-06-18 18:05:04 +02:00
|
|
|
catch ( YAML::Exception& e )
|
2014-06-12 18:47:50 +02:00
|
|
|
{
|
2014-06-13 16:40:42 +02:00
|
|
|
cDebug() << "WARNING: YAML parser error " << e.what();
|
2014-06-12 18:47:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cDebug() << "WARNING: Cannot read " << file.fileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
s_instance = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList
|
2014-07-11 14:40:15 +02:00
|
|
|
Settings::modulesSearchPaths() const
|
2014-06-12 18:47:50 +02:00
|
|
|
{
|
|
|
|
return m_modulesSearchPaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList
|
2014-07-11 14:40:15 +02:00
|
|
|
Settings::modules( Phase phase ) const
|
2014-06-12 18:47:50 +02:00
|
|
|
{
|
2014-07-11 14:40:15 +02:00
|
|
|
switch ( phase )
|
|
|
|
{
|
|
|
|
case Prepare:
|
|
|
|
return m_modulesPrepareList;
|
|
|
|
case Install:
|
|
|
|
return m_modulesInstallList;
|
|
|
|
case PostInstall:
|
|
|
|
return m_modulesPostInstallList;
|
|
|
|
default:
|
|
|
|
return QStringList();
|
|
|
|
}
|
2014-06-12 18:47:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-17 17:44:16 +02:00
|
|
|
bool
|
|
|
|
Settings::debugMode() const
|
|
|
|
{
|
|
|
|
return m_debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-11 13:37:10 +02:00
|
|
|
}
|