mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 18:55:38 +08:00
Ref T515, validate aircraft config values
This commit is contained in:
committed by
Mat Sutcliffe
parent
de680f4fcd
commit
f3dd2425ee
@@ -7,7 +7,8 @@
|
|||||||
* contained in the LICENSE file.
|
* contained in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "blackmisc/simulation/fscommon/fscommonutil.h"
|
#include "fscommonutil.h"
|
||||||
|
#include "aircraftcfgparser.h"
|
||||||
#include "blackmisc/directoryutils.h"
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "blackmisc/fileutils.h"
|
#include "blackmisc/fileutils.h"
|
||||||
#include "blackmisc/stringutils.h"
|
#include "blackmisc/stringutils.h"
|
||||||
@@ -37,6 +38,12 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
using FsRegistryPathPair = QList<QPair<QString, QString>>;
|
using FsRegistryPathPair = QList<QPair<QString, QString>>;
|
||||||
|
|
||||||
|
const CLogCategoryList &CFsCommonUtil::getLogCategories()
|
||||||
|
{
|
||||||
|
static const CLogCategoryList cats({ CLogCategory::validation(), CLogCategory::driver() });
|
||||||
|
return cats;
|
||||||
|
}
|
||||||
|
|
||||||
QString fsxDirFromRegistryImpl()
|
QString fsxDirFromRegistryImpl()
|
||||||
{
|
{
|
||||||
QString fsxPath;
|
QString fsxPath;
|
||||||
@@ -362,17 +369,16 @@ namespace BlackMisc
|
|||||||
|
|
||||||
int CFsCommonUtil::copyFsxTerrainProbeFiles(const QString &simObjectDir, CStatusMessageList &messages)
|
int CFsCommonUtil::copyFsxTerrainProbeFiles(const QString &simObjectDir, CStatusMessageList &messages)
|
||||||
{
|
{
|
||||||
static const CLogCategoryList cats({ CLogCategory::validation(), CLogCategory::driver() });
|
|
||||||
messages.clear();
|
messages.clear();
|
||||||
if (!CDirectoryUtils::existsUnemptyDirectory(CDirectoryUtils::shareTerrainProbeDirectory()))
|
if (!CDirectoryUtils::existsUnemptyDirectory(CDirectoryUtils::shareTerrainProbeDirectory()))
|
||||||
{
|
{
|
||||||
messages.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, QStringLiteral("No terrain probe source files in '%1'").arg(CDirectoryUtils::shareTerrainProbeDirectory())));
|
messages.push_back(CStatusMessage(getLogCategories(), CStatusMessage::SeverityError, QStringLiteral("No terrain probe source files in '%1'").arg(CDirectoryUtils::shareTerrainProbeDirectory())));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (simObjectDir.isEmpty())
|
if (simObjectDir.isEmpty())
|
||||||
{
|
{
|
||||||
messages.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, "No simObject directory"));
|
messages.push_back(CStatusMessage(getLogCategories(), CStatusMessage::SeverityError, "No simObject directory"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +386,7 @@ namespace BlackMisc
|
|||||||
QDir td(targetDir);
|
QDir td(targetDir);
|
||||||
if (!td.exists())
|
if (!td.exists())
|
||||||
{
|
{
|
||||||
messages.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, QStringLiteral("Cannot access target directory '%1'").arg(targetDir)));
|
messages.push_back(CStatusMessage(getLogCategories(), CStatusMessage::SeverityError, QStringLiteral("Cannot access target directory '%1'").arg(targetDir)));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,12 +395,12 @@ namespace BlackMisc
|
|||||||
const bool hasDir = td.mkpath(targetDir);
|
const bool hasDir = td.mkpath(targetDir);
|
||||||
if (!hasDir)
|
if (!hasDir)
|
||||||
{
|
{
|
||||||
messages.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, QStringLiteral("Cannot create target directory '%1'").arg(targetDir)));
|
messages.push_back(CStatusMessage(getLogCategories(), CStatusMessage::SeverityError, QStringLiteral("Cannot create target directory '%1'").arg(targetDir)));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int copied = CDirectoryUtils::copyDirectoryRecursively(CDirectoryUtils::shareTerrainProbeDirectory(), targetDir, true);
|
const int copied = CDirectoryUtils::copyDirectoryRecursively(CDirectoryUtils::shareTerrainProbeDirectory(), targetDir, true);
|
||||||
messages.push_back(CStatusMessage(cats, CStatusMessage::SeverityInfo, QStringLiteral("Copied %1 files from '%2' to '%3'").arg(copied).arg(CDirectoryUtils::shareTerrainProbeDirectory(), targetDir)));
|
messages.push_back(CStatusMessage(getLogCategories(), CStatusMessage::SeverityInfo, QStringLiteral("Copied %1 files from '%2' to '%3'").arg(copied).arg(CDirectoryUtils::shareTerrainProbeDirectory(), targetDir)));
|
||||||
return copied;
|
return copied;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,7 +495,7 @@ namespace BlackMisc
|
|||||||
QStringList files;
|
QStringList files;
|
||||||
for (const QString &path : locations)
|
for (const QString &path : locations)
|
||||||
{
|
{
|
||||||
QString file = CFileUtils::appendFilePaths(CFileUtils::pathUp(path), "Microsoft/FSX/fsx.cfg");
|
const QString file = CFileUtils::appendFilePaths(CFileUtils::pathUp(path), "Microsoft/FSX/fsx.cfg");
|
||||||
const QFileInfo fi(file);
|
const QFileInfo fi(file);
|
||||||
if (fi.exists()) { files.push_back(fi.absoluteFilePath()); }
|
if (fi.exists()) { files.push_back(fi.absoluteFilePath()); }
|
||||||
}
|
}
|
||||||
@@ -536,6 +542,45 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CStatusMessageList CFsCommonUtil::validateConfigFiles(const CAircraftModelList &models, CAircraftModelList &validModels, CAircraftModelList &invalidModels, bool ignoreEmpty, int stopAtFailedFiles, bool &stopped)
|
||||||
|
{
|
||||||
|
CAircraftModelList sorted(models);
|
||||||
|
sorted.sortByFileName();
|
||||||
|
stopped = false;
|
||||||
|
CStatusMessageList msgs = sorted.validateFiles(validModels, invalidModels, ignoreEmpty, stopAtFailedFiles, stopped, true);
|
||||||
|
if (stopped || validModels.isEmpty()) { return msgs; }
|
||||||
|
|
||||||
|
const int d = validModels.removeIfNotFsFamily();
|
||||||
|
if (d > 0)
|
||||||
|
{
|
||||||
|
const CStatusMessage m = CStatusMessage(getLogCategories(), CStatusMessage::SeverityError, QStringLiteral("Removed %1 non FS family models").arg(d), true);
|
||||||
|
msgs.push_back(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
// all those files should work
|
||||||
|
int removedCfgEntries = 0;
|
||||||
|
const QSet<QString> fileNames = validModels.getAllFileNames();
|
||||||
|
for (const QString &fileName : fileNames)
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
const CAircraftCfgEntriesList entries = CAircraftCfgParser::performParsingOfSingleFile(fileName, ok, msgs);
|
||||||
|
const CAircraftModelList removedModels = validModels.removeIfFileButNotInSet(fileName, entries.getTitleSetUpperCase());
|
||||||
|
for (const CAircraftModel &removedModel : removedModels)
|
||||||
|
{
|
||||||
|
removedCfgEntries++;
|
||||||
|
const CStatusMessage m = CStatusMessage(getLogCategories(), CStatusMessage::SeverityError, QStringLiteral("'%1', removed because no longer in '%1'").arg(removedModel.getModelStringAndDbKey(), removedModel.getFileName()), true);
|
||||||
|
msgs.push_back(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removedCfgEntries < 1)
|
||||||
|
{
|
||||||
|
const CStatusMessage m = CStatusMessage(getLogCategories(), CStatusMessage::SeverityInfo, QStringLiteral("Not removed any models, all OK!"), true);
|
||||||
|
msgs.push_back(m);
|
||||||
|
}
|
||||||
|
return msgs;
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -12,8 +12,10 @@
|
|||||||
#ifndef BLACKMISC_SIMULATION_FSCOMMONUTIL_H
|
#ifndef BLACKMISC_SIMULATION_FSCOMMONUTIL_H
|
||||||
#define BLACKMISC_SIMULATION_FSCOMMONUTIL_H
|
#define BLACKMISC_SIMULATION_FSCOMMONUTIL_H
|
||||||
|
|
||||||
#include "blackmisc/simulation/aircraftmodel.h"
|
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||||
|
#include "blackmisc/logcategorylist.h"
|
||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
@@ -27,6 +29,9 @@ namespace BlackMisc
|
|||||||
class BLACKMISC_EXPORT CFsCommonUtil
|
class BLACKMISC_EXPORT CFsCommonUtil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
//! Log categories
|
||||||
|
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CFsCommonUtil() = delete;
|
CFsCommonUtil() = delete;
|
||||||
|
|
||||||
@@ -121,6 +126,10 @@ namespace BlackMisc
|
|||||||
//! Get all the SimObjects files from fsx.cfg
|
//! Get all the SimObjects files from fsx.cfg
|
||||||
// SimObjectPaths.0=SimObjects\Airplanes
|
// SimObjectPaths.0=SimObjects\Airplanes
|
||||||
static QSet<QString> fsxSimObjectsPaths(const QString &fsxFile, bool checked);
|
static QSet<QString> fsxSimObjectsPaths(const QString &fsxFile, bool checked);
|
||||||
|
|
||||||
|
//! Validate aircraft.cfg entries
|
||||||
|
//! \remark only for FSX/P3D/FS9 models
|
||||||
|
static CStatusMessageList validateConfigFiles(const CAircraftModelList &models, CAircraftModelList &validModels, CAircraftModelList &invalidModels, bool ignoreEmpty, int stopAtFailedFiles, bool &stopped);
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user