| 99 | } |
| 100 | |
| 101 | static auto get_config_map() |
| 102 | { |
| 103 | static bool cached = false; |
| 104 | static std::unordered_map<std::string, std::string> map; |
| 105 | |
| 106 | if (!cached) |
| 107 | { |
| 108 | auto path = config::loader_dir() / "config"; |
| 109 | std::ifstream file(path); |
| 110 | |
| 111 | if (file.is_open()) |
| 112 | { |
| 113 | std::string line; |
| 114 | while (std::getline(file, line)) |
| 115 | { |
| 116 | // ignore empty line or comment |
| 117 | if (line.empty() || line[0] == ';' || line[0] == '#') |
| 118 | continue; |
| 119 | |
| 120 | size_t pos = line.find('='); |
| 121 | if (pos != std::string::npos) |
| 122 | { |
| 123 | std::string key = line.substr(0, pos); |
| 124 | std::string value = line.substr(pos + 1); |
| 125 | |
| 126 | trim_tring(key); |
| 127 | trim_tring(value); |
| 128 | |
| 129 | map[key] = value; |
| 130 | } |
| 131 | } |
| 132 | file.close(); |
| 133 | } |
| 134 | |
| 135 | cached = true; |
| 136 | } |
| 137 | |
| 138 | return map; |
| 139 | } |
| 140 | |
| 141 | static std::string get_config_value(const char *key, const char *fallback) |
| 142 | { |
no test coverage detected