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

Loading…
Cancel
Save