diff options
Diffstat (limited to 'src/settings.h.in')
-rw-r--r-- | src/settings.h.in | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/settings.h.in b/src/settings.h.in index 88fbcf5..605288e 100644 --- a/src/settings.h.in +++ b/src/settings.h.in @@ -4,29 +4,28 @@ #include <configuration.h> #include <fstream> -inline const std::string init_conf(const std::string &path) +inline auto init_conf(const std::string &path) { - auto value_map = std::make_unique<Configuration, std::initializer_list<std::pair<std::string, conf_value_t>>>({ + 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__ }); - const std::string cfgpath = [&]() { - if(path.empty()) - return value_map->value<std::string>("poi.cfg.path").value(); - - auto p = path; - if(p.front() == '~') - p.replace(0, 1, QStandardPaths::writableLocation(QStandardPaths::HomeLocation).toStdString()); - return p; - }(); + 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(cfgpath, std::fstream::in); + fs.open(conf.path, std::fstream::in); if(fs.is_open()) { - value_map->read(fs); + conf.ptr->read(fs); fs.close(); } - Configuration::move_global(std::move(value_map)); - return cfgpath; + return conf; } |