diff --git a/src/core/context/contextsimulatorimpl.cpp b/src/core/context/contextsimulatorimpl.cpp index 09f9d8d2f..c14d3efed 100644 --- a/src/core/context/contextsimulatorimpl.cpp +++ b/src/core/context/contextsimulatorimpl.cpp @@ -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) diff --git a/src/misc/simulation/backgroundvalidation.cpp b/src/misc/simulation/backgroundvalidation.cpp index 9aa9a98f7..166999ef9 100644 --- a/src/misc/simulation/backgroundvalidation.cpp +++ b/src/misc/simulation/backgroundvalidation.cpp @@ -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 diff --git a/src/misc/simulation/backgroundvalidation.h b/src/misc/simulation/backgroundvalidation.h index 723627ce8..23926ba5d 100644 --- a/src/misc/simulation/backgroundvalidation.h +++ b/src/misc/simulation/backgroundvalidation.h @@ -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 @@ -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; diff --git a/src/misc/simulation/fscommon/fscommonutil.cpp b/src/misc/simulation/fscommon/fscommonutil.cpp index bd2254916..bd14ae5eb 100644 --- a/src/misc/simulation/fscommon/fscommonutil.cpp +++ b/src/misc/simulation/fscommon/fscommonutil.cpp @@ -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(simObjectPaths.begin(), simObjectPaths.end()), models, validModels, invalidModels, ignoreEmptyFileNames, stopAtFailedFiles, stopped); diff --git a/src/misc/simulation/fscommon/fsdirectories.cpp b/src/misc/simulation/fscommon/fsdirectories.cpp index 65c43acc4..9e4ca66ae 100644 --- a/src/misc/simulation/fscommon/fsdirectories.cpp +++ b/src/misc/simulation/fscommon/fsdirectories.cpp @@ -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) @@ -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() @@ -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", @@ -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, @@ -628,11 +611,6 @@ namespace swift::misc::simulation::fscommon return CFsDirectories::fsxSimObjectsPaths(CFsDirectories::findFsxConfigFiles(), true); } - QSet CFsDirectories::allMsfsSimObjectPaths() - { - return CFsDirectories::msfsSimObjectsPaths(CFsDirectories::findMsfsConfigFiles(), true); - } - QStringList CFsDirectories::findFsxConfigFiles() { const QStringList locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); @@ -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(nullptr)).info(u"MSFS config file: '%1'") - << fi.absoluteFilePath(); - } - } - } - return files; - } - QSet CFsDirectories::fsxSimObjectsPaths(const QStringList &fsxFiles, bool checked) { QSet paths; diff --git a/src/misc/simulation/fscommon/fsdirectories.h b/src/misc/simulation/fscommon/fsdirectories.h index be27ce687..c07b8f118 100644 --- a/src/misc/simulation/fscommon/fsdirectories.h +++ b/src/misc/simulation/fscommon/fsdirectories.h @@ -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(); @@ -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, @@ -129,16 +126,18 @@ namespace swift::misc::simulation::fscommon //! Get all the SimObjects paths from all config files static QSet allFsxSimObjectPaths(); + // TODO TZ //! Get all the SimObjects paths from all config files - static QSet allMsfsSimObjectPaths(); + // static QSet 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 diff --git a/src/misc/simulation/settings/simulatorsettings.cpp b/src/misc/simulation/settings/simulatorsettings.cpp index 4e26e9d53..085ea6cc0 100644 --- a/src/misc/simulation/settings/simulatorsettings.cpp +++ b/src/misc/simulation/settings/simulatorsettings.cpp @@ -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