mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 00:45:46 +08:00
Ref T348, allow to parse a single "aircraft.cfg" file
Related: Ref T317 Ref T247 Ref T335
This commit is contained in:
@@ -73,7 +73,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
if (m_parserWorker && !m_parserWorker->isFinished()) { return; }
|
if (m_parserWorker && !m_parserWorker->isFinished()) { return; }
|
||||||
emit this->diskLoadingStarted(simulator, mode);
|
emit this->diskLoadingStarted(simulator, mode);
|
||||||
m_parserWorker = BlackMisc::CWorker::fromTask(this, "CAircraftCfgParser::changeDirectory",
|
m_parserWorker = CWorker::fromTask(this, "CAircraftCfgParser::changeDirectory",
|
||||||
[this, modelDirs, excludedDirectoryPatterns, simulator, modelConsolidation]()
|
[this, modelDirs, excludedDirectoryPatterns, simulator, modelConsolidation]()
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
@@ -205,12 +205,41 @@ namespace BlackMisc
|
|||||||
// unfortunately some files are malformed which could end up in wrong data
|
// unfortunately some files are malformed which could end up in wrong data
|
||||||
|
|
||||||
const QString fileName = fileInfo.absoluteFilePath();
|
const QString fileName = fileInfo.absoluteFilePath();
|
||||||
QFile file(fileName);
|
bool fileOk = false;
|
||||||
if (!file.open(QFile::ReadOnly | QFile::Text))
|
CStatusMessageList fileMsgs;
|
||||||
|
CAircraftCfgEntriesList fileResults = performParsingOfSingleFile(fileName, fileOk, fileMsgs);
|
||||||
|
if (!fileOk)
|
||||||
{
|
{
|
||||||
CLogMessage(this).warning("Unable to read file %1") << fileName;
|
CLogMessage::preformatted(fileMsgs);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.push_back(fileResults);
|
||||||
|
return result; // do not go any deeper in file tree, we found aircraft.cfg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// all files finished,
|
||||||
|
// normally reached when no aircraft.cfg is found
|
||||||
|
*ok = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
CAircraftCfgEntriesList CAircraftCfgParser::performParsingOfSingleFile(const QString &fileName, bool &ok, CStatusMessageList &msgs)
|
||||||
|
{
|
||||||
|
// due to the filter we expect only "aircraft.cfg" here
|
||||||
|
// remark: in a 1st version I have used QSettings to parse to file as ini file
|
||||||
|
// unfortunately some files are malformed which could end up in wrong data
|
||||||
|
|
||||||
|
ok = false;
|
||||||
|
QFile file(fileName); // includes path
|
||||||
|
if (!file.open(QFile::ReadOnly | QFile::Text))
|
||||||
|
{
|
||||||
|
const CStatusMessage m = CStatusMessage(getLogCategories()).warning("Unable to read file '%1'") << fileName;
|
||||||
|
msgs.push_back(m);
|
||||||
|
return CAircraftCfgEntriesList();
|
||||||
|
}
|
||||||
|
|
||||||
QTextStream in(&file);
|
QTextStream in(&file);
|
||||||
QList<CAircraftCfgEntries> tempEntries;
|
QList<CAircraftCfgEntries> tempEntries;
|
||||||
|
|
||||||
@@ -218,9 +247,11 @@ namespace BlackMisc
|
|||||||
QString atcType;
|
QString atcType;
|
||||||
QString atcModel;
|
QString atcModel;
|
||||||
QString fltSection("[FLTSIM.0]");
|
QString fltSection("[FLTSIM.0]");
|
||||||
|
static const QString fltSectionStr = QString("[FLTSIM.%1]");
|
||||||
|
|
||||||
int fltsimCounter = 0;
|
int fltsimCounter = 0;
|
||||||
FileSection currentSection = Unknown;
|
FileSection currentSection = Unknown;
|
||||||
bool isRotorcraftPath = fileName.contains("rotorcraft", Qt::CaseInsensitive);
|
const bool isRotorcraftPath = fileName.contains("rotorcraft", Qt::CaseInsensitive);
|
||||||
|
|
||||||
while (!in.atEnd())
|
while (!in.atEnd())
|
||||||
{
|
{
|
||||||
@@ -238,7 +269,7 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
tempEntries.append(e);
|
tempEntries.append(e);
|
||||||
currentSection = Fltsim;
|
currentSection = Fltsim;
|
||||||
fltSection = QString("[FLTSIM.%1]").arg(++fltsimCounter);
|
fltSection = fltSectionStr.arg(++fltsimCounter);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
currentSection = Unknown;
|
currentSection = Unknown;
|
||||||
@@ -331,17 +362,21 @@ namespace BlackMisc
|
|||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
// store all entries
|
// store all entries
|
||||||
|
const QFileInfo fileInfo(fileName);
|
||||||
QDateTime fileTimestamp(fileInfo.lastModified());
|
QDateTime fileTimestamp(fileInfo.lastModified());
|
||||||
if (!fileTimestamp.isValid() || fileInfo.created() > fileTimestamp)
|
if (!fileTimestamp.isValid() || fileInfo.created() > fileTimestamp)
|
||||||
{
|
{
|
||||||
fileTimestamp = fileInfo.created();
|
fileTimestamp = fileInfo.created();
|
||||||
}
|
}
|
||||||
Q_ASSERT_X(fileTimestamp.isValid(), Q_FUNC_INFO, "Missing file timestamp");
|
Q_ASSERT_X(fileTimestamp.isValid(), Q_FUNC_INFO, "Missing file timestamp");
|
||||||
|
|
||||||
|
CAircraftCfgEntriesList result;
|
||||||
for (const CAircraftCfgEntries &e : as_const(tempEntries))
|
for (const CAircraftCfgEntries &e : as_const(tempEntries))
|
||||||
{
|
{
|
||||||
if (e.getTitle().isEmpty())
|
if (e.getTitle().isEmpty())
|
||||||
{
|
{
|
||||||
CLogMessage(this).info("FS model in %1, index %2 has no title") << fileName << e.getIndex();
|
const CStatusMessage m = CStatusMessage(getLogCategories()).info("FS model in %1, index %2 has no title") << fileName << e.getIndex();
|
||||||
|
msgs.push_back(m);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CAircraftCfgEntries newEntries(e);
|
CAircraftCfgEntries newEntries(e);
|
||||||
@@ -350,16 +385,9 @@ namespace BlackMisc
|
|||||||
newEntries.setUtcTimestamp(fileTimestamp);
|
newEntries.setUtcTimestamp(fileTimestamp);
|
||||||
result.push_back(newEntries);
|
result.push_back(newEntries);
|
||||||
}
|
}
|
||||||
*ok = true;
|
ok = true;
|
||||||
return result; // do not go any deeper in file tree, we found aircraft.cfg
|
return result; // do not go any deeper in file tree, we found aircraft.cfg
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// all files finished,
|
|
||||||
// normally reached when no aircraft.cfg is found
|
|
||||||
*ok = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CAircraftCfgParser::fixedStringContent(const QSettings &settings, const QString &key)
|
QString CAircraftCfgParser::fixedStringContent(const QSettings &settings, const QString &key)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ namespace BlackMisc
|
|||||||
virtual bool isLoadingFinished() const override;
|
virtual bool isLoadingFinished() const override;
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
|
//! Parse a single file
|
||||||
|
static CAircraftCfgEntriesList performParsingOfSingleFile(const QString &fileName, bool &ok, CStatusMessageList &msgs);
|
||||||
|
|
||||||
//! Create an parser object for given simulator
|
//! Create an parser object for given simulator
|
||||||
static CAircraftCfgParser *createModelLoader(const CSimulatorInfo &simInfo, QObject *parent = nullptr);
|
static CAircraftCfgParser *createModelLoader(const CSimulatorInfo &simInfo, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user