refs #409 Read FS9 installation directory from registry

This commit is contained in:
Roland Winklmeier
2015-05-07 02:18:14 +02:00
parent 2300895176
commit f27d003f61
4 changed files with 62 additions and 7 deletions

View File

@@ -21,19 +21,26 @@ namespace BlackMisc
namespace FsCommon
{
using FsRegistryPathPair = QList<QPair<QString, QString>>;
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 &registryPair : 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 &registryPair : 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

View File

@@ -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