Skip to content

Commit 51f8bf2

Browse files
committed
use semver for Compatibility-checking
1 parent a6afd91 commit 51f8bf2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/vendor/factorioSave/factorioSave.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"encoding/binary"
66
"errors"
77
"io"
8+
"strconv"
9+
"github.com/Masterminds/semver"
810
)
911

1012
type version16 struct {
@@ -66,7 +68,13 @@ func ReadHeader(filePath string) (Header, error) {
6668
return data, err
6769
}
6870

69-
if !data.FactorioVersion.CheckCompatibility(0, 16, 0) {
71+
Constraint, _ := semver.NewConstraint("0.16.0 - 0.17.0")
72+
Compatible, err := data.FactorioVersion.CheckCompatibility(Constraint)
73+
if err != nil {
74+
log.Printf("Error checking compatibility: %s", err)
75+
return data, err
76+
}
77+
if !Compatible {
7078
log.Printf("NOT COMPATIBLE Save-File")
7179
log.Println(data)
7280
return data, ErrorIncompatible
@@ -344,6 +352,12 @@ func readSingleMod(file io.ReadCloser) (singleMod, error) {
344352
return Mod, err
345353
}
346354

347-
func (Version *versionShort16) CheckCompatibility(Major uint16, Minor uint16, Build uint16) (bool) {
348-
return Version.Major >= Major && Version.Minor >= Minor && Version.Build >= Build
355+
func (Version *versionShort16) CheckCompatibility(constraints *semver.Constraints) (bool, error) {
356+
Ver, err := semver.NewVersion(strconv.Itoa(int(Version.Major)) + "." + strconv.Itoa(int(Version.Minor)) + "." + strconv.Itoa(int(Version.Build)))
357+
if err != nil {
358+
log.Printf("Error creating semver-version: %s", err)
359+
return false, err
360+
}
361+
362+
return constraints.Check(Ver), nil
349363
}

0 commit comments

Comments
 (0)