forked from MrBesen/lolautoaccept
85 lines
1.9 KiB
C++
85 lines
1.9 KiB
C++
#include <thread>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <QApplication>
|
|
#include <QFile>
|
|
#include <QMessageBox>
|
|
#include <QTranslator>
|
|
|
|
#include <Log.h>
|
|
|
|
#include "arg.h"
|
|
#include "mainwindow.h"
|
|
#include "lolautoaccept.h"
|
|
|
|
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);
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
Log::init();
|
|
Log::setConsoleLogLevel(Log::Level::INFO);
|
|
#if __unix__
|
|
Log::setColoredOutput(true);
|
|
#endif
|
|
|
|
if(argc == 0) {
|
|
Log::fatal << "arg[0] is not set";
|
|
return 1;
|
|
}
|
|
|
|
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();
|
|
|
|
std::string base = getBaseString(argv);
|
|
Log::info << "appbase: " << base;
|
|
Matcher::setPathBase(base);
|
|
|
|
LolAutoAccept lolaa;
|
|
QApplication app(argc, argv);
|
|
QTranslator translator;
|
|
if(translator.load(QLocale().name(), QString::fromStdString(base + "ts"))) {
|
|
app.installTranslator(&translator);
|
|
} else {
|
|
Log::warn << "translation not found";
|
|
}
|
|
MainWindow win(lolaa);
|
|
|
|
while(!lolaa.init()) {
|
|
QMessageBox warn;
|
|
warn.setWindowTitle(MainWindow::tr("LoL-Auto-Accept"));
|
|
warn.setText(QMessageBox::tr("League of Legends Client not found!"));
|
|
warn.setInformativeText(QMessageBox::tr("Open the client and retry or close."));
|
|
warn.setStandardButtons(QMessageBox::Retry | QMessageBox::Close);
|
|
warn.setDefaultButton(QMessageBox::Retry);
|
|
warn.setIcon(QMessageBox::Warning);
|
|
if(warn.exec() == QMessageBox::Close) {
|
|
Log::stop();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
win.show();
|
|
int ret = app.exec();
|
|
|
|
Log::stop();
|
|
return ret;
|
|
} |