* Fixed some bugs

This commit is contained in:
Antidote 2014-02-26 21:46:26 -08:00
parent ebca406d71
commit 304baa45bb
5 changed files with 221 additions and 174 deletions

View File

@ -18,6 +18,10 @@
#include <string>
#define __STRX(x) #x
#define __STR(x) __STRX(x)
#define __LINE_STRING__ __STR(__LINE__)
namespace zelda
{
namespace error
@ -53,4 +57,10 @@ protected:
} // error
} // zelda
#define THROW_EXCEPTION(msg) \
do \
{ \
throw zelda::error::Exception(__LINE_STRING__ " " __FILE__ " " msg); \
} while(0)
#endif

View File

@ -2,6 +2,7 @@
#define INVALIDDATAEXCEPTION_HPP
#include "Exception.hpp"
#include <sstream>
namespace zelda
{
@ -20,10 +21,17 @@ class InvalidDataException : public Exception
{
public:
inline InvalidDataException(const std::string& error)
: Exception("InvalidDataException: " + error)
: Exception(error)
{
}
};
}
}
#define THROW_INVALID_DATA(msg) \
do \
{ \
throw zelda::error::InvalidDataException(__LINE_STRING__ " " __FILE__ " " msg); \
} while(0)
#endif // INVALIDDATAEXCEPTION_HPP

View File

@ -24,6 +24,8 @@ SkywardSwordFileReader::SkywardSwordFileReader(const std::string& filename)
SkywardSwordFile* SkywardSwordFileReader::read()
{
SkywardSwordFile* file = NULL;
try
{
if (base::length() != 0xFBE0)
throw zelda::error::InvalidOperationException("SSFileReader::read -> File not the expected size of 0xFBE0");
@ -51,6 +53,13 @@ SkywardSwordFile* SkywardSwordFileReader::read()
base::seek(pos, base::Beginning);
file->addQuest(q);
}
}
catch(...)
{
delete file;
file = NULL;
throw;
}
return file;
}

View File

@ -22,6 +22,9 @@ SpriteFileReader::SpriteFileReader(const std::string& filepath)
}
Sakura::SpriteFile* SpriteFileReader::readFile()
{
Sakura::SpriteFile* ret = NULL;
try
{
Uint32 magic = base::readUInt32();
@ -48,7 +51,7 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
Uint16 spriteCount = base::readUInt16();
// Lets go ahead and create or new container.
Sakura::SpriteFile* ret = new Sakura::SpriteFile(width, height, originX, originY);
ret = new Sakura::SpriteFile(width, height, originX, originY);
// The next four bytes are reserved to keep the header 32 byte aligned.
// This isn't necessary for most systems, but it's eventually planned
@ -141,6 +144,13 @@ Sakura::SpriteFile* SpriteFileReader::readFile()
}
ret->setSprites(sprites);
}
catch(...)
{
delete ret;
ret = NULL;
throw;
}
return ret;
}

View File

@ -54,6 +54,8 @@ WiiSaveReader::WiiSaveReader(const std::string& filename)
WiiSave* WiiSaveReader::readSave()
{
WiiSave* ret = new WiiSave;
try
{
if (length() < 0xF0C0)
throw error::InvalidOperationException("WiiSaveReader::readSave -> Not a valid WiiSave");
@ -98,6 +100,14 @@ WiiSave* WiiSaveReader::readSave()
ret->setFiles(files);
readCerts(totalSize);
}
catch(...)
{
delete ret;
ret = NULL;
throw;
}
return ret;
}