GRIM: Fix handling of saves with id > 99 from the gui. Fix #404

This commit is contained in:
Giulio Camuffo 2011-12-09 18:36:56 +01:00
parent 35fade48b6
commit 8e174ee18e
2 changed files with 15 additions and 7 deletions

View File

@ -441,24 +441,28 @@ bool GrimMetaEngine::hasFeature(MetaEngineFeature f) const {
(f == kSupportsLoadingDuringStartup);
}
static bool cmpSave(const SaveStateDescriptor &x, const SaveStateDescriptor &y) {
return x.getSaveSlot() < y.getSaveSlot();
}
SaveStateList GrimMetaEngine::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
Common::String saveDesc;
Common::String pattern = "grim??.gsv";
Common::String pattern = "grim*.gsv";
filenames = saveFileMan->listSavefiles(pattern);
sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)
SaveStateList saveList;
char str[256];
int32 strSize;
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
// Obtain the last digits of the filename, since they correspond to the save slot
int slotNum = atoi(file->c_str() + 4);
if (slotNum >= 0 && slotNum <= 99) {
SaveGame *savedState = SaveGame::openForLoading((*file).c_str());
if (slotNum >= 0) {
SaveGame *savedState = SaveGame::openForLoading(*file);
if (savedState) {
if (savedState->saveVersion() != SaveGame::SAVEGAME_VERSION) {
delete savedState;
@ -475,6 +479,7 @@ SaveStateList GrimMetaEngine::listSaves(const char *target) const {
}
}
Common::sort(saveList.begin(), saveList.end(), cmpSave);
return saveList;
}

View File

@ -276,10 +276,13 @@ Common::Error GrimEngine::run() {
// Load game from specified slot, if any
if (ConfMan.hasKey("save_slot")) {
int slot = ConfMan.getInt("save_slot");
assert(slot <= 99);
assert(slot >= 0);
char saveName[16];
sprintf(saveName, "grim%02d.gsv", slot);
if (slot < 100) {
sprintf(saveName, "grim%02d.gsv", slot);
} else {
sprintf(saveName, "grim%d.gsv", slot);
}
_savegameLoadRequest = true;
_savegameFileName = saveName;
}