-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤓 updater: added pre-releases versions when using a pre-release client (
#93) Pre-release updater
- Loading branch information
Showing
7 changed files
with
395 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef MIRAYA_UPDATERURLS_H | ||
#define MIRAYA_UPDATERURLS_H | ||
|
||
#include <QObject> | ||
|
||
class UpdaterUrls{ | ||
public: | ||
constexpr static const char* latestStable = "https://api.github.com/repos/MirayaProject/miraya/releases/latest"; | ||
constexpr static const char* allReleases = "https://api.github.com/repos/MirayaProject/miraya/releases"; | ||
}; | ||
|
||
|
||
#endif //MIRAYA_UPDATERURLS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "version.h" | ||
|
||
Version::Version(const QVersionNumber &version, const QString &suffix) { | ||
this->version = version; | ||
this->suffix = suffix; | ||
} | ||
|
||
Version Version::fromString(const QString &versionString) { | ||
qsizetype suffixIndex; | ||
auto v = QVersionNumber::fromString(versionString, &suffixIndex); | ||
auto suffix = versionString.mid(suffixIndex); | ||
qDebug() << "[Version] parsed version" << v << "with suffix" << suffix; | ||
return {v, suffix}; | ||
} | ||
|
||
bool Version::isPrerelease() const { | ||
return suffix != ""; | ||
} | ||
|
||
QString Version::toString() const { | ||
return version.toString() + suffix; | ||
} | ||
|
||
|
||
bool Version::operator>(const Version &other) const { | ||
// local version is newer than remote | ||
if (this->version > other.version) { | ||
return true; | ||
} | ||
// version is equal and no suffix | ||
if (this->version == other.version && this->suffix.isEmpty() && other.suffix.isEmpty()) { | ||
return false; | ||
} | ||
|
||
if (this->version == other.version && this->suffix.isEmpty() && !other.suffix.isEmpty()) { | ||
return true; | ||
} | ||
|
||
// local version is equal to remote | ||
if (this->version == other.version && !this->suffix.isEmpty() && !other.suffix.isEmpty()) { | ||
// let's check the suffix | ||
auto preReleaseType = this->suffix.split(".")[0]; | ||
auto otherPreReleaseType = other.suffix.split(".")[0]; | ||
if (preReleaseType > otherPreReleaseType) { | ||
return true; | ||
} else if (preReleaseType < otherPreReleaseType) { | ||
return false; | ||
} | ||
// both are alpha/beta/rc versions, let's check the number at the end | ||
auto preReleaseNumber = this->suffix.split(".")[1]; | ||
auto otherPreReleaseNumber = other.suffix.split(".")[1]; | ||
if (preReleaseNumber > otherPreReleaseNumber) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
return false; | ||
} | ||
|
||
bool Version::operator==(const Version &other) const { | ||
return this->version == other.version && this->suffix == other.suffix; | ||
} | ||
|
||
bool Version::operator>=(const Version &other) const { | ||
return *this > other || *this == other; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef MIRAYA_VERSION_H | ||
#define MIRAYA_VERSION_H | ||
|
||
#include <QVersionNumber> | ||
#include <QDebug> | ||
|
||
class Version { | ||
public: | ||
Version(const QVersionNumber& version, const QString& suffix); | ||
static Version fromString(const QString& versionString); | ||
|
||
[[nodiscard]] bool isPrerelease() const; | ||
[[nodiscard]] QString toString() const; | ||
|
||
bool operator>(const Version& other) const; | ||
bool operator==(const Version& other) const; | ||
bool operator>=(const Version& other) const; | ||
|
||
QVersionNumber version; | ||
QString suffix; | ||
}; | ||
|
||
#endif //MIRAYA_VERSION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
project(tests_updater_version VERSION 1.0.0 LANGUAGES CXX) | ||
|
||
find_package(Qt6 REQUIRED COMPONENTS Test Core) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin") | ||
set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_AUTOUIC_SEARCH_PATHS}) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
enable_testing(true) | ||
|
||
# ===========================Including Project Files=========================== | ||
file(GLOB_RECURSE SOURCES | ||
../../../src/updater/version.cpp | ||
../../../src/updater/version.h | ||
test_updater_version.cpp | ||
) | ||
add_definitions(-DQT_NO_DEBUG_OUTPUT) | ||
|
||
qt_add_executable(${PROJECT_NAME} ${SOURCES}) | ||
add_test(NAME ${PROJECT_NAME} COMMAND "${CMAKE_SOURCE_DIR}/bin/${PROJECT_NAME}") | ||
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE | ||
Qt6::Core | ||
Qt6::Test | ||
) |
Oops, something went wrong.