blob: 605288ef7fd8b8396230e3933e3e3541e2abc4a2 (
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
|
#pragma once
#include <QStandardPaths>
#include <configuration.h>
#include <fstream>
inline auto init_conf(const std::string &path)
{
struct {
std::string path;
std::unique_ptr<Configuration> ptr;
} conf;
conf.ptr = std::make_unique<Configuration, std::initializer_list<std::pair<std::string, conf_value_t>>>({
@__DEFAULT_CFG__
});
conf.path = path.empty() ? conf.ptr->value<std::string>("poi.cfg.path").value() : path;
if(conf.path.front() == '~') {
conf.path.replace(0, 1, QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString());
};
std::fstream fs;
fs.open(conf.path, std::fstream::in);
if(fs.is_open()) {
conf.ptr->read(fs);
fs.close();
}
return conf;
}
|