| 308 | } |
| 309 | |
| 310 | common_presets common_preset_context::load_from_ini(const std::string & path, common_preset & global) const { |
| 311 | common_presets out; |
| 312 | auto ini_data = parse_ini_from_file(path); |
| 313 | |
| 314 | for (auto section : ini_data) { |
| 315 | common_preset preset; |
| 316 | if (section.first.empty()) { |
| 317 | preset.name = COMMON_PRESET_DEFAULT_NAME; |
| 318 | } else { |
| 319 | preset.name = section.first; |
| 320 | } |
| 321 | LOG_DBG("loading preset: %s\n", preset.name.c_str()); |
| 322 | for (const auto & [key, value] : section.second) { |
| 323 | if (key == "version") { |
| 324 | // skip version key (reserved for future use) |
| 325 | continue; |
| 326 | } |
| 327 | |
| 328 | LOG_DBG("option: %s = %s\n", key.c_str(), value.c_str()); |
| 329 | if (filter_allowed_keys && allowed_keys.find(key) == allowed_keys.end()) { |
| 330 | throw std::runtime_error(string_format( |
| 331 | "option '%s' is not allowed in remote presets", |
| 332 | key.c_str() |
| 333 | )); |
| 334 | } |
| 335 | if (key_to_opt.find(key) != key_to_opt.end()) { |
| 336 | const auto & opt = key_to_opt.at(key); |
| 337 | if (is_bool_arg(opt)) { |
| 338 | preset.options[opt] = parse_bool_arg(opt, key, value); |
| 339 | } else { |
| 340 | preset.options[opt] = value; |
| 341 | } |
| 342 | LOG_DBG("accepted option: %s = %s\n", key.c_str(), preset.options[opt].c_str()); |
| 343 | } else { |
| 344 | throw std::runtime_error(string_format( |
| 345 | "option '%s' not recognized in preset '%s'", |
| 346 | key.c_str(), preset.name.c_str() |
| 347 | )); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | if (preset.name == "*") { |
| 352 | // handle global preset |
| 353 | global = preset; |
| 354 | } else { |
| 355 | out[preset.name] = preset; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | return out; |
| 360 | } |
| 361 | |
| 362 | common_presets common_preset_context::load_from_cache() const { |
| 363 | common_presets out; |
no test coverage detected