[Scummvm-git-logs] scummvm master -> 92322ef01adcd3dd7510d72ede2bb86ff908a88d
dreammaster
dreammaster at scummvm.org
Mon Aug 9 01:13:35 UTC 2021
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
9db14ee109 BACKENDS: Update all the backends to support SeekableWriteStream
be06c4eb8a BACKENDS: Extend OutSaveFile to support SeekableWriteStream
92322ef01a AGS: Simplify FileStream now that save files support seeking
Commit: 9db14ee10903f8554f898865d548665f4961cbf6
https://github.com/scummvm/scummvm/commit/9db14ee10903f8554f898865d548665f4961cbf6
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-08-08T18:13:30-07:00
Commit Message:
BACKENDS: Update all the backends to support SeekableWriteStream
Changed paths:
backends/fs/abstract-fs.h
backends/fs/amigaos/amigaos-fs.cpp
backends/fs/amigaos/amigaos-fs.h
backends/fs/chroot/chroot-fs.cpp
backends/fs/chroot/chroot-fs.h
backends/fs/morphos/morphos-fs.cpp
backends/fs/morphos/morphos-fs.h
backends/fs/n64/n64-fs.cpp
backends/fs/n64/n64-fs.h
backends/fs/n64/romfsstream.h
backends/fs/posix-drives/posix-drives-fs.cpp
backends/fs/posix-drives/posix-drives-fs.h
backends/fs/posix/posix-fs.cpp
backends/fs/posix/posix-fs.h
backends/fs/psp/psp-fs.cpp
backends/fs/psp/psp-fs.h
backends/fs/psp/psp-stream.h
backends/fs/riscos/riscos-fs.cpp
backends/fs/riscos/riscos-fs.h
backends/fs/symbian/symbian-fs.cpp
backends/fs/symbian/symbian-fs.h
backends/fs/symbian/symbianstream.h
backends/fs/wii/wii-fs.cpp
backends/fs/wii/wii-fs.h
backends/fs/windows/windows-fs.cpp
backends/fs/windows/windows-fs.h
backends/platform/dc/dc-fs.cpp
backends/saves/default/default-saves.cpp
common/bufferedstream.h
common/fs.cpp
common/fs.h
common/stream.cpp
diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h
index 8b2c1c107d..d94ad53af8 100644
--- a/backends/fs/abstract-fs.h
+++ b/backends/fs/abstract-fs.h
@@ -190,7 +190,7 @@ public:
*
* @return pointer to the stream object, 0 in case of a failure
*/
- virtual Common::WriteStream *createWriteStream() = 0;
+ virtual Common::SeekableWriteStream *createWriteStream() = 0;
/**
* Creates a directory referred by this node.
diff --git a/backends/fs/amigaos/amigaos-fs.cpp b/backends/fs/amigaos/amigaos-fs.cpp
index 155e04be9f..94977d92f2 100644
--- a/backends/fs/amigaos/amigaos-fs.cpp
+++ b/backends/fs/amigaos/amigaos-fs.cpp
@@ -380,7 +380,7 @@ Common::SeekableReadStream *AmigaOSFilesystemNode::createReadStream() {
}
-Common::WriteStream *AmigaOSFilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *AmigaOSFilesystemNode::createWriteStream() {
return StdioStream::makeFromPath(getPath(), true);
}
diff --git a/backends/fs/amigaos/amigaos-fs.h b/backends/fs/amigaos/amigaos-fs.h
index 75d8d01362..80a86f2736 100644
--- a/backends/fs/amigaos/amigaos-fs.h
+++ b/backends/fs/amigaos/amigaos-fs.h
@@ -115,7 +115,7 @@ public:
virtual AbstractFSNode *getParent() const;
virtual Common::SeekableReadStream *createReadStream();
- virtual Common::WriteStream *createWriteStream();
+ virtual Common::SeekableWriteStream *createWriteStream();
virtual bool createDirectory();
};
diff --git a/backends/fs/chroot/chroot-fs.cpp b/backends/fs/chroot/chroot-fs.cpp
index bd1f93ae77..af475e44b9 100644
--- a/backends/fs/chroot/chroot-fs.cpp
+++ b/backends/fs/chroot/chroot-fs.cpp
@@ -96,7 +96,7 @@ Common::SeekableReadStream *ChRootFilesystemNode::createReadStream() {
return _realNode->createReadStream();
}
-Common::WriteStream *ChRootFilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *ChRootFilesystemNode::createWriteStream() {
return _realNode->createWriteStream();
}
diff --git a/backends/fs/chroot/chroot-fs.h b/backends/fs/chroot/chroot-fs.h
index 66cbcbe700..98e56db72e 100644
--- a/backends/fs/chroot/chroot-fs.h
+++ b/backends/fs/chroot/chroot-fs.h
@@ -48,7 +48,7 @@ public:
virtual AbstractFSNode *getParent() const;
virtual Common::SeekableReadStream *createReadStream();
- virtual Common::WriteStream *createWriteStream();
+ virtual Common::SeekableWriteStream *createWriteStream();
virtual bool createDirectory();
private:
diff --git a/backends/fs/morphos/morphos-fs.cpp b/backends/fs/morphos/morphos-fs.cpp
index d30ca919e5..32fc62b8cb 100644
--- a/backends/fs/morphos/morphos-fs.cpp
+++ b/backends/fs/morphos/morphos-fs.cpp
@@ -353,7 +353,7 @@ Common::SeekableReadStream *MorphOSFilesystemNode::createReadStream() {
return readStream;
}
-Common::WriteStream *MorphOSFilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *MorphOSFilesystemNode::createWriteStream() {
return StdioStream::makeFromPath(getPath(), true);
}
diff --git a/backends/fs/morphos/morphos-fs.h b/backends/fs/morphos/morphos-fs.h
index 5b066f1795..69695a2270 100644
--- a/backends/fs/morphos/morphos-fs.h
+++ b/backends/fs/morphos/morphos-fs.h
@@ -116,7 +116,7 @@ public:
virtual AbstractFSNode *getParent() const;
virtual Common::SeekableReadStream *createReadStream();
- virtual Common::WriteStream *createWriteStream();
+ virtual Common::SeekableWriteStream *createWriteStream();
virtual bool createDirectory();
};
diff --git a/backends/fs/n64/n64-fs.cpp b/backends/fs/n64/n64-fs.cpp
index 5049334ccc..d08bb3d55d 100644
--- a/backends/fs/n64/n64-fs.cpp
+++ b/backends/fs/n64/n64-fs.cpp
@@ -156,7 +156,7 @@ Common::SeekableReadStream *N64FilesystemNode::createReadStream() {
return RomfsStream::makeFromPath(getPath(), false);
}
-Common::WriteStream *N64FilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *N64FilesystemNode::createWriteStream() {
return RomfsStream::makeFromPath(getPath(), true);
}
diff --git a/backends/fs/n64/n64-fs.h b/backends/fs/n64/n64-fs.h
index 495fd672e8..5c4b9beb12 100644
--- a/backends/fs/n64/n64-fs.h
+++ b/backends/fs/n64/n64-fs.h
@@ -72,7 +72,7 @@ public:
virtual AbstractFSNode *getParent() const;
virtual Common::SeekableReadStream *createReadStream();
- virtual Common::WriteStream *createWriteStream();
+ virtual Common::SeekableWriteStream *createWriteStream();
virtual bool createDirectory();
};
diff --git a/backends/fs/n64/romfsstream.h b/backends/fs/n64/romfsstream.h
index f084e8ed69..3931e39b23 100644
--- a/backends/fs/n64/romfsstream.h
+++ b/backends/fs/n64/romfsstream.h
@@ -28,7 +28,7 @@
#include "common/stream.h"
#include "common/str.h"
-class RomfsStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable {
+class RomfsStream : public Common::SeekableReadStream, public Common::SeekableWriteStream, public Common::NonCopyable {
protected:
/** File handle to the actual file. */
void *_handle;
diff --git a/backends/fs/posix-drives/posix-drives-fs.cpp b/backends/fs/posix-drives/posix-drives-fs.cpp
index 63776a2fd8..61a5c1d155 100644
--- a/backends/fs/posix-drives/posix-drives-fs.cpp
+++ b/backends/fs/posix-drives/posix-drives-fs.cpp
@@ -87,7 +87,7 @@ Common::SeekableReadStream *DrivePOSIXFilesystemNode::createReadStream() {
return readStream;
}
-Common::WriteStream *DrivePOSIXFilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *DrivePOSIXFilesystemNode::createWriteStream() {
PosixIoStream *writeStream = PosixIoStream::makeFromPath(getPath(), true);
configureStream(writeStream);
diff --git a/backends/fs/posix-drives/posix-drives-fs.h b/backends/fs/posix-drives/posix-drives-fs.h
index 4396889e06..3dc81fb272 100644
--- a/backends/fs/posix-drives/posix-drives-fs.h
+++ b/backends/fs/posix-drives/posix-drives-fs.h
@@ -62,7 +62,7 @@ public:
// AbstractFSNode API
Common::SeekableReadStream *createReadStream() override;
- Common::WriteStream *createWriteStream() override;
+ Common::SeekableWriteStream *createWriteStream() override;
AbstractFSNode *getChild(const Common::String &n) const override;
bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const override;
AbstractFSNode *getParent() const override;
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp
index c357fede00..05f5d3330e 100644
--- a/backends/fs/posix/posix-fs.cpp
+++ b/backends/fs/posix/posix-fs.cpp
@@ -297,7 +297,7 @@ Common::SeekableReadStream *POSIXFilesystemNode::createReadStream() {
return PosixIoStream::makeFromPath(getPath(), false);
}
-Common::WriteStream *POSIXFilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *POSIXFilesystemNode::createWriteStream() {
return PosixIoStream::makeFromPath(getPath(), true);
}
diff --git a/backends/fs/posix/posix-fs.h b/backends/fs/posix/posix-fs.h
index 6a67a616a3..e8e4f5da14 100644
--- a/backends/fs/posix/posix-fs.h
+++ b/backends/fs/posix/posix-fs.h
@@ -67,7 +67,7 @@ public:
virtual AbstractFSNode *getParent() const;
virtual Common::SeekableReadStream *createReadStream();
- virtual Common::WriteStream *createWriteStream();
+ virtual Common::SeekableWriteStream *createWriteStream();
virtual bool createDirectory();
protected:
diff --git a/backends/fs/psp/psp-fs.cpp b/backends/fs/psp/psp-fs.cpp
index 34727a6392..f16f1f990f 100644
--- a/backends/fs/psp/psp-fs.cpp
+++ b/backends/fs/psp/psp-fs.cpp
@@ -231,10 +231,10 @@ Common::SeekableReadStream *PSPFilesystemNode::createReadStream() {
return Common::wrapBufferedSeekableReadStream(stream, READ_BUFFER_SIZE, DisposeAfterUse::YES);
}
-Common::WriteStream *PSPFilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *PSPFilesystemNode::createWriteStream() {
const uint32 WRITE_BUFFER_SIZE = 1024;
- Common::WriteStream *stream = PspIoStream::makeFromPath(getPath(), true);
+ Common::SeekableWriteStream *stream = PspIoStream::makeFromPath(getPath(), true);
return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE);
}
diff --git a/backends/fs/psp/psp-fs.h b/backends/fs/psp/psp-fs.h
index 3d70face0b..74931112df 100644
--- a/backends/fs/psp/psp-fs.h
+++ b/backends/fs/psp/psp-fs.h
@@ -64,7 +64,7 @@ public:
virtual AbstractFSNode *getParent() const;
virtual Common::SeekableReadStream *createReadStream();
- virtual Common::WriteStream *createWriteStream();
+ virtual Common::SeekableWriteStream *createWriteStream();
virtual bool createDirectory();
};
diff --git a/backends/fs/psp/psp-stream.h b/backends/fs/psp/psp-stream.h
index c19b94752b..850a01cb08 100644
--- a/backends/fs/psp/psp-stream.h
+++ b/backends/fs/psp/psp-stream.h
@@ -33,7 +33,7 @@
/**
* Class to handle special suspend/resume needs of PSP IO Streams
*/
-class PspIoStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable, public Suspendable {
+class PspIoStream : public Common::SeekableReadStream, public Common::SeekableWriteStream, public Common::NonCopyable, public Suspendable {
protected:
SceUID _handle; // file handle
Common::String _path;
diff --git a/backends/fs/riscos/riscos-fs.cpp b/backends/fs/riscos/riscos-fs.cpp
index 5979ee4a5f..31f2bc4181 100644
--- a/backends/fs/riscos/riscos-fs.cpp
+++ b/backends/fs/riscos/riscos-fs.cpp
@@ -210,7 +210,7 @@ Common::SeekableReadStream *RISCOSFilesystemNode::createReadStream() {
return StdioStream::makeFromPath(getPath(), false);
}
-Common::WriteStream *RISCOSFilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *RISCOSFilesystemNode::createWriteStream() {
return StdioStream::makeFromPath(getPath(), true);
}
diff --git a/backends/fs/riscos/riscos-fs.h b/backends/fs/riscos/riscos-fs.h
index e3640e57ca..379c47f4db 100644
--- a/backends/fs/riscos/riscos-fs.h
+++ b/backends/fs/riscos/riscos-fs.h
@@ -67,7 +67,7 @@ public:
virtual AbstractFSNode *getParent() const;
virtual Common::SeekableReadStream *createReadStream();
- virtual Common::WriteStream *createWriteStream();
+ virtual Common::SeekableWriteStream *createWriteStream();
virtual bool createDirectory();
private:
/**
diff --git a/backends/fs/symbian/symbian-fs.cpp b/backends/fs/symbian/symbian-fs.cpp
index c8fd23f0c2..32b9b24c7c 100644
--- a/backends/fs/symbian/symbian-fs.cpp
+++ b/backends/fs/symbian/symbian-fs.cpp
@@ -228,7 +228,7 @@ Common::SeekableReadStream *SymbianFilesystemNode::createReadStream() {
return SymbianStdioStream::makeFromPath(getPath(), false);
}
-Common::WriteStream *SymbianFilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *SymbianFilesystemNode::createWriteStream() {
return SymbianStdioStream::makeFromPath(getPath(), true);
}
diff --git a/backends/fs/symbian/symbian-fs.h b/backends/fs/symbian/symbian-fs.h
index cd255f7ec0..e1715669bf 100644
--- a/backends/fs/symbian/symbian-fs.h
+++ b/backends/fs/symbian/symbian-fs.h
@@ -65,7 +65,7 @@ public:
virtual AbstractFSNode *getParent() const;
virtual Common::SeekableReadStream *createReadStream();
- virtual Common::WriteStream *createWriteStream();
+ virtual Common::SeekableWriteStream *createWriteStream();
virtual bool createDirectory();
};
diff --git a/backends/fs/symbian/symbianstream.h b/backends/fs/symbian/symbianstream.h
index 4e6887cd97..2c604ae9f7 100644
--- a/backends/fs/symbian/symbianstream.h
+++ b/backends/fs/symbian/symbianstream.h
@@ -28,7 +28,7 @@
#include "common/stream.h"
#include "common/str.h"
-class SymbianStdioStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable {
+class SymbianStdioStream : public Common::SeekableReadStream, public Common::SeekableWriteStream, public Common::NonCopyable {
protected:
/** File handle to the actual file. */
void *_handle;
diff --git a/backends/fs/wii/wii-fs.cpp b/backends/fs/wii/wii-fs.cpp
index 7a7de18809..cfba54df2f 100644
--- a/backends/fs/wii/wii-fs.cpp
+++ b/backends/fs/wii/wii-fs.cpp
@@ -209,7 +209,7 @@ Common::SeekableReadStream *WiiFilesystemNode::createReadStream() {
return readStream;
}
-Common::WriteStream *WiiFilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *WiiFilesystemNode::createWriteStream() {
StdioStream *writeStream = StdioStream::makeFromPath(getPath(), true);
// disable newlib's buffering, the device libraries handle caching
diff --git a/backends/fs/wii/wii-fs.h b/backends/fs/wii/wii-fs.h
index 2bd45cdbba..1fd2dff9e8 100644
--- a/backends/fs/wii/wii-fs.h
+++ b/backends/fs/wii/wii-fs.h
@@ -68,7 +68,7 @@ public:
virtual AbstractFSNode *getParent() const override;
virtual Common::SeekableReadStream *createReadStream() override;
- virtual Common::WriteStream *createWriteStream() override;
+ virtual Common::SeekableWriteStream *createWriteStream() override;
virtual bool createDirectory() override;
};
diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp
index b12af4018d..4c59f8cf86 100644
--- a/backends/fs/windows/windows-fs.cpp
+++ b/backends/fs/windows/windows-fs.cpp
@@ -234,7 +234,7 @@ Common::SeekableReadStream *WindowsFilesystemNode::createReadStream() {
return StdioStream::makeFromPath(getPath(), false);
}
-Common::WriteStream *WindowsFilesystemNode::createWriteStream() {
+Common::SeekableWriteStream *WindowsFilesystemNode::createWriteStream() {
return StdioStream::makeFromPath(getPath(), true);
}
diff --git a/backends/fs/windows/windows-fs.h b/backends/fs/windows/windows-fs.h
index aba5f75a89..c1de7e4235 100644
--- a/backends/fs/windows/windows-fs.h
+++ b/backends/fs/windows/windows-fs.h
@@ -79,7 +79,7 @@ public:
virtual AbstractFSNode *getParent() const override;
virtual Common::SeekableReadStream *createReadStream() override;
- virtual Common::WriteStream *createWriteStream() override;
+ virtual Common::SeekableWriteStream *createWriteStream() override;
virtual bool createDirectory() override;
private:
diff --git a/backends/platform/dc/dc-fs.cpp b/backends/platform/dc/dc-fs.cpp
index 43d9a9e836..5b08eeddc3 100644
--- a/backends/platform/dc/dc-fs.cpp
+++ b/backends/platform/dc/dc-fs.cpp
@@ -56,7 +56,7 @@ public:
virtual AbstractFSNode *getParent() const;
virtual Common::SeekableReadStream *createReadStream();
- virtual Common::WriteStream *createWriteStream() { return 0; }
+ virtual Common::SeekableWriteStream *createWriteStream() { return 0; }
virtual bool createDirectory() { return false; }
static AbstractFSNode *makeFileNodePath(const Common::String &path);
diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp
index 50c4aa6851..eb5e89bf63 100644
--- a/backends/saves/default/default-saves.cpp
+++ b/backends/saves/default/default-saves.cpp
@@ -168,7 +168,7 @@ Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const Common::String
}
// Open the file for saving.
- Common::WriteStream *const sf = fileNode.createWriteStream();
+ Common::SeekableWriteStream *const sf = fileNode.createWriteStream();
if (!sf)
return nullptr;
Common::OutSaveFile *const result = new Common::OutSaveFile(compress ? Common::wrapCompressedWriteStream(sf) : sf);
diff --git a/common/bufferedstream.h b/common/bufferedstream.h
index 21c4d319d4..ac2ef1a52d 100644
--- a/common/bufferedstream.h
+++ b/common/bufferedstream.h
@@ -80,6 +80,7 @@ SeekableReadStream *wrapBufferedSeekableReadStream(SeekableReadStream *parentStr
* @param bufSize Size of the buffer.
*/
+SeekableWriteStream *wrapBufferedWriteStream(SeekableWriteStream *parentStream, uint32 bufSize);
WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize);
/** @} */
diff --git a/common/fs.cpp b/common/fs.cpp
index 3365dea2dc..247ee59c38 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -142,7 +142,7 @@ SeekableReadStream *FSNode::createReadStream() const {
return _realNode->createReadStream();
}
-WriteStream *FSNode::createWriteStream() const {
+SeekableWriteStream *FSNode::createWriteStream() const {
if (_realNode == nullptr)
return nullptr;
diff --git a/common/fs.h b/common/fs.h
index 94784f39bc..2ed0515f9a 100644
--- a/common/fs.h
+++ b/common/fs.h
@@ -46,6 +46,7 @@ namespace Common {
class FSNode;
class SeekableReadStream;
class WriteStream;
+class SeekableWriteStream;
/**
* List of multiple file system nodes. For example, the contents of a given directory.
@@ -238,7 +239,7 @@ public:
*
* @return Pointer to the stream object, 0 in case of a failure.
*/
- WriteStream *createWriteStream() const;
+ SeekableWriteStream *createWriteStream() const;
/**
* Create a directory referred by this node. This assumes that this
diff --git a/common/stream.cpp b/common/stream.cpp
index ecb3e56e2b..2b013da8be 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -486,7 +486,7 @@ namespace {
/**
* Wrapper class which adds buffering to any WriteStream.
*/
-class BufferedWriteStream : public WriteStream {
+class BufferedWriteStream : public SeekableWriteStream {
protected:
WriteStream *_parentStream;
byte *_buf;
@@ -531,7 +531,7 @@ public:
delete[] _buf;
}
- virtual uint32 write(const void *dataPtr, uint32 dataSize) {
+ uint32 write(const void *dataPtr, uint32 dataSize) override {
// check if we have enough space for writing to the buffer
if (_bufSize - _pos >= dataSize) {
memcpy(_buf + _pos, dataPtr, dataSize);
@@ -549,14 +549,33 @@ public:
return dataSize;
}
- virtual bool flush() { return flushBuffer(); }
+ bool flush() override { return flushBuffer(); }
- virtual int64 pos() const { return _pos; }
+ int64 pos() const override { return _pos; }
+ bool seek(int64 offset, int whence) override {
+ flush();
+
+ Common::SeekableWriteStream *sws =
+ dynamic_cast<Common::SeekableWriteStream *>(_parentStream);
+ return sws ? sws->seek(offset, whence) : false;
+ }
+
+ int64 size() const override {
+ Common::SeekableWriteStream *sws =
+ dynamic_cast<Common::SeekableWriteStream *>(_parentStream);
+ return sws ? MAX(sws->pos() + _pos, sws->size()) : -1;
+ }
};
} // End of anonymous namespace
+SeekableWriteStream *wrapBufferedWriteStream(SeekableWriteStream *parentStream, uint32 bufSize) {
+ if (parentStream)
+ return new BufferedWriteStream(parentStream, bufSize);
+ return nullptr;
+}
+
WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize) {
if (parentStream)
return new BufferedWriteStream(parentStream, bufSize);
Commit: be06c4eb8a17f4c1f60b081ff47c9b308e9249cc
https://github.com/scummvm/scummvm/commit/be06c4eb8a17f4c1f60b081ff47c9b308e9249cc
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-08-08T18:13:30-07:00
Commit Message:
BACKENDS: Extend OutSaveFile to support SeekableWriteStream
The seek and size methods of SeekableWriteStream are only
supported when creating uncompressed save files.
Changed paths:
backends/saves/savefile.cpp
common/savefile.h
diff --git a/backends/saves/savefile.cpp b/backends/saves/savefile.cpp
index e8b35ad8fe..753a1c1fcb 100644
--- a/backends/saves/savefile.cpp
+++ b/backends/saves/savefile.cpp
@@ -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;
diff --git a/common/savefile.h b/common/savefile.h
index 6435ae9d59..17abad38ff 100644
--- a/common/savefile.h
+++ b/common/savefile.h
@@ -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;
};
/**
Commit: 92322ef01adcd3dd7510d72ede2bb86ff908a88d
https://github.com/scummvm/scummvm/commit/92322ef01adcd3dd7510d72ede2bb86ff908a88d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-08-08T18:13:30-07:00
Commit Message:
AGS: Simplify FileStream now that save files support seeking
Changed paths:
engines/ags/shared/util/file_stream.cpp
engines/ags/shared/util/file_stream.h
diff --git a/engines/ags/shared/util/file_stream.cpp b/engines/ags/shared/util/file_stream.cpp
index 4963f81156..28d8ee464a 100644
--- a/engines/ags/shared/util/file_stream.cpp
+++ b/engines/ags/shared/util/file_stream.cpp
@@ -34,8 +34,7 @@ namespace Shared {
FileStream::FileStream(const String &file_name, FileOpenMode open_mode, FileWorkMode work_mode,
DataEndianess stream_endianess)
- : DataStream(stream_endianess), _writeBuffer(DisposeAfterUse::YES),
- _workMode(work_mode), _file(nullptr), _outSave(nullptr) {
+ : DataStream(stream_endianess), _workMode(work_mode), _file(nullptr) {
Open(file_name, open_mode, work_mode);
}
@@ -48,15 +47,7 @@ bool FileStream::HasErrors() const {
}
void FileStream::Close() {
- if (_outSave) {
- _outSave->write(_writeBuffer.getData(), _writeBuffer.size());
- _outSave->finalize();
- delete _outSave;
-
- } else if (_file) {
- delete _file;
- }
-
+ delete _file;
_file = nullptr;
}
@@ -193,7 +184,7 @@ void FileStream::Open(const String &file_name, FileOpenMode open_mode, FileWorkM
} else {
if (!file_name.CompareLeftNoCase(SAVE_FOLDER_PREFIX)) {
- _outSave = g_system->getSavefileManager()->openForSaving(
+ _file = g_system->getSavefileManager()->openForSaving(
file_name.GetCStr() + strlen(SAVE_FOLDER_PREFIX), false);
} else {
Common::String fname = file_name;
@@ -204,15 +195,11 @@ void FileStream::Open(const String &file_name, FileOpenMode open_mode, FileWorkM
else if (fname.findFirstOf('/') != Common::String::npos)
error("Invalid attempt to create file - %s", fname.c_str());
- _outSave = g_system->getSavefileManager()->openForSaving(fname, false);
+ _file = g_system->getSavefileManager()->openForSaving(fname, false);
}
- if (!_outSave)
+ if (!_file)
error("Invalid attempt to create file - %s", file_name.GetCStr());
-
- // Any data written has to first go through the memory stream buffer,
- // since the savegame code uses Seeks, which OutSaveFile doesn't support
- _file = &_writeBuffer;
}
}
diff --git a/engines/ags/shared/util/file_stream.h b/engines/ags/shared/util/file_stream.h
index 39630fb682..590f971706 100644
--- a/engines/ags/shared/util/file_stream.h
+++ b/engines/ags/shared/util/file_stream.h
@@ -23,7 +23,6 @@
#ifndef AGS_SHARED_UTIL_FILE_STREAM_H
#define AGS_SHARED_UTIL_FILE_STREAM_H
-#include "common/memstream.h"
#include "common/savefile.h"
#include "common/stream.h"
#include "ags/shared/util/data_stream.h"
@@ -71,8 +70,6 @@ private:
Common::Stream *_file;
const FileWorkMode _workMode;
- Common::MemoryWriteStreamDynamic _writeBuffer;
- Common::OutSaveFile *_outSave;
};
} // namespace Shared
More information about the Scummvm-git-logs
mailing list