aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorRachel Powers <508861+Ryex@users.noreply.github.com>2023-01-18 10:11:53 -0700
committerEdgars Cīrulis <edgarsscirulis@gmail.com>2023-01-19 09:51:11 +0200
commit7ed993b54e20d74c000a29720bc9317ad4849ed0 (patch)
tree765e3839288061485ef9b56608736285a8361f34 /launcher
parent9934537e19c7ce6f9bf926cc8abba023297b0a40 (diff)
downloadPrismLauncher-7ed993b54e20d74c000a29720bc9317ad4849ed0.tar.gz
PrismLauncher-7ed993b54e20d74c000a29720bc9317ad4849ed0.tar.bz2
PrismLauncher-7ed993b54e20d74c000a29720bc9317ad4849ed0.zip
fix: proper null padded version comparison
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Diffstat (limited to 'launcher')
-rw-r--r--launcher/Version.cpp17
-rw-r--r--launcher/Version.h27
2 files changed, 36 insertions, 8 deletions
diff --git a/launcher/Version.cpp b/launcher/Version.cpp
index 2129ebfd..d59339e7 100644
--- a/launcher/Version.cpp
+++ b/launcher/Version.cpp
@@ -15,9 +15,9 @@ bool Version::operator<(const Version &other) const
const int size = qMax(m_sections.size(), other.m_sections.size());
for (int i = 0; i < size; ++i)
{
- const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i);
+ const Section sec1 = (i >= m_sections.size()) ? Section("") : m_sections.at(i);
const Section sec2 =
- (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i);
+ (i >= other.m_sections.size()) ? Section("") : other.m_sections.at(i);
if (sec1 != sec2)
{
return sec1 < sec2;
@@ -35,9 +35,9 @@ bool Version::operator>(const Version &other) const
const int size = qMax(m_sections.size(), other.m_sections.size());
for (int i = 0; i < size; ++i)
{
- const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i);
+ const Section sec1 = (i >= m_sections.size()) ? Section("") : m_sections.at(i);
const Section sec2 =
- (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i);
+ (i >= other.m_sections.size()) ? Section("") : other.m_sections.at(i);
if (sec1 != sec2)
{
return sec1 > sec2;
@@ -55,9 +55,9 @@ bool Version::operator==(const Version &other) const
const int size = qMax(m_sections.size(), other.m_sections.size());
for (int i = 0; i < size; ++i)
{
- const Section sec1 = (i >= m_sections.size()) ? Section("0") : m_sections.at(i);
+ const Section sec1 = (i >= m_sections.size()) ? Section("") : m_sections.at(i);
const Section sec2 =
- (i >= other.m_sections.size()) ? Section("0") : other.m_sections.at(i);
+ (i >= other.m_sections.size()) ? Section("") : other.m_sections.at(i);
if (sec1 != sec2)
{
return false;
@@ -103,8 +103,11 @@ QDebug operator<<(QDebug debug, const Version& v)
debug.nospace() << "Version{ string: " << v.toString() << ", sections: [ ";
+ bool first = true;
for (auto s : v.m_sections) {
- debug.nospace() << s.m_fullString << ", ";
+ if (!first) debug.nospace() << ", ";
+ debug.nospace() << s.m_fullString;
+ first = false;
}
debug.nospace() << " ]" << " }";
diff --git a/launcher/Version.h b/launcher/Version.h
index c0927374..1f1bea83 100644
--- a/launcher/Version.h
+++ b/launcher/Version.h
@@ -69,6 +69,7 @@ private:
explicit Section(const QString &fullString)
{
m_fullString = fullString;
+ m_isNull = true;
int cutoff = m_fullString.size();
for(int i = 0; i < m_fullString.size(); i++)
{
@@ -86,6 +87,7 @@ private:
if(numPart.size())
{
numValid = true;
+ m_isNull = false;
m_numPart = numPart.toInt();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
@@ -95,6 +97,7 @@ private:
#endif
if(stringPart.size())
{
+ m_isNull = false;
m_stringPart = stringPart.toString();
}
}
@@ -103,9 +106,17 @@ private:
int m_numPart = 0;
QString m_stringPart;
QString m_fullString;
+ bool m_isNull;
inline bool operator!=(const Section &other) const
{
+ if (m_isNull && other.numValid) {
+ return 0 != other.m_numPart;
+ } else if (numValid && other.m_isNull) {
+ return m_numPart != 0;
+ } else if (m_isNull || other.m_isNull) {
+ return false;
+ }
if(numValid && other.numValid)
{
return m_numPart != other.m_numPart || m_stringPart != other.m_stringPart;
@@ -116,7 +127,14 @@ private:
}
}
inline bool operator<(const Section &other) const
- {
+ {
+ if (m_isNull && other.numValid) {
+ return 0 < other.m_numPart;
+ } else if (numValid && other.m_isNull) {
+ return m_numPart < 0;
+ } else if (m_isNull || other.m_isNull) {
+ return true;
+ }
if(numValid && other.numValid)
{
if(m_numPart < other.m_numPart)
@@ -132,6 +150,13 @@ private:
}
inline bool operator>(const Section &other) const
{
+ if (m_isNull && other.numValid) {
+ return 0 > other.m_numPart;
+ } else if (numValid && other.m_isNull) {
+ return m_numPart > 0;
+ } else if (m_isNull || other.m_isNull) {
+ return false;
+ }
if(numValid && other.numValid)
{
if(m_numPart > other.m_numPart)