/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "common/system.h" #include "mm/xeen/metaengine.h" #include "mm/xeen/events.h" #include "mm/xeen/saves.h" namespace MM { namespace Xeen { #define MAX_SAVES 999 SaveStateDescriptor XeenMetaEngine::querySaveMetaInfos(const MetaEngine *metaEngine, const char *target, int slot) { Common::String filename = Common::String::format("%s.%03d", target, slot); Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(filename); if (f) { XeenSavegameHeader header; if (!SavesManager::readSavegameHeader(f, header, false)) { delete f; return SaveStateDescriptor(); } delete f; // Create the return descriptor SaveStateDescriptor desc(metaEngine, slot, header._saveName); desc.setThumbnail(header._thumbnail); desc.setSaveDate(header._year, header._month, header._day); desc.setSaveTime(header._hour, header._minute); desc.setPlayTime(header._totalFrames * GAME_FRAME_TIME); return desc; } return SaveStateDescriptor(); } SaveStateList XeenMetaEngine::listSaves(const MetaEngine *metaEngine, const char *target) { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String saveDesc; Common::String pattern = Common::String::format("%s.###", target); MM::Xeen::XeenSavegameHeader header; filenames = saveFileMan->listSavefiles(pattern); 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) { if (MM::Xeen::SavesManager::readSavegameHeader(in, header)) saveList.push_back(SaveStateDescriptor(metaEngine, slot, header._saveName)); delete in; } } } Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); return saveList; } } // End of namespace Xeen } // End of namespace MM