| 582 | } |
| 583 | |
| 584 | void save(std::string path) { |
| 585 | if (path.empty()) |
| 586 | path = settingsPath; |
| 587 | |
| 588 | INFO("Saving settings %s", path.c_str()); |
| 589 | json_t* rootJ = toJson(); |
| 590 | if (!rootJ) |
| 591 | return; |
| 592 | DEFER({json_decref(rootJ);}); |
| 593 | |
| 594 | std::string tmpPath = path + ".tmp"; |
| 595 | FILE* file = std::fopen(tmpPath.c_str(), "w"); |
| 596 | if (!file) |
| 597 | return; |
| 598 | |
| 599 | json_dumpf(rootJ, file, JSON_INDENT(2)); |
| 600 | std::fclose(file); |
| 601 | system::rename(tmpPath, path); |
| 602 | } |
| 603 | |
| 604 | void load(std::string path) { |
| 605 | if (path.empty()) |
no test coverage detected