summaryrefslogtreecommitdiff
path: root/wii
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--wii/archiveu8.cpp10
-rw-r--r--wii/archiveu8.h10
-rw-r--r--wii/common.cpp28
-rw-r--r--wii/common.h5
-rw-r--r--wii/filesystem.cpp14
-rw-r--r--wii/filesystem.h12
-rw-r--r--wii/stringtablebuilder.cpp2
-rw-r--r--wii/stringtablebuilder.h2
8 files changed, 54 insertions, 29 deletions
diff --git a/wii/archiveu8.cpp b/wii/archiveu8.cpp
index 5e0ad5d..d27dfde 100644
--- a/wii/archiveu8.cpp
+++ b/wii/archiveu8.cpp
@@ -124,7 +124,7 @@ void WiiArchiveU8::readDir(QDataStream &in, WiiDirectory &dir, int lastChild, U8
-void WiiArchiveU8::writeToDataStream(QDataStream &out) {
+void WiiArchiveU8::writeToDataStream(QDataStream &out) const {
U8WriteInfo info;
// first off, before we do anything else, create the string table
@@ -179,7 +179,7 @@ void WiiArchiveU8::writeToDataStream(QDataStream &out) {
}
-void WiiArchiveU8::addNodeToStringTable(WiiFSObject &node, WiiStringTableBuilder &table) {
+void WiiArchiveU8::addNodeToStringTable(const WiiFSObject &node, WiiStringTableBuilder &table) const {
table.add(node.name);
if (node.isDirectory()) {
@@ -191,7 +191,7 @@ void WiiArchiveU8::addNodeToStringTable(WiiFSObject &node, WiiStringTableBuilder
}
-void WiiArchiveU8::countNode(WiiFSObject &node, int *countPtr) {
+void WiiArchiveU8::countNode(const WiiFSObject &node, int *countPtr) const {
(*countPtr)++;
if (node.isDirectory()) {
@@ -203,7 +203,7 @@ void WiiArchiveU8::countNode(WiiFSObject &node, int *countPtr) {
}
-void WiiArchiveU8::writeDir(QDataStream &out, WiiDirectory &dir, U8WriteInfo &info) {
+void WiiArchiveU8::writeDir(QDataStream &out, const WiiDirectory &dir, U8WriteInfo &info) const {
foreach (WiiFSObject *p, dir.children) {
info.currentNode++;
@@ -244,7 +244,7 @@ void WiiArchiveU8::writeDir(QDataStream &out, WiiDirectory &dir, U8WriteInfo &in
}
-void WiiArchiveU8::writeNodeData(QDataStream &out, WiiFSObject &node) {
+void WiiArchiveU8::writeNodeData(QDataStream &out, const WiiFSObject &node) const {
if (node.isDirectory()) {
// write all the children's data
WiiDirectory *thisDir = (WiiDirectory*)&node;
diff --git a/wii/archiveu8.h b/wii/archiveu8.h
index 6f54ba2..5561beb 100644
--- a/wii/archiveu8.h
+++ b/wii/archiveu8.h
@@ -45,17 +45,17 @@ public:
WiiDirectory root;
- void writeToDataStream(QDataStream &out);
+ void writeToDataStream(QDataStream &out) const;
private:
void readDir(QDataStream &in, WiiDirectory &dir, int lastChild, U8ReadInfo &info);
- void addNodeToStringTable(WiiFSObject &node, WiiStringTableBuilder &table);
- void countNode(WiiFSObject &node, int *countPtr);
+ void addNodeToStringTable(const WiiFSObject &node, WiiStringTableBuilder &table) const;
+ void countNode(const WiiFSObject &node, int *countPtr) const;
- void writeDir(QDataStream &out, WiiDirectory &dir, U8WriteInfo &info);
+ void writeDir(QDataStream &out, const WiiDirectory &dir, U8WriteInfo &info) const;
- void writeNodeData(QDataStream &out, WiiFSObject &node);
+ void writeNodeData(QDataStream &out, const WiiFSObject &node) const;
};
#endif // WIIARCHIVEU8_H
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());
}
diff --git a/wii/common.h b/wii/common.h
index 34f1526..b440841 100644
--- a/wii/common.h
+++ b/wii/common.h
@@ -64,7 +64,7 @@ inline void ReadRGBA8Color(QColor &out, QDataStream &in) {
out = RGBAToColor(col);
}
-inline void WriteRGBA8Color(QColor &in, QDataStream &out) {
+inline void WriteRGBA8Color(const QColor in, QDataStream &out) {
out << (quint32)ColorToRGBA(in);
}
@@ -77,7 +77,7 @@ inline void ReadS10Color(QColor &out, QDataStream &in) {
out.setRgb(r, g, b, a);
}
-inline void WriteS10Color(QColor &in, QDataStream &out) {
+inline void WriteS10Color(const QColor in, QDataStream &out) {
out << (quint16)in.red();
out << (quint16)in.green();
out << (quint16)in.blue();
@@ -103,6 +103,7 @@ inline void InitDataStream(QDataStream &stream) {
}
QStringList ReadStringList(QDataStream &in);
+void WriteStringList(QDataStream &out, QStringList list);
QString ReadFixedLengthASCII(QDataStream &in, int length);
void WriteFixedLengthASCII(QDataStream &out, QString str, int length);
diff --git a/wii/filesystem.cpp b/wii/filesystem.cpp
index 09fe207..014b693 100644
--- a/wii/filesystem.cpp
+++ b/wii/filesystem.cpp
@@ -38,16 +38,16 @@ void WiiFSObject::unlinkFromParent() {
this->parent = 0;
}
-bool WiiFSObject::nameIsEqual(QString check) {
+bool WiiFSObject::nameIsEqual(QString check) const {
return (bool)(QString::compare(this->name, check, Qt::CaseInsensitive) == 0);
}
-bool WiiFSObject::isFile() { return false; }
-bool WiiFSObject::isDirectory() { return false; }
+bool WiiFSObject::isFile() const { return false; }
+bool WiiFSObject::isDirectory() const { return false; }
/******************************************************************************/
-bool WiiFile::isFile() { return true; }
+bool WiiFile::isFile() const { return true; }
/******************************************************************************/
@@ -56,9 +56,9 @@ WiiDirectory::~WiiDirectory() {
delete ptr;
}
-bool WiiDirectory::isDirectory() { return true; }
+bool WiiDirectory::isDirectory() const { return true; }
-WiiFSObject *WiiDirectory::findByName(QString name, bool recursive) {
+WiiFSObject *WiiDirectory::findByName(QString name, bool recursive) const {
foreach (WiiFSObject *obj, children) {
if (obj->nameIsEqual(name))
return obj;
@@ -108,7 +108,7 @@ WiiFSObject *WiiDirectory::resolvePath(QString path) {
if (pathComponents.isEmpty()) {
// we've reached the end \o/
- return nextObj;
+ return (WiiFSObject *)nextObj;
}
// verify that this object is a directory
diff --git a/wii/filesystem.h b/wii/filesystem.h
index 1a7ecfa..7527a7d 100644
--- a/wii/filesystem.h
+++ b/wii/filesystem.h
@@ -32,10 +32,10 @@ public:
void unlinkFromParent();
- bool nameIsEqual(QString check);
+ bool nameIsEqual(QString check) const;
- virtual bool isFile();
- virtual bool isDirectory();
+ virtual bool isFile() const;
+ virtual bool isDirectory() const;
protected:
@@ -50,7 +50,7 @@ public:
QByteArray data;
- bool isFile();
+ bool isFile() const;
};
/******************************************************************************/
@@ -62,9 +62,9 @@ public:
QList<WiiFSObject *> children;
- bool isDirectory();
+ bool isDirectory() const;
- WiiFSObject *findByName(QString name, bool recursive);
+ WiiFSObject *findByName(QString name, bool recursive) const;
WiiFSObject *resolvePath(QString path);
bool addChild(WiiFSObject *obj);
};
diff --git a/wii/stringtablebuilder.cpp b/wii/stringtablebuilder.cpp
index 679247c..d1f2d2b 100644
--- a/wii/stringtablebuilder.cpp
+++ b/wii/stringtablebuilder.cpp
@@ -20,6 +20,6 @@ quint32 WiiStringTableBuilder::add(QString str) {
return added;
}
-QByteArray WiiStringTableBuilder::pack() {
+QByteArray WiiStringTableBuilder::pack() const {
return m_data;
}
diff --git a/wii/stringtablebuilder.h b/wii/stringtablebuilder.h
index f416a37..4fce60f 100644
--- a/wii/stringtablebuilder.h
+++ b/wii/stringtablebuilder.h
@@ -11,7 +11,7 @@ public:
WiiStringTableBuilder();
quint32 add(QString str);
- QByteArray pack();
+ QByteArray pack() const;
protected:
int m_nextOffset;