-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
100 lines (82 loc) · 3.21 KB
/
main.cpp
File metadata and controls
100 lines (82 loc) · 3.21 KB
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
95
96
97
98
99
#include <QGuiApplication>
#include <QCommandLineParser>
#include <QFileInfo>
#include <QDirIterator>
#include <QDebug>
#include <QMap>
#include <QXmlStreamReader>
#include "blockinfo.h"
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
QGuiApplication::setApplicationName("Block Generator");
QGuiApplication::setApplicationVersion("1.0");
qSetMessagePattern("[%{type}] %{message}");
QCommandLineParser parser;
parser.setApplicationDescription("Qt application to read XML files of variables of blocks for the Proteo PC "
"and generate a PNG image displaying inputs and outputs of the block. "
"It can be used with a single file or a directory - in this case, it will "
"generate blocks for every file inside the directory.");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("path", QCoreApplication::translate("main", "Path to file or directory to generate block info."));
QCommandLineOption r(QStringList() << "r" << "R" << "recursive", QCoreApplication::translate("main", "Generate PNG image in directories and files recursively"));
parser.addOption(r);
QCommandLineOption c(QStringList() << "c" << "call", QCoreApplication::translate("main", "Generate file with the block calling information"));
parser.addOption(c);
parser.process(a);
const QStringList args = parser.positionalArguments();
if(args.length() != 1)
{
parser.showHelp();
}
bool recursive = parser.isSet(r);
bool calls = parser.isSet(c);
QFileInfo path(args.at(0));
QString callsString;
if(path.isDir()) // If it's a directory, enter and do the regex replacing in all the files.
{
qDebug() << "Argument \"Path\" is a directory.";
// Add the recursive option
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags;
if(recursive)
flags = QDirIterator::Subdirectories;
QDirIterator dirIt(path.path(), flags);
while(dirIt.hasNext())
{
QString filePathStr = dirIt.next();
QFileInfo filePath(filePathStr);
if(!filePath.isFile() || filePath.suffix() != "var")
{
continue;
}
BlockInfo block;
block.parseXML(filePath);
block.saveImage();
callsString += block.getBlockCall() + QString("\n");
}
callsString = callsString.left(callsString.count() - 1);
}
else if(path.isFile())
{
qDebug() << "Argument \"Path\" is a file.";
BlockInfo block;
block.parseXML(path);
block.saveImage();
callsString += block.getBlockCall();
}
if(calls)
{
QString appDirPath = QGuiApplication::applicationDirPath();
QDir textDir(QString("%1/textinfo").arg(appDirPath));
if(!textDir.exists())
textDir.mkpath(".");
QFile file(QString("%1/blockcalls.txt").arg(textDir.path()));
if ( file.open(QIODevice::WriteOnly) )
{
QTextStream stream( &file );
stream << callsString << endl;
}
}
return 0;
}