Skip to content

Commit

Permalink
fix: Correct path for MSFS2020 model validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tzobler authored and ltoenning committed Dec 8, 2024
1 parent 59021f9 commit 937c2aa
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 66 deletions.
7 changes: 5 additions & 2 deletions src/core/context/contextsimulatorimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ namespace swift::core::context
m_validator->startUpdating(60);
}

// For validation we need simulator directory and model directory
// this function is called at start (simulator=0) and when there is an active connection to a simulator
void CContextSimulator::setValidator(const CSimulatorInfo &simulator)
{
if (simulator.isSingleSimulator())
{
const QString simDir = m_multiSimulatorSettings.getSimulatorDirectoryOrDefault(simulator);
m_validator->setCurrentSimulator(simulator, simDir);
const QStringList modelDirList = m_multiSimulatorSettings.getModelDirectoriesOrDefault(simulator);
m_validator->setCurrentSimulator(simulator, simDir, modelDirList);
}
else { m_validator->setCurrentSimulator(CSimulatorInfo::None, {}); }
else { m_validator->setCurrentSimulator(CSimulatorInfo::None, {}, {}); }
}

CContextSimulator *CContextSimulator::registerWithDBus(CDBusServer *server)
Expand Down
4 changes: 3 additions & 1 deletion src/misc/simulation/backgroundvalidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ namespace swift::misc::simulation
m_updateTimer.setInterval(60 * 1000);
}

void CBackgroundValidation::setCurrentSimulator(const CSimulatorInfo &simulator, const QString &simDirectory)
void CBackgroundValidation::setCurrentSimulator(const CSimulatorInfo &simulator, const QString &simDirectory,
const QStringList &modelDirList)
{
QWriteLocker l(&m_lock);
m_simulator = simulator;
m_simDirectory = simDirectory;
m_modelDirList = modelDirList;
}

bool CBackgroundValidation::wasAlreadyChecked(const CSimulatorInfo &simulator) const
Expand Down
5 changes: 3 additions & 2 deletions src/misc/simulation/backgroundvalidation.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ namespace swift::misc::simulation

//! Corresponding simulator
//! \threadsafe
void setCurrentSimulator(const CSimulatorInfo &simulator, const QString &simDirectory);
void setCurrentSimulator(const CSimulatorInfo &simulator, const QString &simDirectory,
const QStringList &modelDirList);

//! Was already checked for simulator?
//! \threadsafe
Expand Down Expand Up @@ -80,7 +81,7 @@ namespace swift::misc::simulation
std::atomic_bool m_wasStopped { false }; //!< has been stopped or should be stopped
CSimulatorInfo m_simulator; //!< simulator
QString m_simDirectory; //!< corresponding sim directory

QStringList m_modelDirList; //!< corresponding modeldirectory
// last result values, mostly needed when running in the distributed swift system and we want to get the values
CAircraftModelList m_lastResultValid;
CAircraftModelList m_lastResultInvalid;
Expand Down
2 changes: 1 addition & 1 deletion src/misc/simulation/fscommon/fscommonutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ namespace swift::misc::simulation::fscommon
std::atomic_bool &stopped, const QString &simulatorDir)
{
Q_UNUSED(simulatorDir)
const QStringList simObjectPaths = CFsDirectories::msfsSimObjectsDirPlusAddOnXmlSimObjectsPaths();
const QStringList simObjectPaths = CFsDirectories::msfsSimObjectsDirPath();
return CFsCommonUtil::validateSimObjectsPath(QSet<QString>(simObjectPaths.begin(), simObjectPaths.end()),
models, validModels, invalidModels, ignoreEmptyFileNames,
stopAtFailedFiles, stopped);
Expand Down
56 changes: 6 additions & 50 deletions src/misc/simulation/fscommon/fsdirectories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace swift::misc::simulation::fscommon
return dir;
}

QString msfsDirImpl()
static QString msfsDirImpl()
{
const QStringList locations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
for (const QString &path : locations)
Expand Down Expand Up @@ -165,7 +165,7 @@ namespace swift::misc::simulation::fscommon
{
QString dir(CFsDirectories::msfsDir());
if (dir.isEmpty()) { return {}; }
return CFsDirectories::msfsSimObjectsDirFromSimDir(dir);
return CFileUtils::normalizeFilePathToQtStandard(msfsPackagesDirImpl());
}

const QString &CFsDirectories::fsxSimObjectsDir()
Expand All @@ -186,12 +186,6 @@ namespace swift::misc::simulation::fscommon
return CFileUtils::appendFilePaths(CFileUtils::normalizeFilePathToQtStandard(simDir), "SimObjects");
}

QString CFsDirectories::msfsSimObjectsDirFromSimDir(const QString &simDir)
{
if (simDir.isEmpty()) { return {}; }
return CFileUtils::appendFilePaths(CFileUtils::normalizeFilePathToQtStandard(simDir), "SimObjects");
}

const QStringList &CFsDirectories::fsxSimObjectsExcludeDirectoryPatterns()
{
static const QStringList exclude { "SimObjects/Animals", "SimObjects/Misc", "SimObjects/GroundVehicles",
Expand Down Expand Up @@ -321,22 +315,11 @@ namespace swift::misc::simulation::fscommon
return allPaths;
}

QStringList CFsDirectories::msfsSimObjectsDirPlusAddOnXmlSimObjectsPaths(const QString &simObjectsDir)
QStringList CFsDirectories::msfsSimObjectsDirPath(const QString &simObjectsDir)
{
// finding the user settings only works on P3D machine
QStringList allPaths = CFsDirectories::allMsfsSimObjectPaths().values();
const QString sod = CFileUtils::normalizeFilePathToQtStandard(
simObjectsDir.isEmpty() ? CFsDirectories::msfsSimObjectsDir() : simObjectsDir);
if (!sod.isEmpty() && !allPaths.contains(sod, Qt::CaseInsensitive))
{
// case insensitive is important here
allPaths.push_front(sod);
}

allPaths.removeAll({}); // remove all empty
allPaths.removeDuplicates();
allPaths.sort(Qt::CaseInsensitive);
return allPaths;
Q_UNUSED(simObjectsDir);
static const QStringList Path { CFsDirectories::msfsSimObjectsDir() };
return Path;
}

QStringList CFsDirectories::p3dSimObjectsDirPlusAddOnXmlSimObjectsPaths(const QString &simObjectsDir,
Expand Down Expand Up @@ -628,11 +611,6 @@ namespace swift::misc::simulation::fscommon
return CFsDirectories::fsxSimObjectsPaths(CFsDirectories::findFsxConfigFiles(), true);
}

QSet<QString> CFsDirectories::allMsfsSimObjectPaths()
{
return CFsDirectories::msfsSimObjectsPaths(CFsDirectories::findMsfsConfigFiles(), true);
}

QStringList CFsDirectories::findFsxConfigFiles()
{
const QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
Expand All @@ -654,28 +632,6 @@ namespace swift::misc::simulation::fscommon
return files;
}

QStringList CFsDirectories::findMsfsConfigFiles()
{
const QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
QStringList files;
for (const QString &path : locations)
{
// TODO this acts as a placeholder. the file msfs.cfg doesn't exist
const QString file = CFileUtils::appendFilePaths(CFileUtils::pathUp(path), "Microsoft/MSFS/msfs.cfg");
const QFileInfo fi(file);
if (fi.exists())
{
files.push_back(fi.absoluteFilePath());
if (logConfigPathReading())
{
CLogMessage(static_cast<CFsDirectories *>(nullptr)).info(u"MSFS config file: '%1'")
<< fi.absoluteFilePath();
}
}
}
return files;
}

QSet<QString> CFsDirectories::fsxSimObjectsPaths(const QStringList &fsxFiles, bool checked)
{
QSet<QString> paths;
Expand Down
11 changes: 5 additions & 6 deletions src/misc/simulation/fscommon/fsdirectories.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ namespace swift::misc::simulation::fscommon
//! FSX aircraft dir, relative to simulator directory
static QString fsxSimObjectsDirFromSimDir(const QString &simDir);

//! MSFS aircraft dir, relative to simulator directory
static QString msfsSimObjectsDirFromSimDir(const QString &simDir);

//! Exclude directories for simObjects
static const QStringList &fsxSimObjectsExcludeDirectoryPatterns();

Expand All @@ -54,7 +51,7 @@ namespace swift::misc::simulation::fscommon
static QStringList fsxSimObjectsDirPlusAddOnXmlSimObjectsPaths(const QString &simObjectsDir = "");

//! MSFS's simObject dir and the add on dirs
static QStringList msfsSimObjectsDirPlusAddOnXmlSimObjectsPaths(const QString &simObjectsDir = "");
static QStringList msfsSimObjectsDirPath(const QString &simObjectsDir = "");

//! P3D's simObject dir and the add on dirs
static QStringList p3dSimObjectsDirPlusAddOnXmlSimObjectsPaths(const QString &simObjectsDir,
Expand Down Expand Up @@ -129,16 +126,18 @@ namespace swift::misc::simulation::fscommon
//! Get all the SimObjects paths from all config files
static QSet<QString> allFsxSimObjectPaths();

// TODO TZ
//! Get all the SimObjects paths from all config files
static QSet<QString> allMsfsSimObjectPaths();
// static QSet<QString> allMsfsSimObjectPaths();

//! Find the config files (fsx.cfg)
// C:/Users/Joe Doe/AppData/Roaming/Microsoft/FSX/fsx.cfg
static QStringList findFsxConfigFiles();

// TODO TZ
//! Find the config files (fsx.cfg)
// C:/Users/Joe Doe/AppData/Roaming/Microsoft/FSX/fsx.cfg
static QStringList findMsfsConfigFiles();
// static QStringList findMsfsConfigFiles();

//! Get all the SimObjects paths from fsx.cfg
// SimObjectPaths.0=SimObjects\Airplanes
Expand Down
8 changes: 4 additions & 4 deletions src/misc/simulation/settings/simulatorsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ namespace swift::misc::simulation::settings
return s.getSimulatorDirectoryOrDefault();
}

QStringList CMultiSimulatorSettings::getModelDirectoriesIfNotDefault(const CSimulatorInfo &simulator) const
QStringList CMultiSimulatorSettings::getModelDirectoriesOrDefault(const CSimulatorInfo &simulator) const
{
const CSpecializedSimulatorSettings s = this->getSpecializedSettings(simulator);
return s.getModelDirectoriesIfNotDefault();
return s.getModelDirectoriesOrDefault();
}

QStringList CMultiSimulatorSettings::getModelDirectoriesOrDefault(const CSimulatorInfo &simulator) const
QStringList CMultiSimulatorSettings::getModelDirectoriesIfNotDefault(const CSimulatorInfo &simulator) const
{
const CSpecializedSimulatorSettings s = this->getSpecializedSettings(simulator);
return s.getModelDirectoriesOrDefault();
return s.getModelDirectoriesIfNotDefault();
}

QString CMultiSimulatorSettings::getFirstModelDirectoryOrDefault(const CSimulatorInfo &simulator) const
Expand Down

0 comments on commit 937c2aa

Please sign in to comment.