aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorbjörn Andersson2008-10-26 11:19:10 +0000
committerTorbjörn Andersson2008-10-26 11:19:10 +0000
commitc8312fdacc55036bae885f454ab0b25ecf4094ee (patch)
treef75f8b3e20709c0895df49890cc32f65357453a1
parented5beecd33b9e53cb4732dcd9559a76cb5092a78 (diff)
downloadscummvm-rg350-c8312fdacc55036bae885f454ab0b25ecf4094ee.tar.gz
scummvm-rg350-c8312fdacc55036bae885f454ab0b25ecf4094ee.tar.bz2
scummvm-rg350-c8312fdacc55036bae885f454ab0b25ecf4094ee.zip
Another attempt at making the Broken Sword 1 savegame list in the launcher match
the in-game one. Only show savegames which actually have a corresponding save file. (That's a trick the in-game dialog doesn't know yet.) The match isn't perfect, though: The launcher lists the first save slot as 0, while the in-game dialog lists it as 1. But changing the launcher one will make it set the wrong "save_slot" value. svn-id: r34851
-rw-r--r--engines/sword1/sword1.cpp61
1 files changed, 41 insertions, 20 deletions
diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp
index 2bc4556be0..05bc3120f0 100644
--- a/engines/sword1/sword1.cpp
+++ b/engines/sword1/sword1.cpp
@@ -207,36 +207,57 @@ SaveStateList SwordMetaEngine::listSaves(const char *target) const {
Common::StringList::const_iterator file = filenames.begin();
Common::InSaveFile *in = saveFileMan->openForLoading("SAVEGAME.INF");
+
if (in) {
- // FIXME: Is it ok to initialize the stop-variable to zero?
+ Common::Array<uint32> offsets;
uint8 stop = 0;
- char saveDesc[32];
- // FIXME: What about if file-iterator goes beyond end before stop == 255 || in->eos()?
- do {
+ int slotsInFile = 0;
+
+ // Find the offset for each savegame name in the file.
+ while (stop != 255 && !in->eos()) {
+ offsets.push_back(in->pos());
+ slotsInFile++;
+ stop = 0;
+ while (stop != 10 && stop != 255 && !in->eos())
+ stop = in->readByte();
+ }
+
+ // Match the savegames to the save slot names.
+ while (file != filenames.end()) {
+ char saveDesc[32];
+
if (file->compareToIgnoreCase("SAVEGAME.INF") == 0) {
file++;
continue;
}
-
+
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNum = atoi(file->c_str() + file->size() - 3);
- uint pos = 0;
- do {
- stop = in->readByte();
- if (pos < (sizeof(saveDesc) - 1)) {
- if ((stop == 10) || (stop == 255) || (in->eos()))
- saveDesc[pos++] = '\0';
- else if (stop >= 32)
- saveDesc[pos++] = stop;
- }
- } while ((stop != 10) && (stop != 255) && (!in->eos()));
-
- if (saveDesc[0] != 0) {
- saveList.push_back(SaveStateDescriptor(slotNum, saveDesc, *file));
- file++;
+ if (slotNum >= 0 && slotNum < slotsInFile) {
+ in->seek(offsets[slotNum]);
+
+ uint pos = 0;
+ do {
+ stop = in->readByte();
+ if (pos < sizeof(saveDesc) - 1) {
+ if (stop == 10 || stop == 255 || in->eos())
+ saveDesc[pos++] = '\0';
+ else if (stop >= 32)
+ saveDesc[pos++] = stop;
+ }
+ } while (stop != 10 && stop != 255 && !in->eos());
}
- } while ((stop != 255) && (!in->eos()));
+
+ if (saveDesc[0] == 0)
+ strcpy(saveDesc, "Unnamed savegame");
+
+ // FIXME: The in-game dialog shows the first save slot as 1, not 0,
+ // but if we change the numbering here, the launcher won̈́t set
+ // "save_slot" correctly.
+ saveList.push_back(SaveStateDescriptor(slotNum, saveDesc, *file));
+ file++;
+ }
}
delete in;