mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-23 12:42:27 +08:00
feat: Updater detect and download AMD64v3 artifact
Co-authored-by: Larvan2 <78135608+larvan2@users.noreply.github.com>
This commit is contained in:
parent
c6fed3e97f
commit
c7557b8e48
@ -17,15 +17,16 @@ import (
|
|||||||
clashHttp "github.com/Dreamacro/clash/component/http"
|
clashHttp "github.com/Dreamacro/clash/component/http"
|
||||||
"github.com/Dreamacro/clash/constant"
|
"github.com/Dreamacro/clash/constant"
|
||||||
"github.com/Dreamacro/clash/log"
|
"github.com/Dreamacro/clash/log"
|
||||||
|
|
||||||
|
"github.com/klauspost/cpuid/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// modify from https://github.com/AdguardTeam/AdGuardHome/blob/595484e0b3fb4c457f9bb727a6b94faa78a66c5f/internal/updater/updater.go
|
// modify from https://github.com/AdguardTeam/AdGuardHome/blob/595484e0b3fb4c457f9bb727a6b94faa78a66c5f/internal/updater/updater.go
|
||||||
// Updater is the Clash.Meta updater.
|
// Updater is the Clash.Meta updater.
|
||||||
var (
|
var (
|
||||||
goarch string
|
goarm string
|
||||||
goos string
|
gomips string
|
||||||
goarm string
|
amd64Compatible string
|
||||||
gomips string
|
|
||||||
|
|
||||||
workDir string
|
workDir string
|
||||||
|
|
||||||
@ -45,6 +46,12 @@ var (
|
|||||||
latestVersion string
|
latestVersion string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if runtime.GOARCH == "amd64" && cpuid.CPU.X64Level() < 3 {
|
||||||
|
amd64Compatible = "-compatible"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type updateError struct {
|
type updateError struct {
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
@ -59,8 +66,6 @@ func Update(execPath string) (err error) {
|
|||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
||||||
goos = runtime.GOOS
|
|
||||||
goarch = runtime.GOARCH
|
|
||||||
latestVersion, err = getLatestVersion()
|
latestVersion, err = getLatestVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -128,12 +133,10 @@ func prepare(exePath string) (err error) {
|
|||||||
//log.Infoln(packageName)
|
//log.Infoln(packageName)
|
||||||
backupDir = filepath.Join(workDir, "meta-backup")
|
backupDir = filepath.Join(workDir, "meta-backup")
|
||||||
|
|
||||||
if goos == "windows" && goarch == "amd64" {
|
if runtime.GOOS == "windows" {
|
||||||
updateExeName = "clash.meta" + "-" + goos + "-" + goarch + "-compatible.exe"
|
updateExeName = "clash.meta" + "-" + runtime.GOOS + "-" + runtime.GOARCH + amd64Compatible + ".exe"
|
||||||
} else if goos == "linux" && goarch == "amd64" {
|
|
||||||
updateExeName = "clash.meta" + "-" + goos + "-" + goarch + "-compatible"
|
|
||||||
} else {
|
} else {
|
||||||
updateExeName = "clash.meta" + "-" + goos + "-" + goarch
|
updateExeName = "clash.meta" + "-" + runtime.GOOS + "-" + runtime.GOARCH + amd64Compatible
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infoln("updateExeName: %s ", updateExeName)
|
log.Infoln("updateExeName: %s ", updateExeName)
|
||||||
@ -198,7 +201,7 @@ func replace() error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
log.Infoln("replacing: %s to %s", updateExeName, currentExeName)
|
log.Infoln("replacing: %s to %s", updateExeName, currentExeName)
|
||||||
if goos == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
// rename fails with "File in use" error
|
// rename fails with "File in use" error
|
||||||
err = copyFile(updateExeName, currentExeName)
|
err = copyFile(updateExeName, currentExeName)
|
||||||
} else {
|
} else {
|
||||||
@ -430,17 +433,15 @@ func getLatestVersion() (version string, err error) {
|
|||||||
func updateDownloadURL() {
|
func updateDownloadURL() {
|
||||||
var middle string
|
var middle string
|
||||||
|
|
||||||
if goarch == "arm" && goarm != "" {
|
if runtime.GOARCH == "arm" && goarm != "" {
|
||||||
middle = fmt.Sprintf("-%s-%sv%s-%s", goos, goarch, goarm, latestVersion)
|
middle = fmt.Sprintf("-%s-%sv%s-%s", runtime.GOOS, runtime.GOARCH, goarm, latestVersion)
|
||||||
} else if isMIPS(goarch) && gomips != "" {
|
} else if isMIPS(runtime.GOARCH) && gomips != "" {
|
||||||
middle = fmt.Sprintf("-%s-%s-%s-%s", goos, goarch, gomips, latestVersion)
|
middle = fmt.Sprintf("-%s-%s-%s-%s", runtime.GOOS, runtime.GOARCH, gomips, latestVersion)
|
||||||
} else if goarch == "amd64" && (goos == "windows" || goos == "linux") {
|
|
||||||
middle = fmt.Sprintf("-%s-%s-compatible-%s", goos, goarch, latestVersion)
|
|
||||||
} else {
|
} else {
|
||||||
middle = fmt.Sprintf("-%s-%s-%s", goos, goarch, latestVersion)
|
middle = fmt.Sprintf("-%s-%s%s-%s", runtime.GOOS, runtime.GOARCH, amd64Compatible, latestVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
if goos == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
middle += ".zip"
|
middle += ".zip"
|
||||||
} else {
|
} else {
|
||||||
middle += ".gz"
|
middle += ".gz"
|
||||||
|
Loading…
Reference in New Issue
Block a user