1 /* ResidualVM - A 3D game interpreter 2 * 3 * ResidualVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #include "engines/advancedDetector.h" 24 #include "engines/stark/savemetadata.h" 25 #include "engines/stark/stark.h" 26 #include "engines/stark/services/stateprovider.h" 27 28 #include "common/savefile.h" 29 #include "common/system.h" 30 31 namespace Stark { 32 33 class StarkMetaEngine : public AdvancedMetaEngine { 34 public: getName() const35 const char *getName() const override { 36 return "stark"; 37 } 38 hasFeature(MetaEngineFeature f) const39 bool hasFeature(MetaEngineFeature f) const override { 40 return 41 (f == kSupportsListSaves) || 42 (f == kSupportsLoadingDuringStartup) || 43 (f == kSupportsDeleteSave) || 44 (f == kSavesSupportThumbnail) || 45 (f == kSavesSupportMetaInfo) || 46 (f == kSavesSupportPlayTime) || 47 (f == kSavesSupportCreationDate); 48 } 49 getMaximumSaveSlot() const50 int getMaximumSaveSlot() const override { 51 return 999; 52 } 53 listSaves(const char * target) const54 SaveStateList listSaves(const char *target) const override { 55 Common::StringArray filenames = StarkEngine::listSaveNames(target); 56 57 SaveStateList saveList; 58 for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { 59 int slot = StarkEngine::getSaveNameSlot(target, *filename); 60 61 // Read the description from the save 62 Common::String description; 63 Common::InSaveFile *save = g_system->getSavefileManager()->openForLoading(*filename); 64 if (save) { 65 StateReadStream stream(save); 66 description = stream.readString(); 67 } 68 69 saveList.push_back(SaveStateDescriptor(this, slot, description)); 70 } 71 72 Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator()); 73 return saveList; 74 } 75 querySaveMetaInfos(const char * target,int slot) const76 SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override { 77 Common::String filename = StarkEngine::formatSaveName(target, slot); 78 Common::InSaveFile *save = g_system->getSavefileManager()->openForLoading(filename); 79 if (!save) { 80 return SaveStateDescriptor(); 81 } 82 83 SaveStateDescriptor descriptor; 84 descriptor.setSaveSlot(slot); 85 86 SaveMetadata metadata; 87 Common::ErrorCode readError = metadata.read(save, filename); 88 if (readError != Common::kNoError) { 89 delete save; 90 return descriptor; 91 } 92 93 descriptor.setDescription(metadata.description); 94 95 if (metadata.version >= 9) { 96 Graphics::Surface *thumb = metadata.readGameScreenThumbnail(save); 97 descriptor.setThumbnail(thumb); 98 descriptor.setPlayTime(metadata.totalPlayTime); 99 descriptor.setSaveDate(metadata.saveYear, metadata.saveMonth, metadata.saveDay); 100 descriptor.setSaveTime(metadata.saveHour, metadata.saveMinute); 101 } 102 103 if (metadata.version >= 13) { 104 descriptor.setAutosave(metadata.isAutoSave); 105 } 106 107 delete save; 108 109 return descriptor; 110 } 111 removeSaveState(const char * target,int slot) const112 void removeSaveState(const char *target, int slot) const override { 113 Common::String filename = StarkEngine::formatSaveName(target, slot); 114 g_system->getSavefileManager()->removeSavefile(filename); 115 } 116 createInstance(OSystem * syst,Engine ** engine,const ADGameDescription * desc) const117 Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override { 118 *engine = new StarkEngine(syst, desc); 119 return Common::kNoError; 120 } 121 getSavegameFile(int saveGameIdx,const char * target) const122 Common::String getSavegameFile(int saveGameIdx, const char *target) const override { 123 if (!target) 124 target = getEngineId(); 125 if (saveGameIdx == kSavegameFilePattern) 126 return Common::String::format("%s-###.tlj", target); 127 else 128 return StarkEngine::formatSaveName(target, saveGameIdx); 129 } 130 }; 131 132 } // End of namespace Stark 133 134 #if PLUGIN_ENABLED_DYNAMIC(STARK) 135 REGISTER_PLUGIN_DYNAMIC(STARK, PLUGIN_TYPE_ENGINE, Stark::StarkMetaEngine); 136 #else 137 REGISTER_PLUGIN_STATIC(STARK, PLUGIN_TYPE_ENGINE, Stark::StarkMetaEngine); 138 #endif 139