Improved MS registry reading

* also read if compiled without support for this simulator (makes sense for tools/mapping)
* check if directory exists
This commit is contained in:
Klaus Basan
2019-07-16 13:45:32 +02:00
committed by Mat Sutcliffe
parent 3835c9b0f8
commit 3e6c4f2ef1

View File

@@ -47,14 +47,12 @@ namespace BlackMisc
QString fsxDirFromRegistryImpl() QString fsxDirFromRegistryImpl()
{ {
QString fsxPath; QString fsxPath;
if (CBuildConfig::isCompiledWithFsxSupport())
{
const FsRegistryPathPair fsxRegistryPathPairs = const FsRegistryPathPair fsxRegistryPathPairs =
{ {
{ QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"), QStringLiteral("AppPath") }, { QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"), QStringLiteral("AppPath") },
{ QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft Games\\Flight Simulator - Steam Edition\\10.0"), QStringLiteral("AppPath") }, { QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft Games\\Flight Simulator - Steam Edition\\10.0"), QStringLiteral("AppPath") },
{ QStringLiteral("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"), QStringLiteral("SetupPath") }, { QStringLiteral("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"), QStringLiteral("SetupPath") },
{ QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft Games\\Flight simulator\\10.0"), QStringLiteral("SetupPath") } { QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"), QStringLiteral("SetupPath") }
}; };
for (const auto &registryPair : fsxRegistryPathPairs) for (const auto &registryPair : fsxRegistryPathPairs)
@@ -62,8 +60,13 @@ namespace BlackMisc
const QSettings fsxRegistry(registryPair.first, QSettings::NativeFormat); const QSettings fsxRegistry(registryPair.first, QSettings::NativeFormat);
fsxPath = fsxRegistry.value(registryPair.second).toString().trimmed(); fsxPath = fsxRegistry.value(registryPair.second).toString().trimmed();
if (!fsxPath.isEmpty()) break; if (fsxPath.isEmpty()) { continue; }
} fsxPath = CFileUtils::normalizeFilePathToQtStandard(fsxPath);
// if path does NOT exists we continue to search, maybe another one does
const QDir dir(fsxPath);
if (dir.exists()) { break; }
fsxPath.clear();
} }
return CFileUtils::normalizeFilePathToQtStandard(fsxPath); return CFileUtils::normalizeFilePathToQtStandard(fsxPath);
} }
@@ -144,8 +147,6 @@ namespace BlackMisc
QString p3dDirFromRegistryImpl() QString p3dDirFromRegistryImpl()
{ {
QString p3dPath; QString p3dPath;
if (CBuildConfig::isCompiledWithP3DSupport())
{
FsRegistryPathPair p3dRegistryPathPairs = FsRegistryPathPair p3dRegistryPathPairs =
{ {
{ QStringLiteral("HKEY_CURRENT_USER\\Software\\Lockheed Martin\\Prepar3d v4"), QStringLiteral("AppPath") }, { QStringLiteral("HKEY_CURRENT_USER\\Software\\Lockheed Martin\\Prepar3d v4"), QStringLiteral("AppPath") },
@@ -158,8 +159,13 @@ namespace BlackMisc
const QSettings p3dRegistry(registryPair.first, QSettings::NativeFormat); const QSettings p3dRegistry(registryPair.first, QSettings::NativeFormat);
p3dPath = p3dRegistry.value(registryPair.second).toString().trimmed(); p3dPath = p3dRegistry.value(registryPair.second).toString().trimmed();
if (!p3dPath.isEmpty()) break; if (p3dPath.isEmpty()) { continue; }
} p3dPath = CFileUtils::normalizeFilePathToQtStandard(p3dPath);
// if path does NOT exists we continue to search, maybe another one does
const QDir dir(p3dPath);
if (dir.exists()) { break; }
p3dPath.clear();
} }
return p3dPath; return p3dPath;
} }
@@ -278,8 +284,6 @@ namespace BlackMisc
QString fs9DirFromRegistryImpl() QString fs9DirFromRegistryImpl()
{ {
QString fs9Path; QString fs9Path;
if (CBuildConfig::isCompiledWithFs9Support())
{
FsRegistryPathPair fs9RegistryPathPairs = FsRegistryPathPair fs9RegistryPathPairs =
{ {
{ QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\DirectPlay\\Applications\\Microsoft Flight Simulator 2004"), QStringLiteral("AppPath") }, { QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\DirectPlay\\Applications\\Microsoft Flight Simulator 2004"), QStringLiteral("AppPath") },
@@ -291,8 +295,13 @@ namespace BlackMisc
QSettings fs9Registry(registryPair.first, QSettings::NativeFormat); QSettings fs9Registry(registryPair.first, QSettings::NativeFormat);
fs9Path = fs9Registry.value(registryPair.second).toString().trimmed(); fs9Path = fs9Registry.value(registryPair.second).toString().trimmed();
if (!fs9Path.isEmpty()) break; if (fs9Path.isEmpty()) { continue; }
} fs9Path = CFileUtils::normalizeFilePathToQtStandard(fs9Path);
// if path does NOT exists we continue to search, maybe another one does
const QDir dir(fs9Path);
if (dir.exists()) { break; }
fs9Path.clear();
} }
return fs9Path; return fs9Path;
} }