SCUMM: Cleanup querySaveMetaInfos implementation.

This results in less code and also less I/O operations (including seeking).
This commit is contained in:
Johannes Schickel 2013-11-27 19:29:21 +01:00
parent 3318c4e4ac
commit fdcb6a6b1a
3 changed files with 33 additions and 72 deletions

View File

@ -1262,25 +1262,21 @@ void ScummMetaEngine::removeSaveState(const char *target, int slot) const {
}
SaveStateDescriptor ScummMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
Common::String filename = ScummEngine::makeSavegameName(target, slot, false);
Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename);
if (!in)
return SaveStateDescriptor();
Common::String saveDesc;
Scumm::getSavegameName(in, saveDesc, 0); // FIXME: heversion?!?
delete in;
Graphics::Surface *thumbnail = nullptr;
SaveStateMetaInfos infos;
memset(&infos, 0, sizeof(infos));
SaveStateMetaInfos *infoPtr = &infos;
// TODO: Cleanup
Graphics::Surface *thumbnail = ScummEngine::loadThumbnailFromSlot(target, slot);
// FIXME: heversion?!?
if (!ScummEngine::querySaveMetaInfos(target, slot, 0, saveDesc, thumbnail, infoPtr)) {
return SaveStateDescriptor();
}
SaveStateDescriptor desc(slot, saveDesc);
desc.setThumbnail(thumbnail);
SaveStateMetaInfos infos;
memset(&infos, 0, sizeof(infos));
if (ScummEngine::loadInfosFromSlot(target, slot, &infos)) {
if (infoPtr) {
int day = (infos.date >> 24) & 0xFF;
int month = (infos.date >> 16) & 0xFF;
int year = infos.date & 0xFFFF;

View File

@ -678,72 +678,39 @@ bool getSavegameName(Common::InSaveFile *in, Common::String &desc, int heversion
return true;
}
Graphics::Surface *ScummEngine::loadThumbnailFromSlot(const char *target, int slot) {
Common::SeekableReadStream *in;
bool ScummEngine::querySaveMetaInfos(const char *target, int slot, int heversion, Common::String &desc, Graphics::Surface *&thumbnail, SaveStateMetaInfos *&timeInfos) {
if (slot < 0) {
return false;
}
SaveGameHeader hdr;
const Common::String filename = ScummEngine::makeSavegameName(target, slot, false);
Common::ScopedPtr<Common::SeekableReadStream> in(g_system->getSavefileManager()->openForLoading(filename));
if (slot < 0)
return 0;
Common::String filename = ScummEngine::makeSavegameName(target, slot, false);
if (!(in = g_system->getSavefileManager()->openForLoading(filename))) {
return 0;
}
// FIXME: HE version?
if (!loadAndCheckSaveGameHeader(in, 0, hdr)) {
delete in;
return 0;
}
if (hdr.ver < VER(52)) {
delete in;
return 0;
}
Graphics::Surface *thumb = 0;
if (Graphics::checkThumbnailHeader(*in)) {
thumb = Graphics::loadThumbnail(*in);
}
delete in;
return thumb;
}
bool ScummEngine::loadInfosFromSlot(const char *target, int slot, SaveStateMetaInfos *stuff) {
Common::SeekableReadStream *in;
SaveGameHeader hdr;
if (slot < 0)
return 0;
Common::String filename = makeSavegameName(target, slot, false);
if (!(in = g_system->getSavefileManager()->openForLoading(filename))) {
if (!in) {
return false;
}
// FIXME: HE version?
if (!loadAndCheckSaveGameHeader(in, 0, hdr)) {
delete in;
if (!loadAndCheckSaveGameHeader(in.get(), heversion, hdr)) {
return false;
}
if (hdr.ver < VER(56)) {
delete in;
return false;
desc = hdr.name;
if (hdr.ver > VER(52)) {
if (Graphics::checkThumbnailHeader(*in)) {
thumbnail = Graphics::loadThumbnail(*in);
}
if (hdr.ver > VER(57)) {
if (!loadInfos(in.get(), timeInfos)) {
return false;
}
} else {
timeInfos = nullptr;
}
}
if (!Graphics::skipThumbnail(*in)) {
delete in;
return false;
}
if (!loadInfos(in, stuff)) {
delete in;
return false;
}
delete in;
return true;
}

View File

@ -620,9 +620,7 @@ public:
// thumbnail + info stuff
public:
static Graphics::Surface *loadThumbnailFromSlot(const char *target, int slot);
static bool loadInfosFromSlot(const char *target, int slot, SaveStateMetaInfos *stuff);
static bool querySaveMetaInfos(const char *target, int slot, int heversion, Common::String &desc, Graphics::Surface *&thumbnail, SaveStateMetaInfos *&timeInfos);
protected:
void saveInfos(Common::WriteStream* file);