diff options
author | Willem Jan Palenstijn | 2013-08-23 19:09:36 +0200 |
---|---|---|
committer | Willem Jan Palenstijn | 2013-08-23 19:09:36 +0200 |
commit | f0c2fa9d65167f03a0aa7879997762c4f3d4702a (patch) | |
tree | a0e1ea838e0f5b405f9f97d798fc644762b79942 | |
parent | acc286142ea5ccccbedda8be5c8aeec23deee326 (diff) | |
download | scummvm-rg350-f0c2fa9d65167f03a0aa7879997762c4f3d4702a.tar.gz scummvm-rg350-f0c2fa9d65167f03a0aa7879997762c4f3d4702a.tar.bz2 scummvm-rg350-f0c2fa9d65167f03a0aa7879997762c4f3d4702a.zip |
AGOS: Use Common::String for savegame filenames
-rw-r--r-- | engines/agos/agos.h | 24 | ||||
-rw-r--r-- | engines/agos/saveload.cpp | 85 | ||||
-rw-r--r-- | engines/agos/script_pn.cpp | 14 |
3 files changed, 52 insertions, 71 deletions
diff --git a/engines/agos/agos.h b/engines/agos/agos.h index 65f8dd1420..87a1228c6a 100644 --- a/engines/agos/agos.h +++ b/engines/agos/agos.h @@ -1272,7 +1272,7 @@ protected: Item *getNextItemPtrStrange(); - virtual bool loadGame(const char *filename, bool restartMode = false); + virtual bool loadGame(const Common::String &filename, bool restartMode = false); virtual bool saveGame(uint slot, const char *caption); void openTextWindow(); @@ -1311,7 +1311,7 @@ protected: int countSaveGames(); - virtual char *genSaveName(int slot); + virtual Common::String genSaveName(int slot) const; }; class AGOSEngine_PN : public AGOSEngine { @@ -1517,8 +1517,8 @@ protected: virtual void windowPutChar(WindowBlock *window, byte c, byte b = 0); bool badload(int8 errorNum); - int loadFile(char *name); - int saveFile(char *name); + int loadFile(const Common::String &name); + int saveFile(const Common::String &name); void getFilename(); void sysftodb(); void dbtosysf(); @@ -1640,7 +1640,7 @@ protected: virtual void drawIcon(WindowBlock *window, uint icon, uint x, uint y); - virtual char *genSaveName(int slot); + virtual Common::String genSaveName(int slot) const; }; class AGOSEngine_Elvira2 : public AGOSEngine_Elvira1 { @@ -1709,7 +1709,7 @@ protected: virtual void readItemChildren(Common::SeekableReadStream *in, Item *item, uint tmp); - virtual bool loadGame(const char *filename, bool restartMode = false); + virtual bool loadGame(const Common::String &filename, bool restartMode = false); virtual bool saveGame(uint slot, const char *caption); virtual void addArrows(WindowBlock *window, uint8 num); @@ -1735,7 +1735,7 @@ protected: virtual void userGame(bool load); virtual int userGameGetKey(bool *b, char *buf, uint maxChar); - virtual char *genSaveName(int slot); + virtual Common::String genSaveName(int slot) const; }; class AGOSEngine_Waxworks : public AGOSEngine_Elvira2 { @@ -1802,7 +1802,7 @@ protected: virtual bool confirmOverWrite(WindowBlock *window); - virtual char *genSaveName(int slot); + virtual Common::String genSaveName(int slot) const; }; class AGOSEngine_Simon1 : public AGOSEngine_Waxworks { @@ -1873,7 +1873,7 @@ protected: virtual void vcStopAnimation(uint16 zone, uint16 sprite); - virtual char *genSaveName(int slot); + virtual Common::String genSaveName(int slot) const; }; class AGOSEngine_Simon2 : public AGOSEngine_Simon1 { @@ -1919,7 +1919,7 @@ protected: virtual void playSpeech(uint16 speechId, uint16 vgaSpriteId); - virtual char *genSaveName(int slot); + virtual Common::String genSaveName(int slot) const; }; #ifdef ENABLE_AGOS2 @@ -2059,7 +2059,7 @@ protected: void saveUserGame(int slot); void windowBackSpace(WindowBlock *window); - virtual char *genSaveName(int slot); + virtual Common::String genSaveName(int slot) const; virtual void quickLoadOrSave(); }; @@ -2139,7 +2139,7 @@ protected: void printInfoText(const char *itemText); - virtual char *genSaveName(int slot); + virtual Common::String genSaveName(int slot) const; }; diff --git a/engines/agos/saveload.cpp b/engines/agos/saveload.cpp index 3a35c094b0..e2e0d80c92 100644 --- a/engines/agos/saveload.cpp +++ b/engines/agos/saveload.cpp @@ -40,9 +40,12 @@ int AGOSEngine::countSaveGames() { 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); @@ -67,68 +70,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 @@ -172,12 +153,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); @@ -212,7 +193,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) { @@ -220,7 +201,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(); @@ -1036,7 +1017,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; @@ -1210,7 +1191,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; @@ -1628,7 +1609,7 @@ void AGOSEngine_PN::getFilename() { } } -int AGOSEngine_PN::loadFile(char *name) { +int AGOSEngine_PN::loadFile(const Common::String &name) { Common::InSaveFile *f; haltAnimation(); @@ -1661,7 +1642,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(); diff --git a/engines/agos/script_pn.cpp b/engines/agos/script_pn.cpp index bea83f141a..e98cd2795a 100644 --- a/engines/agos/script_pn.cpp +++ b/engines/agos/script_pn.cpp @@ -370,7 +370,7 @@ void AGOSEngine_PN::opn_opcode30() { void AGOSEngine_PN::opn_opcode31() { int a, slot = 0; - char bf[60]; + Common::String bf; if ((a = varval()) > 2) { setScriptReturn(false); @@ -381,10 +381,10 @@ void AGOSEngine_PN::opn_opcode31() { case 0: getFilename(); slot = matchSaveGame(_saveFile, countSaveGames()); - Common::strlcpy(bf, genSaveName(slot), sizeof(bf)); + bf = genSaveName(slot); break; case 1: - strcpy(bf, "pn.sav"); + bf = "pn.sav"; break; case 2: // NOTE: Is this case ever used? @@ -404,7 +404,7 @@ void AGOSEngine_PN::opn_opcode31() { } void AGOSEngine_PN::opn_opcode32() { - char bf[60]; + Common::String bf; int a, slot; a = varval(); @@ -419,12 +419,12 @@ void AGOSEngine_PN::opn_opcode32() { getFilename(); slot = matchSaveGame(_saveFile, curSlot); if (slot != -1) - Common::strlcpy(bf, genSaveName(slot), sizeof(bf)); + bf = genSaveName(slot); else - Common::strlcpy(bf, genSaveName(curSlot), sizeof(bf)); + bf = genSaveName(curSlot); break; case 1: - strcpy(bf, "pn.sav"); + bf = "pn.sav"; break; case 2: // NOTE: Is this case ever used? |