2012-02-12 12:34:51 +11:00
|
|
|
/* 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 02:34:22 +01:00
|
|
|
*
|
2012-02-12 12:34:51 +11:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2014-02-18 02:34:22 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-02-12 12:34:51 +11:00
|
|
|
* GNU General Public License for more details.
|
2014-02-18 02:34:22 +01:00
|
|
|
*
|
2012-02-12 12:34:51 +11:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on original Mortville Manor DOS source code
|
2012-03-29 16:39:18 +02:00
|
|
|
* Copyright (c) 1987-1989 Lankhor
|
2012-02-12 12:34:51 +11:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mortevielle/mortevielle.h"
|
2013-07-19 11:51:10 +02:00
|
|
|
#include "mortevielle/dialogs.h"
|
2012-02-12 12:34:51 +11:00
|
|
|
#include "mortevielle/mouse.h"
|
|
|
|
#include "mortevielle/saveload.h"
|
|
|
|
|
2013-07-19 11:51:10 +02:00
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
|
2012-02-12 12:34:51 +11:00
|
|
|
namespace Mortevielle {
|
|
|
|
|
|
|
|
static const char SAVEGAME_ID[4] = { 'M', 'O', 'R', 'T' };
|
|
|
|
|
2014-01-10 01:46:38 +01:00
|
|
|
SavegameManager::SavegameManager(MortevielleEngine *vm) {
|
2013-07-13 19:10:03 -04:00
|
|
|
_vm = vm;
|
2012-02-12 12:34:51 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle saving or loading savegame data
|
|
|
|
*/
|
|
|
|
void SavegameManager::sync_save(Common::Serializer &sz) {
|
2012-03-22 08:36:59 +01:00
|
|
|
sz.syncAsSint16LE(g_vm->_saveStruct._faithScore);
|
2012-03-14 23:29:42 +01:00
|
|
|
for (int i = 0; i < 11; ++i)
|
2012-10-14 21:59:27 +02:00
|
|
|
sz.syncAsByte(g_vm->_saveStruct._pctHintFound[i]);
|
2012-03-14 23:29:42 +01:00
|
|
|
for (int i = 0; i < 43; ++i)
|
2012-10-14 21:59:27 +02:00
|
|
|
sz.syncAsByte(g_vm->_saveStruct._availableQuestion[i]);
|
2012-03-14 23:29:42 +01:00
|
|
|
for (int i = 0; i < 31; ++i)
|
2012-10-14 10:28:03 +02:00
|
|
|
sz.syncAsByte(g_vm->_saveStruct._inventory[i]);
|
2012-03-22 08:36:59 +01:00
|
|
|
|
|
|
|
sz.syncAsSint16LE(g_vm->_saveStruct._currPlace);
|
|
|
|
sz.syncAsSint16LE(g_vm->_saveStruct._atticBallHoleObjectId);
|
|
|
|
sz.syncAsSint16LE(g_vm->_saveStruct._atticRodHoleObjectId);
|
|
|
|
sz.syncAsSint16LE(g_vm->_saveStruct._cellarObjectId);
|
|
|
|
sz.syncAsSint16LE(g_vm->_saveStruct._secretPassageObjectId);
|
|
|
|
sz.syncAsSint16LE(g_vm->_saveStruct._wellObjectId);
|
|
|
|
sz.syncAsSint16LE(g_vm->_saveStruct._selectedObjectId);
|
|
|
|
sz.syncAsSint16LE(g_vm->_saveStruct._purpleRoomObjectId);
|
|
|
|
sz.syncAsSint16LE(g_vm->_saveStruct._cryptObjectId);
|
|
|
|
sz.syncAsByte(g_vm->_saveStruct._alreadyEnteredManor);
|
|
|
|
sz.syncAsByte(g_vm->_saveStruct._fullHour);
|
2012-03-03 00:23:27 +01:00
|
|
|
|
2012-03-23 00:35:19 +01:00
|
|
|
sz.syncBytes(_tabdonSaveBuffer, 391);
|
2012-02-12 12:34:51 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inner code for loading a saved game
|
2012-03-18 09:44:05 +01:00
|
|
|
* @remarks Originally called 'takesav'
|
2012-02-12 12:34:51 +11:00
|
|
|
*/
|
2013-08-21 08:13:59 +02:00
|
|
|
bool SavegameManager::loadSavegame(const Common::String &filename) {
|
2012-02-12 12:34:51 +11:00
|
|
|
// Try loading first from the save area
|
|
|
|
Common::SeekableReadStream *stream = g_system->getSavefileManager()->openForLoading(filename);
|
|
|
|
|
|
|
|
Common::File f;
|
|
|
|
if (stream == NULL) {
|
2013-08-21 08:13:59 +02:00
|
|
|
if (!f.open(filename)) {
|
|
|
|
warning("Unable to open save file '%s'", filename.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-12 12:34:51 +11:00
|
|
|
stream = f.readStream(f.size());
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether it's a ScummVM saved game
|
|
|
|
char buffer[4];
|
|
|
|
stream->read(buffer, 4);
|
|
|
|
if (!strncmp(&buffer[0], &SAVEGAME_ID[0], 4)) {
|
|
|
|
// Yes, it is, so skip over the savegame header
|
|
|
|
SavegameHeader header;
|
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.
2018-04-06 00:06:38 +02:00
|
|
|
if (!readSavegameHeader(stream, header)) {
|
|
|
|
delete stream;
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-12 12:34:51 +11:00
|
|
|
} else {
|
|
|
|
stream->seek(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the game contents
|
|
|
|
Common::Serializer sz(stream, NULL);
|
|
|
|
sync_save(sz);
|
|
|
|
|
2012-03-22 08:36:59 +01:00
|
|
|
g_vm->_coreVar = g_vm->_saveStruct;
|
2012-03-18 09:44:05 +01:00
|
|
|
for (int i = 0; i <= 389; ++i)
|
2012-03-23 00:35:19 +01:00
|
|
|
g_vm->_tabdon[i + kAcha] = _tabdonSaveBuffer[i];
|
2012-02-12 12:34:51 +11:00
|
|
|
|
|
|
|
// Close the stream
|
2012-03-27 22:54:50 +02:00
|
|
|
delete stream;
|
2013-08-21 08:13:59 +02:00
|
|
|
|
|
|
|
return true;
|
2012-02-12 12:34:51 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a saved game
|
|
|
|
*/
|
2013-07-13 19:10:03 -04:00
|
|
|
Common::Error SavegameManager::loadGame(const Common::String &filename) {
|
2014-01-09 08:21:52 +01:00
|
|
|
g_vm->_mouse->hideMouse();
|
2012-03-24 09:47:36 +01:00
|
|
|
g_vm->displayEmptyHand();
|
2013-08-21 08:13:59 +02:00
|
|
|
if (loadSavegame(filename)) {
|
|
|
|
/* Initialization */
|
|
|
|
g_vm->charToHour();
|
|
|
|
g_vm->initGame();
|
|
|
|
g_vm->gameLoaded();
|
2014-01-09 08:21:52 +01:00
|
|
|
g_vm->_mouse->showMouse();
|
2013-08-21 08:13:59 +02:00
|
|
|
return Common::kNoError;
|
2014-02-16 18:24:19 +01:00
|
|
|
} else
|
2013-08-21 08:13:59 +02:00
|
|
|
return Common::kUnknownError;
|
2012-02-12 12:34:51 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the game
|
|
|
|
*/
|
|
|
|
Common::Error SavegameManager::saveGame(int n, const Common::String &saveName) {
|
|
|
|
Common::OutSaveFile *f;
|
|
|
|
int i;
|
|
|
|
|
2014-01-09 08:21:52 +01:00
|
|
|
g_vm->_mouse->hideMouse();
|
2012-03-18 09:44:05 +01:00
|
|
|
g_vm->hourToChar();
|
2012-03-27 22:54:50 +02:00
|
|
|
|
2012-02-21 18:51:44 +01:00
|
|
|
for (i = 0; i <= 389; ++i)
|
2012-03-23 00:35:19 +01:00
|
|
|
_tabdonSaveBuffer[i] = g_vm->_tabdon[i + kAcha];
|
2012-03-22 08:36:59 +01:00
|
|
|
g_vm->_saveStruct = g_vm->_coreVar;
|
2012-03-23 00:35:19 +01:00
|
|
|
if (g_vm->_saveStruct._currPlace == ROOM26)
|
|
|
|
g_vm->_saveStruct._currPlace = LANDING;
|
2012-03-27 22:54:50 +02:00
|
|
|
|
2013-07-13 19:10:03 -04:00
|
|
|
Common::String filename = _vm->generateSaveFilename(n);
|
2012-02-12 12:34:51 +11:00
|
|
|
f = g_system->getSavefileManager()->openForSaving(filename);
|
|
|
|
|
|
|
|
// Write out the savegame header
|
|
|
|
f->write(&SAVEGAME_ID[0], 4);
|
|
|
|
|
|
|
|
// Write out the header
|
|
|
|
SavegameHeader header;
|
|
|
|
writeSavegameHeader(f, saveName);
|
|
|
|
|
|
|
|
// Write out the savegame contents
|
|
|
|
Common::Serializer sz(NULL, f);
|
|
|
|
sync_save(sz);
|
|
|
|
|
|
|
|
// Close the save file
|
|
|
|
f->finalize();
|
|
|
|
delete f;
|
2012-03-27 22:54:50 +02:00
|
|
|
|
2012-03-07 08:33:48 +01:00
|
|
|
// Skipped: dialog asking to swap floppy
|
2012-02-12 12:34:51 +11:00
|
|
|
|
2014-01-09 08:21:52 +01:00
|
|
|
g_vm->_mouse->showMouse();
|
2012-02-12 12:34:51 +11:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2013-07-13 19:10:03 -04:00
|
|
|
Common::Error SavegameManager::loadGame(int slot) {
|
|
|
|
return loadGame(_vm->generateSaveFilename(slot));
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error SavegameManager::saveGame(int slot) {
|
|
|
|
return saveGame(slot, _vm->generateSaveFilename(slot));
|
|
|
|
}
|
|
|
|
|
2012-02-12 12:34:51 +11:00
|
|
|
void SavegameManager::writeSavegameHeader(Common::OutSaveFile *out, const Common::String &saveName) {
|
|
|
|
// Write out a savegame header
|
|
|
|
out->writeByte(SAVEGAME_VERSION);
|
|
|
|
|
|
|
|
// Write savegame name
|
|
|
|
out->writeString(saveName);
|
|
|
|
out->writeByte(0);
|
|
|
|
|
|
|
|
// Get the active palette
|
|
|
|
uint8 thumbPalette[256 * 3];
|
|
|
|
g_system->getPaletteManager()->grabPalette(thumbPalette, 0, 256);
|
|
|
|
|
|
|
|
// Create a thumbnail and save it
|
|
|
|
Graphics::Surface *thumb = new Graphics::Surface();
|
2014-01-10 01:46:38 +01:00
|
|
|
Graphics::Surface s = g_vm->_screenSurface->lockArea(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
|
2012-02-12 12:34:51 +11:00
|
|
|
|
2013-08-03 02:40:37 +02:00
|
|
|
::createThumbnail(thumb, (const byte *)s.getPixels(), SCREEN_WIDTH, SCREEN_HEIGHT, thumbPalette);
|
2012-02-12 12:34:51 +11:00
|
|
|
Graphics::saveThumbnail(*out, *thumb);
|
|
|
|
thumb->free();
|
|
|
|
delete thumb;
|
|
|
|
|
|
|
|
// Write out the save date/time
|
|
|
|
TimeDate td;
|
|
|
|
g_system->getTimeAndDate(td);
|
|
|
|
out->writeSint16LE(td.tm_year + 1900);
|
|
|
|
out->writeSint16LE(td.tm_mon + 1);
|
|
|
|
out->writeSint16LE(td.tm_mday);
|
|
|
|
out->writeSint16LE(td.tm_hour);
|
|
|
|
out->writeSint16LE(td.tm_min);
|
|
|
|
}
|
|
|
|
|
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.
2018-04-06 00:06:38 +02:00
|
|
|
WARN_UNUSED_RESULT bool SavegameManager::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header, bool skipThumbnail) {
|
2012-02-12 12:34:51 +11:00
|
|
|
// Get the savegame version
|
|
|
|
header.version = in->readByte();
|
|
|
|
|
|
|
|
// Read in the save name
|
|
|
|
header.saveName.clear();
|
|
|
|
char ch;
|
|
|
|
while ((ch = (char)in->readByte()) != '\0')
|
|
|
|
header.saveName += ch;
|
|
|
|
|
|
|
|
// Get the thumbnail
|
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.
2018-04-06 00:06:38 +02:00
|
|
|
if (!Graphics::loadThumbnail(*in, header.thumbnail, skipThumbnail)) {
|
2012-02-12 12:34:51 +11:00
|
|
|
return false;
|
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.
2018-04-06 00:06:38 +02:00
|
|
|
}
|
2012-02-12 12:34:51 +11:00
|
|
|
|
|
|
|
// Read in save date/time
|
|
|
|
header.saveYear = in->readSint16LE();
|
|
|
|
header.saveMonth = in->readSint16LE();
|
|
|
|
header.saveDay = in->readSint16LE();
|
|
|
|
header.saveHour = in->readSint16LE();
|
|
|
|
header.saveMinutes = in->readSint16LE();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-13 19:10:03 -04:00
|
|
|
SaveStateList SavegameManager::listSaves(const Common::String &target) {
|
|
|
|
Common::String pattern = target;
|
2016-06-08 10:15:06 +02:00
|
|
|
pattern += ".###";
|
2013-07-13 19:10:03 -04:00
|
|
|
|
2012-02-12 12:34:51 +11:00
|
|
|
Common::StringArray files = g_system->getSavefileManager()->listSavefiles(pattern);
|
|
|
|
|
|
|
|
SaveStateList saveList;
|
|
|
|
for (Common::StringArray::const_iterator file = files.begin(); file != files.end(); ++file) {
|
|
|
|
// Obtain the last 3 digits of the filename, since they correspond to the save slot
|
|
|
|
const Common::String &fname = *file;
|
2013-07-13 19:10:03 -04:00
|
|
|
int slotNumber = atoi(fname.c_str() + fname.size() - 3);
|
2012-02-12 12:34:51 +11:00
|
|
|
|
|
|
|
Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(fname);
|
|
|
|
if (in) {
|
|
|
|
// There can be two types of savegames: original interpreter savegames, and ScummVM savegames.
|
|
|
|
// Original interpreter savegames are 497 bytes, and still need to be supported because the
|
|
|
|
// initial game state is stored as a savegame
|
|
|
|
bool validFlag = false;
|
|
|
|
Common::String saveDescription;
|
|
|
|
|
|
|
|
char buffer[4];
|
|
|
|
in->read(buffer, 4);
|
|
|
|
if (!strncmp(&buffer[0], &SAVEGAME_ID[0], 4)) {
|
|
|
|
// ScummVm savegame. Read in the header to get the savegame name
|
|
|
|
SavegameHeader header;
|
|
|
|
validFlag = readSavegameHeader(in, header);
|
2012-03-27 22:54:50 +02:00
|
|
|
|
2012-02-12 12:34:51 +11:00
|
|
|
if (validFlag) {
|
|
|
|
saveDescription = header.saveName;
|
|
|
|
}
|
|
|
|
} else if (file->size() == 497) {
|
|
|
|
// Form an appropriate savegame name
|
2012-03-27 22:54:50 +02:00
|
|
|
saveDescription = (slotNumber == 0) ? "Initial game state" :
|
2012-02-12 12:34:51 +11:00
|
|
|
Common::String::format("Savegame #%d", slotNumber);
|
|
|
|
validFlag = true;
|
|
|
|
}
|
2012-03-27 22:54:50 +02:00
|
|
|
|
2012-02-12 12:34:51 +11:00
|
|
|
if (validFlag)
|
|
|
|
// Got a valid savegame
|
|
|
|
saveList.push_back(SaveStateDescriptor(slotNumber, saveDescription));
|
|
|
|
|
|
|
|
delete in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-26 00:53:43 +02:00
|
|
|
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
|
2012-02-12 12:34:51 +11:00
|
|
|
return saveList;
|
|
|
|
}
|
|
|
|
|
2013-07-13 19:10:03 -04:00
|
|
|
SaveStateDescriptor SavegameManager::querySaveMetaInfos(const Common::String &fileName) {
|
2012-02-12 12:34:51 +11:00
|
|
|
Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(fileName);
|
2012-03-27 22:54:50 +02:00
|
|
|
|
2012-02-12 12:34:51 +11:00
|
|
|
if (f) {
|
2013-07-13 19:10:03 -04:00
|
|
|
// Get the slot number
|
|
|
|
int slot = 1;
|
|
|
|
if (fileName.size() > 4 && fileName[fileName.size() - 4] == '.')
|
|
|
|
slot = atoi(fileName.c_str() + fileName.size() - 3);
|
|
|
|
|
2012-02-12 12:34:51 +11:00
|
|
|
// Check to see if it's a ScummVM savegame or not
|
|
|
|
char buffer[4];
|
|
|
|
f->read(buffer, 4);
|
|
|
|
|
|
|
|
bool hasHeader = !strncmp(&buffer[0], &SAVEGAME_ID[0], 4);
|
|
|
|
|
|
|
|
if (!hasHeader) {
|
|
|
|
// Original savegame perhaps?
|
|
|
|
delete f;
|
|
|
|
|
2013-07-31 03:36:16 +01:00
|
|
|
SaveStateDescriptor desc(slot, Common::String::format("Savegame - %03d", slot));
|
2012-02-12 12:34:51 +11:00
|
|
|
desc.setDeletableFlag(slot != 0);
|
|
|
|
desc.setWriteProtectedFlag(slot == 0);
|
|
|
|
return desc;
|
|
|
|
} else {
|
|
|
|
// Get the savegame header information
|
|
|
|
SavegameHeader header;
|
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.
2018-04-06 00:06:38 +02:00
|
|
|
if (!readSavegameHeader(f, header, false)) {
|
|
|
|
delete f;
|
|
|
|
return SaveStateDescriptor();
|
|
|
|
}
|
2012-02-12 12:34:51 +11:00
|
|
|
delete f;
|
|
|
|
|
|
|
|
// Create the return descriptor
|
|
|
|
SaveStateDescriptor desc(slot, header.saveName);
|
|
|
|
desc.setDeletableFlag(true);
|
|
|
|
desc.setWriteProtectedFlag(false);
|
|
|
|
desc.setThumbnail(header.thumbnail);
|
|
|
|
desc.setSaveDate(header.saveYear, header.saveMonth, header.saveDay);
|
|
|
|
desc.setSaveTime(header.saveHour, header.saveMinutes);
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
}
|
2012-03-27 22:54:50 +02:00
|
|
|
|
2012-02-12 12:34:51 +11:00
|
|
|
return SaveStateDescriptor();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Mortevielle
|