mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-14 02:33:51 +02:00
Reuse QVersionNumber
This commit is contained in:
parent
60264aae29
commit
dcfafac266
@ -14,75 +14,51 @@
|
|||||||
#include "../../lib/filesystem/CFileInputStream.h"
|
#include "../../lib/filesystem/CFileInputStream.h"
|
||||||
#include "../../lib/GameConstants.h"
|
#include "../../lib/GameConstants.h"
|
||||||
|
|
||||||
const int maxSections = 3; // versions consist from up to 3 sections, major.minor.patch
|
namespace
|
||||||
|
{
|
||||||
bool isCompatible(const QString & verMin, const QString & verMax)
|
bool isCompatible(const QString & verMin, const QString & verMax)
|
||||||
{
|
{
|
||||||
QList<int> vcmiVersionList = {GameConstants::VCMI_VERSION_MAJOR,
|
const int maxSections = 3; // versions consist from up to 3 sections, major.minor.patch
|
||||||
GameConstants::VCMI_VERSION_MINOR,
|
QVersionNumber vcmiVersion(GameConstants::VCMI_VERSION_MAJOR,
|
||||||
GameConstants::VCMI_VERSION_PATCH};
|
GameConstants::VCMI_VERSION_MINOR,
|
||||||
|
GameConstants::VCMI_VERSION_PATCH);
|
||||||
|
|
||||||
if(!verMin.isEmpty())
|
auto versionMin = QVersionNumber::fromString(verMin);
|
||||||
|
auto versionMax = QVersionNumber::fromString(verMax);
|
||||||
|
|
||||||
|
auto buildVersion = [](QVersionNumber & ver)
|
||||||
{
|
{
|
||||||
QStringList verMinList = verMin.split(".");
|
if(ver.segmentCount() < maxSections)
|
||||||
assert(verMinList.size() == maxSections);
|
|
||||||
bool compatibleMin = true;
|
|
||||||
for(int i = 0; i < maxSections; i++)
|
|
||||||
{
|
{
|
||||||
if(verMinList[i].toInt() < vcmiVersionList[i])
|
auto segments = ver.segments();
|
||||||
{
|
for(int i = segments.size() - 1; i < maxSections; ++i)
|
||||||
break;
|
segments.append(0);
|
||||||
}
|
ver = QVersionNumber(segments);
|
||||||
if(verMinList[i].toInt() > vcmiVersionList[i])
|
|
||||||
{
|
|
||||||
compatibleMin = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if(!compatibleMin)
|
if(!versionMin.isNull())
|
||||||
|
{
|
||||||
|
buildVersion(versionMin);
|
||||||
|
if(vcmiVersion < versionMin)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!verMax.isEmpty())
|
if(!versionMax.isNull())
|
||||||
{
|
{
|
||||||
QStringList verMaxList = verMax.split(".");
|
buildVersion(versionMax);
|
||||||
assert(verMaxList.size() == maxSections);
|
if(vcmiVersion > versionMax)
|
||||||
for(int i = 0; i < maxSections; i++)
|
return false;
|
||||||
{
|
|
||||||
if(verMaxList[i].toInt() > vcmiVersionList[i])
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(verMaxList[i].toInt() < vcmiVersionList[i])
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CModEntry::compareVersions(QString lesser, QString greater)
|
bool CModEntry::compareVersions(QString lesser, QString greater)
|
||||||
{
|
{
|
||||||
QStringList lesserList = lesser.split(".");
|
auto versionLesser = QVersionNumber::fromString(lesser);
|
||||||
QStringList greaterList = greater.split(".");
|
auto versionGreater = QVersionNumber::fromString(greater);
|
||||||
|
return versionLesser < versionGreater;
|
||||||
assert(lesserList.size() <= maxSections);
|
|
||||||
assert(greaterList.size() <= maxSections);
|
|
||||||
|
|
||||||
for(int i = 0; i < maxSections; i++)
|
|
||||||
{
|
|
||||||
if(greaterList.size() <= i) // 1.1.1 > 1.1
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if(lesserList.size() <= i) // 1.1 < 1.1.1
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if(lesserList[i].toInt() != greaterList[i].toInt())
|
|
||||||
return lesserList[i].toInt() < greaterList[i].toInt(); // 1.1 < 1.2
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CModEntry::sizeToString(double size)
|
QString CModEntry::sizeToString(double size)
|
||||||
|
Loading…
Reference in New Issue
Block a user