summaryrefslogtreecommitdiff
path: root/wii/common.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2010-10-14 20:17:20 +0200
committerTreeki <treeki@gmail.com>2010-10-14 20:17:20 +0200
commitebcc95da4c26369511caa90d89c5ed06e1e4853a (patch)
tree6ed445f0204a6e6615088d135c4b29c4309077a4 /wii/common.cpp
parentfdf8cfec2b795393d7ee901abaf747575067068b (diff)
downloadLayoutStudio-ebcc95da4c26369511caa90d89c5ed06e1e4853a.tar.gz
LayoutStudio-ebcc95da4c26369511caa90d89c5ed06e1e4853a.zip
brlyt packing added, plus some changes in the existing API (mostly for const correctness). brlyt writing may still need some testing (especially for the material structs)
Diffstat (limited to '')
-rw-r--r--wii/common.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/wii/common.cpp b/wii/common.cpp
index f4a961c..8f552b3 100644
--- a/wii/common.cpp
+++ b/wii/common.cpp
@@ -17,7 +17,7 @@
#include "common.h"
-QByteArray PadByteArray(QByteArray original, int newLength, char padWith) {
+QByteArray PadByteArray(const QByteArray original, int newLength, char padWith) {
QByteArray newArray = original;
if (original.length() > newLength) {
@@ -91,6 +91,30 @@ QStringList ReadStringList(QDataStream &in) {
return output;
}
+void WriteStringList(QDataStream &out, const QStringList list) {
+ out << (quint16)list.count();
+ WritePadding(2, out);
+
+ // calculate offsets for every string, and write them
+ // offset 0 points to the first entry in the offset list, etc, so
+ // take that into account for the string offset calculation
+ quint32 currentOffset = list.count() * 8;
+
+ foreach (QString str, list) {
+ out << (quint32)currentOffset;
+ WritePadding(4, out); // unused?
+
+ currentOffset += str.length() + 1;
+ }
+
+ // now write the strings
+ foreach (QString str, list) {
+ QByteArray rawStr = str.toAscii();
+ rawStr.append('\0');
+ out.writeRawData(rawStr.constData(), rawStr.length());
+ }
+}
+
QString ReadFixedLengthASCII(QDataStream &in, int length) {
QByteArray readStr(length, '\0');
in.readRawData(readStr.data(), readStr.length());
@@ -102,7 +126,7 @@ QString ReadFixedLengthASCII(QDataStream &in, int length) {
return str;
}
-void WriteFixedLengthASCII(QDataStream &out, QString str, int length) {
+void WriteFixedLengthASCII(QDataStream &out, const QString str, int length) {
QByteArray paddedStr = PadByteArray(str.toAscii(), length);
out.writeRawData(paddedStr.constData(), paddedStr.length());
}