mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-27 05:32:45 +00:00
GOB: Add a FakeFileHandler
For temporarily storing save "files" svn-id: r55528
This commit is contained in:
parent
ff13458eb7
commit
0432ca6d0f
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user