added optional format sub-record to tes3 record

actorid
Marc Zinnschlag 12 years ago
parent 16570ce87b
commit 75bd30844d

@ -426,6 +426,7 @@ int clone(Arguments& info)
esm.setAuthor(info.data.author);
esm.setDescription(info.data.description);
esm.setVersion(info.data.version);
esm.setRecordCount (recordCount);
for (std::vector<ESM::Header::MasterData>::iterator it = info.data.masters.begin(); it != info.data.masters.end(); ++it)
esm.addMaster(it->name, it->size);

@ -15,11 +15,16 @@ ESM_Context ESMReader::getContext()
return mCtx;
}
ESMReader::ESMReader(void):
ESMReader::ESMReader():
mBuffer(50*1024)
{
}
int ESMReader::getFormat() const
{
return mHeader.mFormat;
}
void ESMReader::restoreContext(const ESM_Context &rc)
{
// Reopen the file if necessary

@ -35,6 +35,7 @@ public:
const std::string getAuthor() const { return mHeader.mData.author.toString(); }
const std::string getDesc() const { return mHeader.mData.desc.toString(); }
const std::vector<Header::MasterData> &getMasters() const { return mHeader.mMaster; }
int getFormat() const;
const NAME &retSubName() const { return mCtx.subName; }
uint32_t getSubSize() const { return mCtx.leftSub; }

@ -29,6 +29,16 @@ void ESMWriter::setDescription(const std::string& desc)
mHeader.mData.desc.assign (desc);
}
void ESMWriter::setRecordCount (int count)
{
mHeader.mData.records = count;
}
void ESMWriter::setFormat (int format)
{
mHeader.mFormat = format;
}
void ESMWriter::addMaster(const std::string& name, uint64_t size)
{
Header::MasterData d;

@ -26,6 +26,8 @@ public:
void setEncoder(ToUTF8::Utf8Encoder *encoding); // Write strings as UTF-8?
void setAuthor(const std::string& author);
void setDescription(const std::string& desc);
void setRecordCount (int count);
void setFormat (int format);
void addMaster(const std::string& name, uint64_t size);

@ -12,12 +12,22 @@ void ESM::Header::blank()
mData.author.assign ("");
mData.desc.assign ("");
mData.records = 0;
mFormat = CurrentFormat;
}
void ESM::Header::load (ESMReader &esm)
{
esm.getHNT (mData, "HEDR", 300);
if (esm.isNextSub ("FORM"))
{
esm.getHT (mFormat);
if (mFormat<0)
esm.fail ("invalid format code");
}
else
mFormat = 0;
while (esm.isNextSub ("MAST"))
{
MasterData m;
@ -31,6 +41,9 @@ void ESM::Header::save (ESMWriter &esm)
{
esm.writeHNT ("HEDR", mData, 300);
if (mFormat>0)
esm.writeHNT ("FORM", mFormat);
for (std::vector<Header::MasterData>::iterator iter = mMaster.begin();
iter != mMaster.end(); ++iter)
{

@ -16,6 +16,8 @@ namespace ESM
/// \brief File header record
struct Header
{
static const int CurrentFormat = 0; // most recent known format
struct Data
{
/* File format version. This is actually a float, the supported
@ -38,6 +40,7 @@ namespace ESM
};
Data mData;
int mFormat;
std::vector<MasterData> mMaster;
void blank();

Loading…
Cancel
Save