| 602 | } |
| 603 | |
| 604 | void load(std::string path) { |
| 605 | if (path.empty()) |
| 606 | path = settingsPath; |
| 607 | |
| 608 | INFO("Loading settings %s", path.c_str()); |
| 609 | FILE* file = std::fopen(path.c_str(), "r"); |
| 610 | if (!file) |
| 611 | return; |
| 612 | DEFER({std::fclose(file);}); |
| 613 | |
| 614 | json_error_t error; |
| 615 | json_t* rootJ = json_loadf(file, 0, &error); |
| 616 | if (!rootJ) |
| 617 | throw Exception("Settings file has invalid JSON at %d:%d %s", error.line, error.column, error.text); |
| 618 | DEFER({json_decref(rootJ);}); |
| 619 | |
| 620 | fromJson(rootJ); |
| 621 | } |
| 622 | |
| 623 | |
| 624 | } // namespace settings |
no test coverage detected