From 7734771245a58dec8ce7c1d312a7f3b268141427 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 15 Jul 2012 08:31:03 -0700 Subject: [PATCH] Use Ogre to load ESM data instead of Mangle --- components/esm/esm_reader.cpp | 18 ++++++++++-------- components/esm/esm_reader.hpp | 10 +++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/components/esm/esm_reader.cpp b/components/esm/esm_reader.cpp index e9bfcf5eee..6b8409b452 100644 --- a/components/esm/esm_reader.cpp +++ b/components/esm/esm_reader.cpp @@ -27,7 +27,7 @@ void ESMReader::restoreContext(const ESM_Context &rc) void ESMReader::close() { - mEsm.reset(); + mEsm.setNull(); mCtx.filename.clear(); mCtx.leftFile = 0; mCtx.leftRec = 0; @@ -37,7 +37,7 @@ void ESMReader::close() mCtx.subName.val = 0; } -void ESMReader::openRaw(Mangle::Stream::StreamPtr _esm, const std::string &name) +void ESMReader::openRaw(Ogre::DataStreamPtr _esm, const std::string &name) { close(); mEsm = _esm; @@ -57,7 +57,7 @@ void ESMReader::openRaw(Mangle::Stream::StreamPtr _esm, const std::string &name) mSpf = SF_Other; } -void ESMReader::open(Mangle::Stream::StreamPtr _esm, const std::string &name) +void ESMReader::open(Ogre::DataStreamPtr _esm, const std::string &name) { openRaw(_esm, name); @@ -107,14 +107,16 @@ void ESMReader::open(Mangle::Stream::StreamPtr _esm, const std::string &name) void ESMReader::open(const std::string &file) { - using namespace Mangle::Stream; - open(StreamPtr(new FileStream(file)), file); + std::ifstream *stream = new std::ifstream(file.c_str(), std::ios_base::binary); + // Ogre will delete the stream for us + open(Ogre::DataStreamPtr(new Ogre::FileStreamDataStream(stream)), file); } void ESMReader::openRaw(const std::string &file) { - using namespace Mangle::Stream; - openRaw(StreamPtr(new FileStream(file)), file); + std::ifstream *stream = new std::ifstream(file.c_str(), std::ios_base::binary); + // Ogre will delete the stream for us + openRaw(Ogre::DataStreamPtr(new Ogre::FileStreamDataStream(stream)), file); } int64_t ESMReader::getHNLong(const char *name) @@ -339,7 +341,7 @@ void ESMReader::fail(const std::string &msg) ss << "\n File: " << mCtx.filename; ss << "\n Record: " << mCtx.recName.toString(); ss << "\n Subrecord: " << mCtx.subName.toString(); - if (mEsm != NULL) + if (!mEsm.isNull()) ss << "\n Offset: 0x" << hex << mEsm->tell(); throw std::runtime_error(ss.str()); } diff --git a/components/esm/esm_reader.hpp b/components/esm/esm_reader.hpp index 340482891c..17cca7a910 100644 --- a/components/esm/esm_reader.hpp +++ b/components/esm/esm_reader.hpp @@ -11,8 +11,8 @@ #include #include -#include -#include +#include + #include #include @@ -183,11 +183,11 @@ public: /// Raw opening. Opens the file and sets everything up but doesn't /// parse the header. - void openRaw(Mangle::Stream::StreamPtr _esm, const std::string &name); + void openRaw(Ogre::DataStreamPtr _esm, const std::string &name); /// Load ES file from a new stream, parses the header. Closes the /// currently open file first, if any. - void open(Mangle::Stream::StreamPtr _esm, const std::string &name); + void open(Ogre::DataStreamPtr _esm, const std::string &name); void open(const std::string &file); @@ -354,7 +354,7 @@ public: void setEncoding(const std::string& encoding); private: - Mangle::Stream::StreamPtr mEsm; + Ogre::DataStreamPtr mEsm; ESM_Context mCtx;