[libcalamares] Expand GlobalStorage with load()
- Counterpart to save(), for JSON-style dumps
This commit is contained in:
parent
20cf0c8f3d
commit
c19ce26e5f
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Yaml.h"
|
#include "utils/Yaml.h"
|
||||||
|
#include "utils/Units.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@ -37,6 +38,8 @@
|
|||||||
namespace bp = boost::python;
|
namespace bp = boost::python;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using CalamaresUtils::operator""_MiB;
|
||||||
|
|
||||||
namespace Calamares {
|
namespace Calamares {
|
||||||
|
|
||||||
GlobalStorage::GlobalStorage()
|
GlobalStorage::GlobalStorage()
|
||||||
@ -110,6 +113,30 @@ GlobalStorage::save(const QString& filename)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
GlobalStorage::load( const QString& filename )
|
||||||
|
{
|
||||||
|
QFile f( filename );
|
||||||
|
if ( !f.open( QFile::ReadOnly ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QJsonParseError e;
|
||||||
|
QJsonDocument d = QJsonDocument::fromJson( f.read( 1_MiB ), &e );
|
||||||
|
if ( d.isNull() )
|
||||||
|
cWarning() << filename << e.errorString();
|
||||||
|
else if ( !d.isObject() )
|
||||||
|
cWarning() << filename << "Not suitable JSON.";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto map = d.toVariant().toMap();
|
||||||
|
for( auto i = map.constBegin() ; i != map.constEnd() ; ++i )
|
||||||
|
{
|
||||||
|
insert( i.key(), *i );
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalStorage::saveYaml( const QString& filename )
|
GlobalStorage::saveYaml( const QString& filename )
|
||||||
|
@ -70,6 +70,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool save( const QString& filename );
|
bool save( const QString& filename );
|
||||||
|
|
||||||
|
/** @brief Adds the keys from the given JSON file
|
||||||
|
*
|
||||||
|
* No tidying, sanitization, or censoring is done.
|
||||||
|
* The JSON file is read and each key is added as a value to
|
||||||
|
* the global storage.
|
||||||
|
*/
|
||||||
|
bool load( const QString& filename );
|
||||||
|
|
||||||
/** @brief write as YAML to the given filename
|
/** @brief write as YAML to the given filename
|
||||||
*
|
*
|
||||||
* See also save(), above.
|
* See also save(), above.
|
||||||
|
Loading…
Reference in New Issue
Block a user