aheinecke@404: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik aheinecke@404: * Software engineering by Intevation GmbH aheinecke@404: * aheinecke@404: * This file is Free Software under the GNU GPL (v>=2) aheinecke@404: * and comes with ABSOLUTELY NO WARRANTY! aheinecke@404: * See LICENSE.txt for details. aheinecke@404: */ aheinecke@0: #include "mainwindow.h" andre@612: #include "processhelp.h" andre@631: #include "binverify.h" andre@631: #include "logging.h" andre@631: #include "strhelp.h" aheinecke@0: aheinecke@0: #include aheinecke@0: #include aheinecke@0: #include aheinecke@0: #include aheinecke@17: #include aheinecke@423: #include aheinecke@423: #include aheinecke@0: aheinecke@16: #ifndef VERSION aheinecke@16: #define VERSION "0.0.1" aheinecke@16: #endif aheinecke@16: aheinecke@16: #ifndef APPNAME aheinecke@407: #define APPNAME "TrustBridge" aheinecke@16: #endif aheinecke@16: aheinecke@16: #ifndef ORGANIZATION aheinecke@409: #define ORGANIZATION "BSI" aheinecke@16: #endif aheinecke@0: aheinecke@0: #ifdef Q_OS_WIN aheinecke@0: Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) aheinecke@0: #else aheinecke@0: Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) aheinecke@0: #endif aheinecke@0: aheinecke@0: int main(int argc, char **argv) aheinecke@0: { andre@631: /* First verify integrity even before calling QApplication*/ andre@631: #ifdef Q_OS_WIN andre@631: DWORD sizeNeeded = GetModuleFileNameW (NULL, NULL, 0); andre@631: wchar_t wPath[sizeNeeded + 1]; andre@631: char *utf8path = NULL; andre@631: andre@631: if (sizeNeeded == 0) { andre@631: PRINTLASTERROR ("Failed to obtain module file name"); andre@631: syslog_error_printf ("Integrity check failed."); andre@631: return -1; andre@631: } andre@631: andre@631: DWORD realSize = GetModuleFileNameW (NULL, wPath, sizeNeeded + 1); andre@631: andre@631: if (realSize != sizeNeeded) { andre@631: ERRORPRINTF ("Module name changed"); andre@631: syslog_error_printf ("Integrity check failed."); andre@631: return -1; andre@631: } andre@631: andre@631: utf8path = wchar_to_utf8 (wPath, sizeNeeded + 1); andre@631: andre@631: if (utf8path == NULL) { andre@631: ERRORPRINTF ("Failed to convert module path to utf-8"); andre@631: syslog_error_printf ("Integrity check failed."); andre@631: return -1; andre@631: } andre@631: andre@631: if (!verify_binary (utf8path, strlen(utf8path)) != VerifyValid) andre@631: { andre@631: syslog_error_printf ("Integrity check failed."); andre@631: xfree(utf8path); andre@631: #ifdef RELEASE_BUILD andre@631: return -1; andre@631: #endif andre@631: } andre@631: andre@631: xfree(utf8path); andre@631: #else andre@631: if (!verify_binary ("/proc/self/exe", 14) != VerifyValid) andre@631: { andre@631: syslog_error_printf ("Integrity check failed."); andre@631: #ifdef RELEASE_BUILD andre@631: return -1; andre@631: #endif andre@631: } andre@631: #endif andre@631: aheinecke@0: QApplication app (argc, argv); aheinecke@0: rrenkert@482: QApplication::setQuitOnLastWindowClosed(false); rrenkert@482: QApplication::setOrganizationName(QString::fromLatin1(ORGANIZATION)); rrenkert@482: QApplication::setApplicationName(QString::fromLatin1(APPNAME)); rrenkert@482: QApplication::setApplicationVersion(QString::fromLatin1(VERSION)); rrenkert@482: QSettings::setDefaultFormat(QSettings::IniFormat); rrenkert@482: rrenkert@154: QStringList arguments = QApplication::arguments(); rrenkert@154: bool trayMode = arguments.contains("--tray"); rrenkert@154: rrenkert@482: QSettings settings; rrenkert@482: settings.beginGroup("settings"); aheinecke@499: bool autoStart = settings.value("autostart", true).toBool(); rrenkert@482: settings.endGroup(); rrenkert@482: aheinecke@499: if (trayMode && !autoStart) { rrenkert@482: return 0; rrenkert@482: } rrenkert@482: andre@612: if (ProcessHelp::otherProcessesExist(APPNAME)) { andre@612: qDebug() << "Another " << APPNAME << " process is already running. Exiting."; andre@612: ProcessHelp::activateWindowForProcess(APPNAME); andre@612: return 0; andre@612: } andre@612: aheinecke@423: QTranslator translator; aheinecke@423: if (QLocale::system().name() == "C") { aheinecke@423: /* Useful for testing / development as the primary target is german */ aheinecke@423: translator.load(":/l10n/trustbridge_de_DE"); aheinecke@423: } else { aheinecke@423: translator.load(":/l10n/trustbridge_" + QLocale::system().name()); aheinecke@423: qDebug() << "Loading translations for: " << "trustbridge_" + aheinecke@423: QLocale::system().name(); aheinecke@423: } aheinecke@423: app.installTranslator(&translator); aheinecke@423: aheinecke@73: if (!QSystemTrayIcon::isSystemTrayAvailable() || aheinecke@73: !QSystemTrayIcon::supportsMessages()) { aheinecke@16: QMessageBox::critical(0, QString::fromLatin1(APPNAME), aheinecke@0: QObject::tr("Couldn't detect any system tray " aheinecke@0: "on this system. This software can only " aheinecke@0: "be used in a desktop environment.")); aheinecke@0: return 1; aheinecke@0: } aheinecke@16: aheinecke@365: MainWindow mainWin(trayMode); aheinecke@0: aheinecke@0: return app.exec(); aheinecke@0: }