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/lab/lab.h | 2 +- engines/lab/savegame.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'engines/lab') diff --git a/engines/lab/lab.h b/engines/lab/lab.h index 2a1e527098..aedf0181ec 100644 --- a/engines/lab/lab.h +++ b/engines/lab/lab.h @@ -502,7 +502,7 @@ private: void handleTrialWarning(); }; -bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header); +WARN_UNUSED_RESULT bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header, bool skipThumbnail = true); } // End of namespace Lab diff --git a/engines/lab/savegame.cpp b/engines/lab/savegame.cpp index 656595e3e5..46ef1486f0 100644 --- a/engines/lab/savegame.cpp +++ b/engines/lab/savegame.cpp @@ -76,7 +76,7 @@ void LabEngine::writeSaveGameHeader(Common::OutSaveFile *out, const Common::Stri out->writeUint32BE(playTime); } -bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header) { +WARN_UNUSED_RESULT bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header, bool skipThumbnail) { uint32 id = in->readUint32BE(); // Check if it's a valid ScummVM savegame @@ -98,7 +98,11 @@ bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header) { header._descr.setDescription(saveName); // Get the thumbnail - header._descr.setThumbnail(Graphics::loadThumbnail(*in)); + Graphics::Surface *thumbnail; + if (!Graphics::loadThumbnail(*in, thumbnail, skipThumbnail)) { + return false; + } + header._descr.setThumbnail(thumbnail); uint32 saveDate = in->readUint32BE(); uint16 saveTime = in->readUint16BE(); @@ -174,7 +178,11 @@ bool LabEngine::loadGame(int slot) { return false; SaveGameHeader header; - readSaveGameHeader(file, header); + if (!readSaveGameHeader(file, header)) { + delete file; + return false; + } + _roomNum = file->readUint16LE(); _music->checkRoomMusic(1, _roomNum); _direction = file->readUint16LE(); -- cgit v1.2.3