diff options
author | Strangerke | 2013-09-11 21:33:10 +0200 |
---|---|---|
committer | Strangerke | 2013-09-11 21:33:10 +0200 |
commit | da1a427e794434a09cd39ab45e32ae7afca9a170 (patch) | |
tree | 85b4700515bc7853e4f90ddae22bc3b785c4ab3a /engines/agos/saveload.cpp | |
parent | 49dbac6a2a5cde294a4c4c9a47467e7b5d95e08b (diff) | |
parent | 5c6ee7573c0cf05bbbb154d4734e94e478f453e5 (diff) | |
download | scummvm-rg350-da1a427e794434a09cd39ab45e32ae7afca9a170.tar.gz scummvm-rg350-da1a427e794434a09cd39ab45e32ae7afca9a170.tar.bz2 scummvm-rg350-da1a427e794434a09cd39ab45e32ae7afca9a170.zip |
Merge branch 'master' of https://github.com/urukgit/scummvm into avalanche
Diffstat (limited to 'engines/agos/saveload.cpp')
-rw-r--r-- | engines/agos/saveload.cpp | 99 |
1 files changed, 40 insertions, 59 deletions
diff --git a/engines/agos/saveload.cpp b/engines/agos/saveload.cpp index 48671390f0..8eb7f066b3 100644 --- a/engines/agos/saveload.cpp +++ b/engines/agos/saveload.cpp @@ -33,32 +33,35 @@ namespace AGOS { + +// FIXME: This code counts savegames, but callers in many cases assume +// that the return value + 1 indicates an empty slot. int AGOSEngine::countSaveGames() { Common::InSaveFile *f = NULL; Common::StringArray filenames; uint i = 1; - char slot[4]; int slotNum; bool marks[256]; - char *prefix = genSaveName(998); - prefix[strlen(prefix)-3] = '*'; - prefix[strlen(prefix)-2] = '\0'; + // Get the name of (possibly non-existent) savegame slot 998, and replace + // the extension by * to get a pattern. + Common::String tmp = genSaveName(998); + assert(tmp.size() >= 4 && tmp[tmp.size()-4] == '.'); + Common::String prefix = Common::String(tmp.c_str(), tmp.size()-3) + "*"; + memset(marks, false, 256 * sizeof(bool)); //assume no savegames for this title filenames = _saveFileMan->listSavefiles(prefix); for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file){ //Obtain the last 3 digits of the filename, since they correspond to the save slot - slot[0] = file->c_str()[file->size()-3]; - slot[1] = file->c_str()[file->size()-2]; - slot[2] = file->c_str()[file->size()-1]; - slot[3] = '\0'; - - slotNum = atoi(slot); + assert(file->size() >= 4); + slotNum = atoi(file->c_str() + file->size() - 3); if (slotNum >= 0 && slotNum < 256) marks[slotNum] = true; //mark this slot as valid } + // FIXME: Why does this already try to actually open the savegames? + // Historical accident? while (i < 256) { if (marks[i] && (f = _saveFileMan->openForLoading(genSaveName(i)))) { @@ -72,68 +75,46 @@ int AGOSEngine::countSaveGames() { } #ifdef ENABLE_AGOS2 -char *AGOSEngine_PuzzlePack::genSaveName(int slot) { - static char buf[20]; - +Common::String AGOSEngine_PuzzlePack::genSaveName(int slot) const { if (getGameId() == GID_DIMP) - sprintf(buf, "dimp.sav"); + return "dimp.sav"; else - sprintf(buf, "swampy.sav"); - - return buf; + return "swampy.sav"; } -char *AGOSEngine_Feeble::genSaveName(int slot) { - static char buf[20]; - sprintf(buf, "feeble.%.3d", slot); - return buf; +Common::String AGOSEngine_Feeble::genSaveName(int slot) const { + return Common::String::format("feeble.%.3d", slot); } #endif -char *AGOSEngine_Simon2::genSaveName(int slot) { - static char buf[20]; - sprintf(buf, "simon2.%.3d", slot); - return buf; +Common::String AGOSEngine_Simon2::genSaveName(int slot) const { + return Common::String::format("simon2.%.3d", slot); } -char *AGOSEngine_Simon1::genSaveName(int slot) { - static char buf[20]; - sprintf(buf, "simon1.%.3d", slot); - return buf; +Common::String AGOSEngine_Simon1::genSaveName(int slot) const { + return Common::String::format("simon1.%.3d", slot); } -char *AGOSEngine_Waxworks::genSaveName(int slot) { - static char buf[20]; - +Common::String AGOSEngine_Waxworks::genSaveName(int slot) const { if (getPlatform() == Common::kPlatformDOS) - sprintf(buf, "waxworks-pc.%.3d", slot); + return Common::String::format("waxworks-pc.%.3d", slot); else - sprintf(buf, "waxworks.%.3d", slot); - - return buf; + return Common::String::format("waxworks.%.3d", slot); } -char *AGOSEngine_Elvira2::genSaveName(int slot) { - static char buf[20]; - +Common::String AGOSEngine_Elvira2::genSaveName(int slot) const { if (getPlatform() == Common::kPlatformDOS) - sprintf(buf, "elvira2-pc.%.3d", slot); + return Common::String::format("elvira2-pc.%.3d", slot); else - sprintf(buf, "elvira2.%.3d", slot); - - return buf; + return Common::String::format("elvira2.%.3d", slot); } -char *AGOSEngine_Elvira1::genSaveName(int slot) { - static char buf[20]; - sprintf(buf, "elvira1.%.3d", slot); - return buf; +Common::String AGOSEngine_Elvira1::genSaveName(int slot) const { + return Common::String::format("elvira1.%.3d", slot); } -char *AGOSEngine::genSaveName(int slot) { - static char buf[20]; - sprintf(buf, "pn.%.3d", slot); - return buf; +Common::String AGOSEngine::genSaveName(int slot) const { + return Common::String::format("pn.%.3d", slot); } #ifdef ENABLE_AGOS2 @@ -177,12 +158,12 @@ void AGOSEngine::quickLoadOrSave() { waitForSync(1122); } - char *filename = genSaveName(_saveLoadSlot); + Common::String filename = genSaveName(_saveLoadSlot); if (_saveLoadType == 2) { Subroutine *sub; success = loadGame(genSaveName(_saveLoadSlot)); if (!success) { - buf = Common::String::format(_("Failed to load game state from file:\n\n%s"), filename); + buf = Common::String::format(_("Failed to load game state from file:\n\n%s"), filename.c_str()); } else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) { drawIconArray(2, me(), 0, 0); setBitFlag(97, true); @@ -217,7 +198,7 @@ void AGOSEngine::quickLoadOrSave() { } else { success = saveGame(_saveLoadSlot, _saveLoadName); if (!success) - buf = Common::String::format(_("Failed to save game state to file:\n\n%s"), filename); + buf = Common::String::format(_("Failed to save game state to file:\n\n%s"), filename.c_str()); } if (!success) { @@ -225,7 +206,7 @@ void AGOSEngine::quickLoadOrSave() { dialog.runModal(); } else if (_saveLoadType == 1) { - buf = Common::String::format(_("Successfully saved game state in file:\n\n%s"), filename); + buf = Common::String::format(_("Successfully saved game state in file:\n\n%s"), filename.c_str()); GUI::TimedMessageDialog dialog(buf, 1500); dialog.runModal(); @@ -1041,7 +1022,7 @@ void writeItemID(Common::WriteStream *f, uint16 val) { f->writeUint32BE(val - 1); } -bool AGOSEngine::loadGame(const char *filename, bool restartMode) { +bool AGOSEngine::loadGame(const Common::String &filename, bool restartMode) { char ident[100]; Common::SeekableReadStream *f = NULL; uint num, item_index, i; @@ -1215,7 +1196,7 @@ bool AGOSEngine::saveGame(uint slot, const char *caption) { return result; } -bool AGOSEngine_Elvira2::loadGame(const char *filename, bool restartMode) { +bool AGOSEngine_Elvira2::loadGame(const Common::String &filename, bool restartMode) { char ident[100]; Common::SeekableReadStream *f = NULL; uint num, item_index, i, j; @@ -1633,7 +1614,7 @@ void AGOSEngine_PN::getFilename() { } } -int AGOSEngine_PN::loadFile(char *name) { +int AGOSEngine_PN::loadFile(const Common::String &name) { Common::InSaveFile *f; haltAnimation(); @@ -1666,7 +1647,7 @@ int AGOSEngine_PN::loadFile(char *name) { return 0; } -int AGOSEngine_PN::saveFile(char *name) { +int AGOSEngine_PN::saveFile(const Common::String &name) { Common::OutSaveFile *f; sysftodb(); haltAnimation(); |