moved header record struct to separate file

actorid
Marc Zinnschlag 12 years ago
parent 731ac6a160
commit 16570ce87b

@ -39,7 +39,7 @@ add_component_dir (esm
loadclas loadclot loadcont loadcrea loadcrec loaddial loaddoor loadench loadfact loadglob loadgmst
loadinfo loadingr loadland loadlevlist loadligh loadlocks loadltex loadmgef loadmisc loadnpcc
loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat
loadweap records aipackage effectlist spelllist variant variantimp
loadweap records aipackage effectlist spelllist variant variantimp loadtes3
)
add_component_dir (misc

@ -2,7 +2,6 @@
#define OPENMW_ESM_COMMON_H
#include <string>
#include <vector>
#include <cstring>
#include <libs/platform/stdint.h>
@ -54,38 +53,6 @@ typedef NAME_T<32> NAME32;
typedef NAME_T<64> NAME64;
typedef NAME_T<256> NAME256;
#pragma pack(push)
#pragma pack(1)
/// File header data for all ES files
struct Header
{
struct Data
{
/* File format version. This is actually a float, the supported
versions are 1.2 and 1.3. These correspond to:
1.2 = 0x3f99999a and 1.3 = 0x3fa66666
*/
int version;
int type; // 0=esp, 1=esm, 32=ess (unused)
NAME32 author; // Author's name
NAME256 desc; // File description
int records; // Number of records? Not used.
};
// Defines another files (esm or esp) that this file depends upon.
struct MasterData
{
std::string name;
uint64_t size;
int index; // Position of the parent file in the global list of loaded files
};
Data mData;
std::vector<MasterData> mMaster;
};
#pragma pack(pop)
#pragma pack(push)
#pragma pack(1)
// Data that is only present in save game files

@ -62,18 +62,7 @@ void ESMReader::open(Ogre::DataStreamPtr _esm, const std::string &name)
getRecHeader();
// Get the header
getHNT (mHeader.mData, "HEDR", 300);
// Some mods abuse the header.version field for the version of the mod instead of the version of the file format, so we can only ignore it.
while (isNextSub("MAST"))
{
Header::MasterData m;
m.name = getHString();
m.size = getHNLong("DATA");
mHeader.mMaster.push_back(m);
}
mHeader.load (*this);
}
void ESMReader::open(const std::string &file)

@ -12,7 +12,9 @@
#include <components/misc/stringops.hpp>
#include <components/to_utf8/to_utf8.hpp>
#include "esmcommon.hpp"
#include "loadtes3.hpp"
namespace ESM {
@ -20,7 +22,7 @@ class ESMReader
{
public:
ESMReader(void);
ESMReader();
/*************************************************************************
*

@ -1,5 +1,8 @@
#include "esmwriter.hpp"
#include <cassert>
#include <fstream>
#include <iostream>
bool count = true;
@ -47,26 +50,13 @@ void ESMWriter::save(std::ostream& file)
startRecord("TES3", 0);
mHeader.mData.records = 0;
writeHNT("HEDR", mHeader.mData, 300);
m_headerPos = m_stream->tellp() - (std::streampos)4;
for (std::vector<Header::MasterData>::iterator it = mHeader.mMaster.begin();
it != mHeader.mMaster.end(); ++it)
{
writeHNCString("MAST", it->name);
writeHNT("DATA", it->size);
}
mHeader.save (*this);
endRecord("TES3");
}
void ESMWriter::close()
{
std::cout << "Writing amount of saved records (" << m_recordCount - 1 << ")" << std::endl;
m_stream->seekp(m_headerPos);
writeT<int>(m_recordCount-1);
m_stream->seekp(0, std::ios::end);
m_stream->flush();
if (!m_records.empty())

@ -1,13 +1,14 @@
#ifndef OPENMW_ESM_WRITER_H
#define OPENMW_ESM_WRITER_H
#include <iostream>
#include <iosfwd>
#include <list>
#include <assert.h>
#include "esmcommon.hpp"
#include <components/to_utf8/to_utf8.hpp>
#include "esmcommon.hpp"
#include "loadtes3.hpp"
namespace ESM {
class ESMWriter

@ -0,0 +1,40 @@
#include "loadtes3.hpp"
#include "esmcommon.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
void ESM::Header::blank()
{
mData.version = ESM::VER_13;
mData.type = 0;
mData.author.assign ("");
mData.desc.assign ("");
mData.records = 0;
}
void ESM::Header::load (ESMReader &esm)
{
esm.getHNT (mData, "HEDR", 300);
while (esm.isNextSub ("MAST"))
{
MasterData m;
m.name = esm.getHString();
m.size = esm.getHNLong ("DATA");
mMaster.push_back (m);
}
}
void ESM::Header::save (ESMWriter &esm)
{
esm.writeHNT ("HEDR", mData, 300);
for (std::vector<Header::MasterData>::iterator iter = mMaster.begin();
iter != mMaster.end(); ++iter)
{
esm.writeHNCString ("MAST", iter->name);
esm.writeHNT ("DATA", iter->size);
}
}

@ -0,0 +1,52 @@
#ifndef COMPONENT_ESM_TES3_H
#define COMPONENT_ESM_TES3_H
#include <vector>
#include "esmcommon.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
#pragma pack(push)
#pragma pack(1)
/// \brief File header record
struct Header
{
struct Data
{
/* File format version. This is actually a float, the supported
versions are 1.2 and 1.3. These correspond to:
1.2 = 0x3f99999a and 1.3 = 0x3fa66666
*/
int version;
int type; // 0=esp, 1=esm, 32=ess (unused)
NAME32 author; // Author's name
NAME256 desc; // File description
int records; // Number of records? Not used.
};
// Defines another files (esm or esp) that this file depends upon.
struct MasterData
{
std::string name;
uint64_t size;
int index; // Position of the parent file in the global list of loaded files
};
Data mData;
std::vector<MasterData> mMaster;
void blank();
void load (ESMReader &esm);
void save (ESMWriter &esm);
};
#pragma pack(pop)
}
#endif
Loading…
Cancel
Save