void QuickSaves::delete_surplus_saves(size_t max_saves) { if (max_saves < 1) return; // unlimited saves, no need to prune clear(); // Check the directory to count the saves. If there // are fewer than the max, no need to go further. vector<dir_entry> entries; DirectorySpecifier path; path.SetToQuickSavesDir(); if (path.ReadDirectory(entries)) { if (entries.size() <= max_saves) return; } // We might have too many unnamed saves; load and // count them, deleting any extras. enumerate(); size_t unnamed_saves = 0; for (std::vector<QuickSave>::iterator it = begin(); it != end(); ++it) { if (it->name.length()) continue; if (++unnamed_saves > max_saves) delete_quick_save(*it); } clear(); }
void QuickSaves::enumerate() { clear(); logContext("parsing quick saves"); QuickSaveLoader loader; DirectorySpecifier path; path.SetToQuickSavesDir(); loader.ParseDirectory(path); clear_game_error(); std::sort(m_saves.begin(), m_saves.end()); std::reverse(m_saves.begin(), m_saves.end()); }