-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
94 lines (73 loc) · 2.88 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <cstdio>
#include <QFile>
#include <QTimer>
#include <QTextStream>
#include <QCoreApplication>
#include <QCommandLineParser>
#include "blendtoxml.h"
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("blend2xml");
QCoreApplication::setApplicationVersion("1.0");
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("source", "Source .blend file.");
QCommandLineOption outputOption(QStringList() << "o" << "output", "Destination .xml file.", "file");
parser.addOption(outputOption);
QCommandLineOption notypesOption("notypes", "Disable type info.");
parser.addOption(notypesOption);
QCommandLineOption nodataOption("nodata", QCoreApplication::translate("main", "Disable data info."));
parser.addOption(nodataOption);
QCommandLineOption printRawPointersOption("rawpointers", QCoreApplication::translate("main", "Print raw pointers."));
parser.addOption(printRawPointersOption);
parser.process(*qApp);
const QStringList args = parser.positionalArguments();
if (args.count() != 1) {
parser.showHelp(1);
}
QTextStream qerr(stderr);
QFile file(args[0]);
if (!file.open(QIODevice::ReadOnly)) {
qerr << QString("open %1: %2\n").arg(args[0], file.errorString());
return 1;
}
QString outputPath = parser.value(outputOption);
QFile outFile;
if (outputPath.isEmpty()) {
outFile.open(stdout, QIODevice::WriteOnly);
} else {
outFile.setFileName(outputPath);
outFile.open(QIODevice::WriteOnly);
}
if (outFile.error() != QFileDevice::NoError) {
qerr << "open:" << outFile.errorString() << "\n";
return 1;
}
bool notypes = parser.isSet(notypesOption);
bool nodata = parser.isSet(nodataOption);
bool printRawPointers = parser.isSet(printRawPointersOption);
BlendToXml *task = new BlendToXml(&file, &outFile, notypes, nodata, printRawPointers);
QObject::connect(task, &BlendToXml::finished, &app, &QCoreApplication::quit);
QTimer::singleShot(0, task, SLOT(run()));
return app.exec();
}