78 lines
2.4 KiB
C++
78 lines
2.4 KiB
C++
#include <QApplication>
|
|
#include <QTimer>
|
|
#include <QDir>
|
|
#include <QFile>
|
|
#include <QDateTime>
|
|
#include <QMutex>
|
|
|
|
#include "ElaApplication.h"
|
|
#include "ElaTheme.h"
|
|
#include "MainWindow.h"
|
|
#include "CardData.h"
|
|
#include "SettingsManager.h"
|
|
#include "SoundManager.h"
|
|
#include "UpdateChecker.h"
|
|
|
|
static QFile* g_logFile = nullptr;
|
|
static QMutex g_logMutex;
|
|
|
|
void messageHandler(QtMsgType type, const QMessageLogContext& ctx, const QString& msg) {
|
|
Q_UNUSED(ctx)
|
|
QMutexLocker lock(&g_logMutex);
|
|
QString level;
|
|
switch (type) {
|
|
case QtDebugMsg: level = "DEBUG"; break;
|
|
case QtInfoMsg: level = "INFO"; break;
|
|
case QtWarningMsg: level = "WARN"; break;
|
|
case QtCriticalMsg: level = "ERROR"; break;
|
|
case QtFatalMsg: level = "FATAL"; break;
|
|
}
|
|
QString line = QStringLiteral("[%1] [%2] %3\n")
|
|
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"), level, msg);
|
|
#ifndef QT_NO_DEBUG_OUTPUT
|
|
fprintf(stderr, "%s", line.toLocal8Bit().constData());
|
|
#endif
|
|
if (g_logFile && g_logFile->isOpen())
|
|
g_logFile->write(line.toUtf8());
|
|
}
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
QApplication a(argc, argv);
|
|
a.setApplicationVersion(APP_VERSION);
|
|
|
|
QString logDir = QCoreApplication::applicationDirPath() + "/logs";
|
|
QDir().mkpath(logDir);
|
|
QString logPath = logDir + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd_HHmmss") + ".log";
|
|
g_logFile = new QFile(logPath);
|
|
g_logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
|
qInstallMessageHandler(messageHandler);
|
|
|
|
QDir logClean(logDir);
|
|
for (const auto& f : logClean.entryList({"*.log"}, QDir::Files)) {
|
|
QFileInfo fi(logDir + "/" + f);
|
|
if (fi.lastModified().daysTo(QDateTime::currentDateTime()) > 7)
|
|
QFile::remove(fi.absoluteFilePath());
|
|
}
|
|
|
|
eApp->init();
|
|
eTheme->setThemeMode(ElaThemeType::Dark);
|
|
|
|
SettingsManager::instance().load();
|
|
SoundManager::instance().init();
|
|
|
|
CardDatabase::instance().loadFromFile(
|
|
QCoreApplication::applicationDirPath() + "/config/cards.json");
|
|
|
|
MainWindow w;
|
|
w.show();
|
|
|
|
QTimer::singleShot(2000, [&]() {
|
|
auto server = SettingsManager::instance().getString("network", "server_address");
|
|
if (!server.isEmpty())
|
|
UpdateChecker::instance().checkForUpdate(server, true);
|
|
});
|
|
|
|
return QApplication::exec();
|
|
}
|