blob: 9f383f83e21eba0f68f671b1e6aaaa726c74204c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
/* SPDX-License-Identifier: GPL-2.0-only */
#include <QFile>
#include <QString>
#include <QTextStream>
#include "Configuration.h"
#include "Util.h"
QMap<QString, QString> Configuration::fromFile(const QString &curr_path)
{
QFile curr_file(curr_path);
if ( !curr_file.open(QFile::ReadOnly)
|| !curr_file.isReadable()
|| curr_file.atEnd()) {
return {};
}
auto result = Util::parseParameters(curr_file);
curr_file.close();
return result;
}
bool Configuration::toFile(const QString &curr_path, const Parameters ¶ms)
{
QFile output(curr_path);
if(!output.open(QFile::WriteOnly|QFile::Truncate)){
return false;
}
QTextStream outStream(&output);
for(auto it = params.begin(); it != params.end(); ++it){
outStream << it.key() << " = " << it.value() << "\n";
}
output.close();
return true;
}
|