mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 12:35:43 +08:00
Minor performance improvement of subdir check
* follow T689 * no need to always get and init simulator directory as it will not change
This commit is contained in:
@@ -527,12 +527,21 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CDirectoryUtils::isSubDirectoryOf(const QString &dir1, const QString &dir2)
|
bool CDirectoryUtils::isSubDirectoryOf(const QString &dir1, const QString &dir2)
|
||||||
{
|
{
|
||||||
QDir d1(dir1);
|
if (dir1.isEmpty() || dir2.isEmpty()) { return false; }
|
||||||
const QDir d2(dir2);
|
const QDir d2(dir2);
|
||||||
|
return CDirectoryUtils::isSubDirectoryOf(dir1, d2);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CDirectoryUtils::isSubDirectoryOf(const QString &dir1, const QDir &dir2)
|
||||||
|
{
|
||||||
|
QDir d1(dir1);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (d1 == d2) { return true; }
|
if (d1 == dir2) { return true; }
|
||||||
} while (d1.cdUp());
|
}
|
||||||
|
while (d1.cdUp());
|
||||||
|
|
||||||
|
// not found
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,8 +185,13 @@ namespace BlackMisc
|
|||||||
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
|
//! Is dir1 a subdirectory (possibly nested) of dir2 or the same directory
|
||||||
|
//! \remark testing on real directory structure
|
||||||
static bool isSubDirectoryOf(const QString &dir1, const QString &dir2);
|
static bool isSubDirectoryOf(const QString &dir1, const QString &dir2);
|
||||||
|
|
||||||
|
//! Is dir1 a subdirectory (possibly nested) of dir2 or the same directory
|
||||||
|
//! \remark testing on real directory structure
|
||||||
|
static bool isSubDirectoryOf(const QString &dir1, const QDir &dir2);
|
||||||
|
|
||||||
//! Result of directory comparison
|
//! Result of directory comparison
|
||||||
struct DirComparison
|
struct DirComparison
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -567,11 +567,16 @@ namespace BlackSimPlugin
|
|||||||
if (package.isEmpty()) { continue; }
|
if (package.isEmpty()) { continue; }
|
||||||
packages.insert(it, { package.append('/') });
|
packages.insert(it, { package.append('/') });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// comment KB 2019-06
|
||||||
|
// a package is one xsb_aircraft.txt file BB has 9, X-CSL has 76
|
||||||
|
// the reason for the append("/")/chop "/" is explained here: https://discordapp.com/channels/539048679160676382/539925070550794240/594891288751505418
|
||||||
|
const QDir simDir = getSimulatorSettings().getSimulatorDirectoryOrDefault();
|
||||||
for (auto &package : packages)
|
for (auto &package : packages)
|
||||||
{
|
{
|
||||||
Q_ASSERT(package.s.endsWith('/'));
|
Q_ASSERT(package.s.endsWith('/'));
|
||||||
package.s.chop(1);
|
package.s.chop(1);
|
||||||
if (CDirectoryUtils::isSubDirectoryOf(package.s, getSimulatorSettings().getSimulatorDirectoryOrDefault()))
|
if (CDirectoryUtils::isSubDirectoryOf(package.s, simDir))
|
||||||
{
|
{
|
||||||
m_trafficProxy->loadPlanesPackage(package.s);
|
m_trafficProxy->loadPlanesPackage(package.s);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user