MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / autosaveClean

Function autosaveClean

src/OpenLoco/src/OpenLoco.cpp:478–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476 }
477
478 static void autosaveClean()
479 {
480 try
481 {
482 auto autosaveDirectory = Environment::getPath(Environment::PathId::autosave);
483 if (fs::is_directory(autosaveDirectory))
484 {
485 std::vector<fs::path> autosaveFiles;
486
487 // Collect all the autosave files
488 for (auto& f : fs::directory_iterator(autosaveDirectory))
489 {
490 if (f.is_regular_file())
491 {
492 auto& path = f.path();
493 auto filename = path.filename().u8string();
494 if (Utility::startsWith(filename, "autosave_") && Utility::endsWith(filename, S5::extensionSV5, true))
495 {
496 autosaveFiles.push_back(path);
497 }
498 }
499 }
500
501 auto amountToKeep = static_cast<size_t>(std::max(1, Config::get().autosaveAmount));
502 if (autosaveFiles.size() > amountToKeep)
503 {
504 // Sort them by name (which should correspond to date order)
505 std::sort(autosaveFiles.begin(), autosaveFiles.end());
506
507 // Delete excess files
508 auto numToDelete = autosaveFiles.size() - amountToKeep;
509 for (size_t i = 0; i < numToDelete; i++)
510 {
511 auto path8 = autosaveFiles[i].u8string();
512 Logging::info("Deleting old autosave: {}", path8.c_str());
513 fs::remove(autosaveFiles[i]);
514 }
515 }
516 }
517 }
518 catch (const std::exception& e)
519 {
520 Logging::error("Unable to clean autosaves: {}", e.what());
521 }
522 }
523
524 static void autosave()
525 {

Callers 1

autosaveCheckFunction · 0.85

Calls 12

getPathFunction · 0.85
startsWithFunction · 0.85
endsWithFunction · 0.85
infoFunction · 0.85
errorFunction · 0.85
push_backMethod · 0.80
whatMethod · 0.80
getFunction · 0.70
removeFunction · 0.70
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected