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 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 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; }
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; }
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 GrimMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String pattern = "grim*.gsv"; filenames = saveFileMan->listSavefiles(pattern); SaveStateList saveList; char str[256]; int32 strSize; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + 4); if (slotNum >= 0) { SaveGame *savedState = SaveGame::openForLoading(*file); if (savedState && savedState->isCompatible()) { savedState->beginSection('SUBS'); strSize = savedState->readLESint32(); savedState->read(str, strSize); savedState->endSection(); saveList.push_back(SaveStateDescriptor(slotNum, str)); } delete savedState; } } Common::sort(saveList.begin(), saveList.end(), cmpSave); return saveList; }
SaveStateList AccessMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String saveDesc; Common::String pattern = Common::String::format("%s.0##", target); Access::AccessSavegameHeader header; filenames = saveFileMan->listSavefiles(pattern); sort(filenames.begin(), filenames.end()); // Sort to get the files in numerical order SaveStateList saveList; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { const char *ext = strrchr(file->c_str(), '.'); int slot = ext ? atoi(ext + 1) : -1; if (slot >= 0 && slot < MAX_SAVES) { Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file); if (in) { Access::AccessEngine::readSavegameHeader(in, header); saveList.push_back(SaveStateDescriptor(slot, header._saveName)); header._thumbnail->free(); delete header._thumbnail; 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; }
void Lua_V1::TextFileGetLine() { char textBuf[1000]; lua_Object nameObj = lua_getparam(1); lua_Object posObj = lua_getparam(2); Common::SeekableReadStream *file; if (lua_isnil(nameObj) || lua_isnil(posObj)) { lua_pushnil(); return; } const char *filename = lua_getstring(nameObj); Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); file = saveFileMan->openForLoading(filename); if (!file) { lua_pushnil(); return; } int pos = (int)lua_getnumber(posObj); file->seek(pos, SEEK_SET); memset(textBuf, 0, 1000); file->readLine(textBuf, 1000); delete file; lua_pushstring(textBuf); }
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 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; }
Common::InSaveFile *SaveConverter::openSave() const { if (_fileName.empty()) return 0; Common::SaveFileManager *saveMan = g_system->getSavefileManager(); return saveMan->openForLoading(_fileName); }
reg_t kCheckSaveGame(EngineState *s, int funct_nr, int argc, reg_t *argv) { char *game_id = kernel_dereference_char_pointer(s, argv[0], 0); int savedir_nr = argv[1].toUint16(); debug(3, "kCheckSaveGame(%s, %d)", game_id, savedir_nr); Common::Array<SavegameDesc> saves; listSavegames(saves); savedir_nr = saves[savedir_nr].id; if (savedir_nr > MAX_SAVEGAME_NR - 1) { return NULL_REG; } Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); Common::String filename = ((Sci::SciEngine*)g_engine)->getSavegameName(savedir_nr); Common::SeekableReadStream *in; if ((in = saveFileMan->openForLoading(filename))) { // found a savegame file SavegameMetadata meta; if (!get_savegame_metadata(in, &meta)) { // invalid s->r_acc = make_reg(0, 0); } else { s->r_acc = make_reg(0, 1); } delete in; } else { s->r_acc = make_reg(0, 1); } return s->r_acc; }
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); }
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 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; }
static byte *readSavegameThumbnail(const Common::String &filename, uint &fileSize, bool &isPNG) { byte *pFileData; Common::SaveFileManager *sfm = g_system->getSavefileManager(); Common::InSaveFile *file = sfm->openForLoading(lastPathComponent(filename, '/')); if (!file) error("Save file \"%s\" could not be loaded.", filename.c_str()); // Seek to the actual PNG image loadString(*file); // Marker (BS25SAVEGAME) Common::String storedVersionID = loadString(*file); // Version if (storedVersionID != "SCUMMVM1") loadString(*file); loadString(*file); // Description uint32 compressedGamedataSize = atoi(loadString(*file).c_str()); loadString(*file); // Uncompressed game data size file->skip(compressedGamedataSize); // Skip the game data and move to the thumbnail itself uint32 thumbnailStart = file->pos(); fileSize = file->size() - thumbnailStart; // Check if the thumbnail is in our own format, or a PNG file. uint32 header = file->readUint32BE(); isPNG = (header != MKTAG('S','C','R','N')); file->seek(-4, SEEK_CUR); pFileData = new byte[fileSize]; file->read(pFileData, fileSize); delete file; return pFileData; }
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 VoyeurMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String saveDesc; Common::String pattern = Common::String::format("%s.0##", target); filenames = saveFileMan->listSavefiles(pattern); SaveStateList saveList; Voyeur::VoyeurSavegameHeader header; for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { const char *ext = strrchr(file->c_str(), '.'); int slot = ext ? atoi(ext + 1) : -1; if (slot >= 0 && slot <= MAX_SAVES) { Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file); if (in) { if (header.read(in)) { saveList.push_back(SaveStateDescriptor(slot, header._saveName)); header._thumbnail->free(); } delete in; } } } // Sort saves based on slot number. Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; }
Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName) { const char *filename = _vm->getSavegameFile(saveGameIdx); Common::SaveFileManager *saveMan = g_system->getSavefileManager(); Common::OutSaveFile *f = saveMan->openForSaving(filename); if (f == NULL) return Common::kNoGameDataFoundError; // Save the savegame header CruiseSavegameHeader header; header.saveName = saveName; writeSavegameHeader(f, header); if (f->err()) { delete f; saveMan->removeSavefile(filename); return Common::kWritingFailed; } else { // Create the remainder of the savegame Common::Serializer s(NULL, f); DoSync(s); f->finalize(); delete f; return Common::kNoError; } }
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; }
Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName, DraciEngine &vm) { Common::String filename = vm.getSavegameFile(saveGameIdx); Common::SaveFileManager *saveMan = g_system->getSavefileManager(); Common::OutSaveFile *f = saveMan->openForSaving(filename); if (f == NULL) return Common::kNoGameDataFoundError; TimeDate curTime; vm._system->getTimeAndDate(curTime); // Save the savegame header DraciSavegameHeader header; header.saveName = saveName; header.date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF); header.time = ((curTime.tm_hour & 0xFF) << 8) | ((curTime.tm_min) & 0xFF); header.playtime = vm.getTotalPlayTime() / 1000; writeSavegameHeader(f, header); if (f->err()) { delete f; saveMan->removeSavefile(filename); return Common::kWritingFailed; } else { // Create the remainder of the savegame Common::Serializer s(NULL, f); vm._game->DoSync(s); f->finalize(); delete f; return Common::kNoError; } }
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; }
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; }
Common::InSaveFile *SaveReader::openSave(const Common::String &fileName) { if (fileName.empty()) return 0; Common::SaveFileManager *saveMan = g_system->getSavefileManager(); return saveMan->openForLoading(fileName); }
static void io_writeto() { lua_Object f = lua_getparam(FIRSTARG); if (f == LUA_NOOBJECT) { closefile(FOUTPUT); setreturn(2, FOUTPUT); } else if (lua_tag(f) == gettag(IOTAG)) { int32 id = lua_getuserdata(f); LuaFile *current = getfile(id); if (!current->isOpen()) { pushresult(0); return; } setreturn(id, FOUTPUT); } else { Common::String s = Common::lastPathComponent(luaL_check_string(FIRSTARG), '\\'); LuaFile *current; Common::WriteStream *outFile = NULL; Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); outFile = saveFileMan->openForSaving(s); if (!outFile) { pushresult(0); return; } current = new LuaFile(); current->_out = outFile; current->_filename = s; setreturn(addfile(current), FOUTPUT); } }
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; }
static void io_appendto() { Common::String s = Common::lastPathComponent(luaL_check_string(FIRSTARG), '\\'); Common::SeekableReadStream *inFile = NULL; Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); inFile = saveFileMan->openForLoading(s); if (!inFile) { pushresult(0); return; } int size = inFile->size(); byte *buf = new byte[size]; inFile->read(buf, size); delete inFile; Common::WriteStream *outFile = NULL; outFile = saveFileMan->openForSaving(s); if (!outFile) pushresult(0); else { outFile->write(buf, size); LuaFile *current = new LuaFile(); current->_out = outFile; current->_filename = s; setreturn(addfile(current), FOUTPUT); } delete[] buf; }
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 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; }