mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 10:55:46 -05:00
[libcalamares] Implement most of dumpYaml
- Write out bools, strings, lists and maps; this is enough to read and reproduce settings.conf - Fix infinite loop in writeIndent()
This commit is contained in:
parent
f72d6ca403
commit
e25deffa74
1 changed files with 43 additions and 3 deletions
|
@ -207,8 +207,47 @@ loadYaml(const QString& filename, bool* ok)
|
||||||
static void
|
static void
|
||||||
writeIndent( QFile& f, int indent )
|
writeIndent( QFile& f, int indent )
|
||||||
{
|
{
|
||||||
while ( indent > 0 )
|
while ( indent-- > 0 )
|
||||||
f.write( " " );
|
f.write( " " );
|
||||||
|
}
|
||||||
|
|
||||||
|
// forward declaration
|
||||||
|
static bool dumpYaml( QFile& f, const QVariantMap& map, int indent );
|
||||||
|
|
||||||
|
/// @brief Recursive helper to dump a single value
|
||||||
|
static void
|
||||||
|
dumpYamlElement( QFile& f, const QVariant& value, int indent )
|
||||||
|
{
|
||||||
|
if ( value.type() == QVariant::Type::Bool )
|
||||||
|
f.write( value.toBool() ? "true" : "false" );
|
||||||
|
else if ( value.type() == QVariant::Type::String )
|
||||||
|
{
|
||||||
|
static const char quote[] = "\"";
|
||||||
|
f.write( quote );
|
||||||
|
f.write( value.toString().toUtf8() );
|
||||||
|
f.write( quote );
|
||||||
|
}
|
||||||
|
else if ( value.type() == QVariant::Type::List )
|
||||||
|
{
|
||||||
|
int c = 0;
|
||||||
|
for ( const auto& it : value.toList() )
|
||||||
|
{
|
||||||
|
f.write( "\n" );
|
||||||
|
writeIndent( f, indent+1 );
|
||||||
|
f.write( "- " );
|
||||||
|
dumpYamlElement( f, it, indent+1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( value.type() == QVariant::Type::Map )
|
||||||
|
{
|
||||||
|
dumpYaml( f, value.toMap(), indent+1 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
f.write( "<" );
|
||||||
|
f.write( value.typeName() );
|
||||||
|
f.write( ">" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Recursive helper to dump @p map to file
|
/// @brief Recursive helper to dump @p map to file
|
||||||
|
@ -217,8 +256,9 @@ dumpYaml( QFile& f, const QVariantMap& map, int indent )
|
||||||
{
|
{
|
||||||
for ( auto it = map.cbegin(); it != map.cend(); ++it )
|
for ( auto it = map.cbegin(); it != map.cend(); ++it )
|
||||||
{
|
{
|
||||||
writeIndent( f, indent );
|
|
||||||
f.write( it.key().toUtf8() );
|
f.write( it.key().toUtf8() );
|
||||||
|
f.write( ": " );
|
||||||
|
dumpYamlElement( f, it.value(), indent );
|
||||||
f.write( "\n" );
|
f.write( "\n" );
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue