mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 12:35:43 +08:00
refs #921, use QVersionNumber
* CVersion removed * remaining utility functions moved to CBuildConfig * patch version -> micro version (Qt naming) * using classes adjusted
This commit is contained in:
committed by
Mathew Sutcliffe
parent
ec297d5838
commit
f85501c7bf
@@ -16,7 +16,7 @@ include(version.pri)
|
|||||||
!win32 {
|
!win32 {
|
||||||
VER_MAJ = $${BLACK_VER_MAJ}
|
VER_MAJ = $${BLACK_VER_MAJ}
|
||||||
VER_MIN = $${BLACK_VER_MIN}
|
VER_MIN = $${BLACK_VER_MIN}
|
||||||
VER_PAT = $${BLACK_VER_PAT}
|
VER_MIC = $${BLACK_VER_MIC}
|
||||||
VERSION = $${BLACK_VERSION}
|
VERSION = $${BLACK_VERSION}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
BLACK_VER_MAJ = 0
|
BLACK_VER_MAJ = 0
|
||||||
BLACK_VER_MIN = 7
|
BLACK_VER_MIN = 7
|
||||||
BLACK_VER_PAT = 3
|
BLACK_VER_MIC = 3
|
||||||
BLACK_VERSION = $${BLACK_VER_MAJ}.$${BLACK_VER_MIN}.$${BLACK_VER_PAT}
|
BLACK_VERSION = $${BLACK_VER_MAJ}.$${BLACK_VER_MIN}.$${BLACK_VER_MIC}
|
||||||
|
|||||||
@@ -375,6 +375,18 @@ namespace BlackConfig
|
|||||||
return buildDateAndTime;
|
return buildDateAndTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QVersionNumber &CBuildConfig::getVersion()
|
||||||
|
{
|
||||||
|
static const QVersionNumber v { versionMajor(), versionMinor(), versionMicro(), buildTimestampAsVersionSegment(buildTimestamp()) };
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CBuildConfig::getVersionString()
|
||||||
|
{
|
||||||
|
static const QString s(getVersion().toString());
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Private
|
namespace Private
|
||||||
{
|
{
|
||||||
const QDateTime buildTimestampImpl()
|
const QDateTime buildTimestampImpl()
|
||||||
@@ -393,41 +405,7 @@ namespace BlackConfig
|
|||||||
return dt;
|
return dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &CVersion::version()
|
int CBuildConfig::buildTimestampAsVersionSegment(const QDateTime &buildTimestamp)
|
||||||
{
|
|
||||||
static const QString v(versionMajorMinorPatch() + "." + QString::number(buildTimestampAsVersionSegment(CBuildConfig::buildTimestamp())));
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QList<int> &CVersion::getVersionParts()
|
|
||||||
{
|
|
||||||
static const QList<int> parts(splitIntoVersionParts(version()));
|
|
||||||
return parts;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CVersion::isNewerVersion(const QString &versionString)
|
|
||||||
{
|
|
||||||
return isNewerVersion(version(), versionString);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CVersion::isNewerVersion(const QString &aVersion, const QString &bVersion)
|
|
||||||
{
|
|
||||||
if (aVersion.isEmpty() || bVersion.isEmpty()) { return false; }
|
|
||||||
if (aVersion == bVersion) { return true; }
|
|
||||||
|
|
||||||
const QList<int> aParts(splitIntoVersionParts(aVersion));
|
|
||||||
const QList<int> bParts(splitIntoVersionParts(bVersion));
|
|
||||||
for (int i = 0; i < bParts.length(); i++)
|
|
||||||
{
|
|
||||||
if (aParts.length() <= i) { return true; }
|
|
||||||
if (bParts.at(i) > aParts.at(i)) { return true; }
|
|
||||||
if (bParts.at(i) < aParts.at(i)) { return false; }
|
|
||||||
// same, try next part
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CVersion::buildTimestampAsVersionSegment(const QDateTime &buildTimestamp)
|
|
||||||
{
|
{
|
||||||
if (buildTimestamp.isValid())
|
if (buildTimestamp.isValid())
|
||||||
{
|
{
|
||||||
@@ -438,19 +416,6 @@ namespace BlackConfig
|
|||||||
}
|
}
|
||||||
return 0; // intentionally 0 and not zero => 0.7.3.0 <-
|
return 0; // intentionally 0 and not zero => 0.7.3.0 <-
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<int> CVersion::splitIntoVersionParts(const QString &versionString)
|
|
||||||
{
|
|
||||||
const QStringList parts = versionString.split('.');
|
|
||||||
QList<int> partsInt;
|
|
||||||
for (const QString &p : parts)
|
|
||||||
{
|
|
||||||
bool ok = false;
|
|
||||||
int pInt = p.toInt(&ok);
|
|
||||||
partsInt.append(ok ? pInt : -1);
|
|
||||||
}
|
|
||||||
return partsInt;
|
|
||||||
}
|
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
//! \endcond
|
//! \endcond
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QVersionNumber>
|
||||||
|
|
||||||
namespace BlackConfig
|
namespace BlackConfig
|
||||||
{
|
{
|
||||||
@@ -152,26 +153,25 @@ namespace BlackConfig
|
|||||||
//! Returns SHA-1 of git HEAD at build time
|
//! Returns SHA-1 of git HEAD at build time
|
||||||
static const QString &gitHeadSha1();
|
static const QString &gitHeadSha1();
|
||||||
|
|
||||||
|
//! Version info 3 segments e.g. 0.8.3
|
||||||
|
static const QString &versionMajorMinorPatch(); // defined in buildconfig_gen.cpp.in
|
||||||
|
|
||||||
//! Build timestamp
|
//! Build timestamp
|
||||||
static const QDateTime &buildTimestamp();
|
static const QDateTime &buildTimestamp();
|
||||||
|
|
||||||
//! Returns the build date and time as string
|
//! Returns the build date and time as string
|
||||||
static const QString &buildDateAndTime();
|
static const QString &buildDateAndTime();
|
||||||
};
|
|
||||||
|
|
||||||
//! Version
|
//! Version as QVersionNumber
|
||||||
class CVersion
|
static const QVersionNumber &getVersion();
|
||||||
{
|
|
||||||
public:
|
|
||||||
//! Version info 3 segments e.g. 0.8.3
|
|
||||||
static const QString &versionMajorMinorPatch(); // defined in buildconfig_gen.cpp.in
|
|
||||||
|
|
||||||
//! Version info 4 segments e.g. 0.8.3.12131
|
//! Version as QVersionNumber
|
||||||
static const QString &version();
|
static const QString &getVersionString();
|
||||||
|
|
||||||
//! 4 Parts of the version
|
//! Turns build timestamp into a version number
|
||||||
static const QList<int> &getVersionParts();
|
static int buildTimestampAsVersionSegment(const QDateTime &buildTimestamp);
|
||||||
|
|
||||||
|
private:
|
||||||
//! Major version
|
//! Major version
|
||||||
static int versionMajor(); // defined in buildconfig_gen.cpp.in
|
static int versionMajor(); // defined in buildconfig_gen.cpp.in
|
||||||
|
|
||||||
@@ -179,20 +179,7 @@ namespace BlackConfig
|
|||||||
static int versionMinor(); // defined in buildconfig_gen.cpp.in
|
static int versionMinor(); // defined in buildconfig_gen.cpp.in
|
||||||
|
|
||||||
//! Patch version
|
//! Patch version
|
||||||
static int versionPatch(); // defined in buildconfig_gen.cpp.in
|
static int versionMicro(); // defined in buildconfig_gen.cpp.in
|
||||||
|
|
||||||
//! Is the given string representing a newer version (newer than "me")?
|
|
||||||
static bool isNewerVersion(const QString &versionString);
|
|
||||||
|
|
||||||
//! Is the bVersion newer?
|
|
||||||
static bool isNewerVersion(const QString &aVersion, const QString &bVersion);
|
|
||||||
|
|
||||||
//! Turns build timestamp into a version number
|
|
||||||
static int buildTimestampAsVersionSegment(const QDateTime &buildTimestamp);
|
|
||||||
|
|
||||||
private:
|
|
||||||
//! Parts of version string 1.0.2.1234123
|
|
||||||
static QList<int> splitIntoVersionParts(const QString &versionString);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,13 +151,6 @@ const QString &BlackConfig::CBuildConfig::gitHeadSha1()
|
|||||||
return gitHeadSha1;
|
return gitHeadSha1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &BlackConfig::CVersion::versionMajorMinorPatch()
|
int BlackConfig::CBuildConfig::versionMajor() { return $$BLACK_VER_MAJ; }
|
||||||
{
|
int BlackConfig::CBuildConfig::versionMinor() { return $$BLACK_VER_MIN; }
|
||||||
static const QString version(\"$$BLACK_VERSION\");
|
int BlackConfig::CBuildConfig::versionMicro() { return $$BLACK_VER_MIC; }
|
||||||
Q_ASSERT(!version.isEmpty());
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
int BlackConfig::CVersion::versionMajor() { return $$BLACK_VER_MAJ; }
|
|
||||||
int BlackConfig::CVersion::versionMinor() { return $$BLACK_VER_MIN; }
|
|
||||||
int BlackConfig::CVersion::versionPatch() { return $$BLACK_VER_PAT; }
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (withMetadata) { CApplication::registerMetadata(); }
|
if (withMetadata) { CApplication::registerMetadata(); }
|
||||||
QCoreApplication::setApplicationName(this->m_applicationName);
|
QCoreApplication::setApplicationName(this->m_applicationName);
|
||||||
QCoreApplication::setApplicationVersion(CVersion::version());
|
QCoreApplication::setApplicationVersion(CBuildConfig::getVersionString());
|
||||||
this->setObjectName(this->m_applicationName);
|
this->setObjectName(this->m_applicationName);
|
||||||
const QString executable = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
|
const QString executable = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
|
||||||
if (executable.startsWith("test"))
|
if (executable.startsWith("test"))
|
||||||
@@ -184,7 +184,7 @@ namespace BlackCore
|
|||||||
CApplicationInfo::ApplicationMode mode;
|
CApplicationInfo::ApplicationMode mode;
|
||||||
if (isRunningInDeveloperEnvironment()) { mode |= CApplicationInfo::Developer; }
|
if (isRunningInDeveloperEnvironment()) { mode |= CApplicationInfo::Developer; }
|
||||||
if (CBuildConfig::isDevBranch()) { mode |= CApplicationInfo::BetaTest; }
|
if (CBuildConfig::isDevBranch()) { mode |= CApplicationInfo::BetaTest; }
|
||||||
return { CApplication::getSwiftApplication(), mode, QCoreApplication::applicationFilePath(), CVersion::version(), CProcessInfo::currentProcess() };
|
return { CApplication::getSwiftApplication(), mode, QCoreApplication::applicationFilePath(), CBuildConfig::getVersionString(), CProcessInfo::currentProcess() };
|
||||||
}
|
}
|
||||||
|
|
||||||
CApplicationInfoList CApplication::getRunningApplications()
|
CApplicationInfoList CApplication::getRunningApplications()
|
||||||
@@ -213,7 +213,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
const QString &CApplication::getApplicationNameAndVersion() const
|
const QString &CApplication::getApplicationNameAndVersion() const
|
||||||
{
|
{
|
||||||
static const QString s(QCoreApplication::instance()->applicationName() + " " + CVersion::version());
|
static const QString s(QCoreApplication::instance()->applicationName() + " " + CBuildConfig::getVersionString());
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,6 +296,8 @@ namespace BlackCore
|
|||||||
|
|
||||||
bool CApplication::start()
|
bool CApplication::start()
|
||||||
{
|
{
|
||||||
|
this->m_started = false; // reset
|
||||||
|
|
||||||
// parse if needed, parsing contains its own error handling
|
// parse if needed, parsing contains its own error handling
|
||||||
if (!this->m_parsed)
|
if (!this->m_parsed)
|
||||||
{
|
{
|
||||||
@@ -525,7 +527,7 @@ namespace BlackCore
|
|||||||
QString CApplication::getInfoString(const QString &separator) const
|
QString CApplication::getInfoString(const QString &separator) const
|
||||||
{
|
{
|
||||||
const QString str =
|
const QString str =
|
||||||
CVersion::version() %
|
CBuildConfig::getVersionString() %
|
||||||
QLatin1Char(' ') % (CBuildConfig::isReleaseBuild() ? QLatin1String("Release build") : QLatin1String("Debug build")) %
|
QLatin1Char(' ') % (CBuildConfig::isReleaseBuild() ? QLatin1String("Release build") : QLatin1String("Debug build")) %
|
||||||
separator %
|
separator %
|
||||||
getEnvironmentInfoString(separator) %
|
getEnvironmentInfoString(separator) %
|
||||||
@@ -1147,7 +1149,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
// Caliper (mini-breakpad-server) annotations
|
// Caliper (mini-breakpad-server) annotations
|
||||||
annotations["prod"] = executable().toStdString();
|
annotations["prod"] = executable().toStdString();
|
||||||
annotations["ver"] = CVersion::version().toStdString();
|
annotations["ver"] = CBuildConfig::getVersionString().toStdString();
|
||||||
|
|
||||||
QDir().mkpath(database);
|
QDir().mkpath(database);
|
||||||
m_crashReportDatabase = CrashReportDatabase::Initialize(qstringToFilePath(database));
|
m_crashReportDatabase = CrashReportDatabase::Initialize(qstringToFilePath(database));
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ namespace BlackCore
|
|||||||
if (!success) { serverType = CBuildConfig::isVatsimVersion() ? vatServerVatsim : vatServerLegacyFsd; }
|
if (!success) { serverType = CBuildConfig::isVatsimVersion() ? vatServerVatsim : vatServerLegacyFsd; }
|
||||||
|
|
||||||
m_net.reset(Vat_CreateNetworkSession(serverType, sApp->swiftVersionChar(),
|
m_net.reset(Vat_CreateNetworkSession(serverType, sApp->swiftVersionChar(),
|
||||||
CVersion::versionMajor(), CVersion::versionMinor(),
|
CBuildConfig::getVersion().majorVersion(), CBuildConfig::getVersion().minorVersion(),
|
||||||
"None", clientId, clientKey.toLocal8Bit().constData(),
|
"None", clientId, clientKey.toLocal8Bit().constData(),
|
||||||
clientCapabilities));
|
clientCapabilities));
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QVersionNumber>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QFlags>
|
#include <QFlags>
|
||||||
@@ -22,9 +23,10 @@
|
|||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
using namespace BlackConfig;
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|
||||||
CFileLogger::CFileLogger(QObject *parent) :
|
CFileLogger::CFileLogger(QObject *parent) :
|
||||||
CFileLogger(QCoreApplication::applicationName(), QString(), parent)
|
CFileLogger(QCoreApplication::applicationName(), QString(), parent)
|
||||||
{
|
{
|
||||||
@@ -117,12 +119,12 @@ namespace BlackMisc
|
|||||||
void CFileLogger::writeHeaderToFile()
|
void CFileLogger::writeHeaderToFile()
|
||||||
{
|
{
|
||||||
m_stream << "This is " << m_applicationName;
|
m_stream << "This is " << m_applicationName;
|
||||||
m_stream << " version " << BlackConfig::CVersion::version();
|
m_stream << " version " << CBuildConfig::getVersionString();
|
||||||
m_stream << " running on " << QSysInfo::prettyProductName();
|
m_stream << " running on " << QSysInfo::prettyProductName();
|
||||||
m_stream << " " << QSysInfo::currentCpuArchitecture() << endl;
|
m_stream << " " << QSysInfo::currentCpuArchitecture() << endl;
|
||||||
|
|
||||||
m_stream << "Built from revision " << BlackConfig::CBuildConfig::gitHeadSha1();
|
m_stream << "Built from revision " << CBuildConfig::gitHeadSha1();
|
||||||
m_stream << " on " << BlackConfig::CBuildConfig::buildTimestamp().toString() << endl;
|
m_stream << " on " << CBuildConfig::buildTimestamp().toString() << endl;
|
||||||
|
|
||||||
m_stream << "Built with Qt " << QT_VERSION_STR;
|
m_stream << "Built with Qt " << QT_VERSION_STR;
|
||||||
m_stream << " and running with Qt " << qVersion();
|
m_stream << " and running with Qt " << qVersion();
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CNetworkUtils::setSwiftUserAgent(QNetworkRequest &request)
|
void CNetworkUtils::setSwiftUserAgent(QNetworkRequest &request)
|
||||||
{
|
{
|
||||||
static const QString userAgent("swift/" + CVersion::version());
|
static const QString userAgent("swift/" + CBuildConfig::getVersionString());
|
||||||
request.setRawHeader("User-Agent", userAgent.toLatin1());
|
request.setRawHeader("User-Agent", userAgent.toLatin1());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user