diff options
author | Christopher Page | 2008-07-29 05:05:04 +0000 |
---|---|---|
committer | Christopher Page | 2008-07-29 05:05:04 +0000 |
commit | cf97920930df19581c2d5f1a169facdd9a3811ef (patch) | |
tree | ec1f3df2c979659348cd4d005845963a1cf71ccd | |
parent | b0e08965795e18c560bfe26a0dcacb6ffaab611e (diff) | |
download | scummvm-rg350-cf97920930df19581c2d5f1a169facdd9a3811ef.tar.gz scummvm-rg350-cf97920930df19581c2d5f1a169facdd9a3811ef.tar.bz2 scummvm-rg350-cf97920930df19581c2d5f1a169facdd9a3811ef.zip |
Added --list-saves support for SWORD2
svn-id: r33396
-rw-r--r-- | engines/sword2/sword2.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp index fc0da92248..3b6f51050b 100644 --- a/engines/sword2/sword2.cpp +++ b/engines/sword2/sword2.cpp @@ -33,6 +33,7 @@ #include "common/file.h" #include "common/fs.h" #include "common/events.h" +#include "common/savefile.h" #include "common/system.h" #include "engines/metaengine.h" @@ -82,6 +83,7 @@ public: virtual GameList getSupportedGames() const; virtual GameDescriptor findGame(const char *gameid) const; virtual GameList detectGames(const FSList &fslist) const; + virtual SaveStateList listSaves(const char *target) const; virtual PluginError createInstance(OSystem *syst, Engine **engine) const; }; @@ -156,6 +158,35 @@ GameList Sword2MetaEngine::detectGames(const FSList &fslist) const { return detectedGames; } +SaveStateList Sword2MetaEngine::listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringList filenames; + char saveDesc[SAVE_DESCRIPTION_LEN]; + Common::String pattern = target; + pattern += ".???"; + + filenames = saveFileMan->listSavefiles(pattern.c_str()); + sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + SaveStateList saveList; + for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 3); + + if (slotNum >= 0 && slotNum <= 999) { + Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str()); + if (in) { + in->readUint32LE(); + in->read(saveDesc, SAVE_DESCRIPTION_LEN); + saveList.push_back(SaveStateDescriptor(slotNum, Common::String(saveDesc), *file)); + delete in; + } + } + } + + return saveList; +} + PluginError Sword2MetaEngine::createInstance(OSystem *syst, Engine **engine) const { assert(syst); assert(engine); |