# HG changeset patch # User Chris Cannam # Date 1168012150 0 # Node ID 8ee6cf529c4e6b4f2a660cff95021e232badb744 # Parent a75e678f5d3761c30aaecf9540abdad194adcc5f * Further fix for restoring layer visibility from session file * Better handling of error state in bzip file device to avoid spurious errors * Fix #1495001 deleted layers prevail in saved session file diff -r a75e678f5d37 -r 8ee6cf529c4e data/fileio/BZipFileDevice.cpp --- a/data/fileio/BZipFileDevice.cpp Fri Jan 05 14:46:45 2007 +0000 +++ b/data/fileio/BZipFileDevice.cpp Fri Jan 05 15:49:10 2007 +0000 @@ -23,7 +23,8 @@ m_fileName(fileName), m_file(0), m_bzFile(0), - m_atEnd(true) + m_atEnd(true), + m_ok(true) { } @@ -34,6 +35,12 @@ } bool +BZipFileDevice::isOK() const +{ + return m_ok; +} + +bool BZipFileDevice::open(OpenMode mode) { setErrorString(""); @@ -45,16 +52,19 @@ if (mode & Append) { setErrorString(tr("Append mode not supported")); + m_ok = false; return false; } if ((mode & (ReadOnly | WriteOnly)) == 0) { setErrorString(tr("File access mode not specified")); + m_ok = false; return false; } if ((mode & ReadOnly) && (mode & WriteOnly)) { setErrorString(tr("Read and write modes both specified")); + m_ok = false; return false; } @@ -63,6 +73,7 @@ m_file = fopen(m_fileName.toLocal8Bit().data(), "wb"); if (!m_file) { setErrorString(tr("Failed to open file for writing")); + m_ok = false; return false; } @@ -73,6 +84,7 @@ fclose(m_file); m_file = 0; setErrorString(tr("Failed to open bzip2 stream for writing")); + m_ok = false; return false; } @@ -88,6 +100,7 @@ m_file = fopen(m_fileName.toLocal8Bit().data(), "rb"); if (!m_file) { setErrorString(tr("Failed to open file for reading")); + m_ok = false; return false; } @@ -98,6 +111,7 @@ fclose(m_file); m_file = 0; setErrorString(tr("Failed to open bzip2 stream for reading")); + m_ok = false; return false; } @@ -111,6 +125,7 @@ } setErrorString(tr("Internal error (open for neither read nor write)")); + m_ok = false; return false; } @@ -119,6 +134,7 @@ { if (!m_bzFile) { setErrorString(tr("File not open")); + m_ok = false; return; } @@ -134,6 +150,7 @@ fclose(m_file); m_bzFile = 0; m_file = 0; + m_ok = false; return; } @@ -145,6 +162,7 @@ fclose(m_file); m_bzFile = 0; m_file = 0; + m_ok = false; return; } @@ -166,6 +184,7 @@ if (bzError != BZ_STREAM_END) { std::cerr << "BZipFileDevice::readData: error condition" << std::endl; setErrorString(tr("bzip2 stream read error")); + m_ok = false; return -1; } else { // std::cerr << "BZipFileDevice::readData: reached end of file" << std::endl; @@ -173,7 +192,6 @@ } } - setErrorString(""); return read; } @@ -188,12 +206,12 @@ if (bzError != BZ_OK) { std::cerr << "BZipFileDevice::writeData: error condition" << std::endl; setErrorString("bzip2 stream write error"); + m_ok = false; return -1; } // std::cerr << "BZipFileDevice::writeData: wrote " << maxSize << std::endl; - setErrorString(""); return maxSize; } diff -r a75e678f5d37 -r 8ee6cf529c4e data/fileio/BZipFileDevice.h --- a/data/fileio/BZipFileDevice.h Fri Jan 05 14:46:45 2007 +0000 +++ b/data/fileio/BZipFileDevice.h Fri Jan 05 15:49:10 2007 +0000 @@ -31,6 +31,8 @@ virtual bool open(OpenMode mode); virtual void close(); + virtual bool isOK() const; + virtual bool isSequential() const { return true; } protected: @@ -42,6 +44,7 @@ FILE *m_file; BZFILE *m_bzFile; bool m_atEnd; + bool m_ok; }; #endif