diff options
author | uruk | 2013-08-19 21:14:21 +0200 |
---|---|---|
committer | uruk | 2013-08-19 21:14:21 +0200 |
commit | 52c07d08c0602936f33ea569ea6515cc1ae9f976 (patch) | |
tree | bae1cdb4f00f3a15d1aabe7741e64c0bfb77d7c3 | |
parent | 99b4b12b1cd1db9ab2ba092722a528c3703d93e9 (diff) | |
download | scummvm-rg350-52c07d08c0602936f33ea569ea6515cc1ae9f976.tar.gz scummvm-rg350-52c07d08c0602936f33ea569ea6515cc1ae9f976.tar.bz2 scummvm-rg350-52c07d08c0602936f33ea569ea6515cc1ae9f976.zip |
AVALANCHE: AvalancheEngine: Revise synchronize(), saveGame(), loadGameState(). Add loadGame(). Rename generateSaveFileName() to getSaveFileName(). AvalancheMetaEngine: Add listSaves() and removeSaveState().
-rw-r--r-- | engines/avalanche/avalanche.cpp | 76 | ||||
-rw-r--r-- | engines/avalanche/avalanche.h | 7 | ||||
-rw-r--r-- | engines/avalanche/detection.cpp | 62 |
3 files changed, 113 insertions, 32 deletions
diff --git a/engines/avalanche/avalanche.cpp b/engines/avalanche/avalanche.cpp index 113b199fa8..44b736f555 100644 --- a/engines/avalanche/avalanche.cpp +++ b/engines/avalanche/avalanche.cpp @@ -36,10 +36,9 @@ #include "common/textconsole.h" #include "common/savefile.h" - - #include "engines/util.h" +#include "gui/saveload.h" namespace Avalanche { @@ -136,25 +135,6 @@ const char *AvalancheEngine::getCopyrightString() const { void AvalancheEngine::synchronize(Common::Serializer &sz) { - Common::String signature; - if (sz.isSaving()) { - signature = "AVAL"; - for (uint16 i = 0; i < 4; i++) { - char actChr = signature[i]; - sz.syncAsByte(actChr); - } - } else { - if (!signature.empty()) - signature.clear(); - for (uint16 i = 0; i < 4; i++) { - char actChr; - sz.syncAsByte(actChr); - signature += actChr; - } - if (signature != "AVAL") - error("Corrupted save file!"); - } - //blockwrite(f, dna, sizeof(dna)); sz.syncAsByte(_gyro->dna.rw); sz.syncAsByte(_gyro->dna.carrying); @@ -353,13 +333,8 @@ Common::Error AvalancheEngine::saveGameState(int slot, const Common::String &des return (saveGame(slot, desc) ? Common::kNoError : Common::kWritingFailed); } -Common::String AvalancheEngine::generateSaveFileName(Common::String name, const int slot) { - name.toUppercase(); - return Common::String::format("%s-%d.ASG", name.c_str(), slot); -} - bool AvalancheEngine::saveGame(const int16 slot, const Common::String &desc) { - Common::String fileName = generateSaveFileName(desc, slot); + Common::String fileName = getSaveFileName(slot); Common::OutSaveFile *f = g_system->getSavefileManager()->openForSaving(fileName); if (!f) { @@ -367,6 +342,14 @@ bool AvalancheEngine::saveGame(const int16 slot, const Common::String &desc) { return false; } + char *signature = "AVAL"; + + f->write(signature, 4); + + f->writeUint32LE(desc.size()); + + f->write(desc.c_str(), desc.size()); + Common::Serializer sz(NULL, f); synchronize(sz); @@ -380,12 +363,47 @@ bool AvalancheEngine::saveGame(const int16 slot, const Common::String &desc) { +Common::String AvalancheEngine::getSaveFileName(const int slot) { + Common::String upperName = _targetName; + upperName.toUppercase(); + return upperName+ Common::String::format("-%02d.SAV", slot); +} + + + bool AvalancheEngine::canLoadGameStateCurrently() { // TODO: Refine these!!! return true; } -Common::Error AvalancheEngine::loadGameState(int slot, const Common::String &desc) { - return Common::kNoError; +Common::Error AvalancheEngine::loadGameState(int slot) { + return (loadGame(slot) ? Common::kNoError : Common::kReadingFailed); +} + +bool AvalancheEngine::loadGame(const int16 slot) { + Common::String fileName = getSaveFileName(slot); + Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(fileName); + + if (!f) + return false; + + // Check for our signature. + Common::String signature; + for (byte i = 0; i < 4; i++) + signature += f->readByte(); + if (signature != "AVAL") + return false; + + // We dont care about the description here. + uint32 descSize = f->readUint32LE(); + f->skip(descSize); + + Common::Serializer sz(f, NULL); + + synchronize(sz); + + delete f; + + return true; } diff --git a/engines/avalanche/avalanche.h b/engines/avalanche/avalanche.h index 39457ef94f..52472b6128 100644 --- a/engines/avalanche/avalanche.h +++ b/engines/avalanche/avalanche.h @@ -117,13 +117,16 @@ public: void synchronize(Common::Serializer &sz); + virtual bool canSaveGameStateCurrently(); Common::Error saveGameState(int slot, const Common::String &desc); - Common::String generateSaveFileName(Common::String name, const int slot); bool saveGame(const int16 slot, const Common::String &desc); + Common::String getSaveFileName(const int slot); + virtual bool canLoadGameStateCurrently(); - Common::Error loadGameState(int slot, const Common::String &desc); + Common::Error loadGameState(int slot); + bool loadGame(const int16 slot); void updateEvents(); diff --git a/engines/avalanche/detection.cpp b/engines/avalanche/detection.cpp index 701f12be99..fb68e2ec67 100644 --- a/engines/avalanche/detection.cpp +++ b/engines/avalanche/detection.cpp @@ -83,6 +83,10 @@ public: bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const; bool hasFeature(MetaEngineFeature f) const; + + int getMaximumSaveSlot() const { return 99; } + SaveStateList listSaves(const char *target) const; + void removeSaveState(const char *target, int slot) const; }; bool AvalancheMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const { @@ -92,7 +96,63 @@ bool AvalancheMetaEngine::createInstance(OSystem *syst, Engine **engine, const A } bool AvalancheMetaEngine::hasFeature(MetaEngineFeature f) const { - return false; + return (f == kSupportsListSaves) || (f == kSupportsDeleteSave); +} + +SaveStateList AvalancheMetaEngine::listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringArray filenames; + Common::String pattern = target; + pattern.toUppercase(); + pattern += "-??.SAV"; + + filenames = saveFileMan->listSavefiles(pattern); + sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + SaveStateList saveList; + char slot[3]; + int slotNum = 0; + for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { + slot[0] = filename->c_str()[filename->size() - 6]; + slot[1] = filename->c_str()[filename->size() - 5]; + slot[2] = '\0'; + // Obtain the last 2 digits of the filename (without extension), since they correspond to the save slot + slotNum = atoi(slot); + if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) { + Common::InSaveFile *file = saveFileMan->openForLoading(*filename); + if (file) { + /*int saveVersion = file->readByte(); + + if (saveVersion != kSavegameVersion) { + warning("Savegame of incompatible version"); + delete file; + continue; + }*/ + + // Read name + file->seek(4); // We skip the "AVAL" signature. + uint32 nameSize = file->readUint32LE(); + if (nameSize >= 255) { + delete file; + continue; + } + char *name = new char[nameSize + 1]; + file->read(name, nameSize); + name[nameSize] = 0; + + saveList.push_back(SaveStateDescriptor(slotNum, name)); + delete[] name; + delete file; + } + } + } + + return saveList; +} + +void AvalancheMetaEngine::removeSaveState(const char *target, int slot) const { + Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot); + g_system->getSavefileManager()->removeSavefile(fileName); } } // End of namespace Avalanche |