Skip to content

Commit

Permalink
Adapted to MSFS 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
albar965 committed Dec 25, 2024
1 parent 5db44c8 commit 6f8e124
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
10 changes: 10 additions & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ const QLatin1String STARTUP_COMMAND_REPLAY_SPEED("replay-speed");
const QLatin1String STARTUP_COMMAND_WRITE_WHAZZUP("write-whazzup");
const QLatin1String STARTUP_COMMAND_WRITE_WHAZZUP_SPEED("write-whazzup-speed");
const QLatin1String STARTUP_COMMAND_REPLAY_GUI("replay-gui");

// "master" or "release/1.4" VERSION_NUMBER_TODO
const static QString HELP_BRANCH = "release/3.0";

#if defined(WINARCH64)
const QLatin1String SIMCONNECT_DLL_NAME("SimConnect_msfs_2020.dll");
#else
const QLatin1String SIMCONNECT_DLL_NAME("SimConnect.dll");
#endif

} // namespace lnc

#endif // LITTLENAVCONNECT_CONSTANTS_H
32 changes: 20 additions & 12 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "util/properties.h"
#include "util/signalhandler.h"
#include "util/version.h"
#include "win/activationcontext.h"

#include <QCloseEvent>
#include <QCommandLineParser>
Expand All @@ -47,6 +48,7 @@
#include <QSystemTrayIcon>
#include <QTextDocumentFragment>
#include <QTimer>
#include <QStringBuilder>

using atools::settings::Settings;
using atools::fs::sc::SimConnectData;
Expand All @@ -56,11 +58,8 @@ using atools::gui::Application;

atools::gui::DataExchange *MainWindow::dataExchange = nullptr;

// "master" or "release/1.4" VERSION_NUMBER_TODO
const static QString HELP_BRANCH = "release/3.0";

/* Important: keep slash at the end. Otherwise browser might not display the page properly */
const static QString HELP_ONLINE_URL("https://www.littlenavmap.org/manuals/littlenavconnect/" + HELP_BRANCH + "/${LANG}/");
const static QString HELP_ONLINE_URL("https://www.littlenavmap.org/manuals/littlenavconnect/" + lnc::HELP_BRANCH + "/${LANG}/");

const static QString HELP_OFFLINE_FILE("help/little-navconnect-user-manual-${LANG}.pdf");

Expand All @@ -69,6 +68,8 @@ MainWindow::MainWindow()
{
qDebug() << Q_FUNC_INFO;

activationContext = new atools::win::ActivationContext;

aboutMessage =
QObject::tr("<p style='white-space:pre'>is the Flight Simulator Network agent for Little Navmap.</p>"
"<p>This software is licensed under "
Expand Down Expand Up @@ -255,7 +256,13 @@ void MainWindow::deInit()
ATOOLS_DELETE_LATER_LOG(dataReaderThread);
}

ATOOLS_DELETE_LOG(fsxConnectHandler);
if(simConnectHandler != nullptr)
{
simConnectHandler->close();
simConnectHandler->releaseSimConnect();
}

ATOOLS_DELETE_LOG(simConnectHandler);
ATOOLS_DELETE_LOG(xpConnectHandler);

qDebug() << Q_FUNC_INFO << "reset logging";
Expand All @@ -264,6 +271,7 @@ void MainWindow::deInit()
ATOOLS_DELETE_LOG(helpHandler);
ATOOLS_DELETE_LOG(simulatorActionGroup);
ATOOLS_DELETE_LOG(ui);
ATOOLS_DELETE_LOG(activationContext);

#if defined(Q_OS_LINUX)
// Remove signal handler
Expand Down Expand Up @@ -329,7 +337,7 @@ void MainWindow::showOfflineHelp()
atools::fs::sc::ConnectHandler *MainWindow::handlerForSelection()
{
if(ui->actionConnectFsx->isChecked())
return fsxConnectHandler;
return simConnectHandler;
else
return xpConnectHandler;
}
Expand Down Expand Up @@ -608,9 +616,9 @@ void MainWindow::mainWindowShownDelayed()
<< tr("Data Version %1. Reply Version %2.").arg(SimConnectData::getDataVersion()).arg(SimConnectReply::getReplyVersion());

// Build the handler classes which are an abstraction to SimConnect and the Little Xpconnect shared memory
fsxConnectHandler = new atools::fs::sc::SimConnectHandler(verbose);
fsxConnectHandler->loadSimConnect(QApplication::applicationDirPath() +
atools::SEP + "simconnect" + atools::SEP + "simconnect.manifest");
simConnectHandler = new atools::fs::sc::SimConnectHandler(verbose);

simConnectHandler->loadSimConnect(activationContext, lnc::SIMCONNECT_DLL_NAME);
xpConnectHandler = new atools::fs::sc::XpConnectHandler();

#ifdef Q_OS_WIN32
Expand All @@ -619,15 +627,15 @@ void MainWindow::mainWindowShownDelayed()

// Check the first time if SimConnect is available - if yes use FSX settings
// Otherwise fall back to stored value or X-Plane
fsx = settings.getAndStoreValue(lnc::SETTINGS_OPTIONS_SIMULATOR_FSX, fsxConnectHandler->isLoaded()).toBool();
fsx = settings.getAndStoreValue(lnc::SETTINGS_OPTIONS_SIMULATOR_FSX, simConnectHandler->isLoaded()).toBool();

if(!fsxConnectHandler->isLoaded())
if(!simConnectHandler->isLoaded())
// No SimConnect switch to X-Plane
fsx = false;

qDebug() << "FSX status" << fsx;

if(fsxConnectHandler->isLoaded())
if(simConnectHandler->isLoaded())
{
ui->toolBar->insertAction(ui->actionOptions, ui->actionConnectFsx);
ui->toolBar->insertAction(ui->actionOptions, ui->actionConnectXplane);
Expand Down
8 changes: 7 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class MainWindow;

namespace atools {

namespace win {
class ActivationContext;
}

namespace util {
class Properties;
}
Expand Down Expand Up @@ -148,11 +152,13 @@ class MainWindow :

// Runs in background and fetches data from simulator - signals are sent to NavServerWorker threads
atools::fs::sc::DataReaderThread *dataReaderThread = nullptr;
atools::fs::sc::SimConnectHandler *fsxConnectHandler = nullptr;
atools::fs::sc::SimConnectHandler *simConnectHandler = nullptr;
atools::fs::sc::XpConnectHandler *xpConnectHandler = nullptr;
QActionGroup *simulatorActionGroup = nullptr;
atools::fs::sc::ConnectHandler *handlerForSelection();

atools::win::ActivationContext *activationContext = nullptr;

atools::gui::HelpHandler *helpHandler = nullptr;
bool firstStart = true; // Used to emit the first windowShown signal
bool verbose = false;
Expand Down

0 comments on commit 6f8e124

Please sign in to comment.