mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T660, FSX path handling
* exclude paths from exclude patterns * check for *air file * use absolute paths
This commit is contained in:
committed by
Mat Sutcliffe
parent
878a207f85
commit
242bea3636
@@ -436,7 +436,7 @@ namespace BlackMisc
|
||||
|
||||
bool CDirectoryUtils::containsFileInDir(const QString &dir, const QString &filter, bool recursively)
|
||||
{
|
||||
QDir directory(dir);
|
||||
const QDir directory(dir);
|
||||
if (!directory.exists()) { return false; }
|
||||
|
||||
const QStringList nameFilter({ filter });
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace BlackMisc
|
||||
|
||||
// the sim.cfg/aircraft.cfg file should have an *.air file sibling
|
||||
// if not we assume these files can be ignored
|
||||
const QDir dirForAir(directory, QStringLiteral("*.air"), QDir::Name, QDir::Files | QDir::NoDotAndDotDot);
|
||||
const QDir dirForAir(directory, CFsCommonUtil::airFileFilter(), QDir::Name, QDir::Files | QDir::NoDotAndDotDot);
|
||||
const int airFilesCount = dirForAir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::DirsLast).size();
|
||||
const bool hasAirFile = airFilesCount > 0;
|
||||
|
||||
|
||||
@@ -577,7 +577,7 @@ namespace BlackMisc
|
||||
QSet<QString> paths;
|
||||
for (const QString &fsxFile : fsxFiles)
|
||||
{
|
||||
paths.unite(fsxSimObjectsPaths(fsxFile, checked));
|
||||
paths.unite(CFsCommonUtil::fsxSimObjectsPaths(fsxFile, checked));
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
@@ -589,6 +589,9 @@ namespace BlackMisc
|
||||
const QList<QStringRef> lines = splitLinesRefs(fileContent);
|
||||
static const QString p("SimObjectPaths.");
|
||||
|
||||
const QFileInfo fsxFileInfo(fsxFile);
|
||||
const QString relPath = fsxFileInfo.absolutePath();
|
||||
|
||||
QSet<QString> paths;
|
||||
for (const QStringRef &line : lines)
|
||||
{
|
||||
@@ -597,14 +600,32 @@ namespace BlackMisc
|
||||
const int i2 = line.lastIndexOf('=');
|
||||
if (i2 < 0 || i1 >= i2 || line.endsWith('=')) { continue; }
|
||||
const QStringRef path = line.mid(i2 + 1);
|
||||
const QString soPath = QDir::fromNativeSeparators(path.toString());
|
||||
const QFileInfo fi(soPath);
|
||||
QString soPath = QDir::fromNativeSeparators(path.toString());
|
||||
if (logConfigPathReading()) { CLogMessage(getLogCategories()).info(u"FSX SimObjects path checked: '%1' in '%2'") << line << fsxFile; }
|
||||
|
||||
// relative or absolute paths
|
||||
const QString p = (fi.isAbsolute() && (!checked || fi.exists())) ?
|
||||
fi.absolutePath() : soPath;
|
||||
paths.insert(p);
|
||||
if (logConfigPathReading()) { CLogMessage(getLogCategories()).info(u"FSX SimObjects path: '%1'") << p; }
|
||||
// ignore exclude patterns
|
||||
if (containsAny(soPath, CFsCommonUtil::fsxSimObjectsExcludeDirectoryPatterns(), Qt::CaseInsensitive)) { continue; }
|
||||
|
||||
// make absolute
|
||||
if (!soPath.left(3).contains(':')) { soPath = CFileUtils::appendFilePaths(relPath, soPath); }
|
||||
|
||||
const QDir p(soPath); // always absolute path now
|
||||
if (checked && !p.exists())
|
||||
{
|
||||
// skip, not existing
|
||||
if (logConfigPathReading()) { CLogMessage(getLogCategories()).info(u"FSX SimObjects path skipped, not existing: '%1' in '%2'") << p.absolutePath() << fsxFile; }
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString afp = p.absolutePath().toLower();
|
||||
if (!CDirectoryUtils::containsFileInDir(afp, airFileFilter(), true))
|
||||
{
|
||||
if (logConfigPathReading()) { CLogMessage(getLogCategories()).info(u"FSX SimObjects path: Skipping '%1' from '%2', no '%3' file") << afp << fsxFile << airFileFilter(); }
|
||||
continue;
|
||||
}
|
||||
|
||||
paths.insert(afp);
|
||||
if (logConfigPathReading()) { CLogMessage(getLogCategories()).info(u"FSX SimObjects path: '%1' from '%2'") << afp << fsxFile; }
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
@@ -685,6 +706,12 @@ namespace BlackMisc
|
||||
return CFsCommonUtil::validateSimObjectsPath(simObjectPaths, models, validModels, invalidModels, ignoreEmptyFileNames, stopAtFailedFiles, stopped);
|
||||
}
|
||||
|
||||
const QString CFsCommonUtil::airFileFilter()
|
||||
{
|
||||
static const QString a("*.air");
|
||||
return a;
|
||||
}
|
||||
|
||||
CStatusMessageList CFsCommonUtil::validateSimObjectsPath(
|
||||
const QSet<QString> &simObjectDirs, const CAircraftModelList &models,
|
||||
CAircraftModelList &validModels, CAircraftModelList &invalidModels,
|
||||
|
||||
@@ -149,6 +149,9 @@ namespace BlackMisc
|
||||
//! \remark only for FSX
|
||||
static CStatusMessageList validateFSXSimObjectsPath(const CAircraftModelList &models, CAircraftModelList &validModels, CAircraftModelList &invalidModels, bool ignoreEmptyFileNames, int stopAtFailedFiles, bool &stopped, const QString &simulatorDir);
|
||||
|
||||
//! .air file filter
|
||||
static const QString airFileFilter();
|
||||
|
||||
private:
|
||||
//! Utility functions @{
|
||||
static QSet<QString> findP3dConfigFiles(const QString &configFile, const QString &versionHint = "v4");
|
||||
|
||||
Reference in New Issue
Block a user