mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +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 {
|
||||
VER_MAJ = $${BLACK_VER_MAJ}
|
||||
VER_MIN = $${BLACK_VER_MIN}
|
||||
VER_PAT = $${BLACK_VER_PAT}
|
||||
VER_MIC = $${BLACK_VER_MIC}
|
||||
VERSION = $${BLACK_VERSION}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
BLACK_VER_MAJ = 0
|
||||
BLACK_VER_MIN = 7
|
||||
BLACK_VER_PAT = 3
|
||||
BLACK_VERSION = $${BLACK_VER_MAJ}.$${BLACK_VER_MIN}.$${BLACK_VER_PAT}
|
||||
BLACK_VER_MIC = 3
|
||||
BLACK_VERSION = $${BLACK_VER_MAJ}.$${BLACK_VER_MIN}.$${BLACK_VER_MIC}
|
||||
|
||||
@@ -375,6 +375,18 @@ namespace BlackConfig
|
||||
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
|
||||
{
|
||||
const QDateTime buildTimestampImpl()
|
||||
@@ -393,41 +405,7 @@ namespace BlackConfig
|
||||
return dt;
|
||||
}
|
||||
|
||||
const QString &CVersion::version()
|
||||
{
|
||||
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)
|
||||
int CBuildConfig::buildTimestampAsVersionSegment(const QDateTime &buildTimestamp)
|
||||
{
|
||||
if (buildTimestamp.isValid())
|
||||
{
|
||||
@@ -438,19 +416,6 @@ namespace BlackConfig
|
||||
}
|
||||
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
|
||||
|
||||
//! \endcond
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <QList>
|
||||
#include <QStringList>
|
||||
#include <QDateTime>
|
||||
#include <QVersionNumber>
|
||||
|
||||
namespace BlackConfig
|
||||
{
|
||||
@@ -152,26 +153,25 @@ namespace BlackConfig
|
||||
//! Returns SHA-1 of git HEAD at build time
|
||||
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
|
||||
static const QDateTime &buildTimestamp();
|
||||
|
||||
//! Returns the build date and time as string
|
||||
static const QString &buildDateAndTime();
|
||||
};
|
||||
|
||||
//! Version
|
||||
class CVersion
|
||||
{
|
||||
public:
|
||||
//! Version info 3 segments e.g. 0.8.3
|
||||
static const QString &versionMajorMinorPatch(); // defined in buildconfig_gen.cpp.in
|
||||
//! Version as QVersionNumber
|
||||
static const QVersionNumber &getVersion();
|
||||
|
||||
//! Version info 4 segments e.g. 0.8.3.12131
|
||||
static const QString &version();
|
||||
//! Version as QVersionNumber
|
||||
static const QString &getVersionString();
|
||||
|
||||
//! 4 Parts of the version
|
||||
static const QList<int> &getVersionParts();
|
||||
//! Turns build timestamp into a version number
|
||||
static int buildTimestampAsVersionSegment(const QDateTime &buildTimestamp);
|
||||
|
||||
private:
|
||||
//! Major version
|
||||
static int versionMajor(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
@@ -179,20 +179,7 @@ namespace BlackConfig
|
||||
static int versionMinor(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
//! Patch version
|
||||
static int versionPatch(); // 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);
|
||||
static int versionMicro(); // defined in buildconfig_gen.cpp.in
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -151,13 +151,6 @@ const QString &BlackConfig::CBuildConfig::gitHeadSha1()
|
||||
return gitHeadSha1;
|
||||
}
|
||||
|
||||
const QString &BlackConfig::CVersion::versionMajorMinorPatch()
|
||||
{
|
||||
static const QString version(\"$$BLACK_VERSION\");
|
||||
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; }
|
||||
int BlackConfig::CBuildConfig::versionMajor() { return $$BLACK_VER_MAJ; }
|
||||
int BlackConfig::CBuildConfig::versionMinor() { return $$BLACK_VER_MIN; }
|
||||
int BlackConfig::CBuildConfig::versionMicro() { return $$BLACK_VER_MIC; }
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace BlackCore
|
||||
{
|
||||
if (withMetadata) { CApplication::registerMetadata(); }
|
||||
QCoreApplication::setApplicationName(this->m_applicationName);
|
||||
QCoreApplication::setApplicationVersion(CVersion::version());
|
||||
QCoreApplication::setApplicationVersion(CBuildConfig::getVersionString());
|
||||
this->setObjectName(this->m_applicationName);
|
||||
const QString executable = QFileInfo(QCoreApplication::applicationFilePath()).fileName();
|
||||
if (executable.startsWith("test"))
|
||||
@@ -184,7 +184,7 @@ namespace BlackCore
|
||||
CApplicationInfo::ApplicationMode mode;
|
||||
if (isRunningInDeveloperEnvironment()) { mode |= CApplicationInfo::Developer; }
|
||||
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()
|
||||
@@ -213,7 +213,7 @@ namespace BlackCore
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -296,6 +296,8 @@ namespace BlackCore
|
||||
|
||||
bool CApplication::start()
|
||||
{
|
||||
this->m_started = false; // reset
|
||||
|
||||
// parse if needed, parsing contains its own error handling
|
||||
if (!this->m_parsed)
|
||||
{
|
||||
@@ -525,7 +527,7 @@ namespace BlackCore
|
||||
QString CApplication::getInfoString(const QString &separator) const
|
||||
{
|
||||
const QString str =
|
||||
CVersion::version() %
|
||||
CBuildConfig::getVersionString() %
|
||||
QLatin1Char(' ') % (CBuildConfig::isReleaseBuild() ? QLatin1String("Release build") : QLatin1String("Debug build")) %
|
||||
separator %
|
||||
getEnvironmentInfoString(separator) %
|
||||
@@ -1147,7 +1149,7 @@ namespace BlackCore
|
||||
|
||||
// Caliper (mini-breakpad-server) annotations
|
||||
annotations["prod"] = executable().toStdString();
|
||||
annotations["ver"] = CVersion::version().toStdString();
|
||||
annotations["ver"] = CBuildConfig::getVersionString().toStdString();
|
||||
|
||||
QDir().mkpath(database);
|
||||
m_crashReportDatabase = CrashReportDatabase::Initialize(qstringToFilePath(database));
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace BlackCore
|
||||
if (!success) { serverType = CBuildConfig::isVatsimVersion() ? vatServerVatsim : vatServerLegacyFsd; }
|
||||
|
||||
m_net.reset(Vat_CreateNetworkSession(serverType, sApp->swiftVersionChar(),
|
||||
CVersion::versionMajor(), CVersion::versionMinor(),
|
||||
CBuildConfig::getVersion().majorVersion(), CBuildConfig::getVersion().minorVersion(),
|
||||
"None", clientId, clientKey.toLocal8Bit().constData(),
|
||||
clientCapabilities));
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QVersionNumber>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QFlags>
|
||||
@@ -22,9 +23,10 @@
|
||||
#include <QStringBuilder>
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackConfig;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
CFileLogger::CFileLogger(QObject *parent) :
|
||||
CFileLogger(QCoreApplication::applicationName(), QString(), parent)
|
||||
{
|
||||
@@ -117,12 +119,12 @@ namespace BlackMisc
|
||||
void CFileLogger::writeHeaderToFile()
|
||||
{
|
||||
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 << " " << QSysInfo::currentCpuArchitecture() << endl;
|
||||
|
||||
m_stream << "Built from revision " << BlackConfig::CBuildConfig::gitHeadSha1();
|
||||
m_stream << " on " << BlackConfig::CBuildConfig::buildTimestamp().toString() << endl;
|
||||
m_stream << "Built from revision " << CBuildConfig::gitHeadSha1();
|
||||
m_stream << " on " << CBuildConfig::buildTimestamp().toString() << endl;
|
||||
|
||||
m_stream << "Built with Qt " << QT_VERSION_STR;
|
||||
m_stream << " and running with Qt " << qVersion();
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace BlackMisc
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user