mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
refs #217, Project class providing information for compile configuration
* changed .pro / .pri as required * Used info from project class in network_vatlib * Checks / info in GUI/core (e.g. console) * const * versions of systemNameAndVersion / simulators, as mentioned in https://dev.vatsim-germany.org/issues/217#note-4
This commit is contained in:
141
src/blackmisc/project.cpp
Normal file
141
src/blackmisc/project.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "project.h"
|
||||
#include <QStringList>
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
|
||||
#define BLACK_VERSION_STR_X(v) #v
|
||||
#define BLACK_VERSION_STR(v) BLACK_VERSION_STR_X(v)
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
bool CProject::isCompiledWithBlackCore()
|
||||
{
|
||||
#ifdef WITH_BLACKCORE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithBlackSound()
|
||||
{
|
||||
#ifdef WITH_BLACKSOUND
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithFsxSupport()
|
||||
{
|
||||
#ifdef WITH_FSX
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithXPlaneSupport()
|
||||
{
|
||||
#ifdef WITH_XPLANE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithFlightSimulatorSupport()
|
||||
{
|
||||
return isCompiledWithFsxSupport() || isCompiledWithXPlaneSupport();
|
||||
}
|
||||
|
||||
bool BlackMisc::CProject::isCompiledWithGui()
|
||||
{
|
||||
#ifdef WITH_BLACKGUI
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
const QString &CProject::compiledInfo()
|
||||
{
|
||||
static QString info;
|
||||
if (info.isEmpty())
|
||||
{
|
||||
static QStringList sl;
|
||||
if (isCompiledWithBlackCore()) sl << "BlackCore";
|
||||
if (isCompiledWithBlackSound()) sl << "BlackSound";
|
||||
if (isCompiledWithGui()) sl << "BlackGui";
|
||||
if (isCompiledWithFsxSupport()) sl << "FSX";
|
||||
if (isCompiledWithXPlaneSupport()) sl << "XPlane";
|
||||
info = sl.join(", ");
|
||||
if (info.isEmpty()) info = "<none>";
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
const QString &CProject::simulators()
|
||||
{
|
||||
static QString sims;
|
||||
if (sims.isEmpty())
|
||||
{
|
||||
static QStringList sl;
|
||||
if (isCompiledWithFsxSupport()) sl << "FSX";
|
||||
if (isCompiledWithXPlaneSupport()) sl << "XPlane";
|
||||
sims = sl.join(", ");
|
||||
if (sims.isEmpty()) sims = "<none>";
|
||||
}
|
||||
return sims;
|
||||
}
|
||||
|
||||
const char *CProject::simulatorsChar()
|
||||
{
|
||||
static const QByteArray a(simulators().toUtf8());
|
||||
return a.constData();
|
||||
}
|
||||
|
||||
const QString &CProject::version()
|
||||
{
|
||||
#ifdef BLACK_VERSION
|
||||
const static QString v(BLACK_VERSION_STR(BLACK_VERSION));
|
||||
#else
|
||||
const static QString v("?");
|
||||
#endif
|
||||
return v;
|
||||
}
|
||||
|
||||
const QString &CProject::systemNameAndVersion()
|
||||
{
|
||||
static QString s = QString("BlackBox %1").arg(version());
|
||||
return s;
|
||||
}
|
||||
|
||||
const char *CProject::systemNameAndVersionChar()
|
||||
{
|
||||
static const QByteArray a(systemNameAndVersion().toUtf8());
|
||||
return a.constData();
|
||||
}
|
||||
|
||||
int CProject::versionMajor()
|
||||
{
|
||||
return getMajorMinor(0);
|
||||
}
|
||||
|
||||
int CProject::versionMinor()
|
||||
{
|
||||
return getMajorMinor(1);
|
||||
}
|
||||
|
||||
int CProject::getMajorMinor(int index)
|
||||
{
|
||||
QString v = version();
|
||||
if (v.isEmpty() || !v.contains(".")) return -1;
|
||||
bool ok;
|
||||
int vi = v.split(".")[index].toInt(&ok);
|
||||
return ok ? vi : -1;
|
||||
}
|
||||
}
|
||||
|
||||
#undef BLACK_VERSION_STR
|
||||
#undef BLACK_VERSION_STR_X
|
||||
66
src/blackmisc/project.h
Normal file
66
src/blackmisc/project.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef BLACKMISC_CPROJECT_H
|
||||
#define BLACKMISC_CPROJECT_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Metadata about the project
|
||||
*/
|
||||
class CProject
|
||||
{
|
||||
public:
|
||||
//! with BlackCore?
|
||||
static bool isCompiledWithBlackCore();
|
||||
|
||||
//! with BlackSound?
|
||||
static bool isCompiledWithBlackSound();
|
||||
|
||||
//! with FSX support?
|
||||
static bool isCompiledWithFsxSupport();
|
||||
|
||||
//! with XPlane support?
|
||||
static bool isCompiledWithXPlaneSupport();
|
||||
|
||||
//! with any simulator libraries
|
||||
static bool isCompiledWithFlightSimulatorSupport();
|
||||
|
||||
//! with GUI?
|
||||
static bool isCompiledWithGui();
|
||||
|
||||
//! Compiled with as info string
|
||||
static const QString &compiledInfo();
|
||||
|
||||
//! Simulator String info
|
||||
static const QString &simulators();
|
||||
|
||||
//! Simulator String info
|
||||
static const char *simulatorsChar();
|
||||
|
||||
//! Version info
|
||||
static const QString &version();
|
||||
|
||||
//! System's name and version
|
||||
static const QString &systemNameAndVersion();
|
||||
|
||||
//! System's name and version
|
||||
static const char *systemNameAndVersionChar();
|
||||
|
||||
//! Version major
|
||||
static int versionMajor();
|
||||
|
||||
//! Version minor
|
||||
static int versionMinor();
|
||||
|
||||
private:
|
||||
//! Constructor
|
||||
CProject() {}
|
||||
|
||||
//! Split version
|
||||
static int getMajorMinor(int index);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user