[libcalamaresui] Refactor finding config file name

- check for broken custom instances earlier in the loop
 - make free function for finding the config file name
main
Adriaan de Groot 5 years ago
parent a403f1e851
commit 8fbe676280

@ -174,6 +174,33 @@ findCustomInstance( const Settings::InstanceDescriptionList& customInstances, co
return -1;
}
/** @brief Returns the config file name for the fiven @p instanceKey
*
* Custom instances have custom config files, non-custom ones
* have a <modulename>.conf file. Returns an empty QString on
* errors.
*/
static QString
getConfigFileName( const Settings::InstanceDescriptionList& customInstances,
const ModuleSystem::InstanceKey& instanceKey )
{
if ( instanceKey.isCustom() )
{
int found = findCustomInstance( customInstances, instanceKey );
if ( found < 0 )
{
// This should already have been checked and failed the module already
return QString();
}
return customInstances[ found ].value( "config" );
}
else
{
return QString( "%1.conf" ).arg( instanceKey.module() );
}
}
void
ModuleManager::loadModules()
@ -199,38 +226,28 @@ ModuleManager::loadModules()
failedModules.append( moduleEntry );
continue;
}
if ( !m_availableDescriptorsByModuleName.contains( instanceKey.module() )
|| m_availableDescriptorsByModuleName.value( instanceKey.module() ).isEmpty() )
{
cError() << "Module" << instanceKey.toString() << "not found in module search paths."
<< Logger::DebugList( m_paths );
failedModules.append( instanceKey.toString() );
continue;
}
QString configFileName;
if ( instanceKey.isCustom() )
{
int found = findCustomInstance( customInstances, instanceKey );
if ( found > -1 )
{
configFileName = customInstances[ found ].value( "config" );
}
else //ought to be a custom instance, but cannot find instance entry
if ( found < 0 )
{
cError() << "Custom instance" << moduleEntry << "not found in custom instances section.";
failedModules.append( moduleEntry );
continue;
}
}
else
if ( !m_availableDescriptorsByModuleName.contains( instanceKey.module() )
|| m_availableDescriptorsByModuleName.value( instanceKey.module() ).isEmpty() )
{
configFileName = QString( "%1.conf" ).arg( instanceKey.module() );
cError() << "Module" << instanceKey.toString() << "not found in module search paths."
<< Logger::DebugList( m_paths );
failedModules.append( instanceKey.toString() );
continue;
}
QString configFileName = getConfigFileName( customInstances, instanceKey );
// So now we can assume that the module entry is at least valid,
// that we have a descriptor on hand (and therefore that the
// module exists), and that the instance is either default or

Loading…
Cancel
Save