| 90 | } |
| 91 | |
| 92 | void AppData::loadFromFile(const std::filesystem::path& path) |
| 93 | { |
| 94 | std::ifstream ifs(path); |
| 95 | if (!ifs.good()) return; |
| 96 | |
| 97 | auto readPathArray = [](const json& j) |
| 98 | { |
| 99 | std::vector<std::string> strings = j.get<std::vector<std::string>>(); |
| 100 | std::vector<std::filesystem::path> paths; |
| 101 | std::transform(strings.begin(), strings.end(), std::back_inserter(paths), [](const std::string& str) { return str; }); |
| 102 | return paths; |
| 103 | }; |
| 104 | |
| 105 | try |
| 106 | { |
| 107 | const json j = json::parse(ifs); |
| 108 | mRecentScripts = readPathArray(j[kRecentScripts]); |
| 109 | mRecentScenes = readPathArray(j[kRecentScenes]); |
| 110 | } |
| 111 | catch (const std::exception& e) |
| 112 | { |
| 113 | logWarning("Failed to parse Mogwai settings file '{}': {}", path, e.what()); |
| 114 | } |
| 115 | |
| 116 | removeNonExistingPaths(mRecentScripts); |
| 117 | removeNonExistingPaths(mRecentScenes); |
| 118 | } |
| 119 | |
| 120 | void AppData::saveToFile(const std::filesystem::path& path) |
| 121 | { |
nothing calls this directly
no test coverage detected