Skip to content

Commit

Permalink
Merge pull request #228 from upthorn/master
Browse files Browse the repository at this point in the history
DrasculaMetaEngine: added list saves support
  • Loading branch information
bluegr committed Apr 19, 2012
2 parents 7332bc7 + 9c70954 commit 6544a05
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions engines/drascula/detection.cpp
Expand Up @@ -23,6 +23,7 @@
#include "base/plugins.h"

#include "engines/advancedDetector.h"
#include "engines/savestate.h"
#include "common/file.h"

#include "drascula/drascula.h"
Expand Down Expand Up @@ -271,6 +272,62 @@ class DrasculaMetaEngine : public AdvancedMetaEngine {
_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";
}
Expand Down

0 comments on commit 6544a05

Please sign in to comment.