BACKENDS: Extend OutSaveFile to support SeekableWriteStream

The seek and size methods of SeekableWriteStream are only
supported when creating uncompressed save files.
This commit is contained in:
Paul Gilbert 2021-07-29 18:48:07 -07:00
parent 9db14ee109
commit be06c4eb8a
2 changed files with 37 additions and 1 deletions

View File

@ -56,6 +56,30 @@ int64 OutSaveFile::pos() const {
return _wrapped->pos();
}
bool OutSaveFile::seek(int64 offset, int whence) {
Common::SeekableWriteStream *sws =
dynamic_cast<Common::SeekableWriteStream *>(_wrapped);
if (sws) {
return sws->seek(offset, whence);
} else {
warning("Seeking isn't supported for compressed save files");
return false;
}
}
int64 OutSaveFile::size() const {
Common::SeekableWriteStream *sws =
dynamic_cast<Common::SeekableWriteStream *>(_wrapped);
if (sws) {
return sws->size();
} else {
warning("Size isn't supported for compressed save files");
return -1;
}
}
bool SaveFileManager::copySavefile(const String &oldFilename, const String &newFilename, bool compress) {
InSaveFile *inFile = 0;
OutSaveFile *outFile = 0;

View File

@ -52,7 +52,7 @@ typedef SeekableReadStream InSaveFile;
* That typically means "save games", but also includes things like the
* IQ points in Indy3.
*/
class OutSaveFile: public WriteStream {
class OutSaveFile: public SeekableWriteStream {
protected:
WriteStream *_wrapped; /*!< @todo Doc required. */
@ -107,6 +107,18 @@ public:
* @return The current position indicator, or -1 if an error occurred.
*/
virtual int64 pos() const;
/**
* Seeks to a new position within the file.
* This is only supported when creating uncompressed save files.
*/
bool seek(int64 offset, int whence) override;
/**
* Returns the size of the save file
* This is only supported when creating uncompressed save files.
*/
int64 size() const override;
};
/**