void GUI::updateSaveList(bool excludeQuickSaves) { Common::String pattern = _vm->_targetName + ".???"; Common::StringArray saveFileList = _vm->_saveFileMan->listSavefiles(pattern); _saveSlots.clear(); for (Common::StringArray::const_iterator i = saveFileList.begin(); i != saveFileList.end(); ++i) { char s1 = 0, s2 = 0, s3 = 0; s1 = (*i)[i->size()-3]; s2 = (*i)[i->size()-2]; s3 = (*i)[i->size()-1]; if (!isdigit(s1) || !isdigit(s2) || !isdigit(s3)) continue; s1 -= '0'; s2 -= '0'; s3 -= '0'; if (excludeQuickSaves && s1 == 9 && s2 == 9) continue; _saveSlots.push_back(s1*100+s2*10+s3); } if (_saveSlots.begin() == _saveSlots.end()) return; Common::sort(_saveSlots.begin(), _saveSlots.end(), Common::Less<int>()); if (_saveSlots.size() > 2) Common::sort(_saveSlots.begin()+1, _saveSlots.end(), Common::Greater<int>()); }
SaveStateList SagaMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; char saveDesc[SAVE_TITLE_SIZE]; Common::String pattern = target; pattern += ".s##"; filenames = saveFileMan->listSavefiles(pattern); SaveStateList saveList; int slotNum = 0; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 2 digits of the filename, since they correspond to the save slot slotNum = atoi(file->c_str() + file->size() - 2); if (slotNum >= 0 && slotNum < MAX_SAVES) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { for (int i = 0; i < 3; i++) in->readUint32BE(); in->read(saveDesc, SAVE_TITLE_SIZE); saveList.push_back(SaveStateDescriptor(slotNum, saveDesc)); delete in; } } } // Sort saves based on slot number. Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
SaveStateList DraciMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern("draci.s##"); filenames = saveFileMan->listSavefiles(pattern); SaveStateList saveList; for (Common::StringArray::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) { Draci::DraciSavegameHeader header; if (Draci::readSavegameHeader(in, header)) { saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); } delete in; } } } // Sort saves based on slot number. Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
SaveStateList QueenMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; char saveDesc[32]; Common::String pattern("queen.s??"); filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; for (Common::StringArray::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) { for (int i = 0; i < 4; i++) in->readUint32BE(); in->read(saveDesc, 32); saveList.push_back(SaveStateDescriptor(slotNum, saveDesc)); delete in; } } } return saveList; }
SaveStateList LureMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String saveDesc; Common::String pattern = "lure.???"; filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum >= 0 && slotNum <= 999) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { saveDesc = Lure::getSaveName(in); saveList.push_back(SaveStateDescriptor(slotNum, saveDesc)); delete in; } } } return saveList; }
SaveStateList LabMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Lab::SaveGameHeader header; Common::String pattern = target; pattern += ".###"; Common::StringArray filenames; filenames = saveFileMan->listSavefiles(pattern.c_str()); Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)*/ SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); if ((slotNum >= 0) && (slotNum <= 999)) { Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); if (in) { if (Lab::readSaveGameHeader(in, header)) saveList.push_back(SaveStateDescriptor(slotNum, header._descr.getDescription())); delete in; } } } return saveList; }
SaveStateList FullpipeMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern("fullpipe.s##"); filenames = saveFileMan->listSavefiles(pattern); SaveStateList saveList; for (Common::StringArray::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 <= getMaximumSaveSlot()) { Common::ScopedPtr<Common::InSaveFile> in(saveFileMan->openForLoading(*file)); if (in) { Fullpipe::FullpipeSavegameHeader header; Fullpipe::readSavegameHeader(in.get(), header); SaveStateDescriptor desc; parseSavegameHeader(header, desc); desc.setSaveSlot(slotNum); saveList.push_back(desc); } } } // Sort saves based on slot number. Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
SaveStateList TinselMetaEngine::listSaves(const char *target) const { Common::String pattern = target; pattern = pattern + ".???"; Common::StringArray files = g_system->getSavefileManager()->listSavefiles(pattern); sort(files.begin(), files.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; int slotNum = 0; for (Common::StringArray::const_iterator file = files.begin(); file != files.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); const Common::String &fname = *file; Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(fname); if (in) { in->readUint32LE(); // skip id in->readUint32LE(); // skip size in->readUint32LE(); // skip version char saveDesc[Tinsel::SG_DESC_LEN]; in->read(saveDesc, sizeof(saveDesc)); saveDesc[Tinsel::SG_DESC_LEN - 1] = 0; saveList.push_back(SaveStateDescriptor(slotNum, saveDesc)); delete in; } } return saveList; }
SaveStateList SciMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern = target; pattern += ".???"; filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; int slotNum = 0; for (Common::StringArray::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 <= 99) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { SavegameMetadata meta; if (!get_savegame_metadata(in, &meta)) { // invalid delete in; continue; } saveList.push_back(SaveStateDescriptor(slotNum, meta.name)); delete in; } } } return saveList; }
SaveStateList FullpipeMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern("fullpipe.s##"); filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; for (Common::StringArray::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 <= getMaximumSaveSlot()) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { Fullpipe::FullpipeSavegameHeader header; Fullpipe::readSavegameHeader(in, header); saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); delete header.thumbnail; delete in; } } } return saveList; }
void PictureMetaEngine::removeSaveState(const char *target, int slot) const { // Slot 0 can't be deleted, it's for restarting the game(s) if (slot == 0) return; Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::String filename = Picture::PictureEngine::getSavegameFilename(target, slot); saveFileMan->removeSavefile(filename.c_str()); Common::StringArray filenames; Common::String pattern = target; pattern += ".???"; filenames = saveFileMan->listSavefiles(pattern.c_str()); Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); // Rename every slot greater than the deleted slot, // Also do not rename quicksaves. if (slotNum > slot && slotNum < 990) { // FIXME: Our savefile renaming done here is inconsitent with what we do in // GUI_v2::deleteMenu. While here we rename every slot with a greater equal // number of the deleted slot to deleted slot, deleted slot + 1 etc., // we only rename the following slots in GUI_v2::deleteMenu until a slot // is missing. saveFileMan->renameSavefile(file->c_str(), filename.c_str()); filename = Picture::PictureEngine::getSavegameFilename(target, ++slot); } } }
SaveStateList NeverhoodMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Neverhood::NeverhoodEngine::SaveHeader header; Common::String pattern = target; pattern += ".???"; Common::StringArray filenames; filenames = saveFileMan->listSavefiles(pattern.c_str()); Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); file++) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum >= 0 && slotNum <= 999) { Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); if (in) { if (Neverhood::NeverhoodEngine::readSaveHeader(in, false, header) == Neverhood::NeverhoodEngine::kRSHENoError) { saveList.push_back(SaveStateDescriptor(slotNum, header.description)); } delete in; } } } return saveList; }
SaveStateList WageMetaEngine::listSaves(const char *target) const { const uint32 WAGEflag = MKTAG('W','A','G','E'); Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; char saveDesc[31]; Common::String pattern = target; pattern += ".###"; filenames = saveFileMan->listSavefiles(pattern); SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum >= 0 && slotNum <= 999) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { uint32 type = in->readUint32BE(); if (type == WAGEflag) in->read(saveDesc, 31); saveList.push_back(SaveStateDescriptor(slotNum, saveDesc)); delete in; } } } // Sort saves based on slot number. Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
virtual SaveStateList listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); SaveGameHeader header; Common::String pattern = target; pattern += ".###"; Common::StringArray filenames; filenames = saveFileMan->listSavefiles(pattern.c_str()); SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); if ((slotNum >= 0) && (slotNum <= 999)) { Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); if (in) { if (DM::readSaveGameHeader(in, &header)) saveList.push_back(SaveStateDescriptor(slotNum, header._descr.getDescription())); delete in; } } } // Sort saves based on slot number. Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
SaveStateList SwordMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); SaveStateList saveList; char saveName[40]; Common::StringArray filenames = saveFileMan->listSavefiles("sword1.???"); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) int slotNum = 0; for (Common::StringArray::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; }
SaveStateList AgiMetaEngine::listSaves(const char *target) const { const uint32 AGIflag = MKTAG('A','G','I',':'); Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; char saveDesc[31]; Common::String pattern = target; pattern += ".???"; filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum >= 0 && slotNum <= 999) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { uint32 type = in->readUint32BE(); if (type == AGIflag) in->read(saveDesc, 31); saveList.push_back(SaveStateDescriptor(slotNum, saveDesc)); delete in; } } } return saveList; }
SaveStateList TonyMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String saveDesc; Common::String pattern = "tony.0??"; filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum >= 0 && slotNum <= 999) { byte thumbnailData[160 * 120 * 2]; Common::String saveName; byte difficulty; if (Tony::RMOptionScreen::loadThumbnailFromSaveState(slotNum, thumbnailData, saveName, difficulty)) { // Add the save name to the savegame list saveList.push_back(SaveStateDescriptor(slotNum, saveName)); } } } return saveList; }
SaveStateList ToltecsMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Toltecs::ToltecsEngine::SaveHeader header; Common::String pattern = target; pattern += ".###"; Common::StringArray filenames; filenames = saveFileMan->listSavefiles(pattern.c_str()); SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum >= 0 && slotNum <= 999) { Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); if (in) { if (Toltecs::ToltecsEngine::readSaveHeader(in, false, header) == Toltecs::ToltecsEngine::kRSHENoError) { saveList.push_back(SaveStateDescriptor(slotNum, header.description)); } delete in; } } } // Sort saves based on slot number. Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
int MenuSystem::loadSavegamesList() { int maxSlotNum = -1; _savegameListTopIndex = 0; _savegames.clear(); Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Toltecs::ToltecsEngine::SaveHeader header; Common::String pattern = _vm->getTargetName(); pattern += ".???"; Common::StringArray filenames; filenames = saveFileMan->listSavefiles(pattern.c_str()); Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum > maxSlotNum) maxSlotNum = slotNum; if (slotNum >= 0 && slotNum <= 999) { Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); if (in) { if (Toltecs::ToltecsEngine::readSaveHeader(in, false, header) == Toltecs::ToltecsEngine::kRSHENoError) { _savegames.push_back(SavegameItem(slotNum, header.description)); //debug("%s -> %s", file->c_str(), header.description.c_str()); } delete in; } } } return maxSlotNum; }
SaveStateList KyraMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Kyra::KyraEngine_v1::SaveHeader header; Common::String pattern = target; pattern += ".???"; Common::StringArray filenames; filenames = saveFileMan->listSavefiles(pattern); Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum >= 0 && slotNum <= 999) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { if (Kyra::KyraEngine_v1::readSaveHeader(in, false, header) == Kyra::KyraEngine_v1::kRSHENoError) { // WORKAROUND: Old savegames are using 'German' as description for kyra3 restart game save (slot 0), // since that looks odd we replace it by "New Game". if (slotNum == 0 && header.gameID == Kyra::GI_KYRA3) header.description = "New Game"; saveList.push_back(SaveStateDescriptor(slotNum, header.description)); } delete in; } } } return saveList; }
SaveStateList DrasculaMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern = target; pattern += ".###"; filenames = saveFileMan->listSavefiles(pattern); SaveStateList saveList; int slotNum = 0; for (Common::StringArray::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 <= getMaximumSaveSlot()) { Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { SaveStateDescriptor desc = loadMetaData(in, slotNum, false); if (desc.getSaveSlot() != slotNum) { // invalid delete in; continue; } saveList.push_back(desc); delete in; } } } // Sort saves based on slot number. Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
virtual SaveStateList listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::String pattern = Common::String::format("%s??", target); // Get list of savefiles for target game Common::StringArray filenames = saveFileMan->listSavefiles(pattern); Common::Array<int> slots; for (Common::StringArray::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); // Ensure save slot is within valid range if (slotNum >= 1 && slotNum <= 10) { slots.push_back(slotNum); } } // Sort save slot ids Common::sort<int>(slots.begin(), slots.end()); // Load save index Common::String fileEpa = Common::String::format("%s.epa", target); Common::InSaveFile *epa = saveFileMan->openForLoading(fileEpa); // Get savegame names from index Common::String saveDesc; SaveStateList saveList; int line = 1; for (uint i = 0; i < slots.size(); i++) { // ignore lines corresponding to unused saveslots for (; line < slots[i]; line++) epa->readLine(); // copy the name in the line corresponding to the save slot and truncate to 22 characters saveDesc = Common::String(epa->readLine().c_str(), 22); // handle cases where the save directory and save index are detectably out of sync if (saveDesc == "*") saveDesc = "No name specified."; // increment line number to keep it in sync with slot number line++; // Insert savegame name into list saveList.push_back(SaveStateDescriptor(slots[i], saveDesc)); } delete epa; return saveList; }
SaveStateList SkyMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); SaveStateList saveList; // Load the descriptions Common::StringArray savenames; savenames.resize(MAX_SAVE_GAMES+1); Common::InSaveFile *inf; inf = saveFileMan->openForLoading("SKY-VM.SAV"); if (inf != NULL) { char *tmpBuf = new char[MAX_SAVE_GAMES * MAX_TEXT_LEN]; char *tmpPtr = tmpBuf; inf->read(tmpBuf, MAX_SAVE_GAMES * MAX_TEXT_LEN); for (int i = 0; i < MAX_SAVE_GAMES; ++i) { savenames[i] = tmpPtr; tmpPtr += savenames[i].size() + 1; } delete inf; delete[] tmpBuf; } // Find all saves Common::StringArray filenames; filenames = saveFileMan->listSavefiles("SKY-VM.???"); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) // Slot 0 is the autosave, if it exists. // TODO: Check for the existence of the autosave -- but this require us // to know which SKY variant we are looking at. saveList.insert_at(0, SaveStateDescriptor(0, "*AUTOSAVE*")); // Prepare the list of savestates by looping over all matching savefiles for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Extract the extension Common::String ext = file->c_str() + file->size() - 3; ext.toUppercase(); if (Common::isDigit(ext[0]) && Common::isDigit(ext[1]) && Common::isDigit(ext[2])) { int slotNum = atoi(ext.c_str()); Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { saveList.push_back(SaveStateDescriptor(slotNum+1, savenames[slotNum])); delete in; } } } return saveList; }
SaveStateList CGEMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern = target; pattern += ".???"; filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; int slotNum = 0; for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { // Obtain the last 3 digits of the filename, since they correspond to the save slot slotNum = atoi(filename->c_str() + filename->size() - 3); if (slotNum >= 0 && slotNum <= 99) { Common::InSaveFile *file = saveFileMan->openForLoading(*filename); if (file) { CGE::SavegameHeader header; // Check to see if it's a ScummVM savegame or not char buffer[kSavegameStrSize + 1]; file->read(buffer, kSavegameStrSize + 1); if (!strncmp(buffer, CGE::savegameStr, kSavegameStrSize + 1)) { // Valid savegame if (CGE::CGEEngine::readSavegameHeader(file, header)) { saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); if (header.thumbnail) { header.thumbnail->free(); delete header.thumbnail; } } } else { // Must be an original format savegame saveList.push_back(SaveStateDescriptor(slotNum, "Unknown")); } delete file; } } } return saveList; }
SaveStateList CineMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); SaveStateList saveList; Common::String pattern = target; pattern += ".?"; Common::StringArray filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); Common::StringArray::const_iterator file; Common::String filename = target; filename += ".dir"; Common::InSaveFile *in = saveFileMan->openForLoading(filename); if (in) { typedef char CommandeType[20]; CommandeType saveNames[10]; // Initialize all savegames' descriptions to empty strings // so that if the savegames' descriptions can only be partially read from file // then the missing ones are correctly set to empty strings. memset(saveNames, 0, sizeof(saveNames)); in->read(saveNames, 10 * 20); CommandeType saveDesc; for (file = filenames.begin(); file != filenames.end(); ++file) { // Jump over savegame files that don't end with a digit (e.g. "fw.3" is ok, "fw.a" is not). if (!isdigit(file->lastChar())) continue; // Obtain the last digit of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 1); // Copy the savegame description making sure it ends with a trailing zero strncpy(saveDesc, saveNames[slotNum], 20); saveDesc[sizeof(CommandeType) - 1] = 0; saveList.push_back(SaveStateDescriptor(slotNum, saveDesc)); } } delete in; return saveList; }
void GUI::updateSaveFileList(Common::String targetName, bool excludeQuickSaves) { Common::String pattern = targetName + ".###"; Common::StringArray saveFileList = _vm->_saveFileMan->listSavefiles(pattern); _saveSlots.clear(); for (Common::StringArray::const_iterator i = saveFileList.begin(); i != saveFileList.end(); ++i) { // The last 3 digits of the filename correspond to the save slot. const int slotNum = atoi(i->c_str() + i->size() - 3); if (excludeQuickSaves && slotNum >= 990) continue; _saveSlots.push_back(slotNum); } if (_saveSlots.begin() == _saveSlots.end()) return; sortSaveSlots(); }
SaveStateList CGE2MetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern = target; pattern += ".###"; filenames = saveFileMan->listSavefiles(pattern); SaveStateList saveList; for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(filename->c_str() + filename->size() - 3); if (slotNum >= 0 && slotNum <= 99) { Common::InSaveFile *file = saveFileMan->openForLoading(*filename); if (file) { CGE2::SavegameHeader header; // Check to see if it's a ScummVM savegame or not char buffer[kSavegameStrSize + 1]; file->read(buffer, kSavegameStrSize + 1); if (!strncmp(buffer, kSavegameStr, kSavegameStrSize + 1)) { // Valid savegame if (CGE2::CGE2Engine::readSavegameHeader(file, header)) { saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); } } else { // Must be an original format savegame saveList.push_back(SaveStateDescriptor(slotNum, "Unknown")); } delete file; } } } // Sort saves based on slot number. Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
SaveStateList ToonMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern = target; pattern += ".???"; filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) SaveStateList saveList; int slotNum = 0; for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { // Obtain the last 3 digits of the filename, since they correspond to the save slot slotNum = atoi(filename->c_str() + filename->size() - 3); if (slotNum >= 0 && slotNum <= 99) { Common::InSaveFile *file = saveFileMan->openForLoading(*filename); if (file) { int32 version = file->readSint32BE(); if (version != TOON_SAVEGAME_VERSION) { delete file; continue; } // read name uint16 nameSize = file->readUint16BE(); if (nameSize >= 255) { delete file; continue; } char name[256]; file->read(name, nameSize); name[nameSize] = 0; saveList.push_back(SaveStateDescriptor(slotNum, name)); delete file; } } } return saveList; }
SaveStateList SaveFileManager::list(const Common::String &target) { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray files = saveFileMan->listSavefiles(target + ".###"); SaveStateList saveList; for (Common::StringArray::const_iterator fileName = files.begin(); fileName != files.end(); ++fileName) { Common::InSaveFile *saveFile = saveFileMan->openForLoading(*fileName); if (saveFile == nullptr || saveFile->err()) { continue; } BladeRunner::SaveFileHeader header; readHeader(*saveFile, header); int slotNum = atoi(fileName->c_str() + fileName->size() - 3); saveList.push_back(SaveStateDescriptor(slotNum, header._name)); } Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
SaveStateDescriptor MacVentureMetaEngine::querySaveMetaInfos(const char *target, int slot) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); SaveStateDescriptor desc; Common::String saveFileName; Common::String pattern = target; pattern += ".###"; Common::StringArray filenames = saveFileMan->listSavefiles(pattern); for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { int slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum == slot) { saveFileName = *file; } } Common::InSaveFile *in = saveFileMan->openForLoading(saveFileName); if (in) { desc = loadMetaData(in, slot); delete in; return desc; } return SaveStateDescriptor(-1, ""); }