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