| 522 | } |
| 523 | |
| 524 | static void autosave() |
| 525 | { |
| 526 | // Format filename |
| 527 | auto time = std::time(nullptr); |
| 528 | auto localTime = std::localtime(&time); |
| 529 | char filename[64]; |
| 530 | snprintf( |
| 531 | filename, |
| 532 | sizeof(filename), |
| 533 | "autosave_%04u-%02u-%02u_%02u-%02u-%02u%s", |
| 534 | localTime->tm_year + 1900, |
| 535 | localTime->tm_mon + 1, |
| 536 | localTime->tm_mday, |
| 537 | localTime->tm_hour, |
| 538 | localTime->tm_min, |
| 539 | localTime->tm_sec, |
| 540 | S5::extensionSV5); |
| 541 | |
| 542 | try |
| 543 | { |
| 544 | auto autosaveDirectory = Environment::getPath(Environment::PathId::autosave); |
| 545 | Environment::autoCreateDirectory(autosaveDirectory); |
| 546 | |
| 547 | auto autosaveFullPath = autosaveDirectory / filename; |
| 548 | |
| 549 | auto autosaveFullPath8 = autosaveFullPath.u8string(); |
| 550 | Logging::info("Autosaving game to {}", autosaveFullPath8.c_str()); |
| 551 | S5::exportGameStateToFile(autosaveFullPath, S5::SaveFlags::isAutosave | S5::SaveFlags::noWindowClose); |
| 552 | } |
| 553 | catch (const std::exception& e) |
| 554 | { |
| 555 | Logging::error("Unable to autosave game: {}", e.what()); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | static void autosaveCheck() |
| 560 | { |
no test coverage detected