diff options
-rw-r--r-- | engines/sci/engine/file.cpp | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/engines/sci/engine/file.cpp b/engines/sci/engine/file.cpp index b0b753be1e..74cd812f89 100644 --- a/engines/sci/engine/file.cpp +++ b/engines/sci/engine/file.cpp @@ -311,52 +311,57 @@ static bool _savegame_sort_byDate(const SavegameDesc &l, const SavegameDesc &r) return (l.time > r.time); } -// Create a sorted array containing all found savedgames -void listSavegames(Common::Array<SavegameDesc> &saves) { +bool fillSavegameDesc(const Common::String &filename, SavegameDesc *desc) { Common::SaveFileManager *saveFileMan = g_sci->getSaveFileManager(); + Common::SeekableReadStream *in; + if ((in = saveFileMan->openForLoading(filename)) == nullptr) { + return false; + } - // Load all saves - Common::StringArray saveNames = saveFileMan->listSavefiles(g_sci->getSavegamePattern()); + SavegameMetadata meta; + if (!get_savegame_metadata(in, &meta) || meta.name.empty()) { + // invalid + delete in; + return false; + } + delete in; - for (Common::StringArray::const_iterator iter = saveNames.begin(); iter != saveNames.end(); ++iter) { - Common::String filename = *iter; - Common::SeekableReadStream *in; - if ((in = saveFileMan->openForLoading(filename))) { - SavegameMetadata meta; - if (!get_savegame_metadata(in, &meta) || meta.name.empty()) { - // invalid - delete in; - continue; - } - delete in; - - const int id = strtol(filename.end() - 3, NULL, 10); + const int id = strtol(filename.end() - 3, NULL, 10); + desc->id = id; + desc->date = meta.saveDate; + // We need to fix date in here, because we save DDMMYYYY instead of + // YYYYMMDD, so sorting wouldn't work + desc->date = ((desc->date & 0xFFFF) << 16) | ((desc->date & 0xFF0000) >> 8) | ((desc->date & 0xFF000000) >> 24); + desc->time = meta.saveTime; + desc->version = meta.version; + desc->gameVersion = meta.gameVersion; -#ifdef ENABLE_SCI32 - if (id == kNewGameId) { - continue; - } -#endif + if (meta.name.lastChar() == '\n') + meta.name.deleteLastChar(); - SavegameDesc desc; - desc.id = id; - desc.date = meta.saveDate; - // We need to fix date in here, because we save DDMMYYYY instead of - // YYYYMMDD, so sorting wouldn't work - desc.date = ((desc.date & 0xFFFF) << 16) | ((desc.date & 0xFF0000) >> 8) | ((desc.date & 0xFF000000) >> 24); - desc.time = meta.saveTime; - desc.version = meta.version; - desc.gameVersion = meta.gameVersion; + Common::strlcpy(desc->name, meta.name.c_str(), SCI_MAX_SAVENAME_LENGTH); - if (meta.name.lastChar() == '\n') - meta.name.deleteLastChar(); + return desc; +} - Common::strlcpy(desc.name, meta.name.c_str(), SCI_MAX_SAVENAME_LENGTH); +// Create an array containing all found savedgames, sorted by creation date +void listSavegames(Common::Array<SavegameDesc> &saves) { + Common::SaveFileManager *saveFileMan = g_sci->getSaveFileManager(); + Common::StringArray saveNames = saveFileMan->listSavefiles(g_sci->getSavegamePattern()); - debug(3, "Savegame in file %s ok, id %d", filename.c_str(), desc.id); + for (Common::StringArray::const_iterator iter = saveNames.begin(); iter != saveNames.end(); ++iter) { + const Common::String &filename = *iter; - saves.push_back(desc); +#ifdef ENABLE_SCI32 + const int id = strtol(filename.end() - 3, NULL, 10); + if (id == kNewGameId) { + continue; } +#endif + + SavegameDesc desc; + fillSavegameDesc(filename, &desc); + saves.push_back(desc); } // Sort the list by creation date of the saves |