mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
Ref T689 Add validation that XP model directories are within the XP sim directory.
This commit is contained in:
@@ -525,6 +525,17 @@ namespace BlackMisc
|
|||||||
return d1.absolutePath() == d2.absolutePath();
|
return d1.absolutePath() == d2.absolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CDirectoryUtils::isSubDirectoryOf(const QString &dir1, const QString &dir2)
|
||||||
|
{
|
||||||
|
QDir d1(dir1);
|
||||||
|
const QDir d2(dir2);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (d1 == d2) { return true; }
|
||||||
|
} while (d1.cdUp());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QSet<QString> CDirectoryUtils::fileNamesToQSet(const QFileInfoList &fileInfoList)
|
QSet<QString> CDirectoryUtils::fileNamesToQSet(const QFileInfoList &fileInfoList)
|
||||||
{
|
{
|
||||||
QSet<QString> sl;
|
QSet<QString> sl;
|
||||||
|
|||||||
@@ -184,6 +184,9 @@ namespace BlackMisc
|
|||||||
//! Same existing directories
|
//! Same existing directories
|
||||||
static bool isSameExistingDirectory(const QString &dir1, const QString &dir2);
|
static bool isSameExistingDirectory(const QString &dir1, const QString &dir2);
|
||||||
|
|
||||||
|
//! Is dir1 a subdirectory (possibly nested) of dir2 or the same directory
|
||||||
|
static bool isSubDirectoryOf(const QString &dir1, const QString &dir2);
|
||||||
|
|
||||||
//! Result of directory comparison
|
//! Result of directory comparison
|
||||||
struct DirComparison
|
struct DirComparison
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
#include "blackmisc/propertyindex.h"
|
#include "blackmisc/propertyindex.h"
|
||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@@ -385,6 +386,22 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! \copydoc BlackMisc::TSettingTrait::humanReadable
|
//! \copydoc BlackMisc::TSettingTrait::humanReadable
|
||||||
static const QString &humanReadable() { static const QString name("XPlane settings"); return name; }
|
static const QString &humanReadable() { static const QString name("XPlane settings"); return name; }
|
||||||
|
|
||||||
|
//! \copydoc BlackMisc::TSettingTrait::isValid
|
||||||
|
static bool isValid(const CSimulatorSettings &value, QString &reason)
|
||||||
|
{
|
||||||
|
const QString simDir = value.hasSimulatorDirectory() ? value.getSimulatorDirectory()
|
||||||
|
: CSpecializedSimulatorSettings::defaultSimulatorDirectory(CSimulatorInfo::XPLANE);
|
||||||
|
for (const QString &modelDir : value.getModelDirectories())
|
||||||
|
{
|
||||||
|
if (!CDirectoryUtils::isSubDirectoryOf(modelDir, simDir))
|
||||||
|
{
|
||||||
|
reason = QStringLiteral("Model directory must be within the simulator directory structure");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Trait for simulator settings
|
//! Trait for simulator settings
|
||||||
|
|||||||
@@ -571,7 +571,14 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
Q_ASSERT(package.s.endsWith('/'));
|
Q_ASSERT(package.s.endsWith('/'));
|
||||||
package.s.chop(1);
|
package.s.chop(1);
|
||||||
m_trafficProxy->loadPlanesPackage(package.s);
|
if (CDirectoryUtils::isSubDirectoryOf(package.s, getSimulatorInternals().getSimulatorInstallationDirectory()))
|
||||||
|
{
|
||||||
|
m_trafficProxy->loadPlanesPackage(package.s);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CLogMessage(this).validationError(u"CSL package '%1' can not be loaded as it is outside the X-Plane installation directory") << package.s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user