diff options
author | Treeki <treeki@gmail.com> | 2010-10-07 15:56:13 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2010-10-07 15:56:13 +0200 |
commit | 5f6dad55d75cbe146ff7fefc899a02ccd39078ba (patch) | |
tree | 0822df14cc6d2c0329810c9ae7b4a4a638fe82b1 /lyt/binaryfile.cpp | |
download | LayoutStudio-5f6dad55d75cbe146ff7fefc899a02ccd39078ba.tar.gz LayoutStudio-5f6dad55d75cbe146ff7fefc899a02ccd39078ba.zip |
initial commit -- everything compiles except for material.cpp. the material system still needs quite a bit of work; this will come in due time
Diffstat (limited to '')
-rw-r--r-- | lyt/binaryfile.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lyt/binaryfile.cpp b/lyt/binaryfile.cpp new file mode 100644 index 0000000..8ac2a01 --- /dev/null +++ b/lyt/binaryfile.cpp @@ -0,0 +1,66 @@ +#include "binaryfile.h" +#include "binaryfilesection.h" + +#include <QtCore/QDataStream> + +LYTBinaryFile::LYTBinaryFile(Magic magic, Version version) { + this->magic.value = magic.value; + this->version.value = version.value; +} + + +LYTBinaryFile::LYTBinaryFile(QByteArray data) { + QDataStream reader(data); + InitDataStream(reader); + + quint16 endian, firstSectionOffset, sectionCount; + quint32 fileSize; + + reader >> this->magic.value; + reader >> endian; + reader >> this->version.value; + reader >> fileSize; + reader >> firstSectionOffset; + reader >> sectionCount; + + LYTBinaryFileSection section; + + for (int i = 0; i < sectionCount; i++) { + section.readFromDataStream(reader); + this->sections.append(section); + } +} + + +QByteArray LYTBinaryFile::pack() { + // first off, calculate filesize for the header + quint32 fileSize = 16; + + foreach (LYTBinaryFileSection section, this->sections) { + fileSize += section.writtenSize(); + } + + // set up other fields + quint16 endian, firstSectionOffset; + endian = 0xFEFF; + firstSectionOffset = 16; + + + // write it + QByteArray output; + QDataStream writer(&output, QIODevice::WriteOnly); + InitDataStream(writer); + + writer << this->magic.value; + writer << endian; + writer << this->version.value; + writer << fileSize; + writer << firstSectionOffset; + writer << (quint16)this->sections.count(); + + foreach (LYTBinaryFileSection section, this->sections) { + section.writeToDataStream(writer); + } + + return output; +} |