diff --git a/src/blackmisc/project.cpp b/src/blackmisc/project.cpp index 95910565d..c58e9321a 100644 --- a/src/blackmisc/project.cpp +++ b/src/blackmisc/project.cpp @@ -35,6 +35,15 @@ namespace BlackMisc #endif } + bool CProject::isCompiledWithFs9Support() + { +#ifdef WITH_FS9 + return true; +#else + return false; +#endif + } + bool CProject::isCompiledWithFsxSupport() { #ifdef WITH_FSX diff --git a/src/blackmisc/project.h b/src/blackmisc/project.h index d5714035f..b4c77a65e 100644 --- a/src/blackmisc/project.h +++ b/src/blackmisc/project.h @@ -31,6 +31,9 @@ namespace BlackMisc //! with BlackInput? static bool isCompiledWithBlackInput(); + //! with FS9 support? + static bool isCompiledWithFs9Support(); + //! with FSX support? static bool isCompiledWithFsxSupport(); diff --git a/src/blackmisc/simulation/fscommon/fscommonutil.cpp b/src/blackmisc/simulation/fscommon/fscommonutil.cpp index c2fe26d62..0f79c562c 100644 --- a/src/blackmisc/simulation/fscommon/fscommonutil.cpp +++ b/src/blackmisc/simulation/fscommon/fscommonutil.cpp @@ -21,19 +21,26 @@ namespace BlackMisc namespace FsCommon { + using FsRegistryPathPair = QList>; + QString CFsCommonUtil::fsxDirFromRegistry() { QString fsxPath; if (CProject::isCompiledWithFsxSupport()) { - // set FSX path - QSettings fsxRegistry("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0", QSettings::NativeFormat); - fsxPath = fsxRegistry.value("AppPath").toString().trimmed(); - if (fsxPath.isEmpty()) + + FsRegistryPathPair fsxRegistryPathPairs = { - // another trial - QSettings fsxRegistry("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0", QSettings::NativeFormat); - fsxPath = fsxRegistry.value("SetupPath").toString().trimmed(); + { QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"), QStringLiteral("AppPath") }, + { QStringLiteral("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"), QStringLiteral("AppPath") } + }; + + for (const auto ®istryPair : fsxRegistryPathPairs) + { + QSettings fsxRegistry(registryPair.first, QSettings::NativeFormat); + fsxPath = fsxRegistry.value(registryPair.second).toString().trimmed(); + + if (!fsxPath.isEmpty()) break; } } return fsxPath; @@ -47,6 +54,36 @@ namespace BlackMisc return fsxPath; } + QString CFsCommonUtil::fs9DirFromRegistry() + { + QString fs9Path; + if (CProject::isCompiledWithFs9Support()) + { + FsRegistryPathPair fs9RegistryPathPairs = + { + { QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\DirectPlay\\Applications\\Microsoft Flight Simulator 2004"), QStringLiteral("AppPath") }, + { QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\DirectPlay\\Applications\\Microsoft Flight Simulator 2004"), QStringLiteral("AppPath") } + }; + + for (const auto ®istryPair : fs9RegistryPathPairs) + { + QSettings fs9Registry(registryPair.first, QSettings::NativeFormat); + fs9Path = fs9Registry.value(registryPair.second).toString().trimmed(); + + if (!fs9Path.isEmpty()) break; + } + } + return fs9Path; + } + + QString CFsCommonUtil::fs9AircraftDirFromRegistry() + { + QString fs9Path = fs9DirFromRegistry(); + if (fs9Path.isEmpty()) { return ""; } + fs9Path = QDir(fs9Path).filePath("Aircraft"); + return fs9Path; + } + } // namespace } // namespace } // namespace diff --git a/src/blackmisc/simulation/fscommon/fscommonutil.h b/src/blackmisc/simulation/fscommon/fscommonutil.h index 27e0db57b..18b9d4849 100644 --- a/src/blackmisc/simulation/fscommon/fscommonutil.h +++ b/src/blackmisc/simulation/fscommon/fscommonutil.h @@ -33,6 +33,12 @@ namespace BlackMisc //! FSX's simObject directory from registry static QString fsxSimObjectsDirFromRegistry(); + //! FS9 directory obtained from registry + static QString fs9DirFromRegistry(); + + //! FS9's aircraft directory from registry + static QString fs9AircraftDirFromRegistry(); + }; } // namespace