-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (64 loc) · 2.45 KB
/
Copy pathmain.cpp
File metadata and controls
81 lines (64 loc) · 2.45 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
77
78
79
80
81
#include "mainwindow.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QFont>
#include <QCoreApplication>
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QDir>
#include <QDebug>
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
static const qint64 MAX_LOG_SIZE = 5 * 1024 * 1024; // 5 Mo
static bool loggingDisabled = false;
if (loggingDisabled || msg.contains("invalid type") || msg.contains("Trying to construct") ||
msg.contains("QObject::disconnect") || msg.contains("QGraphicsScene")) {
return;
}
QFile logFile(QDir::homePath() + "/.hearts.log");
if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
return;
}
QTextStream out(&logFile);
QString timestamp = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
if (logFile.size() >= MAX_LOG_SIZE) {
out << timestamp
<< " [LOG LIMIT] Taille maximale atteinte (" << MAX_LOG_SIZE / 1024 / 1024 << " Mo). "
<< "Logging désactivé pour éviter une boucle infinie.\n";
out.flush();
logFile.close();
loggingDisabled = true;
qWarning() << "Log file size limit reached. Logging stopped.";
return;
}
switch (type) {
case QtDebugMsg: out << timestamp << " DEBUG: " << msg << "\n"; break;
case QtInfoMsg: out << timestamp << " INFO: " << msg << "\n"; break;
case QtWarningMsg: out << timestamp << " WARNING: " << msg << "\n"; break;
case QtCriticalMsg: out << timestamp << " CRITICAL: " << msg << "\n"; break;
case QtFatalMsg: out << timestamp << " FATAL: " << msg << "\n";
abort();
}
// for debugging
// QByteArray localMsg = msg.toLocal8Bit();
// fprintf(stderr, "%s\n", localMsg.constData());
out.flush();
// → Destruction automatique de QFile + QTextStream à la fin de la fonction
// → close() implicite, flush déjà fait
}
int main(int argc, char *argv[])
{
qputenv("QT_MEDIA_BACKEND", "ffmpeg");
QFile::remove(QDir::homePath() + "/.hearts.log");
qInstallMessageHandler(messageHandler);
QApplication app(argc, argv);
qDebug() << "=== Démarrage de Hearts" << QCoreApplication::applicationVersion()
<< "le" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") << "===";
QFont font("Noto Sans", 11);
font.setStyleName("Regular");
MainWindow w;
w.show();
return app.exec();
}