[calamares] Refactor searching for branding descriptor

main
Adriaan de Groot 7 years ago
parent 22ee24a5ad
commit b0e55c059a

@ -172,6 +172,27 @@ settingsFileCandidates( bool assumeBuilddir )
} }
static QStringList
brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename )
{
QStringList brandingPaths;
if ( CalamaresUtils::isAppDataDirOverridden() )
brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename );
else
{
if ( assumeBuilddir )
{
brandingPaths << ( QDir::currentPath() + QStringLiteral( "/src/" ) + brandingFilename );
brandingPaths << QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" )
.absoluteFilePath( brandingFilename );
brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename);
}
}
return brandingPaths;
}
void void
CalamaresApplication::initQmlPath() CalamaresApplication::initQmlPath()
{ {
@ -250,59 +271,32 @@ CalamaresApplication::initBranding()
::exit( EXIT_FAILURE ); ::exit( EXIT_FAILURE );
} }
QString brandingDescriptorSubpath = QString( "branding/%1/branding.desc" ) QString brandingDescriptorSubpath = QString( "branding/%1/branding.desc" ).arg( brandingComponentName );
.arg( brandingComponentName ); QStringList brandingFileCandidatesByPriority = brandingFileCandidates( isDebug(), brandingDescriptorSubpath);
QFileInfo brandingFile; QFileInfo brandingFile;
if ( CalamaresUtils::isAppDataDirOverridden() ) bool found = false;
foreach ( const QString& path, brandingFileCandidatesByPriority )
{ {
brandingFile = QFileInfo( CalamaresUtils::appDataDir() QFileInfo pathFi( path );
.absoluteFilePath( brandingDescriptorSubpath ) ); if ( pathFi.exists() && pathFi.isReadable() )
if ( !brandingFile.exists() || !brandingFile.isReadable() )
{ {
cError() << "FATAL: explicitly configured application data directory" brandingFile = pathFi;
<< CalamaresUtils::appDataDir().absolutePath() found = true;
<< "does not contain a valid branding component descriptor at" break;
<< brandingFile.absoluteFilePath()
<< "\nCowardly refusing to continue startup without branding.";
::exit( EXIT_FAILURE );
} }
} }
else
{
QStringList brandingFileCandidatesByPriority;
if ( isDebug() )
{
brandingFileCandidatesByPriority.append(
QDir::currentPath() +
QDir::separator() +
"src" +
QDir::separator() +
brandingDescriptorSubpath );
}
brandingFileCandidatesByPriority.append( QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" )
.absoluteFilePath( brandingDescriptorSubpath ) );
brandingFileCandidatesByPriority.append( CalamaresUtils::appDataDir()
.absoluteFilePath( brandingDescriptorSubpath ) );
foreach ( const QString& path, brandingFileCandidatesByPriority )
{
QFileInfo pathFi( path );
if ( pathFi.exists() && pathFi.isReadable() )
{
brandingFile = pathFi;
break;
}
}
if ( !brandingFile.exists() || !brandingFile.isReadable() ) if ( !found || !brandingFile.exists() || !brandingFile.isReadable() )
{ {
cError() << "FATAL: none of the expected branding descriptor file paths (" cError() << "Cowardly refusing to continue startup without branding."
<< brandingFileCandidatesByPriority.join( ", " ) << Logger::DebugList( brandingFileCandidatesByPriority );
<< ") contain a valid branding.desc file." if ( CalamaresUtils::isAppDataDirOverridden() )
<< "\nCowardly refusing to continue startup without branding."; cError() << "FATAL: explicitly configured application data directory is missing" << brandingComponentName;
::exit( EXIT_FAILURE ); else
} cError() << "FATAL: none of the expected branding descriptor file paths exist.";
::exit( EXIT_FAILURE );
} }
new Calamares::Branding( brandingFile.absoluteFilePath(), this ); new Calamares::Branding( brandingFile.absoluteFilePath(), this );

Loading…
Cancel
Save