This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
146 lines (122 loc) · 5.16 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "stdafx.h"
#include <QFontDatabase>
#include <QSslSocket>
#include "mainwindow.h"
#include "qtsingleapplication.h"
#include "settings.h"
#include "scopedguard.h"
#if defined(Q_OS_WIN)
# include "everythingwrapper.h"
#endif
int main(int argc, char *argv[])
{
#if !defined(Q_OS_WIN)
// increase the number of file that can be opened.
struct rlimit rl;
getrlimit(RLIMIT_NOFILE, &rl);
rl.rlim_cur = qMin((rlim_t)OPEN_MAX, rl.rlim_max);
setrlimit(RLIMIT_NOFILE, &rl);
#endif
SharedTools::QtSingleApplication a("Cisco Jabber Log Viewer", argc, argv);
if (!QSslSocket::supportsSsl())
{
QMessageBox::critical(nullptr, QObject::tr("Critical error"), QObject::tr("SSL not supported, exit now."), QMessageBox::Ok);
return -1;
}
QPixmap pixmap(":/cjlv.png");
QSplashScreen splash(pixmap.scaled(500, 500));
splash.show();
a.processEvents();
splash.showMessage("Loading external fonts...");
QStringList fonts {":/Fonts/SourceCodePro-Regular.ttf",
":/Fonts/SourceCodePro-Black.ttf",
":/Fonts/SourceCodePro-Bold.ttf",
":/Fonts/SourceCodePro-ExtraLight.ttf",
":/Fonts/SourceCodePro-Light.ttf",
":/Fonts/SourceCodePro-Medium.ttf",
":/Fonts/SourceCodePro-Semibold.ttf"};
foreach (const QString &f, fonts)
{
QFontDatabase::addApplicationFont(f);
}
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
QCoreApplication::setApplicationName("Cisco Jabber Log Viewer");
QCoreApplication::setApplicationVersion("1.1");
splash.showMessage("Checking evaluating date...");
QDate d = QLocale(QLocale::C).toDate(QString(__DATE__).simplified(), QLatin1String("MMM d yyyy"));
if (d.daysTo(QDate::currentDate()) > 365)
{
QMessageBox::critical(nullptr,
QObject::tr("Expired"),
QObject::tr("This application has been expired, please contact [email protected] for a new build."),
QMessageBox::Ok);
return 1;
}
splash.showMessage("Parsing command line options...");
QCommandLineParser parser;
parser.setApplicationDescription("Cisco Jabber Log Viewer");
parser.addHelpOption();
parser.addVersionOption();
parser.addOption(QCommandLineOption(QStringList() << "f"
<< "file",
"Save temporary database into local file system."));
parser.addOption(QCommandLineOption(QStringList() << "t"
<< "temporary-directory",
"Save temporary files into <directory>.",
"directory"));
parser.addOption(QCommandLineOption(QStringList() << "s"
<< "source-directory",
"Source code stored in <directory>.",
"directory"));
parser.addOption(QCommandLineOption(QStringList() << "m"
<< "disable-multi-monitor",
"Don't show log view and source code view in different monitors."));
parser.addPositionalArgument("logs", "logs files, zip packages or folders.");
// Process the actual command line arguments given by the user
parser.process(a);
splash.showMessage("Applying global configurations...");
g_settings = new Settings;
ScopedGuard sg([](){ delete g_settings;});
g_settings->initialize();
QString t = parser.value("t");
if (!t.isEmpty())
g_settings->setTemporaryDirectory(t);
if (g_settings->temporaryDirectory().isEmpty())
{
t = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
t.append("/CiscoJabberLogs/database");
g_settings->setTemporaryDirectory(t);
}
if (!parser.value("s").isEmpty())
g_settings->setSourceDirectory(parser.value("s"));
g_settings->setInMemoryDatabase(!parser.isSet("f"));
g_settings->setMultiMonitorEnabled(!parser.isSet("m") && QApplication::desktop()->screenCount() > 1);
const QStringList logs = parser.positionalArguments();
if (a.isRunning())
{
if (!logs.isEmpty())
{
a.sendMessage(logs.join("\n"));
}
return 0;
}
splash.showMessage("Creating main window...");
MainWindow w(splash);
w.showMaximized();
w.openLogs(logs);
#if defined(Q_OS_WIN)
if (isEverythingRunning())
{
const QString &path = GetEverythingPath();
g_settings->setEverythingPath(path);
g_settings->save();
}
else
{
launchEverything(g_settings->everythingPath());
}
#endif
QObject::connect(&a, SIGNAL(messageReceived(QString, QObject *)), &w, SLOT(onIPCMessageReceived(QString, QObject *)));
splash.finish(&w);
return a.exec();
}