Skip to content

Commit

Permalink
修改自动更新相关的链接
Browse files Browse the repository at this point in the history
  • Loading branch information
fzls committed Oct 8, 2021
1 parent 84a7dbb commit d9e13bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion global/update/update_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Update(url string, sum []byte) error {
if err != nil {
return err
}
if header.Name == "go-cqhttp" {
if header.Name == "qq_robot_go" {
err, _ := FromStream(tr)
fmt.Println()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion global/update/update_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Update(url string, sum []byte) error {
return errors.New("文件已损坏")
}
reader, _ := zip.NewReader(bytes.NewReader(rsp), resp.ContentLength)
file, err := reader.Open("go-cqhttp.exe")
file, err := reader.Open("qq_robot_go.exe")
if err != nil {
return err
}
Expand Down
19 changes: 11 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,20 +469,23 @@ func PasswordHashDecrypt(encryptedPasswordHash string, key []byte) ([]byte, erro
return result, nil
}

const githubRepo = "fzls/qq_robot_go"
const exeName = "qq_robot_go"

func checkUpdate() {
log.Infof("正在检查更新.")
if coolq.Version == "(devel)" {
log.Warnf("检查更新失败: 使用的 Actions 测试版或自编译版本.")
return
}
var res string
if err := gout.GET("https://api.github.com/repos/Mrs4s/go-cqhttp/releases/latest").BindBody(&res).Do(); err != nil {
if err := gout.GET(fmt.Sprintf("https://api.github.com/repos/%v/releases/latest", githubRepo)).BindBody(&res).Do(); err != nil {
log.Warnf("检查更新失败: %v", err)
return
}
info := gjson.Parse(res)
if global.VersionNameCompare(coolq.Version, info.Get("tag_name").Str) {
log.Infof("当前有更新的 go-cqhttp 可供更新, 请前往 https://github.com/Mrs4s/go-cqhttp/releases 下载.")
log.Infof("当前有更新的 go-cqhttp 可供更新, 请前往 https://github.com/%v/releases 下载.", githubRepo)
log.Infof("当前版本: %v 最新版本: %v", coolq.Version, info.Get("tag_name").Str)
return
}
Expand All @@ -492,7 +495,7 @@ func checkUpdate() {
func selfUpdate(imageURL string) {
log.Infof("正在检查更新.")
var res, r string
if err := gout.GET("https://api.github.com/repos/Mrs4s/go-cqhttp/releases/latest").BindBody(&res).Do(); err != nil {
if err := gout.GET(fmt.Sprintf("https://api.github.com/repos/%v/releases/latest", githubRepo)).BindBody(&res).Do(); err != nil {
log.Warnf("检查更新失败: %v", err)
return
}
Expand All @@ -509,20 +512,20 @@ func selfUpdate(imageURL string) {
log.Warn("已取消更新!")
} else {
log.Info("正在更新,请稍等...")
sumURL := fmt.Sprintf("%v/Mrs4s/go-cqhttp/releases/download/%v/go-cqhttp_checksums.txt",
sumURL := fmt.Sprintf("%v/%v/releases/download/%v/%v_checksums.txt",
func() string {
if imageURL != "" {
return imageURL
}
return "https://github.com"
}(), version)
}(), githubRepo, version, exeName)
closer, err := global.HTTPGetReadCloser(sumURL)
if err != nil {
log.Error("更新失败: ", err)
goto wait
}
rd := bufio.NewReader(closer)
binaryName := fmt.Sprintf("go-cqhttp_%v_%v.%v", runtime.GOOS, func() string {
binaryName := fmt.Sprintf("%v_%v_%v.%v", exeName, runtime.GOOS, func() string {
if runtime.GOARCH == "arm" {
return "armv7"
}
Expand All @@ -545,13 +548,13 @@ func selfUpdate(imageURL string) {
break
}
}
url := fmt.Sprintf("%v/Mrs4s/go-cqhttp/releases/download/%v/%v",
url := fmt.Sprintf("%v/%v/releases/download/%v/%v",
func() string {
if imageURL != "" {
return imageURL
}
return "https://github.com"
}(), version, binaryName)
}(), githubRepo, version, binaryName)

err = update.Update(url, sum)
if err != nil {
Expand Down

0 comments on commit d9e13bc

Please sign in to comment.