90 lines
2.6 KiB
C
90 lines
2.6 KiB
C
|
// MassBuilderSaveTool
|
||
|
// Copyright (C) 2021-2023 Guillaume Jacquemin
|
||
|
//
|
||
|
// This program is free software: you can redistribute it and/or modify
|
||
|
// it under the terms of the GNU General Public License as published by
|
||
|
// the Free Software Foundation, either version 3 of the License, or
|
||
|
// (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
|
||
|
#pragma once
|
||
|
|
||
|
#include <cstdint>
|
||
|
|
||
|
#include <Corrade/Containers/Array.h>
|
||
|
#include <Corrade/Containers/String.h>
|
||
|
#include <Corrade/Containers/StringView.h>
|
||
|
#include <Corrade/Utility/Format.h>
|
||
|
|
||
|
using namespace Corrade;
|
||
|
|
||
|
struct Version {
|
||
|
explicit Version() = default;
|
||
|
|
||
|
explicit Version(Containers::StringView str) {
|
||
|
std::size_t start_point = 0;
|
||
|
|
||
|
if(str[0] == 'v') {
|
||
|
start_point++;
|
||
|
}
|
||
|
|
||
|
auto components = Containers::StringView{str.data() + start_point}.split('.');
|
||
|
|
||
|
major = std::strtol(components[0].data(), nullptr, 10);
|
||
|
minor = std::strtol(components[1].data(), nullptr, 10);
|
||
|
patch = std::strtol(components[2].data(), nullptr, 10);
|
||
|
|
||
|
fullVersion = major * 10000 + minor * 100 + patch;
|
||
|
|
||
|
if(str.hasSuffix("-pre")) {
|
||
|
prerelease = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
constexpr explicit Version(long major_, long minor_, long patch_, bool prerelease_):
|
||
|
major{major_}, minor{minor_}, patch{patch_}, prerelease{prerelease_},
|
||
|
fullVersion{major_ * 10000 + minor_ * 100 + patch_}
|
||
|
{
|
||
|
//ctor
|
||
|
}
|
||
|
|
||
|
long major = 0;
|
||
|
long minor = 0;
|
||
|
long patch = 0;
|
||
|
bool prerelease = false;
|
||
|
long fullVersion = 0;
|
||
|
|
||
|
bool operator==(const Version& other) const {
|
||
|
return fullVersion == other.fullVersion && prerelease == other.prerelease;
|
||
|
}
|
||
|
|
||
|
bool operator>(const Version& other) const {
|
||
|
if((fullVersion > other.fullVersion) ||
|
||
|
(fullVersion == other.fullVersion && !prerelease && other.prerelease))
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
explicit operator Containers::String() const {
|
||
|
return Utility::format("{}.{}.{}{}", major, minor, patch, prerelease ? "-pre" : "");
|
||
|
}
|
||
|
};
|
||
|
|
||
|
constexpr Version current_version{
|
||
|
SAVETOOL_VERSION_MAJOR,
|
||
|
SAVETOOL_VERSION_MINOR,
|
||
|
SAVETOOL_VERSION_PATCH,
|
||
|
SAVETOOL_VERSION_PRERELEASE
|
||
|
};
|