From 1e17f76340bde6612e636bb47b2d3b0db9d45600 Mon Sep 17 00:00:00 2001 From: AzenKain Date: Fri, 26 Sep 2025 10:06:49 +0700 Subject: [PATCH] FIX: Fix bug version parse --- pkg/constant/constant.go | 2 +- pkg/models/binary-version.go | 43 +++++++++--------------------------- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/pkg/constant/constant.go b/pkg/constant/constant.go index 5c58636..af1eb3b 100644 --- a/pkg/constant/constant.go +++ b/pkg/constant/constant.go @@ -10,7 +10,7 @@ const ProxyZipFile = "64bit.zip" const LauncherFile = "firefly-launcher.exe" const TempUrl = "./temp" -const CurrentLauncherVersion = "1.7.1" +const CurrentLauncherVersion = "1.8.0" type ToolFile string diff --git a/pkg/models/binary-version.go b/pkg/models/binary-version.go index 69a83a3..7e2ab14 100644 --- a/pkg/models/binary-version.go +++ b/pkg/models/binary-version.go @@ -6,7 +6,6 @@ import ( "os" "regexp" "strconv" - "strings" ) type BinaryVersion struct { @@ -24,45 +23,25 @@ func ParseBinaryVersion(path string) (*BinaryVersion, error) { } content := string(data) + fmt.Println(content) - lastDash := strings.LastIndex(content, "-") - if lastDash == -1 { - return nil, errors.New("no dash found in version string") - } - - 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 { + re := regexp.MustCompile(`([A-Za-z]+)(\d+)(?:\.(\d+))?(?:\.(\d+))?`) + matches := re.FindStringSubmatch(content) + if len(matches) < 2 { return nil, errors.New("invalid version format") } + binaryVersion := BinaryVersion{ Name: matches[1], } - numbers := strings.Split(matches[2], ".") - - if len(numbers) > 0 { - binaryVersion.Major, err = strconv.Atoi(numbers[0]) - if err != nil { - return nil, err - } + if matches[2] != "" { + binaryVersion.Major, _ = strconv.Atoi(matches[2]) } - if len(numbers) > 1 { - binaryVersion.Minor, err = strconv.Atoi(numbers[1]) - if err != nil { - return nil, err - } + if len(matches) > 3 && matches[3] != "" { + binaryVersion.Minor, _ = strconv.Atoi(matches[3]) } - if len(numbers) > 2 { - binaryVersion.Patch, err = strconv.Atoi(numbers[2]) - if err != nil { - return nil, err - } + if len(matches) > 4 && matches[4] != "" { + binaryVersion.Patch, _ = strconv.Atoi(matches[4]) } binaryVersion.Data = data