aboutsummaryrefslogtreecommitdiff
path: root/backends/dc
diff options
context:
space:
mode:
authorMarcus Comstedt2005-10-13 18:50:53 +0000
committerMarcus Comstedt2005-10-13 18:50:53 +0000
commit57e1c6451dc928f4162de019486e3af259d39423 (patch)
treeccf84f9e49be23c03cac986490c05f6b94c0b555 /backends/dc
parent66fbe2d3c42355d714fd1cd638323f367de4c329 (diff)
downloadscummvm-rg350-57e1c6451dc928f4162de019486e3af259d39423.tar.gz
scummvm-rg350-57e1c6451dc928f4162de019486e3af259d39423.tar.bz2
scummvm-rg350-57e1c6451dc928f4162de019486e3af259d39423.zip
Improved savefile error handling:
* New flush() method in WriteStream class to flush pending I/O, in order to detect any I/O errors * Use of flush() and ioFailed() added to scumm engine save function * Dreamcast backend extended to support the new checks svn-id: r19066
Diffstat (limited to 'backends/dc')
-rw-r--r--backends/dc/vmsave.cpp42
1 files changed, 31 insertions, 11 deletions
diff --git a/backends/dc/vmsave.cpp b/backends/dc/vmsave.cpp
index 16ea470a53..1ce7c55306 100644
--- a/backends/dc/vmsave.cpp
+++ b/backends/dc/vmsave.cpp
@@ -258,20 +258,25 @@ public:
class OutVMSave : public Common::OutSaveFile {
private:
char *buffer;
- int pos, size;
+ int pos, size, committed;
char filename[16];
+ bool iofailed;
+public:
uint32 write(const void *buf, uint32 cnt);
-public:
OutVMSave(const char *_filename)
- : pos(0)
+ : pos(0), committed(-1), iofailed(false)
{
strncpy(filename, _filename, 16);
buffer = new char[size = MAX_SAVE_SIZE];
}
~OutVMSave();
+
+ bool ioFailed() const { return iofailed; }
+ void clearIOFailed() { iofailed = false; }
+ void flush();
};
class VMSaveManager : public Common::SaveFileManager {
@@ -295,23 +300,38 @@ public:
virtual void listSavefiles(const char *prefix, bool *marks, int num);
};
-OutVMSave::~OutVMSave()
+void OutVMSave::flush()
{
extern const char *gGameName;
extern Icon icon;
+ if(committed >= pos)
+ return;
+
+ char *data = buffer, *compbuf = NULL;
+ int len = pos;
+
if(pos) {
// Try compression
- char *compbuf = new char[pos];
+ compbuf = new char[pos];
unsigned long destlen = pos;
if(!compress((Bytef*)compbuf, &destlen, (Bytef*)buffer, pos)) {
- delete[] buffer;
- buffer = compbuf;
- pos = destlen;
- } else delete[] compbuf;
+ data = compbuf;
+ len = destlen;
+ }
}
- displaySaveResult(writeSaveGame(gGameName, buffer,
- pos, filename, icon));
+ vmsaveResult r = writeSaveGame(gGameName, data, len, filename, icon);
+ committed = pos;
+ if(compbuf != NULL)
+ delete[] compbuf;
+ if(r != VMSAVE_OK)
+ iofailed = true;
+ displaySaveResult(r);
+}
+
+OutVMSave::~OutVMSave()
+{
+ flush();
delete[] buffer;
}