diff options
author | Sven Hesse | 2011-01-25 12:14:05 +0000 |
---|---|---|
committer | Sven Hesse | 2011-01-25 12:14:05 +0000 |
commit | 0432ca6d0f4240b7e5640197f4fbce6d512b0f4b (patch) | |
tree | 3dcdb42eec7fc9a9124b6b36082b22314eb588ab /engines/gob | |
parent | ff13458eb74348960baa852e0c6bdcdc97faf88e (diff) | |
download | scummvm-rg350-0432ca6d0f4240b7e5640197f4fbce6d512b0f4b.tar.gz scummvm-rg350-0432ca6d0f4240b7e5640197f4fbce6d512b0f4b.tar.bz2 scummvm-rg350-0432ca6d0f4240b7e5640197f4fbce6d512b0f4b.zip |
GOB: Add a FakeFileHandler
For temporarily storing save "files"
svn-id: r55528
Diffstat (limited to 'engines/gob')
-rw-r--r-- | engines/gob/save/savehandler.cpp | 44 | ||||
-rw-r--r-- | engines/gob/save/savehandler.h | 20 |
2 files changed, 63 insertions, 1 deletions
diff --git a/engines/gob/save/savehandler.cpp b/engines/gob/save/savehandler.cpp index 68f1f22b78..83f6e51cc5 100644 --- a/engines/gob/save/savehandler.cpp +++ b/engines/gob/save/savehandler.cpp @@ -489,4 +489,48 @@ bool NotesHandler::save(int16 dataVar, int32 size, int32 offset) { return writer.writePart(0, &vars); } + +FakeFileHandler::FakeFileHandler(GobEngine *vm) : SaveHandler(vm) { +} + +FakeFileHandler::~FakeFileHandler() { +} + +int32 FakeFileHandler::getSize() { + if (_data.empty()) + return -1; + + return _data.size(); +} + +bool FakeFileHandler::load(int16 dataVar, int32 size, int32 offset) { + if (size <= 0) + return false; + + if ((uint32)(offset + size) > _data.size()) + return false; + + _vm->_inter->_variables->copyFrom(dataVar, &_data[0] + offset, size); + + return true; +} + +bool FakeFileHandler::save(int16 dataVar, int32 size, int32 offset) { + if (size <= 0) + return false; + + if ((uint32)(offset + size) > _data.size()) + _data.resize(offset + size); + + _vm->_inter->_variables->copyTo(dataVar, &_data[0] + offset, size); + + return true; +} + +bool FakeFileHandler::deleteFile() { + _data.clear(); + + return true; +} + } // End of namespace Gob diff --git a/engines/gob/save/savehandler.h b/engines/gob/save/savehandler.h index a5ae1f5c21..d12d6bca0d 100644 --- a/engines/gob/save/savehandler.h +++ b/engines/gob/save/savehandler.h @@ -27,7 +27,9 @@ #define GOB_SAVE_SAVEHANDLER_H #include "common/savefile.h" -#include "engines/gob/video.h" // for SurfacePtr +#include "common/array.h" + +#include "engines/gob/video.h" // for SurfacePtr namespace Gob { @@ -180,6 +182,22 @@ private: SavePartVars *_notes; }; +/** A handler that behaves like a file but keeps the contents in memory. */ +class FakeFileHandler : public SaveHandler { +public: + FakeFileHandler(GobEngine *vm); + ~FakeFileHandler(); + + int32 getSize(); + bool load(int16 dataVar, int32 size, int32 offset); + bool save(int16 dataVar, int32 size, int32 offset); + + bool deleteFile(); + +private: + Common::Array<byte> _data; +}; + } // End of namespace Gob #endif // GOB_SAVE_SAVEHANDLER_H |