chore: update use compatible version for windows/linux amd64

This commit is contained in:
Larvan2 2023-04-01 14:32:34 +08:00
parent 54c2fa98b4
commit 9d7a78e1ef

View file

@ -67,7 +67,7 @@ func Update() (err error) {
return err return err
} }
log.Infoln("current version alpha-%s, latest version alpha-%s", constant.Version, latestVersion) log.Infoln("current version %s, latest version %s", constant.Version, latestVersion)
if latestVersion == constant.Version { if latestVersion == constant.Version {
err := &updateError{Message: "Already using latest version"} err := &updateError{Message: "Already using latest version"}
@ -134,8 +134,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" { if goos == "windows" && goarch == "amd64" {
updateExeName = "clash.meta" + "-" + goos + "-" + goarch + ".exe" updateExeName = "clash.meta" + "-" + goos + "-" + goarch + "-compatible.exe"
} else if goos == "linux" && goarch == "amd64" {
updateExeName = "clash.meta" + "-" + goos + "-" + goarch + "-compatible"
} else { } else {
updateExeName = "clash.meta" + "-" + goos + "-" + goarch updateExeName = "clash.meta" + "-" + goos + "-" + goarch
} }
@ -164,7 +166,7 @@ func unpack() error {
var err error var err error
_, pkgNameOnly := filepath.Split(packageURL) _, pkgNameOnly := filepath.Split(packageURL)
log.Debugln("updater: unpacking package") log.Infoln("updater: unpacking package")
if strings.HasSuffix(pkgNameOnly, ".zip") { if strings.HasSuffix(pkgNameOnly, ".zip") {
_, err = zipFileUnpack(packageName, updateDir) _, err = zipFileUnpack(packageName, updateDir)
if err != nil { if err != nil {
@ -184,15 +186,14 @@ func unpack() error {
return nil return nil
} }
// backup makes a backup of the current configuration and supporting files. It // backup makes a backup of the current configuration and supporting files.
// ignores the configuration file if firstRun is true.
func backup() (err error) { func backup() (err error) {
log.Infoln("updater: backing up current Exefile") log.Infoln("updater: backing up current ExecFile:%s", currentExeName)
_ = os.Mkdir(backupDir, 0o755) _ = os.Mkdir(backupDir, 0o755)
err = copyFile(currentExeName, backupExeName) err = os.Rename(currentExeName, backupExeName)
if err != nil { if err != nil {
return fmt.Errorf("copySupportingFiles(%s, %s) failed: %w", currentExeName, backupExeName, err) return err
} }
return nil return nil
@ -203,24 +204,17 @@ func backup() (err error) {
func replace() error { func replace() error {
var err error var err error
// log.Infoln("updater: renaming: %s to %s", currentExeName, backupExeName) log.Infoln("copying: %s to %s", updateExeName, currentExeName)
// err := os.Rename(currentExeName, backupExeName)
// if err != nil {
// return err
// }
if goos == "windows" { if goos == "windows" {
// rename fails with "File in use" error // rename fails with "File in use" error
log.Infoln("copying: %s to %s", updateExeName, currentExeName)
err = copyFile(updateExeName, currentExeName) err = copyFile(updateExeName, currentExeName)
} else { } else {
log.Infoln("copying: %s to %s", updateExeName, currentExeName)
err = os.Rename(updateExeName, currentExeName) err = os.Rename(updateExeName, currentExeName)
} }
if err != nil { if err != nil {
return err return err
} }
log.Infoln("updater: renamed: %s to %s", updateExeName, currentExeName)
return nil return nil
} }
@ -236,8 +230,6 @@ const MaxPackageFileSize = 32 * 1024 * 1024
// Download package file and save it to disk // Download package file and save it to disk
func downloadPackageFile() (err error) { func downloadPackageFile() (err error) {
// var resp *http.Response
// resp, err = client.Get(packageURL)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*90) ctx, cancel := context.WithTimeout(context.Background(), time.Second*90)
defer cancel() defer cancel()
resp, err := clashHttp.HttpRequest(ctx, packageURL, http.MethodGet, http.Header{"User-Agent": {"clash"}}, nil) resp, err := clashHttp.HttpRequest(ctx, packageURL, http.MethodGet, http.Header{"User-Agent": {"clash"}}, nil)
@ -447,6 +439,8 @@ func updateDownloadURL() {
middle = fmt.Sprintf("-%s-%sv%s-%s", goos, goarch, goarm, latestVersion) middle = fmt.Sprintf("-%s-%sv%s-%s", goos, goarch, goarm, latestVersion)
} else if isMIPS(goarch) && gomips != "" { } else if isMIPS(goarch) && gomips != "" {
middle = fmt.Sprintf("-%s-%s-%s-%s", goos, goarch, gomips, latestVersion) middle = fmt.Sprintf("-%s-%s-%s-%s", goos, 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", goos, goarch, latestVersion)
} }