lolautoaccept/src/main.cpp

74 lines
1.5 KiB
C++
Raw Normal View History

2022-04-20 00:54:10 +02:00
#include <thread>
2022-04-25 23:36:02 +02:00
#include <limits.h>
2022-04-20 00:54:10 +02:00
#include <QApplication>
2022-04-25 23:36:02 +02:00
#include <QFile>
2022-04-20 00:54:10 +02:00
#include <QMessageBox>
#include <QTranslator>
2022-03-01 01:28:30 +01:00
#include <Log.h>
2022-04-26 19:36:15 +02:00
#include "arg.h"
2022-04-20 00:54:10 +02:00
#include "mainwindow.h"
#include "lolautoaccept.h"
2022-06-29 23:09:01 +02:00
#include "clientaccess.h"
#include "clientapi.h"
2022-04-20 00:54:10 +02:00
2022-04-25 23:36:02 +02:00
static std::string getBaseString(char** argv) {
std::string base;
char* appbase = getenv("APPDIR");
if(appbase) {
return std::string(appbase) + '/';
}
char* cresolved = realpath(argv[0], NULL);
std::string resolved(cresolved);
free(cresolved);
return resolved.substr(0, resolved.rfind('/')+1);
}
2022-04-20 00:54:10 +02:00
int main(int argc, char** argv) {
2022-03-01 01:28:30 +01:00
Log::init();
2022-04-24 21:05:10 +02:00
Log::setConsoleLogLevel(Log::Level::INFO);
2022-03-01 01:28:30 +01:00
#if __unix__
Log::setColoredOutput(true);
#endif
2022-04-25 23:36:02 +02:00
if(argc == 0) {
Log::fatal << "arg[0] is not set";
return 1;
}
2022-04-26 19:36:15 +02:00
Args args = parseArgs(argc, argv);
if(args.debugLog) {
Log::setConsoleLogLevel(Log::Level::TRACE);
Log::addLogfile("log.txt", Log::Level::TRACE);
Log::debug << "debug Log enabled";
}
Log::info << "Hello, World!";
Log::note << "Using Locale: " << QLocale().name().toStdString();
2022-04-25 23:36:02 +02:00
std::string base = getBaseString(argv);
Log::info << "appbase: " << base;
LolAutoAccept lolaa;
2022-04-20 00:54:10 +02:00
QApplication app(argc, argv);
QTranslator translator;
2022-04-25 23:36:02 +02:00
if(translator.load(QLocale().name(), QString::fromStdString(base + "ts"))) {
2022-04-20 00:54:10 +02:00
app.installTranslator(&translator);
} else {
Log::warn << "translation not found";
}
2022-04-21 00:47:57 +02:00
MainWindow win(lolaa);
2022-05-21 00:29:36 +02:00
QIcon icon(QString::fromStdString(base + "lolautoaccept.png"));
win.setWindowIcon(icon);
2022-04-24 21:05:10 +02:00
2022-04-20 00:54:10 +02:00
win.show();
int ret = app.exec();
2022-03-08 00:04:56 +01:00
2022-03-01 01:28:30 +01:00
Log::stop();
2022-04-20 00:54:10 +02:00
return ret;
2022-03-01 01:28:30 +01:00
}