Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QCoreApplication>
- #include <QString>
- #include <QMap>
- #include <QFile>
- #include <QVector>
- #include <QStringList>
- #include <QDebug>
- class Node
- {
- public:
- QByteArray name;
- QVector<Node> children;
- };
- bool operator<(const Node &a, const Node &b)
- {
- return a.name.toLower() < b.name.toLower();
- }
- bool operator<(const Node &a, const QByteArray &b)
- {
- return a.name.toLower() < b.toLower();
- }
- void appendNode(QByteArray &result, const Node &n, int indentation)
- {
- QByteArray indentString(indentation, ' ');
- result += indentString + "{value = \"" + n.name + "\",\n"
- + indentString + "text = \"" + n.name + "\"";
- if(n.children.isEmpty()) {
- result += "},\n";
- } else {
- result += ",\n";
- result += indentString + " children = {\n";
- foreach (const Node &n, n.children)
- appendNode(result, n, indentation + 4);
- result += indentString +" }\n";
- result += indentString +"},\n";
- }
- }
- void insertNodes(QVector<Node> &root, const QList<QByteArray> parts, int index)
- {
- if (index >= parts.size())
- return;
- Node n;
- n.name = parts.at(index);
- auto it = std::lower_bound(root.begin(), root.end(), n.name);
- if (it == root.end() || (*it).name.toLower() != n.name.toLower())
- it = root.insert(it, n);
- insertNodes((*it).children, parts, index + 1);
- }
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- if (a.arguments().size() < 2)
- return -1;
- QFile inputFile(a.arguments().at(1));
- inputFile.open(QIODevice::ReadOnly);
- QVector<Node> rootNodes;
- qDebug() << "reading...";
- // read
- while (!inputFile.atEnd()) {
- QByteArray line = inputFile.readLine();
- line = line.trimmed();
- if (line.endsWith(".M2")) {
- line.truncate(line.size() - 2);
- line.append("m2");
- }
- if (!line.endsWith(".m2"))
- continue;
- if (line.left(4).toLower() == ("item"))
- continue;
- if (line.left(7).toLower() == ("cameras"))
- continue;
- // qDebug() << line;
- QList<QByteArray> parts = line.split('\\');
- insertNodes(rootNodes, parts, 0);
- }
- inputFile.close();
- qDebug() << "dumping...";
- // dump
- int indentation = 0;
- QByteArray result = "WeakAuras.ModelPaths = {\n";
- foreach (const Node &n, rootNodes)
- appendNode(result, n, indentation);
- result += "};\n";
- QFile outputFile("ModelPaths.lua");
- outputFile.open(QIODevice::WriteOnly);
- outputFile.write(result);
- outputFile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement