mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #267, moved vPilot reader in namespace fscommon, as it is specific for FSX/FS9/P3D
This commit is contained in:
@@ -6,11 +6,11 @@
|
||||
#include "samplesmodelmapping.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blacksim/blacksimfreefunctions.h"
|
||||
#include "blacksim/vpilotmodelmappings.h"
|
||||
#include "blacksim/fscommon/vpilotmodelmappings.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace BlackSim;
|
||||
using namespace BlackSim::FsCommon;
|
||||
|
||||
namespace BlackSimTest
|
||||
{
|
||||
|
||||
98
src/blacksim/fscommon/vpilotmodelmappings.cpp
Normal file
98
src/blacksim/fscommon/vpilotmodelmappings.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "vpilotmodelmappings.h"
|
||||
#include "blackmisc/nwaircraftmapping.h"
|
||||
|
||||
#include <QtXml/QDomElement>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackSim
|
||||
{
|
||||
namespace FsCommon
|
||||
{
|
||||
|
||||
void CVPilotModelMappings::addFilename(const QString &fileName)
|
||||
{
|
||||
if (this->m_fileList.contains(fileName)) return;
|
||||
this->m_fileList.append(fileName);
|
||||
}
|
||||
|
||||
void CVPilotModelMappings::addDirectory(const QString &directory)
|
||||
{
|
||||
QDir dir(directory);
|
||||
if (!dir.exists()) return;
|
||||
QStringList nameFilters({"*.vmr"});
|
||||
QFileInfoList entries = dir.entryInfoList(nameFilters, QDir::Files | QDir::Readable);
|
||||
foreach(QFileInfo file, entries)
|
||||
{
|
||||
this->addFilename(file.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
const QString &CVPilotModelMappings::standardMappingsDirectory()
|
||||
{
|
||||
static QString directory;
|
||||
if (directory.isEmpty())
|
||||
{
|
||||
directory = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first();
|
||||
if (!directory.endsWith('/')) directory.append('/');
|
||||
directory.append("vPilot Files/Model Matching Rule Sets");
|
||||
}
|
||||
return directory;
|
||||
}
|
||||
|
||||
bool CVPilotModelMappings::load()
|
||||
{
|
||||
bool success = true;
|
||||
foreach(QString fn, this->m_fileList)
|
||||
{
|
||||
bool s = this->loadFile(fn);
|
||||
success = s && success;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool CVPilotModelMappings::loadFile(const QString &fileName)
|
||||
{
|
||||
QFile f(fileName);
|
||||
if (!f.exists()) return false;
|
||||
if (!f.open(QFile::ReadOnly | QFile::Text)) return false;
|
||||
QByteArray fc = f.readAll();
|
||||
if (fc.isEmpty()) return false;
|
||||
QDomDocument doc;
|
||||
if (!doc.setContent(fc)) return false;
|
||||
QDomNodeList rules = doc.elementsByTagName("ModelMatchRule");
|
||||
if (rules.isEmpty()) return false;
|
||||
int size = rules.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
QDomNamedNodeMap attributes = rules.at(i).attributes();
|
||||
const QString typeCode = attributes.namedItem("TypeCode").nodeValue();
|
||||
const QString modelName = attributes.namedItem("ModelName").nodeValue();
|
||||
const QString callsignPrefix = attributes.namedItem("CallsignPrefix").nodeValue();
|
||||
if (modelName.isEmpty()) continue;
|
||||
|
||||
if (modelName.contains("//"))
|
||||
{
|
||||
// multiple models
|
||||
QStringList models = modelName.split("//");
|
||||
foreach(QString model, models)
|
||||
{
|
||||
if (model.isEmpty()) continue;
|
||||
CAircraftMapping mapping(typeCode, callsignPrefix, model);
|
||||
this->m_mappings.push_back(mapping);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// single model
|
||||
CAircraftMapping mapping(typeCode, callsignPrefix, modelName);
|
||||
this->m_mappings.push_back(mapping);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
49
src/blacksim/fscommon/vpilotmodelmappings.h
Normal file
49
src/blacksim/fscommon/vpilotmodelmappings.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef BLACKSIM_FSCOMMON_VPILOTMODELMAPPINGS_H
|
||||
#define BLACKSIM_FSCOMMON_VPILOTMODELMAPPINGS_H
|
||||
|
||||
#include "../simulatormodelmappings.h"
|
||||
#include <QStringList>
|
||||
|
||||
namespace BlackSim
|
||||
{
|
||||
namespace FsCommon
|
||||
{
|
||||
/*!
|
||||
* Model mappings
|
||||
*/
|
||||
class CVPilotModelMappings : public ISimulatorModelMappings
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CVPilotModelMappings(QObject *parent = nullptr) : ISimulatorModelMappings(parent) {}
|
||||
|
||||
//! Destructor
|
||||
virtual ~CVPilotModelMappings() {}
|
||||
|
||||
//! File names
|
||||
void addFilename(const QString &fileName);
|
||||
|
||||
//! Directory with .vmr files
|
||||
void addDirectory(const QString &directory);
|
||||
|
||||
//! The standard directory for vPilot mappings
|
||||
static const QString &standardMappingsDirectory();
|
||||
|
||||
public slots:
|
||||
//! Load data
|
||||
virtual bool load() override;
|
||||
|
||||
private:
|
||||
QStringList m_fileList; //!< list of file names
|
||||
|
||||
//! Single file read and parsing
|
||||
bool loadFile(const QString &fileName);
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
#endif // guard
|
||||
@@ -1,95 +0,0 @@
|
||||
#include "vpilotmodelmappings.h"
|
||||
#include "blackmisc/nwaircraftmapping.h"
|
||||
|
||||
#include <QtXml/QDomElement>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackSim
|
||||
{
|
||||
|
||||
void CVPilotModelMappings::addFilename(const QString &fileName)
|
||||
{
|
||||
if (this->m_fileList.contains(fileName)) return;
|
||||
this->m_fileList.append(fileName);
|
||||
}
|
||||
|
||||
void CVPilotModelMappings::addDirectory(const QString &directory)
|
||||
{
|
||||
QDir dir(directory);
|
||||
if (!dir.exists()) return;
|
||||
QStringList nameFilters({"*.vmr"});
|
||||
QFileInfoList entries = dir.entryInfoList(nameFilters, QDir::Files | QDir::Readable);
|
||||
foreach(QFileInfo file, entries)
|
||||
{
|
||||
this->addFilename(file.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
const QString &CVPilotModelMappings::standardMappingsDirectory()
|
||||
{
|
||||
static QString directory;
|
||||
if (directory.isEmpty())
|
||||
{
|
||||
directory = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first();
|
||||
if (!directory.endsWith('/')) directory.append('/');
|
||||
directory.append("vPilot Files/Model Matching Rule Sets");
|
||||
}
|
||||
return directory;
|
||||
}
|
||||
|
||||
bool CVPilotModelMappings::load()
|
||||
{
|
||||
bool success = true;
|
||||
foreach(QString fn, this->m_fileList)
|
||||
{
|
||||
bool s = this->loadFile(fn);
|
||||
success = s && success;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool CVPilotModelMappings::loadFile(const QString &fileName)
|
||||
{
|
||||
QFile f(fileName);
|
||||
if (!f.exists()) return false;
|
||||
if (!f.open(QFile::ReadOnly | QFile::Text)) return false;
|
||||
QByteArray fc = f.readAll();
|
||||
if (fc.isEmpty()) return false;
|
||||
QDomDocument doc;
|
||||
if (!doc.setContent(fc)) return false;
|
||||
QDomNodeList rules = doc.elementsByTagName("ModelMatchRule");
|
||||
if (rules.isEmpty()) return false;
|
||||
int size = rules.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
QDomNamedNodeMap attributes = rules.at(i).attributes();
|
||||
const QString typeCode = attributes.namedItem("TypeCode").nodeValue();
|
||||
const QString modelName = attributes.namedItem("ModelName").nodeValue();
|
||||
const QString callsignPrefix = attributes.namedItem("CallsignPrefix").nodeValue();
|
||||
if (modelName.isEmpty()) continue;
|
||||
|
||||
if (modelName.contains("//"))
|
||||
{
|
||||
// multiple models
|
||||
QStringList models = modelName.split("//");
|
||||
foreach(QString model, models)
|
||||
{
|
||||
if (model.isEmpty()) continue;
|
||||
CAircraftMapping mapping(typeCode, callsignPrefix, model);
|
||||
this->m_mappings.push_back(mapping);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// single model
|
||||
CAircraftMapping mapping(typeCode, callsignPrefix, modelName);
|
||||
this->m_mappings.push_back(mapping);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
@@ -1,49 +0,0 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef BLACKSIM_VPILOTMODELMAPPINGS_H
|
||||
#define BLACKSIM_VPILOTMODELMAPPINGS_H
|
||||
|
||||
#include "simulatormodelmappings.h"
|
||||
#include <QStringList>
|
||||
|
||||
namespace BlackSim
|
||||
{
|
||||
/*!
|
||||
* \brief Model mappings
|
||||
*/
|
||||
class CVPilotModelMappings : public ISimulatorModelMappings
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CVPilotModelMappings(QObject *parent = nullptr) : ISimulatorModelMappings(parent) {}
|
||||
|
||||
//! Destructor
|
||||
virtual ~CVPilotModelMappings() {}
|
||||
|
||||
//! File names
|
||||
void addFilename(const QString &fileName);
|
||||
|
||||
//! Directory with .vmr files
|
||||
void addDirectory(const QString &directory);
|
||||
|
||||
//! The standard directory for vPilot mappings
|
||||
static const QString &standardMappingsDirectory();
|
||||
|
||||
public slots:
|
||||
//! Load data
|
||||
virtual bool load() override;
|
||||
|
||||
private:
|
||||
QStringList m_fileList; //!< list of file names
|
||||
|
||||
//! Single file read and parsing
|
||||
bool loadFile(const QString &fileName);
|
||||
};
|
||||
} // namespace
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user