-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
55 lines (49 loc) · 2.1 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
#include <QCoreApplication>
#include <QTimer>
#include <QDir>
#include "qhookermain.h"
int main(int argc, char *argv[])
{
QCoreApplication *app = new QCoreApplication(argc, argv);
qhookerMain mainApp;
// argc is a count of arguments starting from 1 (executable inclusive),
// argv is an array containing each argument starting from 0 (executable inclusive).
if(argc > 1) {
QStringList arguments;
for(uint8_t i = 1; i < argc; i++) {
arguments.append(argv[i]);
}
if(arguments.contains("-v")) {
mainApp.verbosity = true;
qInfo() << "Enabling verbose output!";
arguments.removeAt(arguments.indexOf("-v"));
}
if(arguments.contains("-p")) {
if(arguments.length() > 1) {
// QDir::fromNativeSeparators uses forwardslashes on both OSes, thank Parace
mainApp.customPath = QDir::fromNativeSeparators(arguments[arguments.indexOf("-p")+1]);
mainApp.customPathSet = true;
if(QDir::isRelativePath(mainApp.customPath)) {
mainApp.customPath.prepend(QDir::currentPath() + '/');
}
if(!mainApp.customPath.endsWith('/')) {
mainApp.customPath.append('/');
}
qInfo() << "Setting search path to" << mainApp.customPath;
arguments.removeAt(arguments.indexOf("-p")+1);
} else {
qWarning() << "Detected custom path flag without any path specified! Disregarding.";
}
arguments.removeAt(arguments.indexOf("-p"));
}
}
// connect up the signals
QObject::connect(&mainApp, SIGNAL(finished()),
app, SLOT(quit()), Qt::QueuedConnection);
QObject::connect(app, SIGNAL(aboutToQuit()),
&mainApp, SLOT(aboutToQuitApp()), Qt::QueuedConnection);
// This code will start the messaging engine in QT and in
// 10ms it will start the execution in the MainClass.run routine;
QTimer::singleShot(10, &mainApp, SLOT(run()));
return app->exec();
}