-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
104 lines (84 loc) · 3.38 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
95
96
97
98
99
100
101
102
103
#include <QCoreApplication>
#include "lazerdriveapp.h"
#include <QCommandLineParser>
#include <QFileInfo>
#include <QDir>
void messageHandler(QtMsgType type, const QMessageLogContext &, const QString &msg)
{
int verboseLevel = qApp->property("lazerDriveVerboseLevel").toInt();
if (type == QtFatalMsg && verboseLevel >= 1) {
if (verboseLevel >= 1) {
fprintf(stderr, "[FATAL] %s\n", msg.toLocal8Bit().constData());
}
abort();
}
if (type == QtDebugMsg && verboseLevel >= 4) {
fprintf(stderr, "[DEBUG] %s\n", msg.toLocal8Bit().constData());
} else if (type == QtInfoMsg && verboseLevel >= 2) {
fprintf(stderr, "[INFO] %s\n", msg.toLocal8Bit().constData());
} else if (type == QtWarningMsg && verboseLevel >= 1) {
fprintf(stderr, "[WARNING] %s\n", msg.toLocal8Bit().constData());
} else if (type == QtCriticalMsg && verboseLevel >= 1) {
fprintf(stderr, "[CRITICAL] %s\n", msg.toLocal8Bit().constData());
}
}
int main(int argc, char *argv[])
{
qInstallMessageHandler(messageHandler);
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("lazerdrive-leaderboard-sniffer");
QCoreApplication::setApplicationVersion("1.0.0");
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption configFileOption(
QStringList() << "c" << "config",
"Load config from ini file <file>.",
"file"
);
parser.addOption(configFileOption);
QCommandLineOption verboseOption(
"verbose",
"Set the verbose level.\nAvailable levels:\n0 quiet mode, equivalent to -q or --quiet\n1 only displays errors\n2 displays errors and warnings\n3 (default) displays errors, warnings and infos\n4 displays all messages, including debug",
"level",
"3"
);
parser.addOption(verboseOption);
QCommandLineOption quietOption(
QStringList() << "q" << "quiet",
"Run in silent mode, equivalent to --verbose 0."
);
parser.addOption(quietOption);
QCommandLineOption serverOption(
QStringList() << "s" << "server",
"Connect to this server. The default value is \"one.eu.lazerdrive.io\".",
"host",
"one.eu.lazerdrive.io"
);
parser.addOption(serverOption);
QCommandLineOption usernameOption(
QStringList() << "u" << "username",
"Use this username. If you don't specify it, you will have a random username.",
"username"
);
parser.addOption(usernameOption);
parser.process(a);
if (parser.isSet(quietOption)) {
a.setProperty("lazerDriveVerboseLevel", 0);
} else {
a.setProperty("lazerDriveVerboseLevel", parser.value(verboseOption));
}
if (parser.isSet(configFileOption)) {
QString configFile = parser.value(configFileOption);
if (QFileInfo(configFile).isRelative()) {
configFile = QDir::currentPath() + "/" + configFile;
}
if (!LazerDriveConfiguration::init(configFile)) {
qWarning() << "Can't load provided configuration, falling back to default settings";
}
}
LazerDriveConfiguration::instance()->setProperty("lazerDriveServer", parser.value(serverOption));
LazerDriveConfiguration::instance()->setProperty("lazerDriveUsername", parser.value(usernameOption));
LazerDriveApp app;
return a.exec();
}