6 #include <QRegularExpression>
7 #include <QStringBuilder>
12 using namespace swift::config;
13 using namespace swift::misc::network;
17 namespace swift::misc::db
19 CArtifact::CArtifact() {}
22 int size,
bool existing,
const CPlatform &platform)
23 : m_name(name.trimmed()), m_md5(md5), m_type(static_cast<int>(type)), m_size(size), m_existing(existing),
27 if (!name.isEmpty() && version.isEmpty()) {
m_version = versionNumberFromFilename(name); }
34 if (m) {
return true; }
35 return name.startsWith(this->
getName(), cs);
40 if (m_size < 0) {
return {}; }
50 if (distribution.
isEmpty() || !this->hasDistributions()) {
return false; }
53 if (dist == distribution) {
return true; }
54 if (acceptMoreStableDistributions && dist.isStabilityBetter(distribution)) {
return true; }
76 return this->
getQVersion() > CBuildConfig::getVersion();
91 if (index.
isMyself()) {
return QVariant::fromValue(*
this); }
100 case IndexName:
return QVariant::fromValue(m_name);
101 case IndexMd5:
return QVariant::fromValue(m_md5);
103 case IndexType:
return QVariant::fromValue(m_type);
104 case IndexSize:
return QVariant::fromValue(m_size);
106 case IndexVersionString:
return QVariant::fromValue(
m_version);
107 case IndexQVersion:
return QVariant::fromValue(this->
getQVersion());
108 case IndexDistributions:
return QVariant::fromValue(m_distributions);
129 case IndexName: this->
setName(variant.toString());
break;
130 case IndexMd5: m_md5 = variant.toString();
break;
132 case IndexType: m_type = variant.toInt();
break;
133 case IndexSize: m_size = variant.toInt();
break;
134 case IndexVersionString:
m_version = variant.toString();
break;
135 case IndexDistributions: m_distributions = variant.value<
CDistributionList>();
break;
144 const QString name = json.value(
"name").toString();
145 const QString md5 = json.value(
"md5").toString();
146 const QString version = json.value(
"version").toString();
149 const int size = json.value(
"size").toInt(-1);
150 const bool existing = json.value(
"existing").toBool();
152 CArtifact artifact(name, version, md5, type, size, existing, platform);
154 if (json.contains(
"distributions"))
156 const QJsonObject distJson = json.value(
"distributions").toObject();
157 if (!distJson.isEmpty() && distJson.contains(
"distributionArray"))
169 static const QString xswb(
"xswiftbus");
170 static const QString installer(
"pilot client installer");
171 static const QString symbols(
"symbols");
172 static const QString unknown(
"unknown");
177 case PilotClientInstaller:
return installer;
178 case Symbols:
return symbols;
179 case UnknownArtifact:
188 const QString n(name.toLower().trimmed());
189 if (n.contains(
"-windows-") || n.endsWith(
".exe"))
203 QString CArtifact::versionNumberFromFilename(
const QString &filename)
205 if (filename.isEmpty()) {
return {}; }
208 thread_local
const QRegularExpression regex { R
"(\d+\.\d+\.\d+\.\d+)" };
209 const QRegularExpressionMatch match = regex.match(filename);
210 return match.captured();
215 const QString s(str.trimmed().toLower());
216 if (s.contains(
"installer"))
return CArtifact::PilotClientInstaller;
217 if (s.contains(
"client"))
return CArtifact::PilotClientInstaller;
218 if (s.contains(
"symb"))
return CArtifact::Symbols;
219 if (s.contains(
"bus"))
return CArtifact::XSwiftBus;
220 return CArtifact::UnknownArtifact;
223 QString CArtifact::trimVersionString(
const QString &version)
225 if (version.count(
'.') != 3)
return version;
226 QStringList parts = version.split(
'.');
227 const QString p4 = trim4thSegment(parts[3]);
228 if (p4 == parts[3]) {
return version; }
230 const QString v = parts.join(
'.');
234 QString CArtifact::trim4thSegment(
const QString &seg)
237 if (seg.length() >= 9) {
return QStringLiteral(
"0"); }
static QString humanReadableFileSize(qint64 size)
Human readable (GB, MB, ..) file size.
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
QString getFormattedUtcTimestampYmdhms() const
As yyyy MM dd HH mm ss.
QDateTime getUtcTimestamp() const
Get timestamp.
void setUtcTimestamp(const QDateTime ×tamp)
Set timestamp.
Artifacts ("our software" products)
ColumnIndex
Properties by index.
bool hasUnrestrictedDistribution() const
Has unrestricted distribution.
bool isWithDistribution(const CDistribution &distribution, bool acceptMoreStableDistributions) const
Is distributed with given distribution?
bool hasDistributions() const
Has distributions?
void setName(const QString &name)
Set the name.
bool matchesAnyPlatform(const CPlatform &platform) const
Matches any platform.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QString getFileSizeHumanReadable() const
Human readable (GB, MB, ..) file size.
network::CRemoteFile asRemoteFile() const
Turn into remote file.
bool isUnknown() const
Unknown.
int getFileSize() const
File size.
const CPlatform & getPlatform() const
OS.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
static CPlatform artifactNameToPlatform(const QString &name)
Name to platform.
bool isNewerThanCurrentBuild() const
Newer than the current build.
void setDistributions(const CDistributionList &distributions)
Related distributions.
static const QString & typeToString(ArtifactType type)
Type as string.
static CArtifact fromDatabaseJson(const QJsonObject &json, const QString &prefix={})
Object from database JSON format.
bool matchesName(const QString &name, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Matching name?
CDistribution getMostStableDistribution() const
Most stable distribution if any.
const CDistributionList & getDistributions() const
Related distributions.
QString convertToQString(bool i18n=false) const
Cast as QString.
const QString & getName() const
Name (i.e. installer name, symbol name)
Distributions for channel.
const QString & getChannel() const
Version channel (Alpha, Beta, Stable ..)
bool isEmpty() const
Empty?
const network::CUrl & getDownloadUrl() const
Download URL, i.e. here one can download installer.
Multiple distributions for different channels:
bool containsUnrestricted() const
Contains any unrestricted.
static CDistributionList fromDatabaseJson(const QJsonArray &array)
From database JSON by array.
QVersionNumber getQVersion() const
Version as QVersion.
QString m_version
version info
bool hasVersion() const
Having a version?s.
void setVersion(const QString &version)
Version info.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
static bool canHandleIndex(swift::misc::CPropertyIndexRef index)
Can given index be handled?
void setKeyVersionTimestampFromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
Set key and timestamp values.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
QString toQString(bool i18n=false) const
Cast as QString.
void setDescription(const QString &description)
Description.
void setUrl(const CUrl &url)
Set URL.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
bool isEmpty() const
Empty.
Plugin loaded by X-Plane which publishes a DBus service.
SWIFT_MISC_EXPORT bool caseInsensitiveStringCompare(const QString &c1, const QString &c2)
Case insensitive string compare.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.