diff options
author | upthorn | 2012-04-15 11:09:15 -0700 |
---|---|---|
committer | upthorn | 2012-04-15 11:09:15 -0700 |
commit | 9e5015e631ed070b6a500fac1734b6a4e8c04fea (patch) | |
tree | e155196071ba34694c9cd3d93a43407833924c29 | |
parent | 586d9bf32fed9bc2009dcf890a0b714e1e618c2c (diff) | |
download | scummvm-rg350-9e5015e631ed070b6a500fac1734b6a4e8c04fea.tar.gz scummvm-rg350-9e5015e631ed070b6a500fac1734b6a4e8c04fea.tar.bz2 scummvm-rg350-9e5015e631ed070b6a500fac1734b6a4e8c04fea.zip |
DRASCULA: added list saves support
Added kSupportsListSaves to DrasculaMetaEngine::hasFeature
Added working listSaves to DrasculaMetaEngine
-rw-r--r-- | engines/drascula/detection.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/engines/drascula/detection.cpp b/engines/drascula/detection.cpp index 3310ac0598..07f1634d87 100644 --- a/engines/drascula/detection.cpp +++ b/engines/drascula/detection.cpp @@ -23,6 +23,7 @@ #include "base/plugins.h" #include "engines/advancedDetector.h" +#include "engines/savestate.h" #include "common/file.h" #include "drascula/drascula.h" @@ -271,6 +272,59 @@ public: _guioptions = GUIO2(GUIO_NOMIDI, GUIO_NOLAUNCHLOAD); } + virtual bool hasFeature(MetaEngineFeature f) const { + return (f == kSupportsListSaves); + } + + virtual SaveStateList listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::String pattern = Common::String::format("%s??", target); + + // Get list of savefiles for target game + Common::StringArray filenames = saveFileMan->listSavefiles(pattern); + Common::Array<int> slots; + for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + + // Obtain the last 2 digits of the filename, since they correspond to the save slot + int slotNum = atoi(file->c_str() + file->size() - 2); + + // Ensure save slot is within valid range + if (slotNum >= 1 && slotNum <= 10) { + slots.push_back(slotNum); + } + } + + // Sort save slot ids + Common::sort<int>(slots.begin(), slots.end()); + + // Load save index + Common::String fileEpa = Common::String::format("%s.epa", target); + Common::InSaveFile *epa = saveFileMan->openForLoading(fileEpa); + + // Get savegame names from index + Common::String saveDesc; + SaveStateList saveList; + int line = 1; + for (size_t i = 0; i < slots.size(); i++) { + + // ignore lines corresponding to unused saveslots + for (; line < slots[i]; line++) + epa->readLine(); + + // copy the name in the line corresponding to the save slot and truncate to 22 characters + saveDesc = Common::String(epa->readLine().c_str(), 22); + + // increment line number to keep it in sync with slot number + line++; + + // Insert savegame name into list + saveList.push_back(SaveStateDescriptor(slots[i], saveDesc)); + } + delete epa; + + return saveList; + } + virtual const char *getName() const { return "Drascula"; } |