-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
150 lines (118 loc) · 4.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
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
147
148
149
150
#include "OTModules/OTGeneric/wstart.h"
#include "OTModules/OTGeneric/wfirstsetup.h"
#include "OTBackend/OTGlobal.h"
#include <QApplication>
#include <QTranslator>
#include <QDebug>
#include <QFile>
#include "OTBackend/OTLogger.h"
#include "OTBackend/DiscordGameSDK.h"
#include <QThreadPool>
void testArea()
{
}
void updateCleanup()
{
qInfo() << "Update installed, remove old files...";
// Necessary for every update up to 1.1.2-lite:
QDir(QDir::tempPath() + "/OMSI-Tools_tempAppDir").removeRecursively();
}
int main(int argc, char *argv[])
{
OTSettings set;
OTMiscellaneous misc;
OTFileOperations fop;
QApplication a(argc, argv);
/// Setup
{
// If application crashed, save logfile
QString newName;
bool isCrash = false;
if (set.read("main", "closeCheck") == "false")
{
isCrash = true;
newName = QString("logfile_crash_%1.txt").arg(misc.getDate("yyyy-MM-dd") + "_" + misc.getTime("hh-mm-ss"));
QFile::copy("logfile.txt", newName);
}
// Initialize logger
if ((set.read("main", "logfileMode") != -1))
{
OTLogger::attach("logfile.txt", OTInformation::name);
OTLogger::logging = true;
}
// Print all prefs to the logfile
qDebug().noquote() << "Preferences" + set.getAllPreferencesFormatted() + "\n================================================\n";
set.setPreferencesOnStart();
qInfo().noquote() << "Starting " + OTInformation::name + "...";
qApp->setStyle(QStyleFactory::create(set.read("main", "theme").toString()));
set.loadBaseStyleheet();
set.loadTranslator();
if (isCrash)
{
qWarning() << "Crash on last start detected! A logfile has been saved.";
QMessageBox::StandardButton reply = QMessageBox::question(NULL, QObject::tr("Crash detected"), QObject::tr("%1 seems to have crashed on last launch. The logfile of the last start was saved separately. Please contact the developer with this.\nOpen the path of the logfile?").arg(OTInformation::name));
if (reply == QMessageBox::Yes)
fop.showInExplorer(newName);
}
else
qDebug() << "No crash detected.";
set.write("main", "closeCheck", false);
testArea();
// If the application was updated, remove the temporary directory in the temp folder
if ((QCoreApplication::arguments().size() >= 2) && (QCoreApplication::arguments().at(1) == "updateInstalled"))
updateCleanup();
// Start counter
if (set.read("main", "startCount").isValid())
set.write("main", "startCount", set.read("main", "startCount").toInt() + 1);
else
set.write("main", "startCount", 1);
// Start DiscordGameSDK:
if (!set.read("main", "useDiscordGameSDK").toBool())
DiscordGameSDK::stop();
DiscordGameSDK *discord = new DiscordGameSDK();
QFuture<void> discordFuture = QtConcurrent::run([discord]() {
discord->exec();
});
#ifdef QT_DEBUG
DiscordGameSDK::clearActivity();
DiscordGameSDK::setModule("Debugging ☹");
DiscordGameSDK::setStatus("all the way to hell");
DiscordGameSDK::update();
DiscordGameSDK::setBlockUpdate(true);
#else
if (OTInformation::build == OTBuildOptions::Dev)
{
DiscordGameSDK::clearActivity();
DiscordGameSDK::setModule("Developing");
DiscordGameSDK::setStatus(QString("a brand new version of %1").arg(OTInformation::name));
DiscordGameSDK::update();
DiscordGameSDK::setBlockUpdate(true);
}
else DiscordGameSDK::clearActivity();
#endif
}
wStart *WSTART;
wFirstSetup *WFIRSTSETUP;
// if ((QCoreApplication::arguments().size() >= 2) && (QCoreApplication::arguments().at(1) == "..."))
// {
// // ...
// }
// else
if (!set.read("main", "language").isValid())
{
WFIRSTSETUP = new wFirstSetup();
WFIRSTSETUP->show();
}
else
{
WSTART = new wStart();
WSTART->show();
}
int exec = a.exec();
// --------------------------------------------
// Actions on close
DiscordGameSDK::stop();
qInfo().noquote() << OTInformation::name + " is closing...";
set.write("main", "closeCheck", true);
return exec;
}