#include "settings.h" #include #include #include #include #include #include #include namespace settings { std::string getString(const std::string& key) { cfg_opt_t opts[] = { CFG_STR("weapons", "/usr/share/dmtool/weapons/", CFGF_NONE), CFG_STR("armor", "/usr/share/dmtool/armor/", CFGF_NONE), CFG_STR("spells", "/usr/share/dmtool/spells/", CFGF_NONE), CFG_STR("creatures", "/usr/share/dmtool/creatures/", CFGF_NONE), CFG_STR("savedir", NULL, CFGF_NONE), CFG_STR("editor", "vi", CFGF_NONE), CFG_END() }; cfg_t *cfg = cfg_init(opts, CFGF_IGNORE_UNKNOWN); if(cfg_parse(cfg, "/etc/dmtool.conf") == CFG_PARSE_ERROR) { throw std::runtime_error("Configuration file /etc/dmtool.conf could not be read: " + std::string(strerror(errno))); } try { std::string result(cfg_getstr(cfg, key.c_str())); cfg_free(cfg); return result; } catch(std::exception& e) { throw std::runtime_error("Cannot find key in configuration file: \"" + key + "\""); } } const std::vector objectTypes {"weapons", "armor", "spells"}; }