SaveStateList CruiseMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringList filenames; Common::String pattern("cruise.s??"); filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 2 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 2); if (slotNum >= 0 && slotNum <= 99) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { Cruise::CruiseSavegameHeader header; Cruise::readSavegameHeader(in, header); saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); if (header.thumbnail) delete header.thumbnail; delete in; } } } return saveList; }
SaveStateList SwordMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); SaveStateList saveList; char saveName[40]; Common::StringList filenames = saveFileMan->listSavefiles("sword1.???"); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) int slotNum = 0; for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum >= 0 && slotNum <= 999) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { in->readUint32LE(); // header in->read(saveName, 40); saveList.push_back(SaveStateDescriptor(slotNum, saveName)); delete in; } } } return saveList; }
void listSavegames(Common::Array<SavegameDesc> &saves) { Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); // Load all saves Common::StringList saveNames = saveFileMan->listSavefiles(((SciEngine *)g_engine)->getSavegamePattern()); for (Common::StringList::const_iterator iter = saveNames.begin(); iter != saveNames.end(); ++iter) { Common::String filename = *iter; Common::SeekableReadStream *in; if ((in = saveFileMan->openForLoading(filename))) { SavegameMetadata meta; if (!get_savegame_metadata(in, &meta)) { // invalid delete in; continue; } delete in; SavegameDesc desc; desc.id = strtol(filename.end() - 3, NULL, 10); desc.date = meta.savegame_date; desc.time = meta.savegame_time; debug(3, "Savegame in file %s ok, id %d", filename.c_str(), desc.id); saves.push_back(desc); } } // Sort the list by creation date of the saves qsort(saves.begin(), saves.size(), sizeof(SavegameDesc), _savegame_index_struct_compare); }
virtual SaveStateList listSaves(const char *target) const { Common::String pattern = Tucker::generateGameStateFileName(target, 0, true); Common::StringList filenames = g_system->getSavefileManager()->listSavefiles(pattern); bool slotsTable[Tucker::kLastSaveSlot + 1]; memset(slotsTable, 0, sizeof(slotsTable)); SaveStateList saveList; for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { int slot; const char *ext = strrchr(file->c_str(), '.'); if (ext && (slot = atoi(ext + 1)) >= 0 && slot <= Tucker::kLastSaveSlot) { Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file); if (in) { slotsTable[slot] = true; delete in; } } } for (int slot = 0; slot <= Tucker::kLastSaveSlot; ++slot) { if (slotsTable[slot]) { char description[64]; snprintf(description, sizeof(description), "savegm.%02d", slot); saveList.push_back(SaveStateDescriptor(slot, description)); } } return saveList; }