mirror of
https://github.com/tauri-apps/nsis-tauri-utils.git
synced 2026-01-31 00:45:23 +01:00
fix: handle non-semversions
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <strsafe.h>
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "include\nsis\pluginapi.h"
|
||||
@@ -30,8 +31,16 @@ extern "C" void __declspec(dllexport) SemverCompare(HWND hwndParent,
|
||||
std::string ver1(ver1w.begin(), ver1w.end());
|
||||
std::string ver2(ver2w.begin(), ver2w.end());
|
||||
|
||||
semver::version v1 = semver::from_string(ver1);
|
||||
semver::version v2 = semver::from_string(ver2);
|
||||
std::optional<semver::version> v1 = semver::from_string_noexcept(ver1);
|
||||
std::optional<semver::version> v2 = semver::from_string_noexcept(ver2);
|
||||
|
||||
pushint(v1.compare(v2));
|
||||
if (v1.has_value() && !v2.has_value()) {
|
||||
pushint(1);
|
||||
} else if (!v1.has_value() && v2.has_value()) {
|
||||
pushint(-1);
|
||||
} else if (!v1.has_value() && !v2.has_value()) {
|
||||
pushint(0);
|
||||
} else {
|
||||
pushint(v1.value().compare(v2.value()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,13 @@ Section "nsSemverCompare"
|
||||
SemverCompare::SemverCompare "1.2.1-alpha.1" "1.2.1-alpha.1"
|
||||
Pop $1
|
||||
DetailPrint $1
|
||||
SemverCompare::SemverCompare "1.2qe2.1-alpha.1" "1.2.1-alpha.1"
|
||||
Pop $1
|
||||
DetailPrint $1
|
||||
SemverCompare::SemverCompare "1.2.1-alpha.1" "-q1.2.1-alpha.1"
|
||||
Pop $1
|
||||
DetailPrint $1
|
||||
SemverCompare::SemverCompare "1.2.saf1-alpha.1" "-q1.2.1-alpha.1"
|
||||
Pop $1
|
||||
DetailPrint $1
|
||||
SectionEnd
|
||||
|
||||
Reference in New Issue
Block a user