parent
46ceb4d1d8
commit
45ee47b145
87
src/main.cpp
87
src/main.cpp
|
@ -1,93 +1,54 @@
|
||||||
// Copyright 2020, Verizon Media
|
// Copyright 2020, Verizon Media
|
||||||
// Licensed under the terms of MIT. See LICENSE file in project root for terms.
|
// Licensed under the terms of MIT. See LICENSE file in project root for terms.
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
void handleCLI(std::vector<std::string> args);
|
|
||||||
|
|
||||||
#ifndef QT_NO_SYSTEMTRAYICON
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
|
||||||
#include "db/databaseconnection.h"
|
#include "db/databaseconnection.h"
|
||||||
#include "exceptions/fileerror.h"
|
|
||||||
#include "traymanager.h"
|
#include "traymanager.h"
|
||||||
|
|
||||||
QIcon getWindowIcon();
|
QIcon getWindowIcon() { return QIcon(QStringLiteral(":icons/windowIcon.png")); }
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
void showMsgBox(const QString &errorText = QString())
|
||||||
|
{
|
||||||
|
QMessageBox::critical(nullptr, QT_TRANSLATE_NOOP("main", "ASHIRT Error"), errorText);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
Q_INIT_RESOURCE(res_icons);
|
Q_INIT_RESOURCE(res_icons);
|
||||||
Q_INIT_RESOURCE(res_migrations);
|
Q_INIT_RESOURCE(res_migrations);
|
||||||
|
|
||||||
QCoreApplication::setApplicationName("ashirt");
|
QCoreApplication::setApplicationName(QStringLiteral("ashirt"));
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QCoreApplication::setOrganizationName("ashirt");
|
QCoreApplication::setOrganizationName(QCoreApplication::applicationName());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DatabaseConnection* conn = new DatabaseConnection(Constants::dbLocation, Constants::defaultDbName);
|
QApplication app(argc, argv);
|
||||||
if (!conn->connect()) {
|
app.setWindowIcon(getWindowIcon());
|
||||||
QMessageBox::critical(nullptr, QStringLiteral("ASHIRT Error"), QStringLiteral("Unable to connect to database"));
|
|
||||||
|
if(!QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||||
|
showMsgBox(QT_TRANSLATE_NOOP("main", "A System tray is required to interact with the application"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtn;
|
auto conn = new DatabaseConnection(Constants::dbLocation, Constants::defaultDbName);
|
||||||
try {
|
if(!conn->connect()) {
|
||||||
QApplication app(argc, argv);
|
showMsgBox(QT_TRANSLATE_NOOP("main", "Unable to connect to database"));
|
||||||
qRegisterMetaType<model::Tag>();
|
return -1;
|
||||||
|
|
||||||
app.setWindowIcon(getWindowIcon());
|
|
||||||
|
|
||||||
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
|
||||||
handleCLI(std::vector<std::string>(argv, argv + argc));
|
|
||||||
}
|
}
|
||||||
QApplication::setQuitOnLastWindowClosed(false);
|
|
||||||
|
app.setQuitOnLastWindowClosed(false);
|
||||||
|
qRegisterMetaType<model::Tag>();
|
||||||
|
auto window = new TrayManager(nullptr, conn);
|
||||||
|
|
||||||
QObject::connect(&app, &QApplication::aboutToQuit, [conn] {
|
QObject::connect(&app, &QApplication::aboutToQuit, [conn] {
|
||||||
conn->close();
|
conn->close();
|
||||||
delete conn;
|
delete conn;
|
||||||
});
|
});
|
||||||
|
|
||||||
auto window = new TrayManager(nullptr, conn);
|
int rtn = app.exec();
|
||||||
rtn = app.exec();
|
|
||||||
window->deleteLater();
|
window->deleteLater();
|
||||||
}
|
|
||||||
catch (std::exception const& ex) {
|
|
||||||
qWarning() << "Exception while running: " << ex.what();
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
qWarning() << "Unhandled exception while running";
|
|
||||||
}
|
|
||||||
return rtn;
|
return rtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon getWindowIcon() {
|
|
||||||
return QIcon(QStringLiteral(":icons/windowIcon.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QLabel>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) { handleCLI(std::vector<string>(argv, argv + argc)); }
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void handleCLI(std::vector<std::string> args) {
|
|
||||||
size_t trueCount = args.size() - 1;
|
|
||||||
qInfo() << "You provided " << trueCount << " arguments";
|
|
||||||
if (trueCount == 0) {
|
|
||||||
qInfo() << "Next time try suppling some arguments.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
qInfo() << "All arguments:";
|
|
||||||
for (size_t i = 1; i < args.size(); i++) {
|
|
||||||
qInfo() << "\t" << QString::fromStdString(args.at(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue