diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin-luaiup.cc | 108 |
1 files changed, 96 insertions, 12 deletions
diff --git a/src/plugin-luaiup.cc b/src/plugin-luaiup.cc index 4b2322d..7cecba6 100644 --- a/src/plugin-luaiup.cc +++ b/src/plugin-luaiup.cc @@ -30,21 +30,105 @@ class imBinFileHandle : public imBinFileBase { public: - virtual void Open(const char* pFileName) { h = new Input(pFileName); } - virtual void New(const char* pFileName) { h = new Output(pFileName); } - virtual void Close() { delete h; h = 0; } - virtual unsigned long FileSize() { return h->GetSize(); } - virtual int HasError() const { return 0; } - virtual void SeekTo(unsigned long pOffset) { h->seek(pOffset, SEEK_SET); } - virtual void SeekOffset(long pOffset) { h->seek(pOffset, SEEK_CUR); } - virtual void SeekFrom(long pOffset) { h->seek(pOffset, SEEK_END); } - virtual unsigned long Tell() const { return h->tell(); } - virtual int EndOfFile() const { return h->tell() == h->GetSize(); } + imBinFileHandle() : h(NULL), hasError(0) {} + virtual int HasError() const { return hasError; } + virtual void Open(const char* pFileName) { + try { + h = new Input(pFileName); + } catch (...) { + hasError = 1; + } + } + virtual void New(const char* pFileName) { + try { + h = new Output(pFileName); + } catch (...) { + hasError = 1; + } + } + virtual void Close() { + try { + delete h; + h = 0; + } catch (...) { + hasError = 1; + } + } + virtual unsigned long FileSize() { + unsigned long r = 0; + try { + r = h->GetSize(); + } catch (...) { + hasError = 1; + } + + return r; + } + virtual void SeekTo(unsigned long pOffset) { + try { + h->seek(pOffset, SEEK_SET); + } catch (...) { + hasError = 1; + } + } + virtual void SeekOffset(long pOffset) { + try { + h->seek(pOffset, SEEK_CUR); + } catch (...) { + hasError = 1; + } + } + virtual void SeekFrom(long pOffset) { + try { + h->seek(pOffset, SEEK_END); + } catch (...) { + hasError = 1; + } + } + virtual unsigned long Tell() const { + unsigned long r = 0; + try { + r = h->tell(); + } catch (...) { + hasError = 1; + } + + return r; + } + virtual int EndOfFile() const { + int r = 0; + try { + r = h->tell() == h->GetSize(); + } catch (...) { + hasError = 1; + } + + return r; + } protected: - virtual unsigned long ReadBuf(void* pValues, unsigned long pSize) { return h->read(pValues, pSize); } - virtual unsigned long WriteBuf(void* pValues, unsigned long pSize) { return h->write(pValues, pSize); } + virtual unsigned long ReadBuf(void* pValues, unsigned long pSize) { + unsigned long r = 0; + try { + r = h->read(pValues, pSize); + } catch (...) { + hasError = 1; + } + + return r; + } + virtual unsigned long WriteBuf(void* pValues, unsigned long pSize) { + unsigned long r = 0; + try { + r = h->write(pValues, pSize); + } catch (...) { + hasError = 1; + } + + return r; + } private: Handle * h; + int hasError; }; static imBinFileBase * imBinFileHandleFunc() { return new imBinFileHandle(); } |