From 00e59a312211c0b49433ad3e9923460ed85edc50 Mon Sep 17 00:00:00 2001 From: Adrian Frühwirth Date: Fri, 6 Apr 2018 00:06:38 +0200 Subject: ALL: Load savegame thumbnail only when necessary This commit introduces the following changes: 1. Graphics::loadThumbnail() Now returns a boolean and takes a new argument skipThumbnail which defaults to false. In case of true, loadThumbnail() reads past the thumbnail data in the input stream instead of actually loading the thumbnail. This simplifies savegame handling where, up until now, many engines always read the whole savegame metadata (including the thumbnail) and then threw away the thumbnail when not needed (which is in almost all cases, the most common exception being MetaEngine::querySaveMetaInfos() which is responsible for loading savegame metadata for displaying it in the GUI launcher. 2. readSavegameHeader() Engines which already implement such a method (name varies) now take a new argument skipThumbnail (default: true) which is passed through to loadThumbnail(). This means that the default case for readSavegameHeader() is now _not_ loading the thumbnail from a savegame and just reading past it. In those cases, e.g. querySaveMetaInfos(), where we actually are interested in loading the thumbnail readSavegameHeader() needs to explicitely be called with skipThumbnail == false. Engines whose readSavegameHeader() (name varies) already takes an argument loadThumbnail have been adapted to have a similar prototype and semantics. I.e. readSaveHeader(in, loadThumbnail, header) now is readSaveHeader(in, header, skipThumbnail). 3. Error handling Engines which previously did not check the return value of readSavegameHeader() (name varies) now do so ensuring that possibly broken savegames (be it a broken thumbnail or something else) don't make it into the GUI launcher list in the first place. --- engines/voyeur/detection.cpp | 3 +-- engines/voyeur/voyeur.cpp | 11 +++-------- engines/voyeur/voyeur.h | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) (limited to 'engines/voyeur') diff --git a/engines/voyeur/detection.cpp b/engines/voyeur/detection.cpp index eefe174e94..6452e5741f 100644 --- a/engines/voyeur/detection.cpp +++ b/engines/voyeur/detection.cpp @@ -132,7 +132,6 @@ SaveStateList VoyeurMetaEngine::listSaves(const char *target) const { if (in) { if (header.read(in)) { saveList.push_back(SaveStateDescriptor(slot, header._saveName)); - header._thumbnail->free(); } delete in; } @@ -159,7 +158,7 @@ SaveStateDescriptor VoyeurMetaEngine::querySaveMetaInfos(const char *target, int if (f) { Voyeur::VoyeurSavegameHeader header; - header.read(f); + header.read(f, false); delete f; // Create the return descriptor diff --git a/engines/voyeur/voyeur.cpp b/engines/voyeur/voyeur.cpp index 7f2f0e312e..b7769c1fd4 100644 --- a/engines/voyeur/voyeur.cpp +++ b/engines/voyeur/voyeur.cpp @@ -789,9 +789,6 @@ void VoyeurEngine::loadGame(int slot) { VoyeurSavegameHeader header; if (!header.read(saveFile)) return; - if (header._thumbnail) - header._thumbnail->free(); - delete header._thumbnail; serializer.setVersion(header._version); synchronize(serializer); @@ -856,9 +853,7 @@ void VoyeurEngine::synchronize(Common::Serializer &s) { /*------------------------------------------------------------------------*/ -bool VoyeurSavegameHeader::read(Common::InSaveFile *f) { - _thumbnail = NULL; - +bool VoyeurSavegameHeader::read(Common::InSaveFile *f, bool skipThumbnail) { uint32 signature = f->readUint32BE(); if (signature != MKTAG('V', 'O', 'Y', 'R')) { warning("Invalid savegame"); @@ -875,9 +870,9 @@ bool VoyeurSavegameHeader::read(Common::InSaveFile *f) { _saveName += c; // Get the thumbnail - _thumbnail = Graphics::loadThumbnail(*f); - if (!_thumbnail) + if (!Graphics::loadThumbnail(*f, _thumbnail, skipThumbnail)) { return false; + } // Read in the save datet/ime _saveYear = f->readSint16LE(); diff --git a/engines/voyeur/voyeur.h b/engines/voyeur/voyeur.h index dcd82b24a9..a098ba9e62 100644 --- a/engines/voyeur/voyeur.h +++ b/engines/voyeur/voyeur.h @@ -312,7 +312,7 @@ struct VoyeurSavegameHeader { /** * Read in the header from the specified file */ - bool read(Common::InSaveFile *f); + bool read(Common::InSaveFile *f, bool skipThumbnail = true); /** * Write out header information to the specified file -- cgit v1.2.3