From 51f8bf22387ed65c72348622b70adde3a75dfd72 Mon Sep 17 00:00:00 2001 From: knoxfighter Date: Sat, 14 Jul 2018 19:47:30 +0200 Subject: [PATCH] use semver for Compatibility-checking --- src/vendor/factorioSave/factorioSave.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/vendor/factorioSave/factorioSave.go b/src/vendor/factorioSave/factorioSave.go index e496e54..24f18db 100644 --- a/src/vendor/factorioSave/factorioSave.go +++ b/src/vendor/factorioSave/factorioSave.go @@ -5,6 +5,8 @@ import ( "encoding/binary" "errors" "io" + "strconv" + "github.com/Masterminds/semver" ) type version16 struct { @@ -66,7 +68,13 @@ func ReadHeader(filePath string) (Header, error) { return data, err } - if !data.FactorioVersion.CheckCompatibility(0, 16, 0) { + Constraint, _ := semver.NewConstraint("0.16.0 - 0.17.0") + Compatible, err := data.FactorioVersion.CheckCompatibility(Constraint) + if err != nil { + log.Printf("Error checking compatibility: %s", err) + return data, err + } + if !Compatible { log.Printf("NOT COMPATIBLE Save-File") log.Println(data) return data, ErrorIncompatible @@ -344,6 +352,12 @@ func readSingleMod(file io.ReadCloser) (singleMod, error) { return Mod, err } -func (Version *versionShort16) CheckCompatibility(Major uint16, Minor uint16, Build uint16) (bool) { - return Version.Major >= Major && Version.Minor >= Minor && Version.Build >= Build +func (Version *versionShort16) CheckCompatibility(constraints *semver.Constraints) (bool, error) { + Ver, err := semver.NewVersion(strconv.Itoa(int(Version.Major)) + "." + strconv.Itoa(int(Version.Minor)) + "." + strconv.Itoa(int(Version.Build))) + if err != nil { + log.Printf("Error creating semver-version: %s", err) + return false, err + } + + return constraints.Check(Ver), nil }