[Scummvm-cvs-logs] CVS: scummvm/backends/dc vmsave.cpp,1.31,1.32

Marcus Comstedt marcus_c at users.sourceforge.net
Thu Oct 13 11:51:51 CEST 2005


Update of /cvsroot/scummvm/scummvm/backends/dc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27614/backends/dc

Modified Files:
	vmsave.cpp 
Log Message:
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


Index: vmsave.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/dc/vmsave.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- vmsave.cpp	30 Jul 2005 21:10:50 -0000	1.31
+++ vmsave.cpp	13 Oct 2005 18:50:53 -0000	1.32
@@ -258,20 +258,25 @@
 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 @@
   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;
 }
 





More information about the Scummvm-git-logs mailing list