mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-12 15:25:34 +08:00
fix: search model directory adapted for Steam edition
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QStringBuilder>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
#include "misc/fileutils.h"
|
#include "misc/fileutils.h"
|
||||||
#include "misc/logmessage.h"
|
#include "misc/logmessage.h"
|
||||||
#include "misc/stringutils.h"
|
#include "misc/stringutils.h"
|
||||||
|
#include "misc/swiftdirectories.h"
|
||||||
|
|
||||||
using namespace swift::config;
|
using namespace swift::config;
|
||||||
|
|
||||||
@@ -93,6 +95,7 @@ namespace swift::misc::simulation::fscommon
|
|||||||
|
|
||||||
static QString msfsDirImpl()
|
static QString msfsDirImpl()
|
||||||
{
|
{
|
||||||
|
// first we look for a standard installation
|
||||||
const QStringList locations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
const QStringList locations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
||||||
for (const QString &path : locations)
|
for (const QString &path : locations)
|
||||||
{
|
{
|
||||||
@@ -102,6 +105,17 @@ namespace swift::misc::simulation::fscommon
|
|||||||
if (!d.exists()) { continue; }
|
if (!d.exists()) { continue; }
|
||||||
return msfsPackage;
|
return msfsPackage;
|
||||||
}
|
}
|
||||||
|
// then we look for Steam-Edition
|
||||||
|
for (QString path : locations)
|
||||||
|
{
|
||||||
|
path.replace("Local", "Roaming");
|
||||||
|
const QString msfsPackage =
|
||||||
|
CFileUtils::appendFilePaths(CFileUtils::appendFilePaths(path, "Microsoft Flight Simulator"), "");
|
||||||
|
const QString fileName = CFileUtils::appendFilePaths(msfsPackage, "UserCfg.opt");
|
||||||
|
const QFileInfo fi(fileName);
|
||||||
|
if (!fi.exists()) { continue; }
|
||||||
|
return msfsPackage;
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,10 +127,22 @@ namespace swift::misc::simulation::fscommon
|
|||||||
|
|
||||||
QString msfsPackagesDirImpl()
|
QString msfsPackagesDirImpl()
|
||||||
{
|
{
|
||||||
|
QString userCfg = "";
|
||||||
|
|
||||||
QString msfsDirectory(CFsDirectories::msfsDir());
|
QString msfsDirectory(CFsDirectories::msfsDir());
|
||||||
const QString userCfg =
|
|
||||||
CFileUtils::appendFilePaths(CFileUtils::appendFilePaths(msfsDirectory, "LocalCache"), "UserCfg.opt");
|
// for Steam edition
|
||||||
QFile file(userCfg);
|
if (msfsDirectory.contains("Roaming", Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
userCfg = CFileUtils::appendFilePaths(msfsDirectory, "UserCfg.opt");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
userCfg =
|
||||||
|
CFileUtils::appendFilePaths(CFileUtils::appendFilePaths(msfsDirectory, "LocalCache"), "UserCfg.opt");
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile file(CFileUtils::normalizeFilePathToQtStandard(userCfg));
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return {}; }
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return {}; }
|
||||||
|
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
@@ -125,8 +151,10 @@ namespace swift::misc::simulation::fscommon
|
|||||||
QString line = in.readLine();
|
QString line = in.readLine();
|
||||||
if (line.contains("InstalledPackagesPath"))
|
if (line.contains("InstalledPackagesPath"))
|
||||||
{
|
{
|
||||||
QStringList split = line.split(" ");
|
// change the split separator because of path names with multiple spaces in Steamedition
|
||||||
if (split.size() != 2) { return {}; }
|
QStringList split = line.split("\"");
|
||||||
|
// we have 2 quotation marks in the line so 3 parts
|
||||||
|
if (split.size() != 3) { return {}; }
|
||||||
QString packagePath = split[1].remove("\"");
|
QString packagePath = split[1].remove("\"");
|
||||||
const QDir dir(packagePath);
|
const QDir dir(packagePath);
|
||||||
if (dir.exists()) { return packagePath; }
|
if (dir.exists()) { return packagePath; }
|
||||||
@@ -141,6 +169,20 @@ namespace swift::misc::simulation::fscommon
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QString msfs2024DirImpl()
|
||||||
|
{
|
||||||
|
const QStringList locations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
||||||
|
for (const QString &path : locations)
|
||||||
|
{
|
||||||
|
const QString msfs2024Package = CFileUtils::appendFilePaths(CFileUtils::appendFilePaths(path, "Packages"),
|
||||||
|
"Microsoft.Limitless_8wekyb3d8bbwe");
|
||||||
|
const QDir d(msfs2024Package);
|
||||||
|
if (!d.exists()) { continue; }
|
||||||
|
return msfs2024Package;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
QString fsxSimObjectsDirFromRegistryImpl()
|
QString fsxSimObjectsDirFromRegistryImpl()
|
||||||
{
|
{
|
||||||
const QString fsxPath = CFileUtils::normalizeFilePathToQtStandard(CFsDirectories::fsxDirFromRegistry());
|
const QString fsxPath = CFileUtils::normalizeFilePathToQtStandard(CFsDirectories::fsxDirFromRegistry());
|
||||||
|
|||||||
Reference in New Issue
Block a user