| 17 | } |
| 18 | |
| 19 | void ConfigManager::load(json def, bool lock) { |
| 20 | if (lock) { mtx.lock(); } |
| 21 | if (path == "") { |
| 22 | spdlog::error("Config manager tried to load file with no path specified"); |
| 23 | return; |
| 24 | } |
| 25 | if (!std::filesystem::exists(path)) { |
| 26 | spdlog::warn("Config file '{0}' does not exist, creating it", path); |
| 27 | conf = def; |
| 28 | save(false); |
| 29 | } |
| 30 | if (!std::filesystem::is_regular_file(path)) { |
| 31 | spdlog::error("Config file '{0}' isn't a file", path); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | try { |
| 36 | std::ifstream file(path.c_str()); |
| 37 | file >> conf; |
| 38 | file.close(); |
| 39 | } |
| 40 | catch (std::exception e) { |
| 41 | spdlog::error("Config file '{0}' is corrupted, resetting it", path); |
| 42 | conf = def; |
| 43 | save(false); |
| 44 | } |
| 45 | if (lock) { mtx.unlock(); } |
| 46 | } |
| 47 | |
| 48 | void ConfigManager::save(bool lock) { |
| 49 | if (lock) { mtx.lock(); } |
no test coverage detected