Skip to content

Commit

Permalink
添加app.asar翻译包支持
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Feb 14, 2022
1 parent 3cca6a2 commit f076739
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
24 changes: 14 additions & 10 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,26 @@ func transDownloadUrl() string {
fmt.Println(fmt.Sprintf("%s的汉化补丁尚未发布, 若要汉化等后续补丁发布后重新运行工具来更新即可\n", cfwVersion))
return ""
}
url = fmt.Sprintf("https://github.com/%s/releases/latest/download/app.7z", transWay)
} else {
var dTag string
fmt.Println(fmt.Sprintf("正在获取%s的%s版本汉化包...", transWay, cfwVersion))
if transWay == "BoyceLig/Clash_Chinese_Patch" {
dTag = cfwVersion
} else if transWay == "ender-zhao/Clash-for-Windows_Chinese" {
dTag = fmt.Sprintf("CFW-V%s_CN", cfwVersion)
}
searchText := webSearch(fmt.Sprintf("https://github.com/%s/releases/tag/%s", transWay, dTag), "app.7z")
}
var dTag string
if transWay == "BoyceLig/Clash_Chinese_Patch" {
dTag = cfwVersion
} else if transWay == "ender-zhao/Clash-for-Windows_Chinese" {
dTag = fmt.Sprintf("CFW-V%s_CN", cfwVersion)
}
fileName := "app.7z"
searchText := webSearch(fmt.Sprintf("https://github.com/%s/releases/tag/%s", transWay, dTag), fileName)
if searchText == "" {
fileName = "app.asar"
searchText = webSearch(fmt.Sprintf("https://github.com/%s/releases/tag/%s", transWay, dTag), fileName)
if searchText == "" {
fmt.Println(fmt.Sprintf("%s的app.7z包不存在\n", transWay))
fmt.Println(fmt.Sprintf("%s的翻译包不存在\n", transWay))
return ""
}
url = fmt.Sprintf("https://github.com/%s/releases/download/%s/app.7z", transWay, dTag)
}
url = fmt.Sprintf("https://github.com/%s/releases/download/%s/%s", transWay, dTag, fileName)
updateTrans = true
return url
}
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"runtime"
"strings"
"time"
)

Expand Down Expand Up @@ -60,7 +61,9 @@ func getCfw() *downloadInfo {
func getTrans(url string) *downloadInfo {
di := newDI(url)
downloadFile(url, "")
extract7z(di.fileFullName)
if strings.Contains(di.fileFullName, "7z") {
extract7z(di.fileFullName)
}
fmt.Println()
return di
}
Expand Down
10 changes: 8 additions & 2 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ sudo xattr -r -d com.apple.quarantine "$UPDATE_PATH"
}

func updateTransFile(diList []*downloadInfo, stopCh chan struct{}) {
var srcFile string
if strings.Contains(diList[len(diList)-1].fileFullName, "asar") {
srcFile = fullPath("app.asar")
} else {
srcFile = fullPath(path.Join(diList[len(diList)-1].fileName, "app.asar"))
}
if runtime.GOOS == "darwin" {
execCommand(fmt.Sprintf("sudo cp -rp \"%s\" \"%s\"", fullPath(path.Join(diList[len(diList)-1].fileName, "app.asar")), path.Join(ci.rootPath, "Contents/Resources/app.asar")))
execCommand(fmt.Sprintf("sudo cp -rp \"%s\" \"%s\"", srcFile, path.Join(ci.rootPath, "Contents/Resources/app.asar")))
} else {
if err := copy.Copy(fullPath(path.Join(diList[len(diList)-1].fileName, "app.asar")), path.Join(ci.rootPath, "resources/app.asar")); err != nil {
if err := copy.Copy(srcFile, path.Join(ci.rootPath, "resources/app.asar")); err != nil {
close(stopCh)
fmt.Printf("\n\n请尝试以管理员身份运行此程序:\n")
exit(err.Error())
Expand Down

0 comments on commit f076739

Please sign in to comment.