From 0d868742d4016f8f50a8135c20115d911d920cf5 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 21 Aug 2016 16:19:55 +0200 Subject: MACVENTURE: Add thumbnail to savegames --- engines/macventure/detection.cpp | 29 ++++++++++++++++++++++++++++- engines/macventure/saveload.cpp | 34 +++++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 12 deletions(-) (limited to 'engines') diff --git a/engines/macventure/detection.cpp b/engines/macventure/detection.cpp index 2b161142c4..801cc599cd 100644 --- a/engines/macventure/detection.cpp +++ b/engines/macventure/detection.cpp @@ -75,13 +75,16 @@ public: virtual SaveStateList listSaves(const char *target) const; virtual int getMaximumSaveSlot() const; virtual void removeSaveState(const char *target, int slot) const; + SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; }; bool MacVentureMetaEngine::hasFeature(MetaEngineFeature f) const { return (f == kSupportsListSaves) || (f == kSupportsLoadingDuringStartup) || - (f == kSupportsDeleteSave); + (f == kSupportsDeleteSave) || + (f == kSavesSupportMetaInfo) || + (f == kSavesSupportThumbnail); } bool MacVentureEngine::hasFeature(EngineFeature f) const { @@ -141,6 +144,30 @@ void MacVentureMetaEngine::removeSaveState(const char *target, int slot) const { g_system->getSavefileManager()->removeSavefile(Common::String::format("%s.%03d", target, slot)); } + +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, ""); +} + } // End of namespace MacVenture #if PLUGIN_ENABLED_DYNAMIC(MACVENTURE) diff --git a/engines/macventure/saveload.cpp b/engines/macventure/saveload.cpp index 1b56980ecd..a1a5e3c244 100644 --- a/engines/macventure/saveload.cpp +++ b/engines/macventure/saveload.cpp @@ -26,16 +26,19 @@ #include "common/savefile.h" #include "engines/savestate.h" #include "gui/saveload.h" +#include "graphics/thumbnail.h" namespace MacVenture { #define MACVENTURE_SAVE_HEADER MKTAG('M', 'V', 'S', 'S') // (M)ac(V)enture (S)cummVM (S)ave (0x4d565353, uint32) #define MACVENTURE_SAVE_VERSION 1 //1 BYTE -#define MACVENTURE_DESC_LENGTH 1 //1 BYTE for the description length +#define MACVENTURE_DESC_LENGTH 4 //4 BYTE for the metadata length SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot) { // Metadata is stored at the end of the file - // |DESCRIPTION | + // |THUMBNAIL | + // | | + // |DESCSIZE| DESCRIPTION | // |HEADER |VERSION|DESCLEN| s->seek(-(5 + MACVENTURE_DESC_LENGTH), SEEK_END); uint32 sig = s->readUint32BE(); @@ -49,12 +52,18 @@ SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot) { // Save is valid, set its slot number desc.setSaveSlot(slot); + // Depends on MACVENTURE_DESC_LENGTH + uint32 metaSize = s->readUint32BE(); + s->seek(-(5 + MACVENTURE_DESC_LENGTH + metaSize), SEEK_END); + + // Load the thumbnail + Graphics::Surface *thumb = Graphics::loadThumbnail(*s); + desc.setThumbnail(thumb); + // Load the description Common::String name; - // Depends on MACVENTURE_DESC_LENGTH - byte descSize = s->readByte(); - s->seek(-(5 + MACVENTURE_DESC_LENGTH + descSize), SEEK_END); - for (int i = 0; i < descSize; ++i) { + uint32 descSize = s->readUint32BE(); + for (uint32 i = 0; i < descSize; ++i) { name += s->readByte(); } desc.setDescription(name); @@ -63,13 +72,15 @@ SaveStateDescriptor loadMetaData(Common::SeekableReadStream *s, int slot) { } void writeMetaData(Common::OutSaveFile *file, Common::String desc) { - if (desc.size() >= (1 << (MACVENTURE_DESC_LENGTH * 8))) { - desc.erase((1 << (MACVENTURE_DESC_LENGTH * 8)) - 1); - } + uint thumbSize = file->pos(); + Graphics::saveThumbnail(*file); + thumbSize = file->pos() - thumbSize; + + file->writeUint32BE(desc.size()); file->writeString(desc); file->writeUint32BE(MACVENTURE_SAVE_HEADER); file->writeByte(MACVENTURE_SAVE_VERSION); - file->writeByte(desc.size()); + file->writeUint32BE(4 + desc.size() + thumbSize); } Common::Error MacVentureEngine::loadGameState(int slot) { @@ -121,9 +132,10 @@ bool MacVentureEngine::scummVMSaveLoadDialog(bool isSave) { desc = dialog.createDefaultSaveDescription(slot); } + /* if (desc.size() > (1 << MACVENTURE_DESC_LENGTH * 8) - 1) desc = Common::String(desc.c_str(), (1 << MACVENTURE_DESC_LENGTH * 8) - 1); - + */ if (slot < 0) return true; -- cgit v1.2.3