Renamed function id Directory utils and added string only version

This commit is contained in:
Klaus Basan
2019-07-13 03:38:25 +02:00
committed by Mat Sutcliffe
parent cd63712cd7
commit cb77279b4d
3 changed files with 22 additions and 10 deletions

View File

@@ -543,19 +543,19 @@ namespace BlackMisc
return d1.absolutePath() == d2.absolutePath();
}
bool CDirectoryUtils::isSubDirectoryOf(const QString &dir1, const QString &dir2)
bool CDirectoryUtils::isSameOrSubDirectoryOf(const QString &testDir, const QString &dir2)
{
if (dir1.isEmpty() || dir2.isEmpty()) { return false; }
if (testDir.isEmpty() || dir2.isEmpty()) { return false; }
const QDir d2(dir2);
return CDirectoryUtils::isSubDirectoryOf(dir1, d2);
return CDirectoryUtils::isSameOrSubDirectoryOf(testDir, d2);
}
bool CDirectoryUtils::isSubDirectoryOf(const QString &dir1, const QDir &dir2)
bool CDirectoryUtils::isSameOrSubDirectoryOf(const QString &dir1, const QDir &parentDir)
{
QDir d1(dir1);
do
{
if (d1 == dir2) { return true; }
if (d1 == parentDir) { return true; }
}
while (d1.cdUp());
@@ -563,6 +563,14 @@ namespace BlackMisc
return false;
}
bool CDirectoryUtils::isSameOrSubDirectoryOfStringBased(const QString &testDir, const QString &parentDir)
{
const Qt::CaseSensitivity cs = CFileUtils::osFileNameCaseSensitivity();
const QString td = CFileUtils::fixWindowsUncPath(QDir::cleanPath(testDir));
const QString pd = CFileUtils::fixWindowsUncPath(QDir::cleanPath(parentDir));
return td.contains(pd, cs);
}
QSet<QString> CDirectoryUtils::fileNamesToQSet(const QFileInfoList &fileInfoList)
{
QSet<QString> sl;

View File

@@ -187,13 +187,17 @@ namespace BlackMisc
//! Same existing directories
static bool isSameExistingDirectory(const QString &dir1, const QString &dir2);
//! Is dir1 a subdirectory (possibly nested) of dir2 or the same directory
//! Is "testDir" a subdirectory (possibly nested) of "parentDir" or the same directory
//! \remark testing on real directory structure
static bool isSubDirectoryOf(const QString &dir1, const QString &dir2);
static bool isSameOrSubDirectoryOf(const QString &testDir, const QString &parentDir);
//! Is dir1 a subdirectory (possibly nested) of dir2 or the same directory
//! Is "testDir" a subdirectory (possibly nested) of "parentDir" or the same directory
//! \remark testing on real directory structure
static bool isSubDirectoryOf(const QString &dir1, const QDir &dir2);
static bool isSameOrSubDirectoryOf(const QString &testDir, const QDir &parentDir);
//! Is "testDir" a subdirectory (possibly nested) of "parentDir" or the same directory
//! \remark String based only
static bool isSameOrSubDirectoryOfStringBased(const QString &testDir, const QString &parentDir);
//! Result of directory comparison
struct DirComparison

View File

@@ -576,7 +576,7 @@ namespace BlackSimPlugin
{
Q_ASSERT(package.s.endsWith('/'));
package.s.chop(1);
if (CDirectoryUtils::isSubDirectoryOf(package.s, simDir))
if (CDirectoryUtils::isSameOrSubDirectoryOf(package.s, simDir))
{
m_trafficProxy->loadPlanesPackage(package.s);
}