Skip to content

Commit

Permalink
Merge pull request #26 from dddddai/main
Browse files Browse the repository at this point in the history
修复版本比较bug
  • Loading branch information
qjfoidnh authored Jan 15, 2021
2 parents 32b3da8 + c68dce6 commit 2b247d2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/pcsupdate/pcsupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func CheckUpdate(version string, yes bool) {
}

// 没有更新, 或忽略 Beta 版本, 和版本前缀不符的
if strings.Contains(releaseInfo.TagName, "Beta") || !strings.HasPrefix(releaseInfo.TagName, "v") || version >= releaseInfo.TagName {
if strings.Contains(releaseInfo.TagName, "Beta") || !strings.HasPrefix(releaseInfo.TagName, "v") || needUpdate(version, releaseInfo.TagName) {
fmt.Printf("未检测到更新!\n")
return
}
Expand Down Expand Up @@ -255,3 +255,17 @@ func CheckUpdate(version string, yes bool) {

fmt.Printf("更新完毕, 请重启程序\n")
}

func needUpdate(current, latest string) bool {
// 去除第一个字符'v'
v1 := strings.Split(current[1:], ".")
v2 := strings.Split(latest[1:], ".")
for i := range v1 {
a, _ := strconv.Atoi(v1[i])
b, _ := strconv.Atoi(v2[i])
if a < b {
return true
}
}
return false
}

0 comments on commit 2b247d2

Please sign in to comment.