// last time modified by Arvo ES1JA on 20200127 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if QT_VERSION >= 0x050200 #include #include #endif #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) #include #endif #include "JTDXMessageBox.hpp" #include "revision_utils.hpp" #include "MetaDataRegistry.hpp" #include "SettingsGroup.hpp" #include "TraceFile.hpp" #include "mainwindow.h" #include "commons.h" #include "lib/init_random_seed.h" namespace { struct RNGSetup { RNGSetup () { // one time seed of pseudo RNGs from current time #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) QRandomGenerator(); #else auto seed = QDateTime::currentMSecsSinceEpoch (); qsrand (seed); // this is good for rand() as well #endif } } seeding; // We can't use the GUI after QApplication::exit() is called so // uncaught exceptions can get lost on Windows systems where there // is no console terminal, so here we override // QApplication::notify() and wrap the base class call with a try // block to catch and display exceptions in a message box. class ExceptionCatchingApplication final : public QApplication { public: explicit ExceptionCatchingApplication (int& argc, char * * argv) : QApplication {argc, argv} { } bool notify (QObject * receiver, QEvent * e) override { try { return QApplication::notify (receiver, e); } catch (std::exception const& e) { JTDXMessageBox::critical_message (nullptr, "", translate ("main", "Fatal error"), e.what ()); throw; } catch (...) { JTDXMessageBox::critical_message (nullptr, "", translate ("main", "Unexpected fatal error")); throw; } } }; } int main(int argc, char *argv[]) { #if defined(Q_OS_WIN) if (AttachConsole(ATTACH_PARENT_PROCESS)) { freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); } #endif bool has_style = true; int result = 0; for (auto i = 0; i < argc; i++) {if (std::string(argv[i]).find("-style") != std::string::npos && std::string(argv[i]).find("-stylesheet") == std::string::npos) has_style = false;} init_random_seed (); register_types (); // make the Qt magic happen // Multiple instances: QSharedMemory mem_jtdxjt9; auto const env = QProcessEnvironment::systemEnvironment (); ExceptionCatchingApplication a(argc, argv); if (has_style) a.setStyle("Fusion"); try { setlocale (LC_NUMERIC, "C"); // ensure number forms are in // consistent format, do this after // instantiating QApplication so // that GUI has correct l18n // Override programs executable basename as application name. a.setApplicationName ("JTDX"); a.setApplicationVersion (version ()); if (version().replace("_32A","").indexOf("_") > 1) { #include auto expire_date = QLocale(QLocale::English).toDate(QString(__DATE__).replace(" "," "),"MMM d yyyy").addMonths(3); if (QDate().currentDate() > expire_date) { JTDXMessageBox::critical_message (nullptr, a.applicationName(), "Release candidate expired on " + expire_date.toString("dd.MM.yyyy")); return -1; } else if (QDate().currentDate().addDays(5) > expire_date) { JTDXMessageBox::information_message (nullptr, a.applicationName(), "Release candidate will expire on " + expire_date.toString("dd.MM.yyyy")); } } bool multiple {false}; #if QT_VERSION >= 0x050200 QCommandLineParser parser; parser.setApplicationDescription ("\nFT8,JT65A,JT9 & T10 Weak Signal Communications Program."); auto help_option = parser.addHelpOption (); auto version_option = parser.addVersionOption (); // support for multiple instances running from a single installation QCommandLineOption style_option (QString {"style"} , a.translate ("main", "