-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (59 loc) · 1.65 KB
/
main.cpp
File metadata and controls
76 lines (59 loc) · 1.65 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
#include <iostream>
#include <fstream>
using namespace std;
#include <QtGui/QApplication>
#include "dialogs/main/MainWindow.h"
#ifdef COMPILE_TESTS
#include <gtest/gtest.h>
#endif
#include "Databases.h"
#include "Utils.h"
#include "dialogs/utils/PasswordDialog.h"
#include "CommandLine.h"
#ifdef _WIN32
#include "windowscompat/guicon.h"
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
for (int i = 0; i < argc; ++i)
{
#ifdef COMPILE_TESTS
if ((strcmp(argv[i], "-t") == 0) || (strcmp(argv[i], "--test") == 0))
{
char arg1[] = "--gtest_output=xml:test_report.xml";
char *args[] = { argv[0], arg1 };
int argCount = 2;
::testing::InitGoogleTest(&argCount, args);
return RUN_ALL_TESTS();
}
#endif
if ((strcmp(argv[i], "-c") == 0) || (strcmp(argv[i], "--cli") == 0))
{
#ifdef _WIN32
RedirectIOToConsole();
#endif
Databases::init();
CommandLine::run();
Databases::finalise();
return 0;
}
}
// Redirect buffer so that it prints to a logfile instead of the console
ofstream log;
log.open("logfile.log");
streambuf *const coutStreamBuffer = cout.rdbuf();
cout.rdbuf(log.rdbuf());
Databases::init();
int exitCode = 1;
if (PasswordDialog().exec() == PasswordDialog::Accepted)
{
MainWindow w;
w.show();
try { exitCode = a.exec(); } catch(const std::exception &e) { showFatalDialog(e.what()); }
}
Databases::finalise();
log.close();
cout.rdbuf(coutStreamBuffer);
return exitCode;
}