| 120 | namespace cfg_details { |
| 121 | |
| 122 | TStatus LoadConfig(ProgramConfig& cfg) { |
| 123 | try { |
| 124 | |
| 125 | auto p = ProgramConfig::GetPath_Conf(); |
| 126 | if (!std::filesystem::is_regular_file(p)) { |
| 127 | // конфиг файла еще нет - считаем что загружены конфигом по-умолчанию. |
| 128 | RETURN_SUCCESS; |
| 129 | } |
| 130 | |
| 131 | std::ifstream ifs(p, std::ios::binary); |
| 132 | |
| 133 | json data = json::parse(ifs, nullptr, true, true); |
| 134 | data.get_to(cfg); |
| 135 | |
| 136 | const auto& arr = data["hotkeys"]; |
| 137 | |
| 138 | if (arr.is_object()) { |
| 139 | for (auto& elem : cfg.hotkeysList) { |
| 140 | auto key = HotKeyTypeName(elem.hkId); |
| 141 | if (key.empty()) continue; |
| 142 | auto it = arr.find(key); |
| 143 | if (it != arr.end()) { |
| 144 | elem.keys = it.value(); |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | cfg.NormalizePaths(); |
| 150 | |
| 151 | if (cfg.force_DbgMode) { |
| 152 | SetLogLevel_print_info(cfg.logLevel); |
| 153 | } |
| 154 | |
| 155 | |
| 156 | } |
| 157 | catch (std::exception& e) { |
| 158 | LOG_ANY("error load={}", e.what()); |
| 159 | return SW_ERR_JSON; |
| 160 | } |
| 161 | |
| 162 | |
| 163 | RETURN_SUCCESS; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | TStatus Save_conf(const ProgramConfig& gui) { |
no test coverage detected