From 5abed1c32a16043e71915d9a03ab573b392fbfcb Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Sun, 19 Oct 2014 02:54:27 -0400 Subject: [PATCH] Print a NIF file's version information when an error occurs --- components/nif/niffile.cpp | 22 +++++++++++++++++++--- components/nif/niffile.hpp | 6 +++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/components/nif/niffile.cpp b/components/nif/niffile.cpp index 2240d65b0..c689e27b3 100644 --- a/components/nif/niffile.cpp +++ b/components/nif/niffile.cpp @@ -109,6 +109,23 @@ static std::map makeFactory() ///Make the factory map used for parsing the file static const std::map factories = makeFactory(); +/// Get the file's version in a human readable form +std::string NIFFile::printVersion(unsigned int version) +{ + union ver_quad + { + uint32_t full; + uint8_t quad[4]; + } version_out; + + version_out.full = version; + + return Ogre::StringConverter::toString(version_out.quad[3]) + +"." + Ogre::StringConverter::toString(version_out.quad[2]) + +"." + Ogre::StringConverter::toString(version_out.quad[1]) + +"." + Ogre::StringConverter::toString(version_out.quad[0]); +} + void NIFFile::parse() { NIFStream nif (this, Ogre::ResourceGroupManager::getSingleton().openResource(filename)); @@ -119,10 +136,9 @@ void NIFFile::parse() fail("Invalid NIF header"); // Get BCD version - ver = nif.getInt(); + ver = nif.getUInt(); if(ver != VER_MW) - fail("Unsupported NIF version"); - + fail("Unsupported NIF version: " + printVersion(ver)); // Number of records size_t recNum = nif.getInt(); records.resize(recNum); diff --git a/components/nif/niffile.hpp b/components/nif/niffile.hpp index 12e4d10c4..2ef2a6fda 100644 --- a/components/nif/niffile.hpp +++ b/components/nif/niffile.hpp @@ -19,7 +19,7 @@ class NIFFile }; /// Nif file version - int ver; + unsigned int ver; /// File name, used for error messages and opening the file std::string filename; @@ -33,6 +33,10 @@ class NIFFile /// Parse the file void parse(); + /// Get the file's version in a human readable form + ///\returns A string containing a human readable NIF version number + std::string printVersion(unsigned int version); + ///Private Copy Constructor NIFFile (NIFFile const &); ///\overload