FIX: Fix bug version parse
This commit is contained in:
@@ -10,7 +10,7 @@ const ProxyZipFile = "64bit.zip"
|
|||||||
const LauncherFile = "firefly-launcher.exe"
|
const LauncherFile = "firefly-launcher.exe"
|
||||||
const TempUrl = "./temp"
|
const TempUrl = "./temp"
|
||||||
|
|
||||||
const CurrentLauncherVersion = "1.7.1"
|
const CurrentLauncherVersion = "1.8.0"
|
||||||
|
|
||||||
type ToolFile string
|
type ToolFile string
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type BinaryVersion struct {
|
type BinaryVersion struct {
|
||||||
@@ -24,45 +23,25 @@ func ParseBinaryVersion(path string) (*BinaryVersion, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
content := string(data)
|
content := string(data)
|
||||||
|
fmt.Println(content)
|
||||||
|
|
||||||
lastDash := strings.LastIndex(content, "-")
|
re := regexp.MustCompile(`([A-Za-z]+)(\d+)(?:\.(\d+))?(?:\.(\d+))?`)
|
||||||
if lastDash == -1 {
|
matches := re.FindStringSubmatch(content)
|
||||||
return nil, errors.New("no dash found in version string")
|
if len(matches) < 2 {
|
||||||
}
|
|
||||||
|
|
||||||
secondLastDash := strings.LastIndex(content[:lastDash], "-")
|
|
||||||
if secondLastDash == -1 {
|
|
||||||
return nil, errors.New("only one dash found in version string")
|
|
||||||
}
|
|
||||||
|
|
||||||
versionSlice := content[secondLastDash+1 : lastDash]
|
|
||||||
re := regexp.MustCompile(`^([A-Za-z]+)([\d\.]+)$`)
|
|
||||||
matches := re.FindStringSubmatch(versionSlice)
|
|
||||||
if len(matches) < 3 {
|
|
||||||
return nil, errors.New("invalid version format")
|
return nil, errors.New("invalid version format")
|
||||||
}
|
}
|
||||||
|
|
||||||
binaryVersion := BinaryVersion{
|
binaryVersion := BinaryVersion{
|
||||||
Name: matches[1],
|
Name: matches[1],
|
||||||
}
|
}
|
||||||
numbers := strings.Split(matches[2], ".")
|
if matches[2] != "" {
|
||||||
|
binaryVersion.Major, _ = strconv.Atoi(matches[2])
|
||||||
if len(numbers) > 0 {
|
|
||||||
binaryVersion.Major, err = strconv.Atoi(numbers[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if len(numbers) > 1 {
|
if len(matches) > 3 && matches[3] != "" {
|
||||||
binaryVersion.Minor, err = strconv.Atoi(numbers[1])
|
binaryVersion.Minor, _ = strconv.Atoi(matches[3])
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if len(numbers) > 2 {
|
if len(matches) > 4 && matches[4] != "" {
|
||||||
binaryVersion.Patch, err = strconv.Atoi(numbers[2])
|
binaryVersion.Patch, _ = strconv.Atoi(matches[4])
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binaryVersion.Data = data
|
binaryVersion.Data = data
|
||||||
|
|||||||
Reference in New Issue
Block a user