| 235 | |
| 236 | |
| 237 | void Manager::saveAutosave() { |
| 238 | std::string patchPath = system::join(autosavePath, "patch.json"); |
| 239 | INFO("Saving autosave %s", patchPath.c_str()); |
| 240 | json_t* rootJ = toJson(); |
| 241 | if (!rootJ) |
| 242 | return; |
| 243 | DEFER({json_decref(rootJ);}); |
| 244 | |
| 245 | // Write to temporary path and then rename it to the correct path |
| 246 | system::createDirectories(autosavePath); |
| 247 | std::string tmpPath = patchPath + ".tmp"; |
| 248 | FILE* file = std::fopen(tmpPath.c_str(), "w"); |
| 249 | if (!file) { |
| 250 | // Fail silently |
| 251 | return; |
| 252 | } |
| 253 | |
| 254 | json_dumpf(rootJ, file, JSON_INDENT(2)); |
| 255 | std::fclose(file); |
| 256 | system::rename(tmpPath, patchPath); |
| 257 | } |
| 258 | |
| 259 | |
| 260 | void Manager::clearAutosave() { |