Fix settings.conf loading.
This commit is contained in:
parent
277d5d4cc1
commit
5400afa540
@ -31,6 +31,9 @@
|
||||
#include "viewpages/ViewStep.h"
|
||||
#include "ViewManager.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
|
||||
CalamaresApplication::CalamaresApplication( int& argc, char *argv[] )
|
||||
: QApplication( argc, argv )
|
||||
@ -130,7 +133,54 @@ CalamaresApplication::startPhase( Calamares::Phase phase )
|
||||
void
|
||||
CalamaresApplication::initSettings()
|
||||
{
|
||||
new Calamares::Settings( isDebug(), this );
|
||||
QFileInfo settingsFile;
|
||||
if ( CalamaresUtils::isAppDataDirOverridden() )
|
||||
{
|
||||
settingsFile = QFileInfo( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) );
|
||||
if ( !settingsFile.exists() || !settingsFile.isReadable() )
|
||||
{
|
||||
cLog() << "FATAL ERROR: explicitly configured application data directory"
|
||||
<< CalamaresUtils::appDataDir().absolutePath()
|
||||
<< "does not contain a valid settings.conf file."
|
||||
<< "\nCowardly refusing to continue startup without settings.";
|
||||
::exit( EXIT_FAILURE );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QStringList settingsFileCandidatesByPriority;
|
||||
if ( isDebug() )
|
||||
{
|
||||
settingsFileCandidatesByPriority.append(
|
||||
QDir::currentPath() +
|
||||
QDir::separator() +
|
||||
"settings.conf" );
|
||||
}
|
||||
settingsFileCandidatesByPriority.append( "/etc/calamares/settings.conf" );
|
||||
settingsFileCandidatesByPriority.append( CalamaresUtils::appDataDir()
|
||||
.absoluteFilePath( "settings.conf" ) );
|
||||
|
||||
foreach ( const QString& path, settingsFileCandidatesByPriority )
|
||||
{
|
||||
QFileInfo pathFi( path );
|
||||
if ( pathFi.exists() && pathFi.isReadable() )
|
||||
{
|
||||
settingsFile = pathFi;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !settingsFile.exists() || !settingsFile.isReadable() )
|
||||
{
|
||||
cLog() << "FATAL ERROR: none of the expected configuration file paths ("
|
||||
<< settingsFileCandidatesByPriority.join( ", " )
|
||||
<< ") contain a valid settings.conf file."
|
||||
<< "\nCowardly refusing to continue startup without settings.";
|
||||
::exit( EXIT_FAILURE );
|
||||
}
|
||||
}
|
||||
|
||||
new Calamares::Settings( settingsFile.absoluteFilePath(), isDebug(), this );
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,7 +41,7 @@ main( int argc, char *argv[] )
|
||||
parser.addOption( debugOption );
|
||||
|
||||
QCommandLineOption configOption( QStringList() << "c" << "config",
|
||||
"Configuration dir to use, for testing purposes.", "config" );
|
||||
"Configuration directory to use, for testing purposes.", "config" );
|
||||
parser.addOption( configOption );
|
||||
|
||||
parser.process( a );
|
||||
|
@ -42,6 +42,7 @@ namespace CalamaresUtils
|
||||
{
|
||||
|
||||
static QDir s_appDataDir( CMAKE_INSTALL_FULL_DATADIR );
|
||||
static bool s_isAppDataDirOverridden = false;
|
||||
|
||||
static bool
|
||||
isWritableDir( const QDir& dir )
|
||||
@ -76,6 +77,14 @@ void
|
||||
setAppDataDir( const QDir& dir )
|
||||
{
|
||||
s_appDataDir = dir;
|
||||
s_isAppDataDirOverridden = true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
isAppDataDirOverridden()
|
||||
{
|
||||
return s_isAppDataDirOverridden;
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,6 +40,7 @@ namespace CalamaresUtils
|
||||
* Override app data dir. Only for testing purposes.
|
||||
*/
|
||||
DLLEXPORT void setAppDataDir( const QDir& dir );
|
||||
DLLEXPORT bool isAppDataDirOverridden();
|
||||
}
|
||||
|
||||
#endif // CALAMARESUTILS_H
|
||||
|
@ -40,26 +40,17 @@ Settings::instance()
|
||||
}
|
||||
|
||||
|
||||
Settings::Settings( bool debugMode, QObject* parent )
|
||||
Settings::Settings( const QString& settingsFilePath,
|
||||
bool debugMode,
|
||||
QObject* parent )
|
||||
: QObject( parent )
|
||||
, m_debug( debugMode )
|
||||
{
|
||||
QFileInfo settingsFile( "/etc/calamares/settings.conf" );
|
||||
if ( !settingsFile.exists() || !settingsFile.isReadable() )
|
||||
settingsFile = QFileInfo( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) );
|
||||
|
||||
if ( debugMode )
|
||||
{
|
||||
QFileInfo localFile( QDir( QDir::currentPath() ).absoluteFilePath( "settings.conf" ) );
|
||||
if ( localFile.exists() && localFile.isReadable() )
|
||||
settingsFile.setFile( localFile.absoluteFilePath() );
|
||||
}
|
||||
QFile file( settingsFile.absoluteFilePath() );
|
||||
|
||||
cDebug() << "Using Calamares settings file at" << settingsFilePath;
|
||||
QFile file( settingsFilePath );
|
||||
if ( file.exists() && file.open( QFile::ReadOnly | QFile::Text ) )
|
||||
{
|
||||
QByteArray ba = file.readAll();
|
||||
cDebug() << ba;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -33,7 +33,9 @@ class UIDLLEXPORT Settings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Settings( bool debugMode, QObject *parent = nullptr );
|
||||
explicit Settings( const QString& settingsFilePath,
|
||||
bool debugMode,
|
||||
QObject *parent = nullptr );
|
||||
|
||||
static Settings* instance();
|
||||
//TODO: load from JSON then emit ready
|
||||
|
Loading…
Reference in New Issue
Block a user