Skip to content

Commit

Permalink
Adapted database writers for MSFS 2024 changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
albar965 committed Dec 23, 2024
1 parent f41e121 commit 7323944
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 56 deletions.
114 changes: 66 additions & 48 deletions src/fs/db/datawriter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright 2015-2023 Alexander Barthel [email protected]
* Copyright 2015-2024 Alexander Barthel [email protected]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -208,6 +208,16 @@ QString DataWriter::getSurface(const QUuid& key)
return QString();
}

int DataWriter::getNextSceneryId() const
{
return sceneryAreaWriter->getNextId();
}

int DataWriter::getNextFileId() const
{
return bglFileWriter->getNextId();
}

QString DataWriter::getLanguage(const QString& key)
{
if(languageIndex != nullptr)
Expand Down Expand Up @@ -241,7 +251,10 @@ void DataWriter::writeSceneryArea(const SceneryArea& area)
for(int i = 0; i < filepaths.size(); i++)
{
progressHandler->setNumFiles(numFiles);
progressHandler->setNumAirports(airportIdents.size());

// Do not reset airport counter which was read before from MSFS 2024 SimConnect
if(options.getSimulatorType() != FsPaths::MSFS_2024)
progressHandler->setNumAirports(airportIdents.size());
progressHandler->setNumNamelists(numNamelists);
progressHandler->setNumVors(numVors);
progressHandler->setNumIls(numIls);
Expand Down Expand Up @@ -367,67 +380,72 @@ void DataWriter::writeSceneryArea(const SceneryArea& area)
}
}

void DataWriter::readMagDeclBgl(const QString& fileScenery)
void DataWriter::readMagDeclBgl(const QString& fileScenery, bool forceWmm)
{
QString fileSettings = atools::buildPath({atools::settings::Settings::getPath(), "magdec.bgl"});
QString fileApp = atools::buildPath({QCoreApplication::applicationDirPath(), "magdec", "magdec.bgl"});

QString file;
if(QFileInfo::exists(fileScenery) && QFileInfo(fileScenery).isFile())
// Check if there is a file in the simulator scenery directory
file = fileScenery;
else if(QFileInfo::exists(fileSettings) && QFileInfo(fileSettings).isFile())
// Check if there is a file in the settings directory
file = fileSettings;
else if(QFileInfo::exists(fileApp) && QFileInfo(fileApp).isFile())
// Check if there is a file in the application directory
file = fileApp;

qInfo() << "Reading" << file;

bool loaded = false;

if(!file.isEmpty())
if(!forceWmm)
{
try
{
magDecReader->readFromBgl(file);
}
catch(atools::Exception& e)
// Try to read from various places =================================================
QString fileSettings = atools::buildPath({atools::settings::Settings::getPath(), "magdec.bgl"});
QString fileApp = atools::buildPath({QCoreApplication::applicationDirPath(), "magdec", "magdec.bgl"});

if(QFileInfo::exists(fileScenery) && QFileInfo(fileScenery).isFile())
// Check if there is a file in the simulator scenery directory
file = fileScenery;
else if(QFileInfo::exists(fileSettings) && QFileInfo(fileSettings).isFile())
// Check if there is a file in the settings directory
file = fileSettings;
else if(QFileInfo::exists(fileApp) && QFileInfo(fileApp).isFile())
// Check if there is a file in the application directory
file = fileApp;

qInfo() << "Reading" << file;

if(!file.isEmpty())
{
qCritical() << "Caught exception reading" << file << ":" << e.what();
progressHandler->reportError();
if(sceneryErrors != nullptr)
sceneryErrors->fileErrors.append({file, QString(e.what()), 0});
}
catch(...)
{
qCritical() << "Caught unknown exception reading" << file;
progressHandler->reportError();
if(sceneryErrors != nullptr)
sceneryErrors->fileErrors.append({file, tr("Cannot read file. Falling back to world magnetic model."), 0});
}
try
{
magDecReader->readFromBgl(file);
}
catch(atools::Exception& e)
{
qCritical() << "Caught exception reading" << file << ":" << e.what();
progressHandler->reportError();
if(sceneryErrors != nullptr)
sceneryErrors->fileErrors.append({file, QString(e.what()), 0});
}
catch(...)
{
qCritical() << "Caught unknown exception reading" << file;
progressHandler->reportError();
if(sceneryErrors != nullptr)
sceneryErrors->fileErrors.append({file, tr("Cannot read file. Falling back to world magnetic model."), 0});
}

if(magDecReader->isValid())
{
magDecReader->writeToTable(db);
db.commit();
loaded = true;
if(magDecReader->isValid())
{
magDecReader->writeToTable(db);
db.commit();
loaded = true;
}
else
{
progressHandler->reportError();
if(sceneryErrors != nullptr)
sceneryErrors->fileErrors.append({file, tr("File not valid. Falling back to world magnetic model."), 0});
}
}
else
{
progressHandler->reportError();
if(sceneryErrors != nullptr)
sceneryErrors->fileErrors.append({file, tr("File not valid. Falling back to world magnetic model."), 0});
sceneryErrors->fileErrors.append({"magdec.bgl", tr("File not found. Falling back to world magnetic model."), 0});
}
}
else
{
progressHandler->reportError();
if(sceneryErrors != nullptr)
sceneryErrors->fileErrors.append({"magdec.bgl", tr("File not found. Falling back to world magnetic model."), 0});
}

// Eiter no file found above or reading of WMM forced ==========================================
if(!loaded)
{
magDecReader->readFromWmm();
Expand Down
8 changes: 6 additions & 2 deletions src/fs/db/datawriter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright 2015-2020 Alexander Barthel [email protected]
* Copyright 2015-2024 Alexander Barthel [email protected]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -97,7 +97,7 @@ class DataWriter
*/
void writeSceneryArea(const atools::fs::scenery::SceneryArea& area);

void readMagDeclBgl(const QString& fileScenery);
void readMagDeclBgl(const QString& fileScenery, bool forceWmm = false);

/*
* Log written record number, etc. to the log/console.
Expand Down Expand Up @@ -290,6 +290,10 @@ class DataWriter
return db;
}

/* Get next ids from writers */
int getNextSceneryId() const;
int getNextFileId() const;

private:
int numFiles = 0, numNamelists = 0, numVors = 0, numIls = 0,
numNdbs = 0, numMarker = 0, numWaypoints = 0, numBoundaries = 0, numObjectsWritten = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/fs/db/nav/ilswriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ void IlsWriter::writeObject(const Ils *type)
QString locName = loc->getRunwayName().trimmed();

// Try to extract the runway number from the name if invalid ===========================
if(getOptions().getSimulatorType() == atools::fs::FsPaths::MSFS && (locName.isEmpty() || locName == "0" || locName == "00"))
if((getOptions().getSimulatorType() == atools::fs::FsPaths::MSFS ||
getOptions().getSimulatorType() == atools::fs::FsPaths::MSFS_2024) &&
(locName.isEmpty() || locName == "0" || locName == "00"))
{
// "IGS RWY 13", "ILS 01", "ILS 32", "ILS 32R", "ILS CAT III RWY 05R", "ILS CAT III RWY 23", "ILS RW01", "ILS RW01C",
// "ILS RW01L", "ILS RW01R", "ILS RW36L", "ILS RW36R", "ILS RWY 05", "ILS RWY 05L", "ILS RWY 15", "ILS RWY 31", "ILS04",
Expand Down
17 changes: 12 additions & 5 deletions src/fs/db/nav/vorwriter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright 2015-2020 Alexander Barthel [email protected]
* Copyright 2015-2024 Alexander Barthel [email protected]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -16,12 +16,13 @@
*****************************************************************************/

#include "fs/db/nav/vorwriter.h"

#include "atools.h"
#include "fs/bgl/nav/dme.h"
#include "fs/db/meta/bglfilewriter.h"
#include "fs/db/datawriter.h"
#include "fs/bgl/util.h"
#include "fs/db/meta/bglfilewriter.h"
#include "fs/util/tacanfrequencies.h"
#include "geo/calculations.h"
#include "atools.h"

namespace atools {
namespace fs {
Expand Down Expand Up @@ -49,12 +50,18 @@ void VorWriter::writeObject(const Vor *type)
bind(":ident", type->getIdent());
bind(":name", type->getName());
bind(":region", type->getRegion());
bind(":type", bgl::IlsVor::ilsVorTypeToStr(type->getType()));

if(type->isTacan()) // Only MFSF 2024 - P3D uses TacanWriter
bind(":type", "TC");
else
bind(":type", bgl::IlsVor::ilsVorTypeToStr(type->getType()));

bind(":airport_ident", type->getAirportIdent());
bindNullInt(":airport_id");

bind(":frequency", type->getFrequency());
if(type->isTacan()) // Only MFSF 2024
bind(":channel", util::tacanChannelForFrequency(type->getFrequency() / 10));
bind(":range", roundToInt(meterToNm(type->getRange())));

if(type->isDmeOnly())
Expand Down
8 changes: 8 additions & 0 deletions src/fs/db/nav/waypointwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ void WaypointWriter::writeObject(const Waypoint *type)
return;
}

if(type->getRegion().size() == 1)
{
// MSFS 2024 sepciality - a lot of duplicate waypoints at the same position having an invalid region
qWarning() << Q_FUNC_INFO << "Found waypoint" << type->getIdent() << "with invalid region" << type->getRegion() << "in file"
<< getDataWriter().getBglFileWriter()->getCurrentFilepath();
return;
}

QString waypointType = bgl::Waypoint::waypointTypeToStr(type->getType());
if(waypointType.isEmpty())
{
Expand Down

0 comments on commit 7323944

Please sign in to comment.