Config files are YAML, not JSON. We depend on yaml-cpp for parsing.
This commit is contained in:
parent
80640e4bea
commit
05d355f21f
@ -5,6 +5,7 @@ set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" )
|
||||
cmake_policy( SET CMP0023 OLD )
|
||||
|
||||
find_package( Qt5 5.3.0 CONFIG REQUIRED Core Gui Widgets LinguistTools )
|
||||
find_package( YamlCpp 0.5.1 REQUIRED )
|
||||
|
||||
###
|
||||
### Calamares application info
|
||||
|
@ -53,6 +53,7 @@ target_link_libraries( calamares_bin
|
||||
${CALAMARES_LIBRARIES}
|
||||
Qt5Core
|
||||
Qt5Widgets
|
||||
yaml-cpp
|
||||
)
|
||||
|
||||
install( TARGETS calamares_bin
|
||||
|
@ -4,6 +4,7 @@
|
||||
#define CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
|
||||
#define CMAKE_INSTALL_FULL_LIBEXECDIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}"
|
||||
#define CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}"
|
||||
#define CMAKE_INSTALL_FULL_DATADIR "${CMAKE_INSTALL_FULL_DATADIR}"
|
||||
|
||||
//cmakedefines for CMake variables (e.g. for optdepends) go here
|
||||
|
||||
|
@ -17,14 +17,26 @@
|
||||
*/
|
||||
|
||||
#include "Settings.h"
|
||||
|
||||
#include "CalamaresApplication.h"
|
||||
#include "utils/CalamaresUtils.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
|
||||
void
|
||||
operator>>( const YAML::Node& node, QStringList& v )
|
||||
{
|
||||
for ( int i = 0; i < node.size(); ++i )
|
||||
{
|
||||
v.append( QString::fromStdString( node[ i ].as< std::string >() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
@ -41,55 +53,45 @@ Settings::instance()
|
||||
Settings::Settings( QObject* parent )
|
||||
: QObject( parent )
|
||||
{
|
||||
QFile file( CalamaresUtils::appDataDir().absoluteFilePath( "settings.json" ) );
|
||||
if ( file.exists() && file.canReadLine() )
|
||||
QFileInfo settingsFile( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) );
|
||||
if ( APP->isDebug() )
|
||||
{
|
||||
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 ) )
|
||||
{
|
||||
QByteArray ba = file.readAll();
|
||||
QJsonParseError* err = 0;
|
||||
QJsonDocument document = QJsonDocument::fromJson( ba, err );
|
||||
if ( !err && !document.isNull() && !document.isEmpty() )
|
||||
cDebug() << ba;
|
||||
|
||||
try
|
||||
{
|
||||
QJsonObject json = document.object();
|
||||
YAML::Node config = YAML::Load( ba.constData() );
|
||||
Q_ASSERT( config.IsMap() );
|
||||
|
||||
foreach ( const QJsonValue& val, json[ "modules-search" ].toArray() )
|
||||
QStringList rawPaths;
|
||||
config[ "modules-search" ] >> rawPaths;
|
||||
for ( int i = 0; i < rawPaths.length(); ++i )
|
||||
{
|
||||
if ( !val.isString() || val.toString().isEmpty() )
|
||||
continue;
|
||||
|
||||
QString entry = val.toString();
|
||||
|
||||
if ( entry == "local" )
|
||||
{
|
||||
if ( rawPaths[ i ] == "local" )
|
||||
m_modulesSearchPaths.append( CalamaresUtils::appDataDir().absolutePath() + QDir::separator() + "modules" );
|
||||
}
|
||||
else
|
||||
{
|
||||
QDir path( entry );
|
||||
QDir path( rawPaths[ i ] );
|
||||
if ( path.exists() && path.isReadable() )
|
||||
m_modulesSearchPaths.append( path.absolutePath() );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( const QJsonValue& val, json[ "modules-prepare" ].toArray() )
|
||||
{
|
||||
if ( !val.isString() || val.toString().isEmpty() )
|
||||
continue;
|
||||
|
||||
m_viewModulesPrepareList.append( val.toString() );
|
||||
}
|
||||
|
||||
foreach ( const QJsonValue& val, json[ "modules-postinstall" ].toArray() )
|
||||
{
|
||||
if ( !val.isString() || val.toString().isEmpty() )
|
||||
continue;
|
||||
|
||||
m_viewModulesPostInstallList.append( val.toString() );
|
||||
}
|
||||
config[ "modules-prepare" ] >> m_viewModulesPrepareList;
|
||||
config[ "modules-postinstall" ] >> m_viewModulesPostInstallList;
|
||||
}
|
||||
else
|
||||
catch( YAML::Exception& e )
|
||||
{
|
||||
cDebug() << "WARNING: Invalid document " << file.fileName()
|
||||
<< " error: " << err->errorString();
|
||||
cDebug() << "WARNING: YAML parser error " << e.what();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include "CalamaresUtils.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
@ -35,14 +37,11 @@ namespace CalamaresUtils
|
||||
QDir
|
||||
appDataDir()
|
||||
{
|
||||
QString path;
|
||||
path = QDir::home().filePath( ".local/share" );
|
||||
QDir path( CMAKE_INSTALL_FULL_DATADIR );
|
||||
if ( !path.exists() || !path.isReadable() )
|
||||
path.mkpath( path.absolutePath() );
|
||||
|
||||
path += "/" + QCoreApplication::organizationName();
|
||||
QDir d( path );
|
||||
d.mkpath( path );
|
||||
|
||||
return d;
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,8 +50,8 @@ log( const char *msg, unsigned int debugLevel, bool toDisk = true )
|
||||
{
|
||||
if ( s_threshold < 0 )
|
||||
{
|
||||
if ( qApp->arguments().contains( "--verbose" ) ||
|
||||
qApp->arguments().contains( "-v" ) )
|
||||
if ( qApp->arguments().contains( "--debug" ) ||
|
||||
qApp->arguments().contains( "-d" ) )
|
||||
s_threshold = LOGVERBOSE;
|
||||
else
|
||||
#ifdef QT_NO_DEBUG
|
||||
|
Loading…
Reference in New Issue
Block a user