diff options
author | Filippos Karapetis | 2012-04-19 01:01:16 -0700 |
---|---|---|
committer | Filippos Karapetis | 2012-04-19 01:01:16 -0700 |
commit | 6544a05bf83ceea3dbde9bfa2bfdd1e8f001d25d (patch) | |
tree | ce5cec89cf467c78b3871c241db99848c85fc483 | |
parent | 7332bc74756b3d2d43b48496fa81993d3f42e496 (diff) | |
parent | 9c70954f648d86863e260d0b174afd8749319338 (diff) | |
download | scummvm-rg350-6544a05bf83ceea3dbde9bfa2bfdd1e8f001d25d.tar.gz scummvm-rg350-6544a05bf83ceea3dbde9bfa2bfdd1e8f001d25d.tar.bz2 scummvm-rg350-6544a05bf83ceea3dbde9bfa2bfdd1e8f001d25d.zip |
Merge pull request #228 from upthorn/master
DrasculaMetaEngine: added list saves support
-rw-r--r-- | engines/drascula/detection.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/engines/drascula/detection.cpp b/engines/drascula/detection.cpp index 3310ac0598..6e38d49b94 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,62 @@ 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); + + // handle cases where the save directory and save index are detectably out of sync + if (saveDesc == "*") + saveDesc = "No name specified."; + + // 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"; } |